]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.18.7-201502200813.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.7-201502200813.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index a311db8..415b28c 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index f4c71d4..66811b1 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1182,6 +1182,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2260,6 +2264,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2552,6 +2560,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346 + virtualization environments that don't cope well with the
347 + expand down segment used by UDEREF on X86-32 or the frequent
348 + page table updates on X86-64.
349 +
350 + pax_sanitize_slab=
351 + Format: { 0 | 1 | off | fast | full }
352 + Options '0' and '1' are only provided for backward
353 + compatibility, 'off' or 'fast' should be used instead.
354 + 0|off : disable slab object sanitization
355 + 1|fast: enable slab object sanitization excluding
356 + whitelisted slabs (default)
357 + full : sanitize all slabs, even the whitelisted ones
358 +
359 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360 +
361 + pax_extra_latent_entropy
362 + Enable a very simple form of latent entropy extraction
363 + from the first 4GB of memory as the bootmem allocator
364 + passes the memory pages to the buddy allocator.
365 +
366 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367 + when the processor supports PCID.
368 +
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372 diff --git a/Makefile b/Makefile
373 index 0efae22..380e711 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380 -HOSTCXXFLAGS = -O2
381 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387 @@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391 -PHONY += scripts_basic
392 -scripts_basic:
393 +PHONY += scripts_basic gcc-plugins
394 +scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398 @@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402 +ifndef DISABLE_PAX_PLUGINS
403 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405 +else
406 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407 +endif
408 +ifneq ($(PLUGINCC),)
409 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411 +endif
412 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
413 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415 +endif
416 +ifdef CONFIG_KALLOCSTAT_PLUGIN
417 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418 +endif
419 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423 +endif
424 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428 +endif
429 +endif
430 +ifdef CONFIG_CHECKER_PLUGIN
431 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433 +endif
434 +endif
435 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436 +ifdef CONFIG_PAX_SIZE_OVERFLOW
437 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438 +endif
439 +ifdef CONFIG_PAX_LATENT_ENTROPY
440 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441 +endif
442 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444 +endif
445 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451 +ifeq ($(KBUILD_EXTMOD),)
452 +gcc-plugins:
453 + $(Q)$(MAKE) $(build)=tools/gcc
454 +else
455 +gcc-plugins: ;
456 +endif
457 +else
458 +gcc-plugins:
459 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
461 +else
462 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463 +endif
464 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465 +endif
466 +endif
467 +
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471 @@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475 -KBUILD_AFLAGS += -Wa,-gdwarf-2
476 +KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480 @@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489 @@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498 @@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502 -$(vmlinux-dirs): prepare scripts
503 +$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507 @@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521 @@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530 @@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534 -modules_prepare: prepare scripts
535 +modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539 @@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543 - signing_key.x509.signer include/linux/version.h
544 + signing_key.x509.signer include/linux/version.h \
545 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547 + tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551 @@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560 @@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569 @@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573 -%.s: %.c prepare scripts FORCE
574 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576 +%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580 -%.o: %.c prepare scripts FORCE
581 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583 +%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587 -%.s: %.S prepare scripts FORCE
588 +%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590 -%.o: %.S prepare scripts FORCE
591 +%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595 @@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599 -%/: prepare scripts FORCE
600 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602 +%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606 -%.ko: prepare scripts FORCE
607 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609 +%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614 index 8f8eafb..3405f46 100644
615 --- a/arch/alpha/include/asm/atomic.h
616 +++ b/arch/alpha/include/asm/atomic.h
617 @@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621 +#define atomic64_read_unchecked(v) atomic64_read(v)
622 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
627 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
629 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630 +
631 #endif /* _ALPHA_ATOMIC_H */
632 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633 index ad368a9..fbe0f25 100644
634 --- a/arch/alpha/include/asm/cache.h
635 +++ b/arch/alpha/include/asm/cache.h
636 @@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640 +#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644 -# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650 -# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659 index 968d999..d36b2df 100644
660 --- a/arch/alpha/include/asm/elf.h
661 +++ b/arch/alpha/include/asm/elf.h
662 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666 +#ifdef CONFIG_PAX_ASLR
667 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668 +
669 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671 +#endif
672 +
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677 index aab14a0..b4fa3e7 100644
678 --- a/arch/alpha/include/asm/pgalloc.h
679 +++ b/arch/alpha/include/asm/pgalloc.h
680 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684 +static inline void
685 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686 +{
687 + pgd_populate(mm, pgd, pmd);
688 +}
689 +
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694 index d8f9b7e..f6222fa 100644
695 --- a/arch/alpha/include/asm/pgtable.h
696 +++ b/arch/alpha/include/asm/pgtable.h
697 @@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 +
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +#else
707 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
708 +# define PAGE_COPY_NOEXEC PAGE_COPY
709 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
710 +#endif
711 +
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716 index 2fd00b7..cfd5069 100644
717 --- a/arch/alpha/kernel/module.c
718 +++ b/arch/alpha/kernel/module.c
719 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723 - gp = (u64)me->module_core + me->core_size - 0x8000;
724 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729 index f9c732e..78fbb0f 100644
730 --- a/arch/alpha/kernel/osf_sys.c
731 +++ b/arch/alpha/kernel/osf_sys.c
732 @@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737 - unsigned long limit)
738 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739 + unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746 @@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750 + info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754 @@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758 +#ifdef CONFIG_PAX_RANDMMAP
759 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760 +#endif
761 +
762 if (addr) {
763 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771 - len, limit);
772 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773 +
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784 index 9d0ac09..479a962 100644
785 --- a/arch/alpha/mm/fault.c
786 +++ b/arch/alpha/mm/fault.c
787 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791 +#ifdef CONFIG_PAX_PAGEEXEC
792 +/*
793 + * PaX: decide what to do with offenders (regs->pc = fault address)
794 + *
795 + * returns 1 when task should be killed
796 + * 2 when patched PLT trampoline was detected
797 + * 3 when unpatched PLT trampoline was detected
798 + */
799 +static int pax_handle_fetch_fault(struct pt_regs *regs)
800 +{
801 +
802 +#ifdef CONFIG_PAX_EMUPLT
803 + int err;
804 +
805 + do { /* PaX: patched PLT emulation #1 */
806 + unsigned int ldah, ldq, jmp;
807 +
808 + err = get_user(ldah, (unsigned int *)regs->pc);
809 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811 +
812 + if (err)
813 + break;
814 +
815 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817 + jmp == 0x6BFB0000U)
818 + {
819 + unsigned long r27, addr;
820 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822 +
823 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824 + err = get_user(r27, (unsigned long *)addr);
825 + if (err)
826 + break;
827 +
828 + regs->r27 = r27;
829 + regs->pc = r27;
830 + return 2;
831 + }
832 + } while (0);
833 +
834 + do { /* PaX: patched PLT emulation #2 */
835 + unsigned int ldah, lda, br;
836 +
837 + err = get_user(ldah, (unsigned int *)regs->pc);
838 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
839 + err |= get_user(br, (unsigned int *)(regs->pc+8));
840 +
841 + if (err)
842 + break;
843 +
844 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
846 + (br & 0xFFE00000U) == 0xC3E00000U)
847 + {
848 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851 +
852 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854 + return 2;
855 + }
856 + } while (0);
857 +
858 + do { /* PaX: unpatched PLT emulation */
859 + unsigned int br;
860 +
861 + err = get_user(br, (unsigned int *)regs->pc);
862 +
863 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864 + unsigned int br2, ldq, nop, jmp;
865 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866 +
867 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868 + err = get_user(br2, (unsigned int *)addr);
869 + err |= get_user(ldq, (unsigned int *)(addr+4));
870 + err |= get_user(nop, (unsigned int *)(addr+8));
871 + err |= get_user(jmp, (unsigned int *)(addr+12));
872 + err |= get_user(resolver, (unsigned long *)(addr+16));
873 +
874 + if (err)
875 + break;
876 +
877 + if (br2 == 0xC3600000U &&
878 + ldq == 0xA77B000CU &&
879 + nop == 0x47FF041FU &&
880 + jmp == 0x6B7B0000U)
881 + {
882 + regs->r28 = regs->pc+4;
883 + regs->r27 = addr+16;
884 + regs->pc = resolver;
885 + return 3;
886 + }
887 + }
888 + } while (0);
889 +#endif
890 +
891 + return 1;
892 +}
893 +
894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895 +{
896 + unsigned long i;
897 +
898 + printk(KERN_ERR "PAX: bytes at PC: ");
899 + for (i = 0; i < 5; i++) {
900 + unsigned int c;
901 + if (get_user(c, (unsigned int *)pc+i))
902 + printk(KERN_CONT "???????? ");
903 + else
904 + printk(KERN_CONT "%08x ", c);
905 + }
906 + printk("\n");
907 +}
908 +#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912 @@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916 - if (!(vma->vm_flags & VM_EXEC))
917 + if (!(vma->vm_flags & VM_EXEC)) {
918 +
919 +#ifdef CONFIG_PAX_PAGEEXEC
920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921 + goto bad_area;
922 +
923 + up_read(&mm->mmap_sem);
924 + switch (pax_handle_fetch_fault(regs)) {
925 +
926 +#ifdef CONFIG_PAX_EMUPLT
927 + case 2:
928 + case 3:
929 + return;
930 +#endif
931 +
932 + }
933 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934 + do_group_exit(SIGKILL);
935 +#else
936 goto bad_area;
937 +#endif
938 +
939 + }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944 index 89c4b5c..847a7be 100644
945 --- a/arch/arm/Kconfig
946 +++ b/arch/arm/Kconfig
947 @@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951 - depends on MMU
952 + depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956 @@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960 + depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965 index e22c119..eaa807d 100644
966 --- a/arch/arm/include/asm/atomic.h
967 +++ b/arch/arm/include/asm/atomic.h
968 @@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972 +#ifdef CONFIG_GENERIC_ATOMIC64
973 +#include <asm-generic/atomic64.h>
974 +#endif
975 +
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980 +#ifdef CONFIG_THUMB2_KERNEL
981 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982 +#else
983 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984 +#endif
985 +
986 +#define _ASM_EXTABLE(from, to) \
987 +" .pushsection __ex_table,\"a\"\n"\
988 +" .align 3\n" \
989 +" .long " #from ", " #to"\n" \
990 +" .popsection"
991 +
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999 +{
1000 + return ACCESS_ONCE(v->counter);
1001 +}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004 +{
1005 + v->counter = i;
1006 +}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010 @@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014 -#define ATOMIC_OP(op, c_op, asm_op) \
1015 -static inline void atomic_##op(int i, atomic_t *v) \
1016 +#ifdef CONFIG_PAX_REFCOUNT
1017 +#define __OVERFLOW_POST \
1018 + " bvc 3f\n" \
1019 + "2: " REFCOUNT_TRAP_INSN "\n"\
1020 + "3:\n"
1021 +#define __OVERFLOW_POST_RETURN \
1022 + " bvc 3f\n" \
1023 +" mov %0, %1\n" \
1024 + "2: " REFCOUNT_TRAP_INSN "\n"\
1025 + "3:\n"
1026 +#define __OVERFLOW_EXTABLE \
1027 + "4:\n" \
1028 + _ASM_EXTABLE(2b, 4b)
1029 +#else
1030 +#define __OVERFLOW_POST
1031 +#define __OVERFLOW_POST_RETURN
1032 +#define __OVERFLOW_EXTABLE
1033 +#endif
1034 +
1035 +#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042 - __asm__ __volatile__("@ atomic_" #op "\n" \
1043 + __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046 + post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049 -" bne 1b" \
1050 +" bne 1b\n" \
1051 + extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1059 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060 + __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061 +
1062 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067 @@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071 - __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072 + __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075 + post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078 -" bne 1b" \
1079 +" bne 1b\n" \
1080 + extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084 @@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090 +
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094 @@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098 -" beq 2f\n"
1099 -" add %1, %0, %6\n"
1100 +" beq 4f\n"
1101 +" adds %1, %0, %6\n"
1102 +
1103 +#ifdef CONFIG_PAX_REFCOUNT
1104 +" bvc 3f\n"
1105 +"2: " REFCOUNT_TRAP_INSN "\n"
1106 +"3:\n"
1107 +#endif
1108 +
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112 -"2:"
1113 +"4:"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122 @@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127 +{
1128 + unsigned long oldval, res;
1129 +
1130 + smp_mb();
1131 +
1132 + do {
1133 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134 + "ldrex %1, [%3]\n"
1135 + "mov %0, #0\n"
1136 + "teq %1, %4\n"
1137 + "strexeq %0, %5, [%3]\n"
1138 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140 + : "cc");
1141 + } while (res);
1142 +
1143 + smp_mb();
1144 +
1145 + return oldval;
1146 +}
1147 +
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154 -#define ATOMIC_OP(op, c_op, asm_op) \
1155 -static inline void atomic_##op(int i, atomic_t *v) \
1156 +#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161 @@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1167 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168 + __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169 +
1170 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175 @@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181 +
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185 @@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190 +{
1191 + return atomic_cmpxchg((atomic_t *)v, old, new);
1192 +}
1193 +
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197 @@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201 +#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203 +#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207 +{
1208 + return xchg(&v->counter, new);
1209 +}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213 +{
1214 + atomic_add_unchecked(1, v);
1215 +}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218 +{
1219 + atomic_sub_unchecked(1, v);
1220 +}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224 +{
1225 + return atomic_add_return_unchecked(1, v) == 0;
1226 +}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230 +{
1231 + return atomic_add_return_unchecked(1, v);
1232 +}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236 @@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +typedef struct {
1242 + long long counter;
1243 +} atomic64_unchecked_t;
1244 +#else
1245 +typedef atomic64_t atomic64_unchecked_t;
1246 +#endif
1247 +
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251 @@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256 +{
1257 + long long result;
1258 +
1259 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260 +" ldrd %0, %H0, [%1]"
1261 + : "=&r" (result)
1262 + : "r" (&v->counter), "Qo" (v->counter)
1263 + );
1264 +
1265 + return result;
1266 +}
1267 +
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271 @@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275 +
1276 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277 +{
1278 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279 +" strd %2, %H2, [%1]"
1280 + : "=Qo" (v->counter)
1281 + : "r" (&v->counter), "r" (i)
1282 + );
1283 +}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287 @@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292 +{
1293 + long long result;
1294 +
1295 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296 +" ldrexd %0, %H0, [%1]"
1297 + : "=&r" (result)
1298 + : "r" (&v->counter), "Qo" (v->counter)
1299 + );
1300 +
1301 + return result;
1302 +}
1303 +
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307 @@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311 +
1312 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313 +{
1314 + long long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%2]\n"
1319 +" strexd %0, %3, %H3, [%2]\n"
1320 +" teq %0, #0\n"
1321 +" bne 1b"
1322 + : "=&r" (tmp), "=Qo" (v->counter)
1323 + : "r" (&v->counter), "r" (i)
1324 + : "cc");
1325 +}
1326 #endif
1327
1328 -#define ATOMIC64_OP(op, op1, op2) \
1329 -static inline void atomic64_##op(long long i, atomic64_t *v) \
1330 +#undef __OVERFLOW_POST_RETURN
1331 +#define __OVERFLOW_POST_RETURN \
1332 + " bvc 3f\n" \
1333 +" mov %0, %1\n" \
1334 +" mov %H0, %H1\n" \
1335 + "2: " REFCOUNT_TRAP_INSN "\n"\
1336 + "3:\n"
1337 +
1338 +#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339 +static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345 - __asm__ __volatile__("@ atomic64_" #op "\n" \
1346 + __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350 + post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353 -" bne 1b" \
1354 +" bne 1b\n" \
1355 + extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361 -#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362 -static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363 +#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364 + __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365 +
1366 +#define __ATOMIC64_OP_RETURN(op, suffix, op1, op2, post_op, extable) \
1367 +static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371 @@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375 - __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376 + __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380 + post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383 -" bne 1b" \
1384 +" bne 1b\n" \
1385 + extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389 @@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393 +#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394 + __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395 +
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399 @@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403 +#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405 +#undef __ATOMIC64_OP
1406 +#undef __OVERFLOW_EXTABLE
1407 +#undef __OVERFLOW_POST_RETURN
1408 +#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412 @@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417 + long long new)
1418 +{
1419 + long long oldval;
1420 + unsigned long res;
1421 +
1422 + smp_mb();
1423 +
1424 + do {
1425 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426 + "ldrexd %1, %H1, [%3]\n"
1427 + "mov %0, #0\n"
1428 + "teq %1, %4\n"
1429 + "teqeq %H1, %H4\n"
1430 + "strexdeq %0, %5, %H5, [%3]"
1431 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432 + : "r" (&ptr->counter), "r" (old), "r" (new)
1433 + : "cc");
1434 + } while (res);
1435 +
1436 + smp_mb();
1437 +
1438 + return oldval;
1439 +}
1440 +
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444 @@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448 - unsigned long tmp;
1449 + u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455 -"1: ldrexd %0, %H0, [%3]\n"
1456 -" subs %Q0, %Q0, #1\n"
1457 -" sbc %R0, %R0, #0\n"
1458 +"1: ldrexd %1, %H1, [%3]\n"
1459 +" subs %Q0, %Q1, #1\n"
1460 +" sbcs %R0, %R1, #0\n"
1461 +
1462 +#ifdef CONFIG_PAX_REFCOUNT
1463 +" bvc 3f\n"
1464 +" mov %Q0, %Q1\n"
1465 +" mov %R0, %R1\n"
1466 +"2: " REFCOUNT_TRAP_INSN "\n"
1467 +"3:\n"
1468 +#endif
1469 +
1470 " teq %R0, #0\n"
1471 -" bmi 2f\n"
1472 +" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476 -"2:"
1477 +"4:\n"
1478 +
1479 +#ifdef CONFIG_PAX_REFCOUNT
1480 + _ASM_EXTABLE(2b, 4b)
1481 +#endif
1482 +
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486 @@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490 -" beq 2f\n"
1491 +" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493 -" adc %R0, %R0, %R6\n"
1494 +" adcs %R0, %R0, %R6\n"
1495 +
1496 +#ifdef CONFIG_PAX_REFCOUNT
1497 +" bvc 3f\n"
1498 +"2: " REFCOUNT_TRAP_INSN "\n"
1499 +"3:\n"
1500 +#endif
1501 +
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505 -"2:"
1506 +"4:\n"
1507 +
1508 +#ifdef CONFIG_PAX_REFCOUNT
1509 + _ASM_EXTABLE(2b, 4b)
1510 +#endif
1511 +
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515 @@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530 index c6a3e73..35cca85 100644
1531 --- a/arch/arm/include/asm/barrier.h
1532 +++ b/arch/arm/include/asm/barrier.h
1533 @@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537 - ACCESS_ONCE(*p) = (v); \
1538 + ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543 index 75fe66b..ba3dee4 100644
1544 --- a/arch/arm/include/asm/cache.h
1545 +++ b/arch/arm/include/asm/cache.h
1546 @@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550 +#include <linux/const.h>
1551 +
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558 @@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566 index 10e78d0..dc8505d 100644
1567 --- a/arch/arm/include/asm/cacheflush.h
1568 +++ b/arch/arm/include/asm/cacheflush.h
1569 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573 -};
1574 +} __no_const;
1575
1576 /*
1577 * Select the calling method
1578 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579 index 5233151..87a71fa 100644
1580 --- a/arch/arm/include/asm/checksum.h
1581 +++ b/arch/arm/include/asm/checksum.h
1582 @@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588 +
1589 +static inline __wsum
1590 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591 +{
1592 + __wsum ret;
1593 + pax_open_userland();
1594 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595 + pax_close_userland();
1596 + return ret;
1597 +}
1598 +
1599 +
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604 index abb2c37..96db950 100644
1605 --- a/arch/arm/include/asm/cmpxchg.h
1606 +++ b/arch/arm/include/asm/cmpxchg.h
1607 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611 +#define xchg_unchecked(ptr,x) \
1612 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617 index 6ddbe44..b5e38b1 100644
1618 --- a/arch/arm/include/asm/domain.h
1619 +++ b/arch/arm/include/asm/domain.h
1620 @@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624 -#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626 +#define DOMAIN_USERCLIENT 1
1627 +#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629 +#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631 +
1632 +#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634 +#define DOMAIN_KERNEXEC 3
1635 +#else
1636 +#define DOMAIN_MANAGER 1
1637 +#endif
1638 +
1639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1640 +#define DOMAIN_USERCLIENT 0
1641 +#define DOMAIN_UDEREF 1
1642 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1643 +#else
1644 +#define DOMAIN_USERCLIENT 1
1645 +#define DOMAIN_VECTORS DOMAIN_USER
1646 +#endif
1647 +#define DOMAIN_KERNELCLIENT 1
1648 +
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655 -#ifdef CONFIG_CPU_USE_DOMAINS
1656 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664 -#define modify_domain(dom,type) \
1665 - do { \
1666 - struct thread_info *thread = current_thread_info(); \
1667 - unsigned int domain = thread->cpu_domain; \
1668 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669 - thread->cpu_domain = domain | domain_val(dom, type); \
1670 - set_domain(thread->cpu_domain); \
1671 - } while (0)
1672 -
1673 +extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678 index afb9caf..9a0bac0 100644
1679 --- a/arch/arm/include/asm/elf.h
1680 +++ b/arch/arm/include/asm/elf.h
1681 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687 +
1688 +#ifdef CONFIG_PAX_ASLR
1689 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690 +
1691 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693 +#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701 -struct mm_struct;
1702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703 -#define arch_randomize_brk arch_randomize_brk
1704 -
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709 index de53547..52b9a28 100644
1710 --- a/arch/arm/include/asm/fncpy.h
1711 +++ b/arch/arm/include/asm/fncpy.h
1712 @@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716 + pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718 + pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723 index 53e69da..3fdc896 100644
1724 --- a/arch/arm/include/asm/futex.h
1725 +++ b/arch/arm/include/asm/futex.h
1726 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730 + pax_open_userland();
1731 +
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739 + pax_close_userland();
1740 +
1741 *uval = val;
1742 return ret;
1743 }
1744 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748 + pax_open_userland();
1749 +
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757 + pax_close_userland();
1758 +
1759 *uval = val;
1760 return ret;
1761 }
1762 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766 + pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774 + pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779 index 83eb2f7..ed77159 100644
1780 --- a/arch/arm/include/asm/kmap_types.h
1781 +++ b/arch/arm/include/asm/kmap_types.h
1782 @@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786 -#define KM_TYPE_NR 16
1787 +#define KM_TYPE_NR 17
1788
1789 #endif
1790 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791 index 9e614a1..3302cca 100644
1792 --- a/arch/arm/include/asm/mach/dma.h
1793 +++ b/arch/arm/include/asm/mach/dma.h
1794 @@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798 -};
1799 +} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804 index f98c7f3..e5c626d 100644
1805 --- a/arch/arm/include/asm/mach/map.h
1806 +++ b/arch/arm/include/asm/mach/map.h
1807 @@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811 - MT_UNCACHED = 4,
1812 - MT_CACHECLEAN,
1813 - MT_MINICLEAN,
1814 + MT_UNCACHED_RW = 4,
1815 + MT_CACHECLEAN_RO,
1816 + MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819 - MT_MEMORY_RWX,
1820 + __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822 - MT_ROM,
1823 - MT_MEMORY_RWX_NONCACHED,
1824 + MT_MEMORY_RX,
1825 + MT_ROM_RX,
1826 + MT_MEMORY_RW_NONCACHED,
1827 + MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829 - MT_MEMORY_RWX_ITCM,
1830 + MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index 891a56b..48f337e 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index f027941..f36ce30 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 9fd61c7..f8f1cff 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index a31ecdad..95e98d4 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003 @@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017 index 3b30062..01a5f9d 100644
2018 --- a/arch/arm/include/asm/pgtable.h
2019 +++ b/arch/arm/include/asm/pgtable.h
2020 @@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024 +#define ktla_ktva(addr) (addr)
2025 +#define ktva_ktla(addr) (addr)
2026 +
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030 @@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034 +extern pteval_t __supported_pte_mask;
2035 +extern pmdval_t __supported_pmd_mask;
2036 +
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046 +
2047 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048 +#include <asm/domain.h>
2049 +#include <linux/thread_info.h>
2050 +#include <linux/preempt.h>
2051 +
2052 +static inline int test_domain(int domain, int domaintype)
2053 +{
2054 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055 +}
2056 +#endif
2057 +
2058 +#ifdef CONFIG_PAX_KERNEXEC
2059 +static inline unsigned long pax_open_kernel(void) {
2060 +#ifdef CONFIG_ARM_LPAE
2061 + /* TODO */
2062 +#else
2063 + preempt_disable();
2064 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066 +#endif
2067 + return 0;
2068 +}
2069 +
2070 +static inline unsigned long pax_close_kernel(void) {
2071 +#ifdef CONFIG_ARM_LPAE
2072 + /* TODO */
2073 +#else
2074 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077 + preempt_enable_no_resched();
2078 +#endif
2079 + return 0;
2080 +}
2081 +#else
2082 +static inline unsigned long pax_open_kernel(void) { return 0; }
2083 +static inline unsigned long pax_close_kernel(void) { return 0; }
2084 +#endif
2085 +
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093 - * as well as any architecture dependent bits like global/ASID and SMP
2094 - * shared mapping bits.
2095 + * as well as any architecture dependent bits like global/ASID, PXN,
2096 + * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100 @@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104 - L_PTE_NONE | L_PTE_VALID;
2105 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110 index c25ef3e..735f14b 100644
2111 --- a/arch/arm/include/asm/psci.h
2112 +++ b/arch/arm/include/asm/psci.h
2113 @@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117 -};
2118 +} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123 index 18f5a55..5072a40 100644
2124 --- a/arch/arm/include/asm/smp.h
2125 +++ b/arch/arm/include/asm/smp.h
2126 @@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130 -};
2131 +} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136 index ce73ab6..7310f8a 100644
2137 --- a/arch/arm/include/asm/thread_info.h
2138 +++ b/arch/arm/include/asm/thread_info.h
2139 @@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157 +/* within 8 bits of TIF_SYSCALL_TRACE
2158 + * to meet flexible second operand requirements
2159 + */
2160 +#define TIF_GRSEC_SETXID 12
2161 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179 index 5f833f7..76e6644 100644
2180 --- a/arch/arm/include/asm/tls.h
2181 +++ b/arch/arm/include/asm/tls.h
2182 @@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186 +#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194 + pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196 + pax_close_kernel();
2197 #endif
2198 }
2199
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 4767eb9..bf00668 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index a88671c..1cc895e 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 2f5555d..d493c91 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: str r4, [sp, #S_PC] @ retry current instruction
2605 +4: pax_close_userland
2606 + str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610 @@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index 6bb09d4..113e875 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index 4176df7..a901f8d 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770 @@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index b37752a..ff5cb72 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 664eee8..f470938 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 6a4dffe..4a86a70 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index fe972a2..a772d83 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932 -/* If possible, provide a placement hint at a random offset from the
2933 - * stack for the signal page.
2934 - */
2935 -static unsigned long sigpage_addr(const struct mm_struct *mm,
2936 - unsigned int npages)
2937 -{
2938 - unsigned long offset;
2939 - unsigned long first;
2940 - unsigned long last;
2941 - unsigned long addr;
2942 - unsigned int slots;
2943 -
2944 - first = PAGE_ALIGN(mm->start_stack);
2945 -
2946 - last = TASK_SIZE - (npages << PAGE_SHIFT);
2947 -
2948 - /* No room after stack? */
2949 - if (first > last)
2950 - return 0;
2951 -
2952 - /* Just enough room? */
2953 - if (first == last)
2954 - return first;
2955 -
2956 - slots = ((last - first) >> PAGE_SHIFT) + 1;
2957 -
2958 - offset = get_random_int() % slots;
2959 -
2960 - addr = first + (offset << PAGE_SHIFT);
2961 -
2962 - return addr;
2963 -}
2964 -
2965 -static struct page *signal_page;
2966 -extern struct page *get_signal_page(void);
2967 -
2968 -static const struct vm_special_mapping sigpage_mapping = {
2969 - .name = "[sigpage]",
2970 - .pages = &signal_page,
2971 -};
2972 -
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976 - struct vm_area_struct *vma;
2977 - unsigned long addr;
2978 - unsigned long hint;
2979 - int ret = 0;
2980 -
2981 - if (!signal_page)
2982 - signal_page = get_signal_page();
2983 - if (!signal_page)
2984 - return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987 - hint = sigpage_addr(mm, 1);
2988 - addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989 - if (IS_ERR_VALUE(addr)) {
2990 - ret = addr;
2991 - goto up_fail;
2992 - }
2993 -
2994 - vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996 - &sigpage_mapping);
2997 -
2998 - if (IS_ERR(vma)) {
2999 - ret = PTR_ERR(vma);
3000 - goto up_fail;
3001 - }
3002 -
3003 - mm->context.sigpage = addr;
3004 -
3005 - up_fail:
3006 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008 - return ret;
3009 + return 0;
3010 }
3011 #endif
3012 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013 index f73891b..cf3004e 100644
3014 --- a/arch/arm/kernel/psci.c
3015 +++ b/arch/arm/kernel/psci.c
3016 @@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020 -struct psci_operations psci_ops;
3021 +struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026 index ef9119f..31995a3 100644
3027 --- a/arch/arm/kernel/ptrace.c
3028 +++ b/arch/arm/kernel/ptrace.c
3029 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033 +#ifdef CONFIG_GRKERNSEC_SETXID
3034 +extern void gr_delayed_cred_worker(void);
3035 +#endif
3036 +
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041 +#ifdef CONFIG_GRKERNSEC_SETXID
3042 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043 + gr_delayed_cred_worker();
3044 +#endif
3045 +
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050 index 306e1ac..1b477ed 100644
3051 --- a/arch/arm/kernel/setup.c
3052 +++ b/arch/arm/kernel/setup.c
3053 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057 +pteval_t __supported_pte_mask __read_only;
3058 +pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061 -struct processor processor __read_mostly;
3062 +struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3066 +struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069 -struct cpu_user_fns cpu_user __read_mostly;
3070 +struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073 -struct cpu_cache_fns cpu_cache __read_mostly;
3074 +struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077 -struct outer_cache_fns outer_cache __read_mostly;
3078 +struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082 @@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086 - (mmfr0 & 0x000000f0) >= 0x00000030)
3087 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091 + __supported_pte_mask |= L_PTE_PXN;
3092 + __supported_pmd_mask |= PMD_PXNTABLE;
3093 + }
3094 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099 index bd19834..e4d8c66 100644
3100 --- a/arch/arm/kernel/signal.c
3101 +++ b/arch/arm/kernel/signal.c
3102 @@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106 -static unsigned long signal_return_offset;
3107 -
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115 - retcode = mm->context.sigpage + signal_return_offset +
3116 - (idx << 2) + thumb;
3117 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125 -
3126 -struct page *get_signal_page(void)
3127 -{
3128 - unsigned long ptr;
3129 - unsigned offset;
3130 - struct page *page;
3131 - void *addr;
3132 -
3133 - page = alloc_pages(GFP_KERNEL, 0);
3134 -
3135 - if (!page)
3136 - return NULL;
3137 -
3138 - addr = page_address(page);
3139 -
3140 - /* Give the signal return code some randomness */
3141 - offset = 0x200 + (get_random_int() & 0x7fc);
3142 - signal_return_offset = offset;
3143 -
3144 - /*
3145 - * Copy signal return handlers into the vector page, and
3146 - * set sigreturn to be a pointer to these.
3147 - */
3148 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149 -
3150 - ptr = (unsigned long)addr + offset;
3151 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152 -
3153 - return page;
3154 -}
3155 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156 index a8e32aa..b2f7198 100644
3157 --- a/arch/arm/kernel/smp.c
3158 +++ b/arch/arm/kernel/smp.c
3159 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163 -static struct smp_operations smp_ops;
3164 +static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169 index 7a3be1d..b00c7de 100644
3170 --- a/arch/arm/kernel/tcm.c
3171 +++ b/arch/arm/kernel/tcm.c
3172 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176 - .type = MT_MEMORY_RWX_ITCM,
3177 + .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181 @@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185 + pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187 + pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192 index 9f5d818..e013427 100644
3193 --- a/arch/arm/kernel/traps.c
3194 +++ b/arch/arm/kernel/traps.c
3195 @@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204 @@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208 +extern void gr_handle_kernel_exploit(void);
3209 +
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213 @@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217 +
3218 + gr_handle_kernel_exploit();
3219 +
3220 if (signr)
3221 do_exit(signr);
3222 }
3223 @@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228 +
3229 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3230 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231 +#endif
3232 +
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237 index 8e95aa4..595dfc8 100644
3238 --- a/arch/arm/kernel/vmlinux.lds.S
3239 +++ b/arch/arm/kernel/vmlinux.lds.S
3240 @@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244 -
3245 +
3246 +#ifdef CONFIG_PAX_KERNEXEC
3247 +#include <asm/pgtable.h>
3248 +#endif
3249 +
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253 @@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257 - defined(CONFIG_GENERIC_BUG)
3258 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262 @@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266 +
3267 +#ifdef CONFIG_PAX_KERNEXEC
3268 + . = ALIGN(1<<SECTION_SHIFT);
3269 +#endif
3270 +
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274 @@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278 + _etext = .; /* End of text section */
3279 +
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283 @@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287 - _etext = .; /* End of text and rodata section */
3288 +#ifdef CONFIG_PAX_KERNEXEC
3289 + . = ALIGN(1<<SECTION_SHIFT);
3290 +#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294 @@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298 +
3299 +#ifdef CONFIG_PAX_KERNEXEC
3300 + . = ALIGN(1<<SECTION_SHIFT);
3301 +#endif
3302 +
3303 __data_loc = .;
3304 #endif
3305
3306 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307 index 9e193c8..3560fe6 100644
3308 --- a/arch/arm/kvm/arm.c
3309 +++ b/arch/arm/kvm/arm.c
3310 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319 @@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328 @@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332 - atomic64_inc(&kvm_vmid_gen);
3333 + atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337 @@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346 @@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350 -int kvm_arch_init(void *opaque)
3351 +int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356 index 14a0d98..7771a7d 100644
3357 --- a/arch/arm/lib/clear_user.S
3358 +++ b/arch/arm/lib/clear_user.S
3359 @@ -12,14 +12,14 @@
3360
3361 .text
3362
3363 -/* Prototype: int __clear_user(void *addr, size_t sz)
3364 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371 -WEAK(__clear_user)
3372 +WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380 -ENDPROC(__clear_user)
3381 +ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386 index 66a477a..bee61d3 100644
3387 --- a/arch/arm/lib/copy_from_user.S
3388 +++ b/arch/arm/lib/copy_from_user.S
3389 @@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3394 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398 @@ -84,11 +84,11 @@
3399
3400 .text
3401
3402 -ENTRY(__copy_from_user)
3403 +ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407 -ENDPROC(__copy_from_user)
3408 +ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413 index 6ee2f67..d1cce76 100644
3414 --- a/arch/arm/lib/copy_page.S
3415 +++ b/arch/arm/lib/copy_page.S
3416 @@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420 +#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425 index d066df6..df28194 100644
3426 --- a/arch/arm/lib/copy_to_user.S
3427 +++ b/arch/arm/lib/copy_to_user.S
3428 @@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3433 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437 @@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441 -WEAK(__copy_to_user)
3442 +WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446 -ENDPROC(__copy_to_user)
3447 +ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452 index 7d08b43..f7ca7ea 100644
3453 --- a/arch/arm/lib/csumpartialcopyuser.S
3454 +++ b/arch/arm/lib/csumpartialcopyuser.S
3455 @@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467 index 312d43e..21d2322 100644
3468 --- a/arch/arm/lib/delay.c
3469 +++ b/arch/arm/lib/delay.c
3470 @@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474 -struct arm_delay_ops arm_delay_ops = {
3475 +struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480 index 3e58d71..029817c 100644
3481 --- a/arch/arm/lib/uaccess_with_memcpy.c
3482 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3483 @@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3488 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492 @@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496 -unsigned long __clear_user(void __user *addr, unsigned long n)
3497 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502 index 9610792..4dfb851 100644
3503 --- a/arch/arm/mach-at91/setup.c
3504 +++ b/arch/arm/mach-at91/setup.c
3505 @@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509 - desc->type = MT_MEMORY_RWX_NONCACHED;
3510 + desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515 index 7f352de..6dc0929 100644
3516 --- a/arch/arm/mach-keystone/keystone.c
3517 +++ b/arch/arm/mach-keystone/keystone.c
3518 @@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522 -static struct notifier_block platform_nb;
3523 +static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528 index 2ffccd4..69ffe115 100644
3529 --- a/arch/arm/mach-mvebu/coherency.c
3530 +++ b/arch/arm/mach-mvebu/coherency.c
3531 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544 - mtype = MT_UNCACHED;
3545 + mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550 index 97767a2..9233746 100644
3551 --- a/arch/arm/mach-omap2/board-n8x0.c
3552 +++ b/arch/arm/mach-omap2/board-n8x0.c
3553 @@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557 -struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558 +struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563 index 5fa3755..1e8c247 100644
3564 --- a/arch/arm/mach-omap2/gpmc.c
3565 +++ b/arch/arm/mach-omap2/gpmc.c
3566 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570 -static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578 +static struct irq_chip gpmc_irq_chip = {
3579 + .name = "gpmc",
3580 + .irq_startup = gpmc_irq_noop_ret,
3581 + .irq_enable = gpmc_irq_enable,
3582 + .irq_disable = gpmc_irq_disable,
3583 + .irq_shutdown = gpmc_irq_noop,
3584 + .irq_ack = gpmc_irq_noop,
3585 + .irq_mask = gpmc_irq_noop,
3586 + .irq_unmask = gpmc_irq_noop,
3587 +
3588 +};
3589 +
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597 - gpmc_irq_chip.name = "gpmc";
3598 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605 -
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610 index 6944ae3..bc587ca 100644
3611 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613 @@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617 -};
3618 +} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622 @@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626 -struct cpu_pm_ops omap_pm_ops = {
3627 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632 index f961c46..4a453dc 100644
3633 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635 @@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639 -static struct notifier_block __refdata irq_hotplug_notifier = {
3640 +static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645 index 8c58b71..95b655f 100644
3646 --- a/arch/arm/mach-omap2/omap_device.c
3647 +++ b/arch/arm/mach-omap2/omap_device.c
3648 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652 - void *pdata, int pdata_len)
3653 + const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661 - int oh_cnt, void *pdata,
3662 + int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667 index 78c02b3..c94109a 100644
3668 --- a/arch/arm/mach-omap2/omap_device.h
3669 +++ b/arch/arm/mach-omap2/omap_device.h
3670 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674 - struct omap_hwmod *oh, void *pdata,
3675 + struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680 - void *pdata, int pdata_len);
3681 + const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686 index 716247e..8df346d 100644
3687 --- a/arch/arm/mach-omap2/omap_hwmod.c
3688 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3689 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693 -};
3694 +} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697 -static struct omap_hwmod_soc_ops soc_ops;
3698 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703 index 95fee54..cfa9cf1 100644
3704 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706 @@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710 +#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719 + pax_open_kernel();
3720 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721 + pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726 index ff0a68c..b312aa0 100644
3727 --- a/arch/arm/mach-omap2/wd_timer.c
3728 +++ b/arch/arm/mach-omap2/wd_timer.c
3729 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733 - struct omap_wd_timer_platform_data pdata;
3734 + static struct omap_wd_timer_platform_data pdata = {
3735 + .read_reset_sources = prm_read_reset_sources
3736 + };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744 - pdata.read_reset_sources = prm_read_reset_sources;
3745 -
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750 index b30bf5c..d0825bf 100644
3751 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757 - ACCESS_ONCE(abort_flag) = true;
3758 + ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763 index 2dea8b5..6499da2 100644
3764 --- a/arch/arm/mach-ux500/setup.h
3765 +++ b/arch/arm/mach-ux500/setup.h
3766 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770 -#define __MEM_DEV_DESC(x, sz) { \
3771 - .virtual = IO_ADDRESS(x), \
3772 - .pfn = __phys_to_pfn(x), \
3773 - .length = sz, \
3774 - .type = MT_MEMORY_RWX, \
3775 -}
3776 -
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781 index 7eb94e6..799ad3e 100644
3782 --- a/arch/arm/mm/Kconfig
3783 +++ b/arch/arm/mm/Kconfig
3784 @@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804 - depends on MMU
3805 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813 - by ROP (return orientated programming) authors when creating
3814 + by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819 index 83792f4..c25d36b 100644
3820 --- a/arch/arm/mm/alignment.c
3821 +++ b/arch/arm/mm/alignment.c
3822 @@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826 + pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839 + pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 @@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 @@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871 + pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875 @@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879 + pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884 index 5e65ca8..879e7b3 100644
3885 --- a/arch/arm/mm/cache-l2x0.c
3886 +++ b/arch/arm/mm/cache-l2x0.c
3887 @@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891 -};
3892 +} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897 index 4370933..e77848e 100644
3898 --- a/arch/arm/mm/context.c
3899 +++ b/arch/arm/mm/context.c
3900 @@ -43,7 +43,7 @@
3901 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3902
3903 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3904 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3905 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3906 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3907
3908 static DEFINE_PER_CPU(atomic64_t, active_asids);
3909 @@ -178,7 +178,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3910 {
3911 static u32 cur_idx = 1;
3912 u64 asid = atomic64_read(&mm->context.id);
3913 - u64 generation = atomic64_read(&asid_generation);
3914 + u64 generation = atomic64_read_unchecked(&asid_generation);
3915
3916 if (asid != 0 && is_reserved_asid(asid)) {
3917 /*
3918 @@ -199,7 +199,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3919 */
3920 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3921 if (asid == NUM_USER_ASIDS) {
3922 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3923 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3924 &asid_generation);
3925 flush_context(cpu);
3926 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3927 @@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3928 cpu_set_reserved_ttbr0();
3929
3930 asid = atomic64_read(&mm->context.id);
3931 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3932 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3933 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3934 goto switch_mm_fastpath;
3935
3936 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3937 /* Check that our ASID belongs to the current generation. */
3938 asid = atomic64_read(&mm->context.id);
3939 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3940 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3941 asid = new_context(mm, cpu);
3942 atomic64_set(&mm->context.id, asid);
3943 }
3944 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3945 index eb8830a..e8ff52e 100644
3946 --- a/arch/arm/mm/fault.c
3947 +++ b/arch/arm/mm/fault.c
3948 @@ -25,6 +25,7 @@
3949 #include <asm/system_misc.h>
3950 #include <asm/system_info.h>
3951 #include <asm/tlbflush.h>
3952 +#include <asm/sections.h>
3953
3954 #include "fault.h"
3955
3956 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3957 if (fixup_exception(regs))
3958 return;
3959
3960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3961 + if (addr < TASK_SIZE) {
3962 + if (current->signal->curr_ip)
3963 + 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),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + else
3966 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968 + }
3969 +#endif
3970 +
3971 +#ifdef CONFIG_PAX_KERNEXEC
3972 + if ((fsr & FSR_WRITE) &&
3973 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3974 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3975 + {
3976 + if (current->signal->curr_ip)
3977 + 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),
3978 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979 + else
3980 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3981 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3982 + }
3983 +#endif
3984 +
3985 /*
3986 * No handler, we'll have to terminate things with extreme prejudice.
3987 */
3988 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3989 }
3990 #endif
3991
3992 +#ifdef CONFIG_PAX_PAGEEXEC
3993 + if (fsr & FSR_LNX_PF) {
3994 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3995 + do_group_exit(SIGKILL);
3996 + }
3997 +#endif
3998 +
3999 tsk->thread.address = addr;
4000 tsk->thread.error_code = fsr;
4001 tsk->thread.trap_no = 14;
4002 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4003 }
4004 #endif /* CONFIG_MMU */
4005
4006 +#ifdef CONFIG_PAX_PAGEEXEC
4007 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4008 +{
4009 + long i;
4010 +
4011 + printk(KERN_ERR "PAX: bytes at PC: ");
4012 + for (i = 0; i < 20; i++) {
4013 + unsigned char c;
4014 + if (get_user(c, (__force unsigned char __user *)pc+i))
4015 + printk(KERN_CONT "?? ");
4016 + else
4017 + printk(KERN_CONT "%02x ", c);
4018 + }
4019 + printk("\n");
4020 +
4021 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4022 + for (i = -1; i < 20; i++) {
4023 + unsigned long c;
4024 + if (get_user(c, (__force unsigned long __user *)sp+i))
4025 + printk(KERN_CONT "???????? ");
4026 + else
4027 + printk(KERN_CONT "%08lx ", c);
4028 + }
4029 + printk("\n");
4030 +}
4031 +#endif
4032 +
4033 /*
4034 * First Level Translation Fault Handler
4035 *
4036 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4037 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4038 struct siginfo info;
4039
4040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4041 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4042 + if (current->signal->curr_ip)
4043 + 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),
4044 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045 + else
4046 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4047 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4048 + goto die;
4049 + }
4050 +#endif
4051 +
4052 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4053 return;
4054
4055 +die:
4056 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4057 inf->name, fsr, addr);
4058
4059 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4060 ifsr_info[nr].name = name;
4061 }
4062
4063 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4064 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4065 +
4066 asmlinkage void __exception
4067 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4068 {
4069 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4070 struct siginfo info;
4071 + unsigned long pc = instruction_pointer(regs);
4072 +
4073 + if (user_mode(regs)) {
4074 + unsigned long sigpage = current->mm->context.sigpage;
4075 +
4076 + if (sigpage <= pc && pc < sigpage + 7*4) {
4077 + if (pc < sigpage + 3*4)
4078 + sys_sigreturn(regs);
4079 + else
4080 + sys_rt_sigreturn(regs);
4081 + return;
4082 + }
4083 + if (pc == 0xffff0f60UL) {
4084 + /*
4085 + * PaX: __kuser_cmpxchg64 emulation
4086 + */
4087 + // TODO
4088 + //regs->ARM_pc = regs->ARM_lr;
4089 + //return;
4090 + }
4091 + if (pc == 0xffff0fa0UL) {
4092 + /*
4093 + * PaX: __kuser_memory_barrier emulation
4094 + */
4095 + // dmb(); implied by the exception
4096 + regs->ARM_pc = regs->ARM_lr;
4097 + return;
4098 + }
4099 + if (pc == 0xffff0fc0UL) {
4100 + /*
4101 + * PaX: __kuser_cmpxchg emulation
4102 + */
4103 + // TODO
4104 + //long new;
4105 + //int op;
4106 +
4107 + //op = FUTEX_OP_SET << 28;
4108 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4109 + //regs->ARM_r0 = old != new;
4110 + //regs->ARM_pc = regs->ARM_lr;
4111 + //return;
4112 + }
4113 + if (pc == 0xffff0fe0UL) {
4114 + /*
4115 + * PaX: __kuser_get_tls emulation
4116 + */
4117 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4118 + regs->ARM_pc = regs->ARM_lr;
4119 + return;
4120 + }
4121 + }
4122 +
4123 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4124 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4125 + if (current->signal->curr_ip)
4126 + 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),
4127 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4128 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4129 + else
4130 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4131 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4132 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4133 + goto die;
4134 + }
4135 +#endif
4136 +
4137 +#ifdef CONFIG_PAX_REFCOUNT
4138 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4139 +#ifdef CONFIG_THUMB2_KERNEL
4140 + unsigned short bkpt;
4141 +
4142 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4143 +#else
4144 + unsigned int bkpt;
4145 +
4146 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4147 +#endif
4148 + current->thread.error_code = ifsr;
4149 + current->thread.trap_no = 0;
4150 + pax_report_refcount_overflow(regs);
4151 + fixup_exception(regs);
4152 + return;
4153 + }
4154 + }
4155 +#endif
4156
4157 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4158 return;
4159
4160 +die:
4161 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4162 inf->name, ifsr, addr);
4163
4164 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4165 index cf08bdf..772656c 100644
4166 --- a/arch/arm/mm/fault.h
4167 +++ b/arch/arm/mm/fault.h
4168 @@ -3,6 +3,7 @@
4169
4170 /*
4171 * Fault status register encodings. We steal bit 31 for our own purposes.
4172 + * Set when the FSR value is from an instruction fault.
4173 */
4174 #define FSR_LNX_PF (1 << 31)
4175 #define FSR_WRITE (1 << 11)
4176 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4177 }
4178 #endif
4179
4180 +/* valid for LPAE and !LPAE */
4181 +static inline int is_xn_fault(unsigned int fsr)
4182 +{
4183 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4184 +}
4185 +
4186 +static inline int is_domain_fault(unsigned int fsr)
4187 +{
4188 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4189 +}
4190 +
4191 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4192 unsigned long search_exception_table(unsigned long addr);
4193
4194 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4195 index 9481f85..6dae261 100644
4196 --- a/arch/arm/mm/init.c
4197 +++ b/arch/arm/mm/init.c
4198 @@ -31,6 +31,8 @@
4199 #include <asm/setup.h>
4200 #include <asm/tlb.h>
4201 #include <asm/fixmap.h>
4202 +#include <asm/system_info.h>
4203 +#include <asm/cp15.h>
4204
4205 #include <asm/mach/arch.h>
4206 #include <asm/mach/map.h>
4207 @@ -619,7 +621,46 @@ void free_initmem(void)
4208 {
4209 #ifdef CONFIG_HAVE_TCM
4210 extern char __tcm_start, __tcm_end;
4211 +#endif
4212
4213 +#ifdef CONFIG_PAX_KERNEXEC
4214 + unsigned long addr;
4215 + pgd_t *pgd;
4216 + pud_t *pud;
4217 + pmd_t *pmd;
4218 + int cpu_arch = cpu_architecture();
4219 + unsigned int cr = get_cr();
4220 +
4221 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4222 + /* make pages tables, etc before .text NX */
4223 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4224 + pgd = pgd_offset_k(addr);
4225 + pud = pud_offset(pgd, addr);
4226 + pmd = pmd_offset(pud, addr);
4227 + __section_update(pmd, addr, PMD_SECT_XN);
4228 + }
4229 + /* make init NX */
4230 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4231 + pgd = pgd_offset_k(addr);
4232 + pud = pud_offset(pgd, addr);
4233 + pmd = pmd_offset(pud, addr);
4234 + __section_update(pmd, addr, PMD_SECT_XN);
4235 + }
4236 + /* make kernel code/rodata RX */
4237 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4238 + pgd = pgd_offset_k(addr);
4239 + pud = pud_offset(pgd, addr);
4240 + pmd = pmd_offset(pud, addr);
4241 +#ifdef CONFIG_ARM_LPAE
4242 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4243 +#else
4244 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4245 +#endif
4246 + }
4247 + }
4248 +#endif
4249 +
4250 +#ifdef CONFIG_HAVE_TCM
4251 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4252 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4253 #endif
4254 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4255 index d1e5ad7..84dcbf2 100644
4256 --- a/arch/arm/mm/ioremap.c
4257 +++ b/arch/arm/mm/ioremap.c
4258 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4259 unsigned int mtype;
4260
4261 if (cached)
4262 - mtype = MT_MEMORY_RWX;
4263 + mtype = MT_MEMORY_RX;
4264 else
4265 - mtype = MT_MEMORY_RWX_NONCACHED;
4266 + mtype = MT_MEMORY_RX_NONCACHED;
4267
4268 return __arm_ioremap_caller(phys_addr, size, mtype,
4269 __builtin_return_address(0));
4270 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4271 index 5e85ed3..b10a7ed 100644
4272 --- a/arch/arm/mm/mmap.c
4273 +++ b/arch/arm/mm/mmap.c
4274 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4275 struct vm_area_struct *vma;
4276 int do_align = 0;
4277 int aliasing = cache_is_vipt_aliasing();
4278 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4279 struct vm_unmapped_area_info info;
4280
4281 /*
4282 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4283 if (len > TASK_SIZE)
4284 return -ENOMEM;
4285
4286 +#ifdef CONFIG_PAX_RANDMMAP
4287 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4288 +#endif
4289 +
4290 if (addr) {
4291 if (do_align)
4292 addr = COLOUR_ALIGN(addr, pgoff);
4293 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4294 addr = PAGE_ALIGN(addr);
4295
4296 vma = find_vma(mm, addr);
4297 - if (TASK_SIZE - len >= addr &&
4298 - (!vma || addr + len <= vma->vm_start))
4299 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4300 return addr;
4301 }
4302
4303 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4304 info.high_limit = TASK_SIZE;
4305 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4306 info.align_offset = pgoff << PAGE_SHIFT;
4307 + info.threadstack_offset = offset;
4308 return vm_unmapped_area(&info);
4309 }
4310
4311 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4312 unsigned long addr = addr0;
4313 int do_align = 0;
4314 int aliasing = cache_is_vipt_aliasing();
4315 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4316 struct vm_unmapped_area_info info;
4317
4318 /*
4319 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4320 return addr;
4321 }
4322
4323 +#ifdef CONFIG_PAX_RANDMMAP
4324 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4325 +#endif
4326 +
4327 /* requesting a specific address */
4328 if (addr) {
4329 if (do_align)
4330 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4331 else
4332 addr = PAGE_ALIGN(addr);
4333 vma = find_vma(mm, addr);
4334 - if (TASK_SIZE - len >= addr &&
4335 - (!vma || addr + len <= vma->vm_start))
4336 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4337 return addr;
4338 }
4339
4340 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4341 info.high_limit = mm->mmap_base;
4342 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4343 info.align_offset = pgoff << PAGE_SHIFT;
4344 + info.threadstack_offset = offset;
4345 addr = vm_unmapped_area(&info);
4346
4347 /*
4348 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4349 {
4350 unsigned long random_factor = 0UL;
4351
4352 +#ifdef CONFIG_PAX_RANDMMAP
4353 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4354 +#endif
4355 +
4356 /* 8 bits of randomness in 20 address space bits */
4357 if ((current->flags & PF_RANDOMIZE) &&
4358 !(current->personality & ADDR_NO_RANDOMIZE))
4359 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4360
4361 if (mmap_is_legacy()) {
4362 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4363 +
4364 +#ifdef CONFIG_PAX_RANDMMAP
4365 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4366 + mm->mmap_base += mm->delta_mmap;
4367 +#endif
4368 +
4369 mm->get_unmapped_area = arch_get_unmapped_area;
4370 } else {
4371 mm->mmap_base = mmap_base(random_factor);
4372 +
4373 +#ifdef CONFIG_PAX_RANDMMAP
4374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4375 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4376 +#endif
4377 +
4378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4379 }
4380 }
4381 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4382 index 9f98cec..115fcb6 100644
4383 --- a/arch/arm/mm/mmu.c
4384 +++ b/arch/arm/mm/mmu.c
4385 @@ -40,6 +40,22 @@
4386 #include "mm.h"
4387 #include "tcm.h"
4388
4389 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4390 +void modify_domain(unsigned int dom, unsigned int type)
4391 +{
4392 + struct thread_info *thread = current_thread_info();
4393 + unsigned int domain = thread->cpu_domain;
4394 + /*
4395 + * DOMAIN_MANAGER might be defined to some other value,
4396 + * use the arch-defined constant
4397 + */
4398 + domain &= ~domain_val(dom, 3);
4399 + thread->cpu_domain = domain | domain_val(dom, type);
4400 + set_domain(thread->cpu_domain);
4401 +}
4402 +EXPORT_SYMBOL(modify_domain);
4403 +#endif
4404 +
4405 /*
4406 * empty_zero_page is a special page that is used for
4407 * zero-initialized data and COW.
4408 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4409 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4410 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4411
4412 -static struct mem_type mem_types[] = {
4413 +#ifdef CONFIG_PAX_KERNEXEC
4414 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4415 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4416 +#else
4417 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4418 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4419 +#endif
4420 +
4421 +static struct mem_type mem_types[] __read_only = {
4422 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4423 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4424 L_PTE_SHARED,
4425 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4426 .prot_sect = PROT_SECT_DEVICE,
4427 .domain = DOMAIN_IO,
4428 },
4429 - [MT_UNCACHED] = {
4430 + [MT_UNCACHED_RW] = {
4431 .prot_pte = PROT_PTE_DEVICE,
4432 .prot_l1 = PMD_TYPE_TABLE,
4433 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4434 .domain = DOMAIN_IO,
4435 },
4436 - [MT_CACHECLEAN] = {
4437 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4438 + [MT_CACHECLEAN_RO] = {
4439 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4440 .domain = DOMAIN_KERNEL,
4441 },
4442 #ifndef CONFIG_ARM_LPAE
4443 - [MT_MINICLEAN] = {
4444 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4445 + [MT_MINICLEAN_RO] = {
4446 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4447 .domain = DOMAIN_KERNEL,
4448 },
4449 #endif
4450 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4451 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4452 L_PTE_RDONLY,
4453 .prot_l1 = PMD_TYPE_TABLE,
4454 - .domain = DOMAIN_USER,
4455 + .domain = DOMAIN_VECTORS,
4456 },
4457 [MT_HIGH_VECTORS] = {
4458 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4459 L_PTE_USER | L_PTE_RDONLY,
4460 .prot_l1 = PMD_TYPE_TABLE,
4461 - .domain = DOMAIN_USER,
4462 + .domain = DOMAIN_VECTORS,
4463 },
4464 - [MT_MEMORY_RWX] = {
4465 + [__MT_MEMORY_RWX] = {
4466 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4470 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4471 .domain = DOMAIN_KERNEL,
4472 },
4473 - [MT_ROM] = {
4474 - .prot_sect = PMD_TYPE_SECT,
4475 + [MT_MEMORY_RX] = {
4476 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4477 + .prot_l1 = PMD_TYPE_TABLE,
4478 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4479 + .domain = DOMAIN_KERNEL,
4480 + },
4481 + [MT_ROM_RX] = {
4482 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485 - [MT_MEMORY_RWX_NONCACHED] = {
4486 + [MT_MEMORY_RW_NONCACHED] = {
4487 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4488 L_PTE_MT_BUFFERABLE,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493 + [MT_MEMORY_RX_NONCACHED] = {
4494 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4495 + L_PTE_MT_BUFFERABLE,
4496 + .prot_l1 = PMD_TYPE_TABLE,
4497 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4498 + .domain = DOMAIN_KERNEL,
4499 + },
4500 [MT_MEMORY_RW_DTCM] = {
4501 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4502 L_PTE_XN,
4503 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4504 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4505 .domain = DOMAIN_KERNEL,
4506 },
4507 - [MT_MEMORY_RWX_ITCM] = {
4508 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4509 + [MT_MEMORY_RX_ITCM] = {
4510 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4511 .prot_l1 = PMD_TYPE_TABLE,
4512 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4513 .domain = DOMAIN_KERNEL,
4514 },
4515 [MT_MEMORY_RW_SO] = {
4516 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4517 * Mark cache clean areas and XIP ROM read only
4518 * from SVC mode and no access from userspace.
4519 */
4520 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4523 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4524 +#ifdef CONFIG_PAX_KERNEXEC
4525 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4526 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4527 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4528 +#endif
4529 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4530 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4531 #endif
4532
4533 /*
4534 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4535 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4536 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4537 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4538 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4539 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4540 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4541 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4542 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4543 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4544 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4545 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4546 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4547 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4548 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4549 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4550 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4551 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4552 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4553 }
4554 }
4555
4556 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4557 if (cpu_arch >= CPU_ARCH_ARMv6) {
4558 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4559 /* Non-cacheable Normal is XCB = 001 */
4560 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4561 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4562 + PMD_SECT_BUFFERED;
4563 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4564 PMD_SECT_BUFFERED;
4565 } else {
4566 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4567 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4568 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4569 + PMD_SECT_TEX(1);
4570 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4571 PMD_SECT_TEX(1);
4572 }
4573 } else {
4574 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4575 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4576 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4577 }
4578
4579 #ifdef CONFIG_ARM_LPAE
4580 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4581 vecs_pgprot |= PTE_EXT_AF;
4582 #endif
4583
4584 + user_pgprot |= __supported_pte_mask;
4585 +
4586 for (i = 0; i < 16; i++) {
4587 pteval_t v = pgprot_val(protection_map[i]);
4588 protection_map[i] = __pgprot(v | user_pgprot);
4589 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4590
4591 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4592 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4593 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4594 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4595 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4596 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4597 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4598 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4599 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4600 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4601 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4602 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4603 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4604 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4605 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4606 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4607
4608 switch (cp->pmd) {
4609 case PMD_SECT_WT:
4610 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4611 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4612 break;
4613 case PMD_SECT_WB:
4614 case PMD_SECT_WBWA:
4615 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4616 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4617 break;
4618 }
4619 pr_info("Memory policy: %sData cache %s\n",
4620 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4621 return;
4622 }
4623
4624 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4625 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4626 md->virtual >= PAGE_OFFSET &&
4627 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4628 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4629 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4630 * called function. This means you can't use any function or debugging
4631 * method which may touch any device, otherwise the kernel _will_ crash.
4632 */
4633 +
4634 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4635 +
4636 static void __init devicemaps_init(const struct machine_desc *mdesc)
4637 {
4638 struct map_desc map;
4639 unsigned long addr;
4640 - void *vectors;
4641
4642 - /*
4643 - * Allocate the vector page early.
4644 - */
4645 - vectors = early_alloc(PAGE_SIZE * 2);
4646 -
4647 - early_trap_init(vectors);
4648 + early_trap_init(&vectors);
4649
4650 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4651 pmd_clear(pmd_off_k(addr));
4652 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4654 map.virtual = MODULES_VADDR;
4655 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4656 - map.type = MT_ROM;
4657 + map.type = MT_ROM_RX;
4658 create_mapping(&map);
4659 #endif
4660
4661 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4662 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4663 map.virtual = FLUSH_BASE;
4664 map.length = SZ_1M;
4665 - map.type = MT_CACHECLEAN;
4666 + map.type = MT_CACHECLEAN_RO;
4667 create_mapping(&map);
4668 #endif
4669 #ifdef FLUSH_BASE_MINICACHE
4670 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4671 map.virtual = FLUSH_BASE_MINICACHE;
4672 map.length = SZ_1M;
4673 - map.type = MT_MINICLEAN;
4674 + map.type = MT_MINICLEAN_RO;
4675 create_mapping(&map);
4676 #endif
4677
4678 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4679 * location (0xffff0000). If we aren't using high-vectors, also
4680 * create a mapping at the low-vectors virtual address.
4681 */
4682 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4683 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4684 map.virtual = 0xffff0000;
4685 map.length = PAGE_SIZE;
4686 #ifdef CONFIG_KUSER_HELPERS
4687 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4688 static void __init map_lowmem(void)
4689 {
4690 struct memblock_region *reg;
4691 +#ifndef CONFIG_PAX_KERNEXEC
4692 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4693 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4694 +#endif
4695
4696 /* Map all the lowmem memory banks. */
4697 for_each_memblock(memory, reg) {
4698 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4699 if (start >= end)
4700 break;
4701
4702 +#ifdef CONFIG_PAX_KERNEXEC
4703 + map.pfn = __phys_to_pfn(start);
4704 + map.virtual = __phys_to_virt(start);
4705 + map.length = end - start;
4706 +
4707 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4708 + struct map_desc kernel;
4709 + struct map_desc initmap;
4710 +
4711 + /* when freeing initmem we will make this RW */
4712 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4713 + initmap.virtual = (unsigned long)__init_begin;
4714 + initmap.length = _sdata - __init_begin;
4715 + initmap.type = __MT_MEMORY_RWX;
4716 + create_mapping(&initmap);
4717 +
4718 + /* when freeing initmem we will make this RX */
4719 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4720 + kernel.virtual = (unsigned long)_stext;
4721 + kernel.length = __init_begin - _stext;
4722 + kernel.type = __MT_MEMORY_RWX;
4723 + create_mapping(&kernel);
4724 +
4725 + if (map.virtual < (unsigned long)_stext) {
4726 + map.length = (unsigned long)_stext - map.virtual;
4727 + map.type = __MT_MEMORY_RWX;
4728 + create_mapping(&map);
4729 + }
4730 +
4731 + map.pfn = __phys_to_pfn(__pa(_sdata));
4732 + map.virtual = (unsigned long)_sdata;
4733 + map.length = end - __pa(_sdata);
4734 + }
4735 +
4736 + map.type = MT_MEMORY_RW;
4737 + create_mapping(&map);
4738 +#else
4739 if (end < kernel_x_start || start >= kernel_x_end) {
4740 map.pfn = __phys_to_pfn(start);
4741 map.virtual = __phys_to_virt(start);
4742 map.length = end - start;
4743 - map.type = MT_MEMORY_RWX;
4744 + map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747 } else {
4748 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4749 map.pfn = __phys_to_pfn(kernel_x_start);
4750 map.virtual = __phys_to_virt(kernel_x_start);
4751 map.length = kernel_x_end - kernel_x_start;
4752 - map.type = MT_MEMORY_RWX;
4753 + map.type = __MT_MEMORY_RWX;
4754
4755 create_mapping(&map);
4756
4757 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4758 create_mapping(&map);
4759 }
4760 }
4761 +#endif
4762 }
4763 }
4764
4765 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4766 index e1268f9..a9755a7 100644
4767 --- a/arch/arm/net/bpf_jit_32.c
4768 +++ b/arch/arm/net/bpf_jit_32.c
4769 @@ -20,6 +20,7 @@
4770 #include <asm/cacheflush.h>
4771 #include <asm/hwcap.h>
4772 #include <asm/opcodes.h>
4773 +#include <asm/pgtable.h>
4774
4775 #include "bpf_jit_32.h"
4776
4777 @@ -71,7 +72,11 @@ struct jit_ctx {
4778 #endif
4779 };
4780
4781 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4782 +int bpf_jit_enable __read_only;
4783 +#else
4784 int bpf_jit_enable __read_mostly;
4785 +#endif
4786
4787 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4788 {
4789 @@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4790 {
4791 u32 *ptr;
4792 /* We are guaranteed to have aligned memory. */
4793 + pax_open_kernel();
4794 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4795 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4796 + pax_close_kernel();
4797 }
4798
4799 static void build_prologue(struct jit_ctx *ctx)
4800 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4801 index 5b217f4..c23f40e 100644
4802 --- a/arch/arm/plat-iop/setup.c
4803 +++ b/arch/arm/plat-iop/setup.c
4804 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4805 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4806 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4807 .length = IOP3XX_PERIPHERAL_SIZE,
4808 - .type = MT_UNCACHED,
4809 + .type = MT_UNCACHED_RW,
4810 },
4811 };
4812
4813 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4814 index a5bc92d..0bb4730 100644
4815 --- a/arch/arm/plat-omap/sram.c
4816 +++ b/arch/arm/plat-omap/sram.c
4817 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4818 * Looks like we need to preserve some bootloader code at the
4819 * beginning of SRAM for jumping to flash for reboot to work...
4820 */
4821 + pax_open_kernel();
4822 memset_io(omap_sram_base + omap_sram_skip, 0,
4823 omap_sram_size - omap_sram_skip);
4824 + pax_close_kernel();
4825 }
4826 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4827 index ce6d763..cfea917 100644
4828 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4829 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4830 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4831 int (*started)(unsigned ch);
4832 int (*flush)(unsigned ch);
4833 int (*stop)(unsigned ch);
4834 -};
4835 +} __no_const;
4836
4837 extern void *samsung_dmadev_get_ops(void);
4838 extern void *s3c_dma_get_ops(void);
4839 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4840 index 6389d60..b5d3bdd 100644
4841 --- a/arch/arm64/include/asm/barrier.h
4842 +++ b/arch/arm64/include/asm/barrier.h
4843 @@ -41,7 +41,7 @@
4844 do { \
4845 compiletime_assert_atomic_type(*p); \
4846 barrier(); \
4847 - ACCESS_ONCE(*p) = (v); \
4848 + ACCESS_ONCE_RW(*p) = (v); \
4849 } while (0)
4850
4851 #define smp_load_acquire(p) \
4852 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4853 index 3bf8f4e..5dd5491 100644
4854 --- a/arch/arm64/include/asm/uaccess.h
4855 +++ b/arch/arm64/include/asm/uaccess.h
4856 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4857 flag; \
4858 })
4859
4860 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4861 #define access_ok(type, addr, size) __range_ok(addr, size)
4862 #define user_addr_max get_fs
4863
4864 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4865 index c3a58a1..78fbf54 100644
4866 --- a/arch/avr32/include/asm/cache.h
4867 +++ b/arch/avr32/include/asm/cache.h
4868 @@ -1,8 +1,10 @@
4869 #ifndef __ASM_AVR32_CACHE_H
4870 #define __ASM_AVR32_CACHE_H
4871
4872 +#include <linux/const.h>
4873 +
4874 #define L1_CACHE_SHIFT 5
4875 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4876 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 /*
4879 * Memory returned by kmalloc() may be used for DMA, so we must make
4880 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4881 index d232888..87c8df1 100644
4882 --- a/arch/avr32/include/asm/elf.h
4883 +++ b/arch/avr32/include/asm/elf.h
4884 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4885 the loader. We need to make sure that it is out of the way of the program
4886 that it will "exec", and that there is sufficient room for the brk. */
4887
4888 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4889 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4890
4891 +#ifdef CONFIG_PAX_ASLR
4892 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4893 +
4894 +#define PAX_DELTA_MMAP_LEN 15
4895 +#define PAX_DELTA_STACK_LEN 15
4896 +#endif
4897
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this CPU supports. This could be done in user space,
4900 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4901 index 479330b..53717a8 100644
4902 --- a/arch/avr32/include/asm/kmap_types.h
4903 +++ b/arch/avr32/include/asm/kmap_types.h
4904 @@ -2,9 +2,9 @@
4905 #define __ASM_AVR32_KMAP_TYPES_H
4906
4907 #ifdef CONFIG_DEBUG_HIGHMEM
4908 -# define KM_TYPE_NR 29
4909 +# define KM_TYPE_NR 30
4910 #else
4911 -# define KM_TYPE_NR 14
4912 +# define KM_TYPE_NR 15
4913 #endif
4914
4915 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4916 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4917 index d223a8b..69c5210 100644
4918 --- a/arch/avr32/mm/fault.c
4919 +++ b/arch/avr32/mm/fault.c
4920 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4921
4922 int exception_trace = 1;
4923
4924 +#ifdef CONFIG_PAX_PAGEEXEC
4925 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4926 +{
4927 + unsigned long i;
4928 +
4929 + printk(KERN_ERR "PAX: bytes at PC: ");
4930 + for (i = 0; i < 20; i++) {
4931 + unsigned char c;
4932 + if (get_user(c, (unsigned char *)pc+i))
4933 + printk(KERN_CONT "???????? ");
4934 + else
4935 + printk(KERN_CONT "%02x ", c);
4936 + }
4937 + printk("\n");
4938 +}
4939 +#endif
4940 +
4941 /*
4942 * This routine handles page faults. It determines the address and the
4943 * problem, and then passes it off to one of the appropriate routines.
4944 @@ -178,6 +195,16 @@ bad_area:
4945 up_read(&mm->mmap_sem);
4946
4947 if (user_mode(regs)) {
4948 +
4949 +#ifdef CONFIG_PAX_PAGEEXEC
4950 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4951 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4952 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4953 + do_group_exit(SIGKILL);
4954 + }
4955 + }
4956 +#endif
4957 +
4958 if (exception_trace && printk_ratelimit())
4959 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4960 "sp %08lx ecr %lu\n",
4961 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4962 index 568885a..f8008df 100644
4963 --- a/arch/blackfin/include/asm/cache.h
4964 +++ b/arch/blackfin/include/asm/cache.h
4965 @@ -7,6 +7,7 @@
4966 #ifndef __ARCH_BLACKFIN_CACHE_H
4967 #define __ARCH_BLACKFIN_CACHE_H
4968
4969 +#include <linux/const.h>
4970 #include <linux/linkage.h> /* for asmlinkage */
4971
4972 /*
4973 @@ -14,7 +15,7 @@
4974 * Blackfin loads 32 bytes for cache
4975 */
4976 #define L1_CACHE_SHIFT 5
4977 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4980
4981 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4982 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4983 index aea2718..3639a60 100644
4984 --- a/arch/cris/include/arch-v10/arch/cache.h
4985 +++ b/arch/cris/include/arch-v10/arch/cache.h
4986 @@ -1,8 +1,9 @@
4987 #ifndef _ASM_ARCH_CACHE_H
4988 #define _ASM_ARCH_CACHE_H
4989
4990 +#include <linux/const.h>
4991 /* Etrax 100LX have 32-byte cache-lines. */
4992 -#define L1_CACHE_BYTES 32
4993 #define L1_CACHE_SHIFT 5
4994 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4995
4996 #endif /* _ASM_ARCH_CACHE_H */
4997 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4998 index 7caf25d..ee65ac5 100644
4999 --- a/arch/cris/include/arch-v32/arch/cache.h
5000 +++ b/arch/cris/include/arch-v32/arch/cache.h
5001 @@ -1,11 +1,12 @@
5002 #ifndef _ASM_CRIS_ARCH_CACHE_H
5003 #define _ASM_CRIS_ARCH_CACHE_H
5004
5005 +#include <linux/const.h>
5006 #include <arch/hwregs/dma.h>
5007
5008 /* A cache-line is 32 bytes. */
5009 -#define L1_CACHE_BYTES 32
5010 #define L1_CACHE_SHIFT 5
5011 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5012
5013 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5014
5015 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5016 index 102190a..5334cea 100644
5017 --- a/arch/frv/include/asm/atomic.h
5018 +++ b/arch/frv/include/asm/atomic.h
5019 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5020 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5021 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5022
5023 +#define atomic64_read_unchecked(v) atomic64_read(v)
5024 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5025 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5026 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5027 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5028 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5029 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5030 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5031 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5032 +
5033 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5034 {
5035 int c, old;
5036 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5037 index 2797163..c2a401df9 100644
5038 --- a/arch/frv/include/asm/cache.h
5039 +++ b/arch/frv/include/asm/cache.h
5040 @@ -12,10 +12,11 @@
5041 #ifndef __ASM_CACHE_H
5042 #define __ASM_CACHE_H
5043
5044 +#include <linux/const.h>
5045
5046 /* bytes per L1 cache line */
5047 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5048 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5049 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5050
5051 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5052 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5053 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5054 index 43901f2..0d8b865 100644
5055 --- a/arch/frv/include/asm/kmap_types.h
5056 +++ b/arch/frv/include/asm/kmap_types.h
5057 @@ -2,6 +2,6 @@
5058 #ifndef _ASM_KMAP_TYPES_H
5059 #define _ASM_KMAP_TYPES_H
5060
5061 -#define KM_TYPE_NR 17
5062 +#define KM_TYPE_NR 18
5063
5064 #endif
5065 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5066 index 836f147..4cf23f5 100644
5067 --- a/arch/frv/mm/elf-fdpic.c
5068 +++ b/arch/frv/mm/elf-fdpic.c
5069 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5070 {
5071 struct vm_area_struct *vma;
5072 struct vm_unmapped_area_info info;
5073 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5074
5075 if (len > TASK_SIZE)
5076 return -ENOMEM;
5077 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5078 if (addr) {
5079 addr = PAGE_ALIGN(addr);
5080 vma = find_vma(current->mm, addr);
5081 - if (TASK_SIZE - len >= addr &&
5082 - (!vma || addr + len <= vma->vm_start))
5083 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5084 goto success;
5085 }
5086
5087 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5088 info.high_limit = (current->mm->start_stack - 0x00200000);
5089 info.align_mask = 0;
5090 info.align_offset = 0;
5091 + info.threadstack_offset = offset;
5092 addr = vm_unmapped_area(&info);
5093 if (!(addr & ~PAGE_MASK))
5094 goto success;
5095 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5096 index 2635117..fa223cb 100644
5097 --- a/arch/hexagon/include/asm/cache.h
5098 +++ b/arch/hexagon/include/asm/cache.h
5099 @@ -21,9 +21,11 @@
5100 #ifndef __ASM_CACHE_H
5101 #define __ASM_CACHE_H
5102
5103 +#include <linux/const.h>
5104 +
5105 /* Bytes per L1 cache line */
5106 -#define L1_CACHE_SHIFT (5)
5107 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5108 +#define L1_CACHE_SHIFT 5
5109 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5110
5111 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5112 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5113 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5114 index c84c88b..2a6e1ba 100644
5115 --- a/arch/ia64/Kconfig
5116 +++ b/arch/ia64/Kconfig
5117 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5118 config KEXEC
5119 bool "kexec system call"
5120 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5121 + depends on !GRKERNSEC_KMEM
5122 help
5123 kexec is a system call that implements the ability to shutdown your
5124 current kernel, and to start another kernel. It is like a reboot
5125 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5126 index 5441b14..039a446 100644
5127 --- a/arch/ia64/Makefile
5128 +++ b/arch/ia64/Makefile
5129 @@ -99,5 +99,6 @@ endef
5130 archprepare: make_nr_irqs_h FORCE
5131 PHONY += make_nr_irqs_h FORCE
5132
5133 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5134 make_nr_irqs_h: FORCE
5135 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5136 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5137 index 0bf0350..2ad1957 100644
5138 --- a/arch/ia64/include/asm/atomic.h
5139 +++ b/arch/ia64/include/asm/atomic.h
5140 @@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5141 #define atomic64_inc(v) atomic64_add(1, (v))
5142 #define atomic64_dec(v) atomic64_sub(1, (v))
5143
5144 +#define atomic64_read_unchecked(v) atomic64_read(v)
5145 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5146 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5147 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5148 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5149 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5150 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5151 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5152 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5153 +
5154 #endif /* _ASM_IA64_ATOMIC_H */
5155 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5156 index a48957c..e097b56 100644
5157 --- a/arch/ia64/include/asm/barrier.h
5158 +++ b/arch/ia64/include/asm/barrier.h
5159 @@ -67,7 +67,7 @@
5160 do { \
5161 compiletime_assert_atomic_type(*p); \
5162 barrier(); \
5163 - ACCESS_ONCE(*p) = (v); \
5164 + ACCESS_ONCE_RW(*p) = (v); \
5165 } while (0)
5166
5167 #define smp_load_acquire(p) \
5168 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5169 index 988254a..e1ee885 100644
5170 --- a/arch/ia64/include/asm/cache.h
5171 +++ b/arch/ia64/include/asm/cache.h
5172 @@ -1,6 +1,7 @@
5173 #ifndef _ASM_IA64_CACHE_H
5174 #define _ASM_IA64_CACHE_H
5175
5176 +#include <linux/const.h>
5177
5178 /*
5179 * Copyright (C) 1998-2000 Hewlett-Packard Co
5180 @@ -9,7 +10,7 @@
5181
5182 /* Bytes per L1 (data) cache line. */
5183 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5184 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5185 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5186
5187 #ifdef CONFIG_SMP
5188 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5189 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5190 index 5a83c5c..4d7f553 100644
5191 --- a/arch/ia64/include/asm/elf.h
5192 +++ b/arch/ia64/include/asm/elf.h
5193 @@ -42,6 +42,13 @@
5194 */
5195 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5196
5197 +#ifdef CONFIG_PAX_ASLR
5198 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5199 +
5200 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5201 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5202 +#endif
5203 +
5204 #define PT_IA_64_UNWIND 0x70000001
5205
5206 /* IA-64 relocations: */
5207 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5208 index 5767cdf..7462574 100644
5209 --- a/arch/ia64/include/asm/pgalloc.h
5210 +++ b/arch/ia64/include/asm/pgalloc.h
5211 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5212 pgd_val(*pgd_entry) = __pa(pud);
5213 }
5214
5215 +static inline void
5216 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5217 +{
5218 + pgd_populate(mm, pgd_entry, pud);
5219 +}
5220 +
5221 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5222 {
5223 return quicklist_alloc(0, GFP_KERNEL, NULL);
5224 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5225 pud_val(*pud_entry) = __pa(pmd);
5226 }
5227
5228 +static inline void
5229 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5230 +{
5231 + pud_populate(mm, pud_entry, pmd);
5232 +}
5233 +
5234 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5235 {
5236 return quicklist_alloc(0, GFP_KERNEL, NULL);
5237 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5238 index 7935115..c0eca6a 100644
5239 --- a/arch/ia64/include/asm/pgtable.h
5240 +++ b/arch/ia64/include/asm/pgtable.h
5241 @@ -12,7 +12,7 @@
5242 * David Mosberger-Tang <davidm@hpl.hp.com>
5243 */
5244
5245 -
5246 +#include <linux/const.h>
5247 #include <asm/mman.h>
5248 #include <asm/page.h>
5249 #include <asm/processor.h>
5250 @@ -142,6 +142,17 @@
5251 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5252 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5253 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5254 +
5255 +#ifdef CONFIG_PAX_PAGEEXEC
5256 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5257 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5258 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5259 +#else
5260 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5261 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5262 +# define PAGE_COPY_NOEXEC PAGE_COPY
5263 +#endif
5264 +
5265 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5266 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5267 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5268 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5269 index 45698cd..e8e2dbc 100644
5270 --- a/arch/ia64/include/asm/spinlock.h
5271 +++ b/arch/ia64/include/asm/spinlock.h
5272 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5273 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5274
5275 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5276 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5277 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5278 }
5279
5280 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5281 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5282 index 449c8c0..3d4b1e9 100644
5283 --- a/arch/ia64/include/asm/uaccess.h
5284 +++ b/arch/ia64/include/asm/uaccess.h
5285 @@ -70,6 +70,7 @@
5286 && ((segment).seg == KERNEL_DS.seg \
5287 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5288 })
5289 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5290 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5291
5292 /*
5293 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5294 static inline unsigned long
5295 __copy_to_user (void __user *to, const void *from, unsigned long count)
5296 {
5297 + if (count > INT_MAX)
5298 + return count;
5299 +
5300 + if (!__builtin_constant_p(count))
5301 + check_object_size(from, count, true);
5302 +
5303 return __copy_user(to, (__force void __user *) from, count);
5304 }
5305
5306 static inline unsigned long
5307 __copy_from_user (void *to, const void __user *from, unsigned long count)
5308 {
5309 + if (count > INT_MAX)
5310 + return count;
5311 +
5312 + if (!__builtin_constant_p(count))
5313 + check_object_size(to, count, false);
5314 +
5315 return __copy_user((__force void __user *) to, from, count);
5316 }
5317
5318 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5319 ({ \
5320 void __user *__cu_to = (to); \
5321 const void *__cu_from = (from); \
5322 - long __cu_len = (n); \
5323 + unsigned long __cu_len = (n); \
5324 \
5325 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5326 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5327 + if (!__builtin_constant_p(n)) \
5328 + check_object_size(__cu_from, __cu_len, true); \
5329 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5330 + } \
5331 __cu_len; \
5332 })
5333
5334 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5335 ({ \
5336 void *__cu_to = (to); \
5337 const void __user *__cu_from = (from); \
5338 - long __cu_len = (n); \
5339 + unsigned long __cu_len = (n); \
5340 \
5341 __chk_user_ptr(__cu_from); \
5342 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5343 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5344 + if (!__builtin_constant_p(n)) \
5345 + check_object_size(__cu_to, __cu_len, false); \
5346 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5347 + } \
5348 __cu_len; \
5349 })
5350
5351 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5352 index 24603be..948052d 100644
5353 --- a/arch/ia64/kernel/module.c
5354 +++ b/arch/ia64/kernel/module.c
5355 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5356 void
5357 module_free (struct module *mod, void *module_region)
5358 {
5359 - if (mod && mod->arch.init_unw_table &&
5360 - module_region == mod->module_init) {
5361 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5362 unw_remove_unwind_table(mod->arch.init_unw_table);
5363 mod->arch.init_unw_table = NULL;
5364 }
5365 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5366 }
5367
5368 static inline int
5369 +in_init_rx (const struct module *mod, uint64_t addr)
5370 +{
5371 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5372 +}
5373 +
5374 +static inline int
5375 +in_init_rw (const struct module *mod, uint64_t addr)
5376 +{
5377 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5378 +}
5379 +
5380 +static inline int
5381 in_init (const struct module *mod, uint64_t addr)
5382 {
5383 - return addr - (uint64_t) mod->module_init < mod->init_size;
5384 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5385 +}
5386 +
5387 +static inline int
5388 +in_core_rx (const struct module *mod, uint64_t addr)
5389 +{
5390 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5391 +}
5392 +
5393 +static inline int
5394 +in_core_rw (const struct module *mod, uint64_t addr)
5395 +{
5396 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5397 }
5398
5399 static inline int
5400 in_core (const struct module *mod, uint64_t addr)
5401 {
5402 - return addr - (uint64_t) mod->module_core < mod->core_size;
5403 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5404 }
5405
5406 static inline int
5407 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5408 break;
5409
5410 case RV_BDREL:
5411 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5412 + if (in_init_rx(mod, val))
5413 + val -= (uint64_t) mod->module_init_rx;
5414 + else if (in_init_rw(mod, val))
5415 + val -= (uint64_t) mod->module_init_rw;
5416 + else if (in_core_rx(mod, val))
5417 + val -= (uint64_t) mod->module_core_rx;
5418 + else if (in_core_rw(mod, val))
5419 + val -= (uint64_t) mod->module_core_rw;
5420 break;
5421
5422 case RV_LTV:
5423 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5424 * addresses have been selected...
5425 */
5426 uint64_t gp;
5427 - if (mod->core_size > MAX_LTOFF)
5428 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5429 /*
5430 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5431 * at the end of the module.
5432 */
5433 - gp = mod->core_size - MAX_LTOFF / 2;
5434 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5435 else
5436 - gp = mod->core_size / 2;
5437 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5438 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5439 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5440 mod->arch.gp = gp;
5441 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5442 }
5443 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5444 index c39c3cd..3c77738 100644
5445 --- a/arch/ia64/kernel/palinfo.c
5446 +++ b/arch/ia64/kernel/palinfo.c
5447 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5448 return NOTIFY_OK;
5449 }
5450
5451 -static struct notifier_block __refdata palinfo_cpu_notifier =
5452 +static struct notifier_block palinfo_cpu_notifier =
5453 {
5454 .notifier_call = palinfo_cpu_callback,
5455 .priority = 0,
5456 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5457 index 41e33f8..65180b2a 100644
5458 --- a/arch/ia64/kernel/sys_ia64.c
5459 +++ b/arch/ia64/kernel/sys_ia64.c
5460 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5461 unsigned long align_mask = 0;
5462 struct mm_struct *mm = current->mm;
5463 struct vm_unmapped_area_info info;
5464 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5465
5466 if (len > RGN_MAP_LIMIT)
5467 return -ENOMEM;
5468 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5469 if (REGION_NUMBER(addr) == RGN_HPAGE)
5470 addr = 0;
5471 #endif
5472 +
5473 +#ifdef CONFIG_PAX_RANDMMAP
5474 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5475 + addr = mm->free_area_cache;
5476 + else
5477 +#endif
5478 +
5479 if (!addr)
5480 addr = TASK_UNMAPPED_BASE;
5481
5482 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5483 info.high_limit = TASK_SIZE;
5484 info.align_mask = align_mask;
5485 info.align_offset = 0;
5486 + info.threadstack_offset = offset;
5487 return vm_unmapped_area(&info);
5488 }
5489
5490 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5491 index 84f8a52..7c76178 100644
5492 --- a/arch/ia64/kernel/vmlinux.lds.S
5493 +++ b/arch/ia64/kernel/vmlinux.lds.S
5494 @@ -192,7 +192,7 @@ SECTIONS {
5495 /* Per-cpu data: */
5496 . = ALIGN(PERCPU_PAGE_SIZE);
5497 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5498 - __phys_per_cpu_start = __per_cpu_load;
5499 + __phys_per_cpu_start = per_cpu_load;
5500 /*
5501 * ensure percpu data fits
5502 * into percpu page size
5503 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5504 index ba5ba7a..36e9d3a 100644
5505 --- a/arch/ia64/mm/fault.c
5506 +++ b/arch/ia64/mm/fault.c
5507 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5508 return pte_present(pte);
5509 }
5510
5511 +#ifdef CONFIG_PAX_PAGEEXEC
5512 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5513 +{
5514 + unsigned long i;
5515 +
5516 + printk(KERN_ERR "PAX: bytes at PC: ");
5517 + for (i = 0; i < 8; i++) {
5518 + unsigned int c;
5519 + if (get_user(c, (unsigned int *)pc+i))
5520 + printk(KERN_CONT "???????? ");
5521 + else
5522 + printk(KERN_CONT "%08x ", c);
5523 + }
5524 + printk("\n");
5525 +}
5526 +#endif
5527 +
5528 # define VM_READ_BIT 0
5529 # define VM_WRITE_BIT 1
5530 # define VM_EXEC_BIT 2
5531 @@ -151,8 +168,21 @@ retry:
5532 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5533 goto bad_area;
5534
5535 - if ((vma->vm_flags & mask) != mask)
5536 + if ((vma->vm_flags & mask) != mask) {
5537 +
5538 +#ifdef CONFIG_PAX_PAGEEXEC
5539 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5540 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5541 + goto bad_area;
5542 +
5543 + up_read(&mm->mmap_sem);
5544 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5545 + do_group_exit(SIGKILL);
5546 + }
5547 +#endif
5548 +
5549 goto bad_area;
5550 + }
5551
5552 /*
5553 * If for any reason at all we couldn't handle the fault, make
5554 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5555 index 76069c1..c2aa816 100644
5556 --- a/arch/ia64/mm/hugetlbpage.c
5557 +++ b/arch/ia64/mm/hugetlbpage.c
5558 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5559 unsigned long pgoff, unsigned long flags)
5560 {
5561 struct vm_unmapped_area_info info;
5562 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5563
5564 if (len > RGN_MAP_LIMIT)
5565 return -ENOMEM;
5566 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5567 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5568 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5569 info.align_offset = 0;
5570 + info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5575 index 6b33457..88b5124 100644
5576 --- a/arch/ia64/mm/init.c
5577 +++ b/arch/ia64/mm/init.c
5578 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5579 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5580 vma->vm_end = vma->vm_start + PAGE_SIZE;
5581 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5582 +
5583 +#ifdef CONFIG_PAX_PAGEEXEC
5584 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5585 + vma->vm_flags &= ~VM_EXEC;
5586 +
5587 +#ifdef CONFIG_PAX_MPROTECT
5588 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5589 + vma->vm_flags &= ~VM_MAYEXEC;
5590 +#endif
5591 +
5592 + }
5593 +#endif
5594 +
5595 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5596 down_write(&current->mm->mmap_sem);
5597 if (insert_vm_struct(current->mm, vma)) {
5598 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5599 gate_vma.vm_start = FIXADDR_USER_START;
5600 gate_vma.vm_end = FIXADDR_USER_END;
5601 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5602 - gate_vma.vm_page_prot = __P101;
5603 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5604
5605 return 0;
5606 }
5607 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5608 index 40b3ee9..8c2c112 100644
5609 --- a/arch/m32r/include/asm/cache.h
5610 +++ b/arch/m32r/include/asm/cache.h
5611 @@ -1,8 +1,10 @@
5612 #ifndef _ASM_M32R_CACHE_H
5613 #define _ASM_M32R_CACHE_H
5614
5615 +#include <linux/const.h>
5616 +
5617 /* L1 cache line size */
5618 #define L1_CACHE_SHIFT 4
5619 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5620 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5621
5622 #endif /* _ASM_M32R_CACHE_H */
5623 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5624 index 82abd15..d95ae5d 100644
5625 --- a/arch/m32r/lib/usercopy.c
5626 +++ b/arch/m32r/lib/usercopy.c
5627 @@ -14,6 +14,9 @@
5628 unsigned long
5629 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5630 {
5631 + if ((long)n < 0)
5632 + return n;
5633 +
5634 prefetch(from);
5635 if (access_ok(VERIFY_WRITE, to, n))
5636 __copy_user(to,from,n);
5637 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5638 unsigned long
5639 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5640 {
5641 + if ((long)n < 0)
5642 + return n;
5643 +
5644 prefetchw(to);
5645 if (access_ok(VERIFY_READ, from, n))
5646 __copy_user_zeroing(to,from,n);
5647 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5648 index 0395c51..5f26031 100644
5649 --- a/arch/m68k/include/asm/cache.h
5650 +++ b/arch/m68k/include/asm/cache.h
5651 @@ -4,9 +4,11 @@
5652 #ifndef __ARCH_M68K_CACHE_H
5653 #define __ARCH_M68K_CACHE_H
5654
5655 +#include <linux/const.h>
5656 +
5657 /* bytes per L1 cache line */
5658 #define L1_CACHE_SHIFT 4
5659 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5661
5662 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5663
5664 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5665 index c7591e8..ecef036 100644
5666 --- a/arch/metag/include/asm/barrier.h
5667 +++ b/arch/metag/include/asm/barrier.h
5668 @@ -89,7 +89,7 @@ static inline void fence(void)
5669 do { \
5670 compiletime_assert_atomic_type(*p); \
5671 smp_mb(); \
5672 - ACCESS_ONCE(*p) = (v); \
5673 + ACCESS_ONCE_RW(*p) = (v); \
5674 } while (0)
5675
5676 #define smp_load_acquire(p) \
5677 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5678 index 3c32075..ae0ae75 100644
5679 --- a/arch/metag/mm/hugetlbpage.c
5680 +++ b/arch/metag/mm/hugetlbpage.c
5681 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5682 info.high_limit = TASK_SIZE;
5683 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5684 info.align_offset = 0;
5685 + info.threadstack_offset = 0;
5686 return vm_unmapped_area(&info);
5687 }
5688
5689 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5690 index 4efe96a..60e8699 100644
5691 --- a/arch/microblaze/include/asm/cache.h
5692 +++ b/arch/microblaze/include/asm/cache.h
5693 @@ -13,11 +13,12 @@
5694 #ifndef _ASM_MICROBLAZE_CACHE_H
5695 #define _ASM_MICROBLAZE_CACHE_H
5696
5697 +#include <linux/const.h>
5698 #include <asm/registers.h>
5699
5700 #define L1_CACHE_SHIFT 5
5701 /* word-granular cache in microblaze */
5702 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5703 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5704
5705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5706
5707 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5708 index 9536ef9..9333776 100644
5709 --- a/arch/mips/Kconfig
5710 +++ b/arch/mips/Kconfig
5711 @@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5712
5713 config KEXEC
5714 bool "Kexec system call"
5715 + depends on !GRKERNSEC_KMEM
5716 help
5717 kexec is a system call that implements the ability to shutdown your
5718 current kernel, and to start another kernel. It is like a reboot
5719 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5720 index 02f2444..506969c 100644
5721 --- a/arch/mips/cavium-octeon/dma-octeon.c
5722 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5723 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5724 if (dma_release_from_coherent(dev, order, vaddr))
5725 return;
5726
5727 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5728 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5729 }
5730
5731 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5732 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5733 index 6dd6bfc..903b0d6 100644
5734 --- a/arch/mips/include/asm/atomic.h
5735 +++ b/arch/mips/include/asm/atomic.h
5736 @@ -21,15 +21,39 @@
5737 #include <asm/cmpxchg.h>
5738 #include <asm/war.h>
5739
5740 +#ifdef CONFIG_GENERIC_ATOMIC64
5741 +#include <asm-generic/atomic64.h>
5742 +#endif
5743 +
5744 #define ATOMIC_INIT(i) { (i) }
5745
5746 +#ifdef CONFIG_64BIT
5747 +#define _ASM_EXTABLE(from, to) \
5748 +" .section __ex_table,\"a\"\n" \
5749 +" .dword " #from ", " #to"\n" \
5750 +" .previous\n"
5751 +#else
5752 +#define _ASM_EXTABLE(from, to) \
5753 +" .section __ex_table,\"a\"\n" \
5754 +" .word " #from ", " #to"\n" \
5755 +" .previous\n"
5756 +#endif
5757 +
5758 /*
5759 * atomic_read - read atomic variable
5760 * @v: pointer of type atomic_t
5761 *
5762 * Atomically reads the value of @v.
5763 */
5764 -#define atomic_read(v) ACCESS_ONCE((v)->counter)
5765 +static inline int atomic_read(const atomic_t *v)
5766 +{
5767 + return ACCESS_ONCE(v->counter);
5768 +}
5769 +
5770 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5771 +{
5772 + return ACCESS_ONCE(v->counter);
5773 +}
5774
5775 /*
5776 * atomic_set - set atomic variable
5777 @@ -38,47 +62,77 @@
5778 *
5779 * Atomically sets the value of @v to @i.
5780 */
5781 -#define atomic_set(v, i) ((v)->counter = (i))
5782 +static inline void atomic_set(atomic_t *v, int i)
5783 +{
5784 + v->counter = i;
5785 +}
5786
5787 -#define ATOMIC_OP(op, c_op, asm_op) \
5788 -static __inline__ void atomic_##op(int i, atomic_t * v) \
5789 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5790 +{
5791 + v->counter = i;
5792 +}
5793 +
5794 +#ifdef CONFIG_PAX_REFCOUNT
5795 +#define __OVERFLOW_POST \
5796 + " b 4f \n" \
5797 + " .set noreorder \n" \
5798 + "3: b 5f \n" \
5799 + " move %0, %1 \n" \
5800 + " .set reorder \n"
5801 +#define __OVERFLOW_EXTABLE \
5802 + "3:\n" \
5803 + _ASM_EXTABLE(2b, 3b)
5804 +#else
5805 +#define __OVERFLOW_POST
5806 +#define __OVERFLOW_EXTABLE
5807 +#endif
5808 +
5809 +#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5810 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5811 { \
5812 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5813 int temp; \
5814 \
5815 __asm__ __volatile__( \
5816 - " .set arch=r4000 \n" \
5817 - "1: ll %0, %1 # atomic_" #op " \n" \
5818 - " " #asm_op " %0, %2 \n" \
5819 + " .set mips3 \n" \
5820 + "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5821 + "2: " #asm_op " %0, %2 \n" \
5822 " sc %0, %1 \n" \
5823 " beqzl %0, 1b \n" \
5824 + extable \
5825 " .set mips0 \n" \
5826 : "=&r" (temp), "+m" (v->counter) \
5827 : "Ir" (i)); \
5828 } else if (kernel_uses_llsc) { \
5829 int temp; \
5830 \
5831 - do { \
5832 - __asm__ __volatile__( \
5833 - " .set arch=r4000 \n" \
5834 - " ll %0, %1 # atomic_" #op "\n" \
5835 - " " #asm_op " %0, %2 \n" \
5836 - " sc %0, %1 \n" \
5837 - " .set mips0 \n" \
5838 - : "=&r" (temp), "+m" (v->counter) \
5839 - : "Ir" (i)); \
5840 - } while (unlikely(!temp)); \
5841 + __asm__ __volatile__( \
5842 + " .set mips3 \n" \
5843 + " ll %0, %1 # atomic_" #op #suffix "\n" \
5844 + "2: " #asm_op " %0, %2 \n" \
5845 + " sc %0, %1 \n" \
5846 + " beqz %0, 1b \n" \
5847 + extable \
5848 + " .set mips0 \n" \
5849 + : "=&r" (temp), "+m" (v->counter) \
5850 + : "Ir" (i)); \
5851 } else { \
5852 unsigned long flags; \
5853 \
5854 raw_local_irq_save(flags); \
5855 - v->counter c_op i; \
5856 + __asm__ __volatile__( \
5857 + "2: " #asm_op " %0, %1 \n" \
5858 + extable \
5859 + : "+r" (v->counter) : "Ir" (i)); \
5860 raw_local_irq_restore(flags); \
5861 } \
5862 } \
5863
5864 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5865 -static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5866 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5867 + __ATOMIC_OP(op, _unchecked, asm_op)
5868 +
5869 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5870 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5871 { \
5872 int result; \
5873 \
5874 @@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5875 int temp; \
5876 \
5877 __asm__ __volatile__( \
5878 - " .set arch=r4000 \n" \
5879 - "1: ll %1, %2 # atomic_" #op "_return \n" \
5880 - " " #asm_op " %0, %1, %3 \n" \
5881 + " .set mips3 \n" \
5882 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5883 + "2: " #asm_op " %0, %1, %3 \n" \
5884 " sc %0, %2 \n" \
5885 " beqzl %0, 1b \n" \
5886 - " " #asm_op " %0, %1, %3 \n" \
5887 + post_op \
5888 + extable \
5889 + "4: " #asm_op " %0, %1, %3 \n" \
5890 + "5: \n" \
5891 " .set mips0 \n" \
5892 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5893 : "Ir" (i)); \
5894 } else if (kernel_uses_llsc) { \
5895 int temp; \
5896 \
5897 - do { \
5898 - __asm__ __volatile__( \
5899 - " .set arch=r4000 \n" \
5900 - " ll %1, %2 # atomic_" #op "_return \n" \
5901 - " " #asm_op " %0, %1, %3 \n" \
5902 - " sc %0, %2 \n" \
5903 - " .set mips0 \n" \
5904 - : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5905 - : "Ir" (i)); \
5906 - } while (unlikely(!result)); \
5907 + __asm__ __volatile__( \
5908 + " .set mips3 \n" \
5909 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5910 + "2: " #asm_op " %0, %1, %3 \n" \
5911 + " sc %0, %2 \n" \
5912 + " beqz %0, 1b \n" \
5913 + post_op \
5914 + extable \
5915 + "4: " #asm_op " %0, %1, %3 \n" \
5916 + "5: \n" \
5917 + " .set mips0 \n" \
5918 + : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5919 + : "Ir" (i)); \
5920 \
5921 result = temp; result c_op i; \
5922 } else { \
5923 unsigned long flags; \
5924 \
5925 raw_local_irq_save(flags); \
5926 - result = v->counter; \
5927 - result c_op i; \
5928 - v->counter = result; \
5929 + __asm__ __volatile__( \
5930 + " lw %0, %1 \n" \
5931 + "2: " #asm_op " %0, %1, %2 \n" \
5932 + " sw %0, %1 \n" \
5933 + "3: \n" \
5934 + extable \
5935 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5936 raw_local_irq_restore(flags); \
5937 } \
5938 \
5939 @@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5940 return result; \
5941 }
5942
5943 -#define ATOMIC_OPS(op, c_op, asm_op) \
5944 - ATOMIC_OP(op, c_op, asm_op) \
5945 - ATOMIC_OP_RETURN(op, c_op, asm_op)
5946 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5947 + __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5948
5949 -ATOMIC_OPS(add, +=, addu)
5950 -ATOMIC_OPS(sub, -=, subu)
5951 +#define ATOMIC_OPS(op, asm_op) \
5952 + ATOMIC_OP(op, asm_op) \
5953 + ATOMIC_OP_RETURN(op, asm_op)
5954 +
5955 +ATOMIC_OPS(add, add)
5956 +ATOMIC_OPS(sub, sub)
5957
5958 #undef ATOMIC_OPS
5959 #undef ATOMIC_OP_RETURN
5960 +#undef __ATOMIC_OP_RETURN
5961 #undef ATOMIC_OP
5962 +#undef __ATOMIC_OP
5963
5964 /*
5965 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5966 @@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5967 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5968 * The function returns the old value of @v minus @i.
5969 */
5970 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5971 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5972 {
5973 int result;
5974
5975 @@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5976 return result;
5977 }
5978
5979 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5980 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5981 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5982 +{
5983 + return cmpxchg(&v->counter, old, new);
5984 +}
5985 +
5986 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5987 + int new)
5988 +{
5989 + return cmpxchg(&(v->counter), old, new);
5990 +}
5991 +
5992 +static inline int atomic_xchg(atomic_t *v, int new)
5993 +{
5994 + return xchg(&v->counter, new);
5995 +}
5996 +
5997 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5998 +{
5999 + return xchg(&(v->counter), new);
6000 +}
6001
6002 /**
6003 * __atomic_add_unless - add unless the number is a given value
6004 @@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005
6006 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6007 #define atomic_inc_return(v) atomic_add_return(1, (v))
6008 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6009 +{
6010 + return atomic_add_return_unchecked(1, v);
6011 +}
6012
6013 /*
6014 * atomic_sub_and_test - subtract value from variable and test result
6015 @@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * other cases.
6017 */
6018 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6019 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6020 +{
6021 + return atomic_add_return_unchecked(1, v) == 0;
6022 +}
6023
6024 /*
6025 * atomic_dec_and_test - decrement by 1 and test
6026 @@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * Atomically increments @v by 1.
6028 */
6029 #define atomic_inc(v) atomic_add(1, (v))
6030 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6031 +{
6032 + atomic_add_unchecked(1, v);
6033 +}
6034
6035 /*
6036 * atomic_dec - decrement and test
6037 @@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6038 * Atomically decrements @v by 1.
6039 */
6040 #define atomic_dec(v) atomic_sub(1, (v))
6041 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6042 +{
6043 + atomic_sub_unchecked(1, v);
6044 +}
6045
6046 /*
6047 * atomic_add_negative - add and test if negative
6048 @@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6049 * @v: pointer of type atomic64_t
6050 *
6051 */
6052 -#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6053 +static inline long atomic64_read(const atomic64_t *v)
6054 +{
6055 + return ACCESS_ONCE(v->counter);
6056 +}
6057 +
6058 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6059 +{
6060 + return ACCESS_ONCE(v->counter);
6061 +}
6062
6063 /*
6064 * atomic64_set - set atomic variable
6065 * @v: pointer of type atomic64_t
6066 * @i: required value
6067 */
6068 -#define atomic64_set(v, i) ((v)->counter = (i))
6069 +static inline void atomic64_set(atomic64_t *v, long i)
6070 +{
6071 + v->counter = i;
6072 +}
6073
6074 -#define ATOMIC64_OP(op, c_op, asm_op) \
6075 -static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6076 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6077 +{
6078 + v->counter = i;
6079 +}
6080 +
6081 +#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6082 +static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6083 { \
6084 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6085 long temp; \
6086 \
6087 __asm__ __volatile__( \
6088 - " .set arch=r4000 \n" \
6089 - "1: lld %0, %1 # atomic64_" #op " \n" \
6090 - " " #asm_op " %0, %2 \n" \
6091 + " .set mips3 \n" \
6092 + "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6093 + "2: " #asm_op " %0, %2 \n" \
6094 " scd %0, %1 \n" \
6095 " beqzl %0, 1b \n" \
6096 + extable \
6097 " .set mips0 \n" \
6098 : "=&r" (temp), "+m" (v->counter) \
6099 : "Ir" (i)); \
6100 } else if (kernel_uses_llsc) { \
6101 long temp; \
6102 \
6103 - do { \
6104 - __asm__ __volatile__( \
6105 - " .set arch=r4000 \n" \
6106 - " lld %0, %1 # atomic64_" #op "\n" \
6107 - " " #asm_op " %0, %2 \n" \
6108 - " scd %0, %1 \n" \
6109 - " .set mips0 \n" \
6110 - : "=&r" (temp), "+m" (v->counter) \
6111 - : "Ir" (i)); \
6112 - } while (unlikely(!temp)); \
6113 + __asm__ __volatile__( \
6114 + " .set mips3 \n" \
6115 + " lld %0, %1 # atomic64_" #op #suffix "\n" \
6116 + "2: " #asm_op " %0, %2 \n" \
6117 + " scd %0, %1 \n" \
6118 + " beqz %0, 1b \n" \
6119 + extable \
6120 + " .set mips0 \n" \
6121 + : "=&r" (temp), "+m" (v->counter) \
6122 + : "Ir" (i)); \
6123 } else { \
6124 unsigned long flags; \
6125 \
6126 raw_local_irq_save(flags); \
6127 - v->counter c_op i; \
6128 + __asm__ __volatile__( \
6129 + "2: " #asm_op " %0, %1 \n" \
6130 + extable \
6131 + : "+r" (v->counter) : "Ir" (i)); \
6132 raw_local_irq_restore(flags); \
6133 } \
6134 } \
6135
6136 -#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6137 -static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6138 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6139 + __ATOMIC64_OP(op, _unchecked, asm_op)
6140 +
6141 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6142 +static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6143 { \
6144 long result; \
6145 \
6146 @@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6147 long temp; \
6148 \
6149 __asm__ __volatile__( \
6150 - " .set arch=r4000 \n" \
6151 + " .set mips3 \n" \
6152 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6153 - " " #asm_op " %0, %1, %3 \n" \
6154 + "2: " #asm_op " %0, %1, %3 \n" \
6155 " scd %0, %2 \n" \
6156 " beqzl %0, 1b \n" \
6157 - " " #asm_op " %0, %1, %3 \n" \
6158 + post_op \
6159 + extable \
6160 + "4: " #asm_op " %0, %1, %3 \n" \
6161 + "5: \n" \
6162 " .set mips0 \n" \
6163 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6164 : "Ir" (i)); \
6165 } else if (kernel_uses_llsc) { \
6166 long temp; \
6167 \
6168 - do { \
6169 - __asm__ __volatile__( \
6170 - " .set arch=r4000 \n" \
6171 - " lld %1, %2 # atomic64_" #op "_return\n" \
6172 - " " #asm_op " %0, %1, %3 \n" \
6173 - " scd %0, %2 \n" \
6174 - " .set mips0 \n" \
6175 - : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6176 - : "Ir" (i), "m" (v->counter) \
6177 - : "memory"); \
6178 - } while (unlikely(!result)); \
6179 + __asm__ __volatile__( \
6180 + " .set mips3 \n" \
6181 + "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6182 + "2: " #asm_op " %0, %1, %3 \n" \
6183 + " scd %0, %2 \n" \
6184 + " beqz %0, 1b \n" \
6185 + post_op \
6186 + extable \
6187 + "4: " #asm_op " %0, %1, %3 \n" \
6188 + "5: \n" \
6189 + " .set mips0 \n" \
6190 + : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6191 + : "Ir" (i), "m" (v->counter) \
6192 + : "memory"); \
6193 \
6194 result = temp; result c_op i; \
6195 } else { \
6196 unsigned long flags; \
6197 \
6198 raw_local_irq_save(flags); \
6199 - result = v->counter; \
6200 - result c_op i; \
6201 - v->counter = result; \
6202 + __asm__ __volatile__( \
6203 + " ld %0, %1 \n" \
6204 + "2: " #asm_op " %0, %1, %2 \n" \
6205 + " sd %0, %1 \n" \
6206 + "3: \n" \
6207 + extable \
6208 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6209 raw_local_irq_restore(flags); \
6210 } \
6211 \
6212 @@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6213 return result; \
6214 }
6215
6216 -#define ATOMIC64_OPS(op, c_op, asm_op) \
6217 - ATOMIC64_OP(op, c_op, asm_op) \
6218 - ATOMIC64_OP_RETURN(op, c_op, asm_op)
6219 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6220 + __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6221
6222 -ATOMIC64_OPS(add, +=, daddu)
6223 -ATOMIC64_OPS(sub, -=, dsubu)
6224 +#define ATOMIC64_OPS(op, asm_op) \
6225 + ATOMIC64_OP(op, asm_op) \
6226 + ATOMIC64_OP_RETURN(op, asm_op)
6227 +
6228 +ATOMIC64_OPS(add, dadd)
6229 +ATOMIC64_OPS(sub, dsub)
6230
6231 #undef ATOMIC64_OPS
6232 #undef ATOMIC64_OP_RETURN
6233 +#undef __ATOMIC64_OP_RETURN
6234 #undef ATOMIC64_OP
6235 +#undef __ATOMIC64_OP
6236 +#undef __OVERFLOW_EXTABLE
6237 +#undef __OVERFLOW_POST
6238
6239 /*
6240 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6241 @@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6242 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6243 * The function returns the old value of @v minus @i.
6244 */
6245 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6246 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6247 {
6248 long result;
6249
6250 @@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6251 return result;
6252 }
6253
6254 -#define atomic64_cmpxchg(v, o, n) \
6255 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6256 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6257 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6258 +{
6259 + return cmpxchg(&v->counter, old, new);
6260 +}
6261 +
6262 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6263 + long new)
6264 +{
6265 + return cmpxchg(&(v->counter), old, new);
6266 +}
6267 +
6268 +static inline long atomic64_xchg(atomic64_t *v, long new)
6269 +{
6270 + return xchg(&v->counter, new);
6271 +}
6272 +
6273 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6274 +{
6275 + return xchg(&(v->counter), new);
6276 +}
6277
6278 /**
6279 * atomic64_add_unless - add unless the number is a given value
6280 @@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6281
6282 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6283 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6284 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6285
6286 /*
6287 * atomic64_sub_and_test - subtract value from variable and test result
6288 @@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6289 * other cases.
6290 */
6291 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6292 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6293
6294 /*
6295 * atomic64_dec_and_test - decrement by 1 and test
6296 @@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6297 * Atomically increments @v by 1.
6298 */
6299 #define atomic64_inc(v) atomic64_add(1, (v))
6300 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6301
6302 /*
6303 * atomic64_dec - decrement and test
6304 @@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6305 * Atomically decrements @v by 1.
6306 */
6307 #define atomic64_dec(v) atomic64_sub(1, (v))
6308 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6309
6310 /*
6311 * atomic64_add_negative - add and test if negative
6312 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6313 index d0101dd..266982c 100644
6314 --- a/arch/mips/include/asm/barrier.h
6315 +++ b/arch/mips/include/asm/barrier.h
6316 @@ -184,7 +184,7 @@
6317 do { \
6318 compiletime_assert_atomic_type(*p); \
6319 smp_mb(); \
6320 - ACCESS_ONCE(*p) = (v); \
6321 + ACCESS_ONCE_RW(*p) = (v); \
6322 } while (0)
6323
6324 #define smp_load_acquire(p) \
6325 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6326 index b4db69f..8f3b093 100644
6327 --- a/arch/mips/include/asm/cache.h
6328 +++ b/arch/mips/include/asm/cache.h
6329 @@ -9,10 +9,11 @@
6330 #ifndef _ASM_CACHE_H
6331 #define _ASM_CACHE_H
6332
6333 +#include <linux/const.h>
6334 #include <kmalloc.h>
6335
6336 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6337 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6338 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6339
6340 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6341 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6342 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6343 index 1d38fe0..9beabc9 100644
6344 --- a/arch/mips/include/asm/elf.h
6345 +++ b/arch/mips/include/asm/elf.h
6346 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6347 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6348 #endif
6349
6350 +#ifdef CONFIG_PAX_ASLR
6351 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6352 +
6353 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6354 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6355 +#endif
6356 +
6357 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6358 struct linux_binprm;
6359 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6360 int uses_interp);
6361
6362 -struct mm_struct;
6363 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6364 -#define arch_randomize_brk arch_randomize_brk
6365 -
6366 #endif /* _ASM_ELF_H */
6367 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6368 index c1f6afa..38cc6e9 100644
6369 --- a/arch/mips/include/asm/exec.h
6370 +++ b/arch/mips/include/asm/exec.h
6371 @@ -12,6 +12,6 @@
6372 #ifndef _ASM_EXEC_H
6373 #define _ASM_EXEC_H
6374
6375 -extern unsigned long arch_align_stack(unsigned long sp);
6376 +#define arch_align_stack(x) ((x) & ~0xfUL)
6377
6378 #endif /* _ASM_EXEC_H */
6379 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6380 index 9e8ef59..1139d6b 100644
6381 --- a/arch/mips/include/asm/hw_irq.h
6382 +++ b/arch/mips/include/asm/hw_irq.h
6383 @@ -10,7 +10,7 @@
6384
6385 #include <linux/atomic.h>
6386
6387 -extern atomic_t irq_err_count;
6388 +extern atomic_unchecked_t irq_err_count;
6389
6390 /*
6391 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6392 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6393 index 46dfc3c..a16b13a 100644
6394 --- a/arch/mips/include/asm/local.h
6395 +++ b/arch/mips/include/asm/local.h
6396 @@ -12,15 +12,25 @@ typedef struct
6397 atomic_long_t a;
6398 } local_t;
6399
6400 +typedef struct {
6401 + atomic_long_unchecked_t a;
6402 +} local_unchecked_t;
6403 +
6404 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6405
6406 #define local_read(l) atomic_long_read(&(l)->a)
6407 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6408 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6409 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6410
6411 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6412 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6413 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6414 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6415 #define local_inc(l) atomic_long_inc(&(l)->a)
6416 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6417 #define local_dec(l) atomic_long_dec(&(l)->a)
6418 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6419
6420 /*
6421 * Same as above, but return the result value
6422 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6423 return result;
6424 }
6425
6426 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6427 +{
6428 + unsigned long result;
6429 +
6430 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6431 + unsigned long temp;
6432 +
6433 + __asm__ __volatile__(
6434 + " .set mips3 \n"
6435 + "1:" __LL "%1, %2 # local_add_return \n"
6436 + " addu %0, %1, %3 \n"
6437 + __SC "%0, %2 \n"
6438 + " beqzl %0, 1b \n"
6439 + " addu %0, %1, %3 \n"
6440 + " .set mips0 \n"
6441 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6442 + : "Ir" (i), "m" (l->a.counter)
6443 + : "memory");
6444 + } else if (kernel_uses_llsc) {
6445 + unsigned long temp;
6446 +
6447 + __asm__ __volatile__(
6448 + " .set mips3 \n"
6449 + "1:" __LL "%1, %2 # local_add_return \n"
6450 + " addu %0, %1, %3 \n"
6451 + __SC "%0, %2 \n"
6452 + " beqz %0, 1b \n"
6453 + " addu %0, %1, %3 \n"
6454 + " .set mips0 \n"
6455 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6456 + : "Ir" (i), "m" (l->a.counter)
6457 + : "memory");
6458 + } else {
6459 + unsigned long flags;
6460 +
6461 + local_irq_save(flags);
6462 + result = l->a.counter;
6463 + result += i;
6464 + l->a.counter = result;
6465 + local_irq_restore(flags);
6466 + }
6467 +
6468 + return result;
6469 +}
6470 +
6471 static __inline__ long local_sub_return(long i, local_t * l)
6472 {
6473 unsigned long result;
6474 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6475
6476 #define local_cmpxchg(l, o, n) \
6477 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6478 +#define local_cmpxchg_unchecked(l, o, n) \
6479 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6480 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6481
6482 /**
6483 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6484 index 3be8180..c4798d5 100644
6485 --- a/arch/mips/include/asm/page.h
6486 +++ b/arch/mips/include/asm/page.h
6487 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6488 #ifdef CONFIG_CPU_MIPS32
6489 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6490 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6491 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6492 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6493 #else
6494 typedef struct { unsigned long long pte; } pte_t;
6495 #define pte_val(x) ((x).pte)
6496 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6497 index b336037..5b874cc 100644
6498 --- a/arch/mips/include/asm/pgalloc.h
6499 +++ b/arch/mips/include/asm/pgalloc.h
6500 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6501 {
6502 set_pud(pud, __pud((unsigned long)pmd));
6503 }
6504 +
6505 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6506 +{
6507 + pud_populate(mm, pud, pmd);
6508 +}
6509 #endif
6510
6511 /*
6512 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6513 index d6d1928..ce4f822 100644
6514 --- a/arch/mips/include/asm/pgtable.h
6515 +++ b/arch/mips/include/asm/pgtable.h
6516 @@ -20,6 +20,9 @@
6517 #include <asm/io.h>
6518 #include <asm/pgtable-bits.h>
6519
6520 +#define ktla_ktva(addr) (addr)
6521 +#define ktva_ktla(addr) (addr)
6522 +
6523 struct mm_struct;
6524 struct vm_area_struct;
6525
6526 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6527 index 7de8658..c109224 100644
6528 --- a/arch/mips/include/asm/thread_info.h
6529 +++ b/arch/mips/include/asm/thread_info.h
6530 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6531 #define TIF_SECCOMP 4 /* secure computing */
6532 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6533 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6534 +/* li takes a 32bit immediate */
6535 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6536 +
6537 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6538 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6539 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6540 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6541 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6542 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6543 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6544 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6545
6546 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6547 _TIF_SYSCALL_AUDIT | \
6548 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6549 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6550 + _TIF_GRSEC_SETXID)
6551
6552 /* work to do in syscall_trace_leave() */
6553 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6554 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6555 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6556
6557 /* work to do on interrupt/exception return */
6558 #define _TIF_WORK_MASK \
6559 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6560 /* work to do on any return to u-space */
6561 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6562 _TIF_WORK_SYSCALL_EXIT | \
6563 - _TIF_SYSCALL_TRACEPOINT)
6564 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6565
6566 /*
6567 * We stash processor id into a COP0 register to retrieve it fast
6568 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6569 index 22a5624..7c96295 100644
6570 --- a/arch/mips/include/asm/uaccess.h
6571 +++ b/arch/mips/include/asm/uaccess.h
6572 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6573 __ok == 0; \
6574 })
6575
6576 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6577 #define access_ok(type, addr, size) \
6578 likely(__access_ok((addr), (size), __access_mask))
6579
6580 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6581 index 1188e00..41cf144 100644
6582 --- a/arch/mips/kernel/binfmt_elfn32.c
6583 +++ b/arch/mips/kernel/binfmt_elfn32.c
6584 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6585 #undef ELF_ET_DYN_BASE
6586 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6587
6588 +#ifdef CONFIG_PAX_ASLR
6589 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6590 +
6591 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6592 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6593 +#endif
6594 +
6595 #include <asm/processor.h>
6596 #include <linux/module.h>
6597 #include <linux/elfcore.h>
6598 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6599 index 9287678..f870e47 100644
6600 --- a/arch/mips/kernel/binfmt_elfo32.c
6601 +++ b/arch/mips/kernel/binfmt_elfo32.c
6602 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6603 #undef ELF_ET_DYN_BASE
6604 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6605
6606 +#ifdef CONFIG_PAX_ASLR
6607 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6608 +
6609 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6610 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6611 +#endif
6612 +
6613 #include <asm/processor.h>
6614
6615 #include <linux/module.h>
6616 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6617 index 50b3648..c2f3cec 100644
6618 --- a/arch/mips/kernel/i8259.c
6619 +++ b/arch/mips/kernel/i8259.c
6620 @@ -201,7 +201,7 @@ spurious_8259A_irq:
6621 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6622 spurious_irq_mask |= irqmask;
6623 }
6624 - atomic_inc(&irq_err_count);
6625 + atomic_inc_unchecked(&irq_err_count);
6626 /*
6627 * Theoretically we do not have to handle this IRQ,
6628 * but in Linux this does not cause problems and is
6629 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6630 index 44a1f79..2bd6aa3 100644
6631 --- a/arch/mips/kernel/irq-gt641xx.c
6632 +++ b/arch/mips/kernel/irq-gt641xx.c
6633 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6634 }
6635 }
6636
6637 - atomic_inc(&irq_err_count);
6638 + atomic_inc_unchecked(&irq_err_count);
6639 }
6640
6641 void __init gt641xx_irq_init(void)
6642 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6643 index d2bfbc2..a8eacd2 100644
6644 --- a/arch/mips/kernel/irq.c
6645 +++ b/arch/mips/kernel/irq.c
6646 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6647 printk("unexpected IRQ # %d\n", irq);
6648 }
6649
6650 -atomic_t irq_err_count;
6651 +atomic_unchecked_t irq_err_count;
6652
6653 int arch_show_interrupts(struct seq_file *p, int prec)
6654 {
6655 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6656 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6657 return 0;
6658 }
6659
6660 asmlinkage void spurious_interrupt(void)
6661 {
6662 - atomic_inc(&irq_err_count);
6663 + atomic_inc_unchecked(&irq_err_count);
6664 }
6665
6666 void __init init_IRQ(void)
6667 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
6668 #endif
6669 }
6670
6671 +
6672 #ifdef DEBUG_STACKOVERFLOW
6673 +extern void gr_handle_kernel_exploit(void);
6674 +
6675 static inline void check_stack_overflow(void)
6676 {
6677 unsigned long sp;
6678 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6679 printk("do_IRQ: stack overflow: %ld\n",
6680 sp - sizeof(struct thread_info));
6681 dump_stack();
6682 + gr_handle_kernel_exploit();
6683 }
6684 }
6685 #else
6686 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6687 index 0614717..002fa43 100644
6688 --- a/arch/mips/kernel/pm-cps.c
6689 +++ b/arch/mips/kernel/pm-cps.c
6690 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6691 nc_core_ready_count = nc_addr;
6692
6693 /* Ensure ready_count is zero-initialised before the assembly runs */
6694 - ACCESS_ONCE(*nc_core_ready_count) = 0;
6695 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6696 coupled_barrier(&per_cpu(pm_barrier, core), online);
6697
6698 /* Run the generated entry code */
6699 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6700 index 636b074..8fbb91f 100644
6701 --- a/arch/mips/kernel/process.c
6702 +++ b/arch/mips/kernel/process.c
6703 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6704 out:
6705 return pc;
6706 }
6707 -
6708 -/*
6709 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6710 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6711 - */
6712 -unsigned long arch_align_stack(unsigned long sp)
6713 -{
6714 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6715 - sp -= get_random_int() & ~PAGE_MASK;
6716 -
6717 - return sp & ALMASK;
6718 -}
6719 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6720 index 9d1487d..10c5da5 100644
6721 --- a/arch/mips/kernel/ptrace.c
6722 +++ b/arch/mips/kernel/ptrace.c
6723 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6724 return ret;
6725 }
6726
6727 +#ifdef CONFIG_GRKERNSEC_SETXID
6728 +extern void gr_delayed_cred_worker(void);
6729 +#endif
6730 +
6731 /*
6732 * Notification of system call entry/exit
6733 * - triggered by current->work.syscall_trace
6734 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6735 tracehook_report_syscall_entry(regs))
6736 ret = -1;
6737
6738 +#ifdef CONFIG_GRKERNSEC_SETXID
6739 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6740 + gr_delayed_cred_worker();
6741 +#endif
6742 +
6743 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6744 trace_sys_enter(regs, regs->regs[2]);
6745
6746 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6747 index 07fc524..b9d7f28 100644
6748 --- a/arch/mips/kernel/reset.c
6749 +++ b/arch/mips/kernel/reset.c
6750 @@ -13,6 +13,7 @@
6751 #include <linux/reboot.h>
6752
6753 #include <asm/reboot.h>
6754 +#include <asm/bug.h>
6755
6756 /*
6757 * Urgs ... Too many MIPS machines to handle this in a generic way.
6758 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6759 {
6760 if (_machine_restart)
6761 _machine_restart(command);
6762 + BUG();
6763 }
6764
6765 void machine_halt(void)
6766 {
6767 if (_machine_halt)
6768 _machine_halt();
6769 + BUG();
6770 }
6771
6772 void machine_power_off(void)
6773 {
6774 if (pm_power_off)
6775 pm_power_off();
6776 + BUG();
6777 }
6778 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6779 index 2242bdd..b284048 100644
6780 --- a/arch/mips/kernel/sync-r4k.c
6781 +++ b/arch/mips/kernel/sync-r4k.c
6782 @@ -18,8 +18,8 @@
6783 #include <asm/mipsregs.h>
6784
6785 static atomic_t count_start_flag = ATOMIC_INIT(0);
6786 -static atomic_t count_count_start = ATOMIC_INIT(0);
6787 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6788 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6789 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6790 static atomic_t count_reference = ATOMIC_INIT(0);
6791
6792 #define COUNTON 100
6793 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6794
6795 for (i = 0; i < NR_LOOPS; i++) {
6796 /* slaves loop on '!= 2' */
6797 - while (atomic_read(&count_count_start) != 1)
6798 + while (atomic_read_unchecked(&count_count_start) != 1)
6799 mb();
6800 - atomic_set(&count_count_stop, 0);
6801 + atomic_set_unchecked(&count_count_stop, 0);
6802 smp_wmb();
6803
6804 /* this lets the slaves write their count register */
6805 - atomic_inc(&count_count_start);
6806 + atomic_inc_unchecked(&count_count_start);
6807
6808 /*
6809 * Everyone initialises count in the last loop:
6810 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6811 /*
6812 * Wait for all slaves to leave the synchronization point:
6813 */
6814 - while (atomic_read(&count_count_stop) != 1)
6815 + while (atomic_read_unchecked(&count_count_stop) != 1)
6816 mb();
6817 - atomic_set(&count_count_start, 0);
6818 + atomic_set_unchecked(&count_count_start, 0);
6819 smp_wmb();
6820 - atomic_inc(&count_count_stop);
6821 + atomic_inc_unchecked(&count_count_stop);
6822 }
6823 /* Arrange for an interrupt in a short while */
6824 write_c0_compare(read_c0_count() + COUNTON);
6825 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6826 initcount = atomic_read(&count_reference);
6827
6828 for (i = 0; i < NR_LOOPS; i++) {
6829 - atomic_inc(&count_count_start);
6830 - while (atomic_read(&count_count_start) != 2)
6831 + atomic_inc_unchecked(&count_count_start);
6832 + while (atomic_read_unchecked(&count_count_start) != 2)
6833 mb();
6834
6835 /*
6836 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6837 if (i == NR_LOOPS-1)
6838 write_c0_count(initcount);
6839
6840 - atomic_inc(&count_count_stop);
6841 - while (atomic_read(&count_count_stop) != 2)
6842 + atomic_inc_unchecked(&count_count_stop);
6843 + while (atomic_read_unchecked(&count_count_stop) != 2)
6844 mb();
6845 }
6846 /* Arrange for an interrupt in a short while */
6847 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6848 index d255a2a..916271c 100644
6849 --- a/arch/mips/kernel/traps.c
6850 +++ b/arch/mips/kernel/traps.c
6851 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6852 siginfo_t info;
6853
6854 prev_state = exception_enter();
6855 - die_if_kernel("Integer overflow", regs);
6856 + if (unlikely(!user_mode(regs))) {
6857 +
6858 +#ifdef CONFIG_PAX_REFCOUNT
6859 + if (fixup_exception(regs)) {
6860 + pax_report_refcount_overflow(regs);
6861 + exception_exit(prev_state);
6862 + return;
6863 + }
6864 +#endif
6865 +
6866 + die("Integer overflow", regs);
6867 + }
6868
6869 info.si_code = FPE_INTOVF;
6870 info.si_signo = SIGFPE;
6871 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6872 index e3b21e5..ea5ff7c 100644
6873 --- a/arch/mips/kvm/mips.c
6874 +++ b/arch/mips/kvm/mips.c
6875 @@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6876 return r;
6877 }
6878
6879 -int kvm_arch_init(void *opaque)
6880 +int kvm_arch_init(const void *opaque)
6881 {
6882 if (kvm_mips_callbacks) {
6883 kvm_err("kvm: module already exists\n");
6884 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6885 index 70ab5d6..62940fe 100644
6886 --- a/arch/mips/mm/fault.c
6887 +++ b/arch/mips/mm/fault.c
6888 @@ -28,6 +28,23 @@
6889 #include <asm/highmem.h> /* For VMALLOC_END */
6890 #include <linux/kdebug.h>
6891
6892 +#ifdef CONFIG_PAX_PAGEEXEC
6893 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6894 +{
6895 + unsigned long i;
6896 +
6897 + printk(KERN_ERR "PAX: bytes at PC: ");
6898 + for (i = 0; i < 5; i++) {
6899 + unsigned int c;
6900 + if (get_user(c, (unsigned int *)pc+i))
6901 + printk(KERN_CONT "???????? ");
6902 + else
6903 + printk(KERN_CONT "%08x ", c);
6904 + }
6905 + printk("\n");
6906 +}
6907 +#endif
6908 +
6909 /*
6910 * This routine handles page faults. It determines the address,
6911 * and the problem, and then passes it off to one of the appropriate
6912 @@ -201,6 +218,14 @@ bad_area:
6913 bad_area_nosemaphore:
6914 /* User mode accesses just cause a SIGSEGV */
6915 if (user_mode(regs)) {
6916 +
6917 +#ifdef CONFIG_PAX_PAGEEXEC
6918 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6919 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6920 + do_group_exit(SIGKILL);
6921 + }
6922 +#endif
6923 +
6924 tsk->thread.cp0_badvaddr = address;
6925 tsk->thread.error_code = write;
6926 #if 0
6927 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6928 index f1baadd..5472dca 100644
6929 --- a/arch/mips/mm/mmap.c
6930 +++ b/arch/mips/mm/mmap.c
6931 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6932 struct vm_area_struct *vma;
6933 unsigned long addr = addr0;
6934 int do_color_align;
6935 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6936 struct vm_unmapped_area_info info;
6937
6938 if (unlikely(len > TASK_SIZE))
6939 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6940 do_color_align = 1;
6941
6942 /* requesting a specific address */
6943 +
6944 +#ifdef CONFIG_PAX_RANDMMAP
6945 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6946 +#endif
6947 +
6948 if (addr) {
6949 if (do_color_align)
6950 addr = COLOUR_ALIGN(addr, pgoff);
6951 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6952 addr = PAGE_ALIGN(addr);
6953
6954 vma = find_vma(mm, addr);
6955 - if (TASK_SIZE - len >= addr &&
6956 - (!vma || addr + len <= vma->vm_start))
6957 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6958 return addr;
6959 }
6960
6961 info.length = len;
6962 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6963 info.align_offset = pgoff << PAGE_SHIFT;
6964 + info.threadstack_offset = offset;
6965
6966 if (dir == DOWN) {
6967 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6968 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6969 {
6970 unsigned long random_factor = 0UL;
6971
6972 +#ifdef CONFIG_PAX_RANDMMAP
6973 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6974 +#endif
6975 +
6976 if (current->flags & PF_RANDOMIZE) {
6977 random_factor = get_random_int();
6978 random_factor = random_factor << PAGE_SHIFT;
6979 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6980
6981 if (mmap_is_legacy()) {
6982 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6983 +
6984 +#ifdef CONFIG_PAX_RANDMMAP
6985 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6986 + mm->mmap_base += mm->delta_mmap;
6987 +#endif
6988 +
6989 mm->get_unmapped_area = arch_get_unmapped_area;
6990 } else {
6991 mm->mmap_base = mmap_base(random_factor);
6992 +
6993 +#ifdef CONFIG_PAX_RANDMMAP
6994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6995 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6996 +#endif
6997 +
6998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6999 }
7000 }
7001
7002 -static inline unsigned long brk_rnd(void)
7003 -{
7004 - unsigned long rnd = get_random_int();
7005 -
7006 - rnd = rnd << PAGE_SHIFT;
7007 - /* 8MB for 32bit, 256MB for 64bit */
7008 - if (TASK_IS_32BIT_ADDR)
7009 - rnd = rnd & 0x7ffffful;
7010 - else
7011 - rnd = rnd & 0xffffffful;
7012 -
7013 - return rnd;
7014 -}
7015 -
7016 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7017 -{
7018 - unsigned long base = mm->brk;
7019 - unsigned long ret;
7020 -
7021 - ret = PAGE_ALIGN(base + brk_rnd());
7022 -
7023 - if (ret < mm->brk)
7024 - return mm->brk;
7025 -
7026 - return ret;
7027 -}
7028 -
7029 int __virt_addr_valid(const volatile void *kaddr)
7030 {
7031 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7032 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7033 index 59cccd9..f39ac2f 100644
7034 --- a/arch/mips/pci/pci-octeon.c
7035 +++ b/arch/mips/pci/pci-octeon.c
7036 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7037
7038
7039 static struct pci_ops octeon_pci_ops = {
7040 - octeon_read_config,
7041 - octeon_write_config,
7042 + .read = octeon_read_config,
7043 + .write = octeon_write_config,
7044 };
7045
7046 static struct resource octeon_pci_mem_resource = {
7047 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7048 index 5e36c33..eb4a17b 100644
7049 --- a/arch/mips/pci/pcie-octeon.c
7050 +++ b/arch/mips/pci/pcie-octeon.c
7051 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7052 }
7053
7054 static struct pci_ops octeon_pcie0_ops = {
7055 - octeon_pcie0_read_config,
7056 - octeon_pcie0_write_config,
7057 + .read = octeon_pcie0_read_config,
7058 + .write = octeon_pcie0_write_config,
7059 };
7060
7061 static struct resource octeon_pcie0_mem_resource = {
7062 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7063 };
7064
7065 static struct pci_ops octeon_pcie1_ops = {
7066 - octeon_pcie1_read_config,
7067 - octeon_pcie1_write_config,
7068 + .read = octeon_pcie1_read_config,
7069 + .write = octeon_pcie1_write_config,
7070 };
7071
7072 static struct resource octeon_pcie1_mem_resource = {
7073 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7074 };
7075
7076 static struct pci_ops octeon_dummy_ops = {
7077 - octeon_dummy_read_config,
7078 - octeon_dummy_write_config,
7079 + .read = octeon_dummy_read_config,
7080 + .write = octeon_dummy_write_config,
7081 };
7082
7083 static struct resource octeon_dummy_mem_resource = {
7084 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7085 index a2358b4..7cead4f 100644
7086 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7087 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7088 @@ -187,9 +187,9 @@ void
7089 cont_nmi_dump(void)
7090 {
7091 #ifndef REAL_NMI_SIGNAL
7092 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7093 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7094
7095 - atomic_inc(&nmied_cpus);
7096 + atomic_inc_unchecked(&nmied_cpus);
7097 #endif
7098 /*
7099 * Only allow 1 cpu to proceed
7100 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7101 udelay(10000);
7102 }
7103 #else
7104 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7105 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7106 #endif
7107
7108 /*
7109 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7110 index a046b30..6799527 100644
7111 --- a/arch/mips/sni/rm200.c
7112 +++ b/arch/mips/sni/rm200.c
7113 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7114 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7115 spurious_irq_mask |= irqmask;
7116 }
7117 - atomic_inc(&irq_err_count);
7118 + atomic_inc_unchecked(&irq_err_count);
7119 /*
7120 * Theoretically we do not have to handle this IRQ,
7121 * but in Linux this does not cause problems and is
7122 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7123 index 41e873b..34d33a7 100644
7124 --- a/arch/mips/vr41xx/common/icu.c
7125 +++ b/arch/mips/vr41xx/common/icu.c
7126 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7127
7128 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7129
7130 - atomic_inc(&irq_err_count);
7131 + atomic_inc_unchecked(&irq_err_count);
7132
7133 return -1;
7134 }
7135 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7136 index ae0e4ee..e8f0692 100644
7137 --- a/arch/mips/vr41xx/common/irq.c
7138 +++ b/arch/mips/vr41xx/common/irq.c
7139 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7140 irq_cascade_t *cascade;
7141
7142 if (irq >= NR_IRQS) {
7143 - atomic_inc(&irq_err_count);
7144 + atomic_inc_unchecked(&irq_err_count);
7145 return;
7146 }
7147
7148 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7149 ret = cascade->get_irq(irq);
7150 irq = ret;
7151 if (ret < 0)
7152 - atomic_inc(&irq_err_count);
7153 + atomic_inc_unchecked(&irq_err_count);
7154 else
7155 irq_dispatch(irq);
7156 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7157 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7158 index 967d144..db12197 100644
7159 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7160 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7161 @@ -11,12 +11,14 @@
7162 #ifndef _ASM_PROC_CACHE_H
7163 #define _ASM_PROC_CACHE_H
7164
7165 +#include <linux/const.h>
7166 +
7167 /* L1 cache */
7168
7169 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7170 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7171 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7172 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7173 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7174 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7175
7176 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7177 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7178 index bcb5df2..84fabd2 100644
7179 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7180 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7181 @@ -16,13 +16,15 @@
7182 #ifndef _ASM_PROC_CACHE_H
7183 #define _ASM_PROC_CACHE_H
7184
7185 +#include <linux/const.h>
7186 +
7187 /*
7188 * L1 cache
7189 */
7190 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7191 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7192 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7193 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7194 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7195 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7196
7197 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7198 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7199 index 4ce7a01..449202a 100644
7200 --- a/arch/openrisc/include/asm/cache.h
7201 +++ b/arch/openrisc/include/asm/cache.h
7202 @@ -19,11 +19,13 @@
7203 #ifndef __ASM_OPENRISC_CACHE_H
7204 #define __ASM_OPENRISC_CACHE_H
7205
7206 +#include <linux/const.h>
7207 +
7208 /* FIXME: How can we replace these with values from the CPU...
7209 * they shouldn't be hard-coded!
7210 */
7211
7212 -#define L1_CACHE_BYTES 16
7213 #define L1_CACHE_SHIFT 4
7214 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7215
7216 #endif /* __ASM_OPENRISC_CACHE_H */
7217 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7218 index 226f8ca..9d9b87d 100644
7219 --- a/arch/parisc/include/asm/atomic.h
7220 +++ b/arch/parisc/include/asm/atomic.h
7221 @@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7222 return dec;
7223 }
7224
7225 +#define atomic64_read_unchecked(v) atomic64_read(v)
7226 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7227 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7228 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7229 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7230 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7231 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7232 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7233 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7234 +
7235 #endif /* !CONFIG_64BIT */
7236
7237
7238 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7239 index 47f11c7..3420df2 100644
7240 --- a/arch/parisc/include/asm/cache.h
7241 +++ b/arch/parisc/include/asm/cache.h
7242 @@ -5,6 +5,7 @@
7243 #ifndef __ARCH_PARISC_CACHE_H
7244 #define __ARCH_PARISC_CACHE_H
7245
7246 +#include <linux/const.h>
7247
7248 /*
7249 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7250 @@ -15,13 +16,13 @@
7251 * just ruin performance.
7252 */
7253 #ifdef CONFIG_PA20
7254 -#define L1_CACHE_BYTES 64
7255 #define L1_CACHE_SHIFT 6
7256 #else
7257 -#define L1_CACHE_BYTES 32
7258 #define L1_CACHE_SHIFT 5
7259 #endif
7260
7261 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7262 +
7263 #ifndef __ASSEMBLY__
7264
7265 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7266 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7267 index 3391d06..c23a2cc 100644
7268 --- a/arch/parisc/include/asm/elf.h
7269 +++ b/arch/parisc/include/asm/elf.h
7270 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7271
7272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7273
7274 +#ifdef CONFIG_PAX_ASLR
7275 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7276 +
7277 +#define PAX_DELTA_MMAP_LEN 16
7278 +#define PAX_DELTA_STACK_LEN 16
7279 +#endif
7280 +
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. This could be done in user space,
7283 but it's not easy, and we've already done it here. */
7284 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7285 index f213f5b..0af3e8e 100644
7286 --- a/arch/parisc/include/asm/pgalloc.h
7287 +++ b/arch/parisc/include/asm/pgalloc.h
7288 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7289 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7290 }
7291
7292 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7293 +{
7294 + pgd_populate(mm, pgd, pmd);
7295 +}
7296 +
7297 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7298 {
7299 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7300 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7301 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7302 #define pmd_free(mm, x) do { } while (0)
7303 #define pgd_populate(mm, pmd, pte) BUG()
7304 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7305
7306 #endif
7307
7308 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7309 index 22b89d1..ce34230 100644
7310 --- a/arch/parisc/include/asm/pgtable.h
7311 +++ b/arch/parisc/include/asm/pgtable.h
7312 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7313 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7314 #define PAGE_COPY PAGE_EXECREAD
7315 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7316 +
7317 +#ifdef CONFIG_PAX_PAGEEXEC
7318 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7319 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7320 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7321 +#else
7322 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7323 +# define PAGE_COPY_NOEXEC PAGE_COPY
7324 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7325 +#endif
7326 +
7327 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7328 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7329 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7330 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7331 index a5cb070..8604ddc 100644
7332 --- a/arch/parisc/include/asm/uaccess.h
7333 +++ b/arch/parisc/include/asm/uaccess.h
7334 @@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7335 const void __user *from,
7336 unsigned long n)
7337 {
7338 - int sz = __compiletime_object_size(to);
7339 + size_t sz = __compiletime_object_size(to);
7340 int ret = -EFAULT;
7341
7342 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7343 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7344 ret = __copy_from_user(to, from, n);
7345 else
7346 copy_from_user_overflow();
7347 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7348 index 50dfafc..b9fc230 100644
7349 --- a/arch/parisc/kernel/module.c
7350 +++ b/arch/parisc/kernel/module.c
7351 @@ -98,16 +98,38 @@
7352
7353 /* three functions to determine where in the module core
7354 * or init pieces the location is */
7355 +static inline int in_init_rx(struct module *me, void *loc)
7356 +{
7357 + return (loc >= me->module_init_rx &&
7358 + loc < (me->module_init_rx + me->init_size_rx));
7359 +}
7360 +
7361 +static inline int in_init_rw(struct module *me, void *loc)
7362 +{
7363 + return (loc >= me->module_init_rw &&
7364 + loc < (me->module_init_rw + me->init_size_rw));
7365 +}
7366 +
7367 static inline int in_init(struct module *me, void *loc)
7368 {
7369 - return (loc >= me->module_init &&
7370 - loc <= (me->module_init + me->init_size));
7371 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7372 +}
7373 +
7374 +static inline int in_core_rx(struct module *me, void *loc)
7375 +{
7376 + return (loc >= me->module_core_rx &&
7377 + loc < (me->module_core_rx + me->core_size_rx));
7378 +}
7379 +
7380 +static inline int in_core_rw(struct module *me, void *loc)
7381 +{
7382 + return (loc >= me->module_core_rw &&
7383 + loc < (me->module_core_rw + me->core_size_rw));
7384 }
7385
7386 static inline int in_core(struct module *me, void *loc)
7387 {
7388 - return (loc >= me->module_core &&
7389 - loc <= (me->module_core + me->core_size));
7390 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7391 }
7392
7393 static inline int in_local(struct module *me, void *loc)
7394 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7395 }
7396
7397 /* align things a bit */
7398 - me->core_size = ALIGN(me->core_size, 16);
7399 - me->arch.got_offset = me->core_size;
7400 - me->core_size += gots * sizeof(struct got_entry);
7401 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7402 + me->arch.got_offset = me->core_size_rw;
7403 + me->core_size_rw += gots * sizeof(struct got_entry);
7404
7405 - me->core_size = ALIGN(me->core_size, 16);
7406 - me->arch.fdesc_offset = me->core_size;
7407 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7408 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7409 + me->arch.fdesc_offset = me->core_size_rw;
7410 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7411
7412 me->arch.got_max = gots;
7413 me->arch.fdesc_max = fdescs;
7414 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7415
7416 BUG_ON(value == 0);
7417
7418 - got = me->module_core + me->arch.got_offset;
7419 + got = me->module_core_rw + me->arch.got_offset;
7420 for (i = 0; got[i].addr; i++)
7421 if (got[i].addr == value)
7422 goto out;
7423 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7424 #ifdef CONFIG_64BIT
7425 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7426 {
7427 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7428 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7429
7430 if (!value) {
7431 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7432 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7433
7434 /* Create new one */
7435 fdesc->addr = value;
7436 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7437 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7438 return (Elf_Addr)fdesc;
7439 }
7440 #endif /* CONFIG_64BIT */
7441 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7442
7443 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7444 end = table + sechdrs[me->arch.unwind_section].sh_size;
7445 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7446 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7447
7448 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7449 me->arch.unwind_section, table, end, gp);
7450 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7451 index e1ffea2..46ed66e 100644
7452 --- a/arch/parisc/kernel/sys_parisc.c
7453 +++ b/arch/parisc/kernel/sys_parisc.c
7454 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7455 unsigned long task_size = TASK_SIZE;
7456 int do_color_align, last_mmap;
7457 struct vm_unmapped_area_info info;
7458 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7459
7460 if (len > task_size)
7461 return -ENOMEM;
7462 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7463 goto found_addr;
7464 }
7465
7466 +#ifdef CONFIG_PAX_RANDMMAP
7467 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7468 +#endif
7469 +
7470 if (addr) {
7471 if (do_color_align && last_mmap)
7472 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7473 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7474 info.high_limit = mmap_upper_limit();
7475 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7476 info.align_offset = shared_align_offset(last_mmap, pgoff);
7477 + info.threadstack_offset = offset;
7478 addr = vm_unmapped_area(&info);
7479
7480 found_addr:
7481 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7482 unsigned long addr = addr0;
7483 int do_color_align, last_mmap;
7484 struct vm_unmapped_area_info info;
7485 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7486
7487 #ifdef CONFIG_64BIT
7488 /* This should only ever run for 32-bit processes. */
7489 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7490 }
7491
7492 /* requesting a specific address */
7493 +#ifdef CONFIG_PAX_RANDMMAP
7494 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7495 +#endif
7496 +
7497 if (addr) {
7498 if (do_color_align && last_mmap)
7499 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7500 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7501 info.high_limit = mm->mmap_base;
7502 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7503 info.align_offset = shared_align_offset(last_mmap, pgoff);
7504 + info.threadstack_offset = offset;
7505 addr = vm_unmapped_area(&info);
7506 if (!(addr & ~PAGE_MASK))
7507 goto found_addr;
7508 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7509 mm->mmap_legacy_base = mmap_legacy_base();
7510 mm->mmap_base = mmap_upper_limit();
7511
7512 +#ifdef CONFIG_PAX_RANDMMAP
7513 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7514 + mm->mmap_legacy_base += mm->delta_mmap;
7515 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7516 + }
7517 +#endif
7518 +
7519 if (mmap_is_legacy()) {
7520 mm->mmap_base = mm->mmap_legacy_base;
7521 mm->get_unmapped_area = arch_get_unmapped_area;
7522 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7523 index 47ee620..1107387 100644
7524 --- a/arch/parisc/kernel/traps.c
7525 +++ b/arch/parisc/kernel/traps.c
7526 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7527
7528 down_read(&current->mm->mmap_sem);
7529 vma = find_vma(current->mm,regs->iaoq[0]);
7530 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7531 - && (vma->vm_flags & VM_EXEC)) {
7532 -
7533 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7534 fault_address = regs->iaoq[0];
7535 fault_space = regs->iasq[0];
7536
7537 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7538 index e5120e6..8ddb5cc 100644
7539 --- a/arch/parisc/mm/fault.c
7540 +++ b/arch/parisc/mm/fault.c
7541 @@ -15,6 +15,7 @@
7542 #include <linux/sched.h>
7543 #include <linux/interrupt.h>
7544 #include <linux/module.h>
7545 +#include <linux/unistd.h>
7546
7547 #include <asm/uaccess.h>
7548 #include <asm/traps.h>
7549 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7550 static unsigned long
7551 parisc_acctyp(unsigned long code, unsigned int inst)
7552 {
7553 - if (code == 6 || code == 16)
7554 + if (code == 6 || code == 7 || code == 16)
7555 return VM_EXEC;
7556
7557 switch (inst & 0xf0000000) {
7558 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7559 }
7560 #endif
7561
7562 +#ifdef CONFIG_PAX_PAGEEXEC
7563 +/*
7564 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7565 + *
7566 + * returns 1 when task should be killed
7567 + * 2 when rt_sigreturn trampoline was detected
7568 + * 3 when unpatched PLT trampoline was detected
7569 + */
7570 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7571 +{
7572 +
7573 +#ifdef CONFIG_PAX_EMUPLT
7574 + int err;
7575 +
7576 + do { /* PaX: unpatched PLT emulation */
7577 + unsigned int bl, depwi;
7578 +
7579 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7580 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7581 +
7582 + if (err)
7583 + break;
7584 +
7585 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7586 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7587 +
7588 + err = get_user(ldw, (unsigned int *)addr);
7589 + err |= get_user(bv, (unsigned int *)(addr+4));
7590 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7591 +
7592 + if (err)
7593 + break;
7594 +
7595 + if (ldw == 0x0E801096U &&
7596 + bv == 0xEAC0C000U &&
7597 + ldw2 == 0x0E881095U)
7598 + {
7599 + unsigned int resolver, map;
7600 +
7601 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7602 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7603 + if (err)
7604 + break;
7605 +
7606 + regs->gr[20] = instruction_pointer(regs)+8;
7607 + regs->gr[21] = map;
7608 + regs->gr[22] = resolver;
7609 + regs->iaoq[0] = resolver | 3UL;
7610 + regs->iaoq[1] = regs->iaoq[0] + 4;
7611 + return 3;
7612 + }
7613 + }
7614 + } while (0);
7615 +#endif
7616 +
7617 +#ifdef CONFIG_PAX_EMUTRAMP
7618 +
7619 +#ifndef CONFIG_PAX_EMUSIGRT
7620 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7621 + return 1;
7622 +#endif
7623 +
7624 + do { /* PaX: rt_sigreturn emulation */
7625 + unsigned int ldi1, ldi2, bel, nop;
7626 +
7627 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7628 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7629 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7630 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7631 +
7632 + if (err)
7633 + break;
7634 +
7635 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7636 + ldi2 == 0x3414015AU &&
7637 + bel == 0xE4008200U &&
7638 + nop == 0x08000240U)
7639 + {
7640 + regs->gr[25] = (ldi1 & 2) >> 1;
7641 + regs->gr[20] = __NR_rt_sigreturn;
7642 + regs->gr[31] = regs->iaoq[1] + 16;
7643 + regs->sr[0] = regs->iasq[1];
7644 + regs->iaoq[0] = 0x100UL;
7645 + regs->iaoq[1] = regs->iaoq[0] + 4;
7646 + regs->iasq[0] = regs->sr[2];
7647 + regs->iasq[1] = regs->sr[2];
7648 + return 2;
7649 + }
7650 + } while (0);
7651 +#endif
7652 +
7653 + return 1;
7654 +}
7655 +
7656 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7657 +{
7658 + unsigned long i;
7659 +
7660 + printk(KERN_ERR "PAX: bytes at PC: ");
7661 + for (i = 0; i < 5; i++) {
7662 + unsigned int c;
7663 + if (get_user(c, (unsigned int *)pc+i))
7664 + printk(KERN_CONT "???????? ");
7665 + else
7666 + printk(KERN_CONT "%08x ", c);
7667 + }
7668 + printk("\n");
7669 +}
7670 +#endif
7671 +
7672 int fixup_exception(struct pt_regs *regs)
7673 {
7674 const struct exception_table_entry *fix;
7675 @@ -234,8 +345,33 @@ retry:
7676
7677 good_area:
7678
7679 - if ((vma->vm_flags & acc_type) != acc_type)
7680 + if ((vma->vm_flags & acc_type) != acc_type) {
7681 +
7682 +#ifdef CONFIG_PAX_PAGEEXEC
7683 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7684 + (address & ~3UL) == instruction_pointer(regs))
7685 + {
7686 + up_read(&mm->mmap_sem);
7687 + switch (pax_handle_fetch_fault(regs)) {
7688 +
7689 +#ifdef CONFIG_PAX_EMUPLT
7690 + case 3:
7691 + return;
7692 +#endif
7693 +
7694 +#ifdef CONFIG_PAX_EMUTRAMP
7695 + case 2:
7696 + return;
7697 +#endif
7698 +
7699 + }
7700 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7701 + do_group_exit(SIGKILL);
7702 + }
7703 +#endif
7704 +
7705 goto bad_area;
7706 + }
7707
7708 /*
7709 * If for any reason at all we couldn't handle the fault, make
7710 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7711 index 88eace4..4ba2591 100644
7712 --- a/arch/powerpc/Kconfig
7713 +++ b/arch/powerpc/Kconfig
7714 @@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7715 config KEXEC
7716 bool "kexec system call"
7717 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7718 + depends on !GRKERNSEC_KMEM
7719 help
7720 kexec is a system call that implements the ability to shutdown your
7721 current kernel, and to start another kernel. It is like a reboot
7722 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7723 index 512d278..d31fadd 100644
7724 --- a/arch/powerpc/include/asm/atomic.h
7725 +++ b/arch/powerpc/include/asm/atomic.h
7726 @@ -12,6 +12,11 @@
7727
7728 #define ATOMIC_INIT(i) { (i) }
7729
7730 +#define _ASM_EXTABLE(from, to) \
7731 +" .section __ex_table,\"a\"\n" \
7732 + PPC_LONG" " #from ", " #to"\n" \
7733 +" .previous\n"
7734 +
7735 static __inline__ int atomic_read(const atomic_t *v)
7736 {
7737 int t;
7738 @@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7739 return t;
7740 }
7741
7742 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7743 +{
7744 + int t;
7745 +
7746 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7747 +
7748 + return t;
7749 +}
7750 +
7751 static __inline__ void atomic_set(atomic_t *v, int i)
7752 {
7753 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7754 }
7755
7756 -#define ATOMIC_OP(op, asm_op) \
7757 -static __inline__ void atomic_##op(int a, atomic_t *v) \
7758 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7759 +{
7760 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7761 +}
7762 +
7763 +#ifdef CONFIG_PAX_REFCOUNT
7764 +#define __REFCOUNT_OP(op) op##o.
7765 +#define __OVERFLOW_PRE \
7766 + " mcrxr cr0\n"
7767 +#define __OVERFLOW_POST \
7768 + " bf 4*cr0+so, 3f\n" \
7769 + "2: .long 0x00c00b00\n" \
7770 + "3:\n"
7771 +#define __OVERFLOW_EXTABLE \
7772 + "\n4:\n"
7773 + _ASM_EXTABLE(2b, 4b)
7774 +#else
7775 +#define __REFCOUNT_OP(op) op
7776 +#define __OVERFLOW_PRE
7777 +#define __OVERFLOW_POST
7778 +#define __OVERFLOW_EXTABLE
7779 +#endif
7780 +
7781 +#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7782 +static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7783 { \
7784 int t; \
7785 \
7786 __asm__ __volatile__( \
7787 -"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7788 +"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7789 + pre_op \
7790 #asm_op " %0,%2,%0\n" \
7791 + post_op \
7792 PPC405_ERR77(0,%3) \
7793 " stwcx. %0,0,%3 \n" \
7794 " bne- 1b\n" \
7795 + extable \
7796 : "=&r" (t), "+m" (v->counter) \
7797 : "r" (a), "r" (&v->counter) \
7798 : "cc"); \
7799 } \
7800
7801 -#define ATOMIC_OP_RETURN(op, asm_op) \
7802 -static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7803 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7804 + __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7805 +
7806 +#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7807 +static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7808 { \
7809 int t; \
7810 \
7811 __asm__ __volatile__( \
7812 PPC_ATOMIC_ENTRY_BARRIER \
7813 -"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7814 +"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7815 + pre_op \
7816 #asm_op " %0,%1,%0\n" \
7817 + post_op \
7818 PPC405_ERR77(0,%2) \
7819 " stwcx. %0,0,%2 \n" \
7820 " bne- 1b\n" \
7821 + extable \
7822 PPC_ATOMIC_EXIT_BARRIER \
7823 : "=&r" (t) \
7824 : "r" (a), "r" (&v->counter) \
7825 @@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7826 return t; \
7827 }
7828
7829 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7830 + __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7831 +
7832 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7833
7834 ATOMIC_OPS(add, add)
7835 @@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7836
7837 #undef ATOMIC_OPS
7838 #undef ATOMIC_OP_RETURN
7839 +#undef __ATOMIC_OP_RETURN
7840 #undef ATOMIC_OP
7841 +#undef __ATOMIC_OP
7842
7843 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7844
7845 -static __inline__ void atomic_inc(atomic_t *v)
7846 -{
7847 - int t;
7848 +/*
7849 + * atomic_inc - increment atomic variable
7850 + * @v: pointer of type atomic_t
7851 + *
7852 + * Automatically increments @v by 1
7853 + */
7854 +#define atomic_inc(v) atomic_add(1, (v))
7855 +#define atomic_inc_return(v) atomic_add_return(1, (v))
7856
7857 - __asm__ __volatile__(
7858 -"1: lwarx %0,0,%2 # atomic_inc\n\
7859 - addic %0,%0,1\n"
7860 - PPC405_ERR77(0,%2)
7861 -" stwcx. %0,0,%2 \n\
7862 - bne- 1b"
7863 - : "=&r" (t), "+m" (v->counter)
7864 - : "r" (&v->counter)
7865 - : "cc", "xer");
7866 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7867 +{
7868 + atomic_add_unchecked(1, v);
7869 }
7870
7871 -static __inline__ int atomic_inc_return(atomic_t *v)
7872 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7873 {
7874 - int t;
7875 -
7876 - __asm__ __volatile__(
7877 - PPC_ATOMIC_ENTRY_BARRIER
7878 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
7879 - addic %0,%0,1\n"
7880 - PPC405_ERR77(0,%1)
7881 -" stwcx. %0,0,%1 \n\
7882 - bne- 1b"
7883 - PPC_ATOMIC_EXIT_BARRIER
7884 - : "=&r" (t)
7885 - : "r" (&v->counter)
7886 - : "cc", "xer", "memory");
7887 -
7888 - return t;
7889 + return atomic_add_return_unchecked(1, v);
7890 }
7891
7892 /*
7893 @@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7894 */
7895 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7896
7897 -static __inline__ void atomic_dec(atomic_t *v)
7898 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7899 {
7900 - int t;
7901 -
7902 - __asm__ __volatile__(
7903 -"1: lwarx %0,0,%2 # atomic_dec\n\
7904 - addic %0,%0,-1\n"
7905 - PPC405_ERR77(0,%2)\
7906 -" stwcx. %0,0,%2\n\
7907 - bne- 1b"
7908 - : "=&r" (t), "+m" (v->counter)
7909 - : "r" (&v->counter)
7910 - : "cc", "xer");
7911 + return atomic_add_return_unchecked(1, v) == 0;
7912 }
7913
7914 -static __inline__ int atomic_dec_return(atomic_t *v)
7915 +/*
7916 + * atomic_dec - decrement atomic variable
7917 + * @v: pointer of type atomic_t
7918 + *
7919 + * Atomically decrements @v by 1
7920 + */
7921 +#define atomic_dec(v) atomic_sub(1, (v))
7922 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
7923 +
7924 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7925 {
7926 - int t;
7927 -
7928 - __asm__ __volatile__(
7929 - PPC_ATOMIC_ENTRY_BARRIER
7930 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
7931 - addic %0,%0,-1\n"
7932 - PPC405_ERR77(0,%1)
7933 -" stwcx. %0,0,%1\n\
7934 - bne- 1b"
7935 - PPC_ATOMIC_EXIT_BARRIER
7936 - : "=&r" (t)
7937 - : "r" (&v->counter)
7938 - : "cc", "xer", "memory");
7939 -
7940 - return t;
7941 + atomic_sub_unchecked(1, v);
7942 }
7943
7944 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7945 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7946
7947 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7948 +{
7949 + return cmpxchg(&(v->counter), old, new);
7950 +}
7951 +
7952 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7953 +{
7954 + return xchg(&(v->counter), new);
7955 +}
7956 +
7957 /**
7958 * __atomic_add_unless - add unless the number is a given value
7959 * @v: pointer of type atomic_t
7960 @@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7961 PPC_ATOMIC_ENTRY_BARRIER
7962 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7963 cmpw 0,%0,%3 \n\
7964 - beq- 2f \n\
7965 - add %0,%2,%0 \n"
7966 + beq- 2f \n"
7967 +
7968 +#ifdef CONFIG_PAX_REFCOUNT
7969 +" mcrxr cr0\n"
7970 +" addo. %0,%2,%0\n"
7971 +" bf 4*cr0+so, 4f\n"
7972 +"3:.long " "0x00c00b00""\n"
7973 +"4:\n"
7974 +#else
7975 + "add %0,%2,%0 \n"
7976 +#endif
7977 +
7978 PPC405_ERR77(0,%2)
7979 " stwcx. %0,0,%1 \n\
7980 bne- 1b \n"
7981 +"5:"
7982 +
7983 +#ifdef CONFIG_PAX_REFCOUNT
7984 + _ASM_EXTABLE(3b, 5b)
7985 +#endif
7986 +
7987 PPC_ATOMIC_EXIT_BARRIER
7988 " subf %0,%2,%0 \n\
7989 2:"
7990 @@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7991 }
7992 #define atomic_dec_if_positive atomic_dec_if_positive
7993
7994 +#define smp_mb__before_atomic_dec() smp_mb()
7995 +#define smp_mb__after_atomic_dec() smp_mb()
7996 +#define smp_mb__before_atomic_inc() smp_mb()
7997 +#define smp_mb__after_atomic_inc() smp_mb()
7998 +
7999 #ifdef __powerpc64__
8000
8001 #define ATOMIC64_INIT(i) { (i) }
8002 @@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8003 return t;
8004 }
8005
8006 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8007 +{
8008 + long t;
8009 +
8010 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8011 +
8012 + return t;
8013 +}
8014 +
8015 static __inline__ void atomic64_set(atomic64_t *v, long i)
8016 {
8017 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8018 }
8019
8020 -#define ATOMIC64_OP(op, asm_op) \
8021 -static __inline__ void atomic64_##op(long a, atomic64_t *v) \
8022 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8023 +{
8024 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8025 +}
8026 +
8027 +#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
8028 +static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
8029 { \
8030 long t; \
8031 \
8032 __asm__ __volatile__( \
8033 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8034 + pre_op \
8035 #asm_op " %0,%2,%0\n" \
8036 + post_op \
8037 " stdcx. %0,0,%3 \n" \
8038 " bne- 1b\n" \
8039 + extable \
8040 : "=&r" (t), "+m" (v->counter) \
8041 : "r" (a), "r" (&v->counter) \
8042 : "cc"); \
8043 }
8044
8045 -#define ATOMIC64_OP_RETURN(op, asm_op) \
8046 -static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8047 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8048 + __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8049 +
8050 +#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8051 +static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8052 { \
8053 long t; \
8054 \
8055 __asm__ __volatile__( \
8056 PPC_ATOMIC_ENTRY_BARRIER \
8057 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8058 + pre_op \
8059 #asm_op " %0,%1,%0\n" \
8060 + post_op \
8061 " stdcx. %0,0,%2 \n" \
8062 " bne- 1b\n" \
8063 + extable \
8064 PPC_ATOMIC_EXIT_BARRIER \
8065 : "=&r" (t) \
8066 : "r" (a), "r" (&v->counter) \
8067 @@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8068 return t; \
8069 }
8070
8071 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8072 + __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8073 +
8074 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8075
8076 ATOMIC64_OPS(add, add)
8077 @@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8078
8079 #undef ATOMIC64_OPS
8080 #undef ATOMIC64_OP_RETURN
8081 +#undef __ATOMIC64_OP_RETURN
8082 #undef ATOMIC64_OP
8083 +#undef __ATOMIC64_OP
8084 +#undef __OVERFLOW_EXTABLE
8085 +#undef __OVERFLOW_POST
8086 +#undef __OVERFLOW_PRE
8087 +#undef __REFCOUNT_OP
8088
8089 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8090
8091 -static __inline__ void atomic64_inc(atomic64_t *v)
8092 -{
8093 - long t;
8094 +/*
8095 + * atomic64_inc - increment atomic variable
8096 + * @v: pointer of type atomic64_t
8097 + *
8098 + * Automatically increments @v by 1
8099 + */
8100 +#define atomic64_inc(v) atomic64_add(1, (v))
8101 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8102
8103 - __asm__ __volatile__(
8104 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8105 - addic %0,%0,1\n\
8106 - stdcx. %0,0,%2 \n\
8107 - bne- 1b"
8108 - : "=&r" (t), "+m" (v->counter)
8109 - : "r" (&v->counter)
8110 - : "cc", "xer");
8111 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8112 +{
8113 + atomic64_add_unchecked(1, v);
8114 }
8115
8116 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8117 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8118 {
8119 - long t;
8120 -
8121 - __asm__ __volatile__(
8122 - PPC_ATOMIC_ENTRY_BARRIER
8123 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8124 - addic %0,%0,1\n\
8125 - stdcx. %0,0,%1 \n\
8126 - bne- 1b"
8127 - PPC_ATOMIC_EXIT_BARRIER
8128 - : "=&r" (t)
8129 - : "r" (&v->counter)
8130 - : "cc", "xer", "memory");
8131 -
8132 - return t;
8133 + return atomic64_add_return_unchecked(1, v);
8134 }
8135
8136 /*
8137 @@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8138 */
8139 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8140
8141 -static __inline__ void atomic64_dec(atomic64_t *v)
8142 +/*
8143 + * atomic64_dec - decrement atomic variable
8144 + * @v: pointer of type atomic64_t
8145 + *
8146 + * Atomically decrements @v by 1
8147 + */
8148 +#define atomic64_dec(v) atomic64_sub(1, (v))
8149 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8150 +
8151 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8152 {
8153 - long t;
8154 -
8155 - __asm__ __volatile__(
8156 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8157 - addic %0,%0,-1\n\
8158 - stdcx. %0,0,%2\n\
8159 - bne- 1b"
8160 - : "=&r" (t), "+m" (v->counter)
8161 - : "r" (&v->counter)
8162 - : "cc", "xer");
8163 -}
8164 -
8165 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8166 -{
8167 - long t;
8168 -
8169 - __asm__ __volatile__(
8170 - PPC_ATOMIC_ENTRY_BARRIER
8171 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8172 - addic %0,%0,-1\n\
8173 - stdcx. %0,0,%1\n\
8174 - bne- 1b"
8175 - PPC_ATOMIC_EXIT_BARRIER
8176 - : "=&r" (t)
8177 - : "r" (&v->counter)
8178 - : "cc", "xer", "memory");
8179 -
8180 - return t;
8181 + atomic64_sub_unchecked(1, v);
8182 }
8183
8184 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8185 @@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8186 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8187 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8188
8189 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8190 +{
8191 + return cmpxchg(&(v->counter), old, new);
8192 +}
8193 +
8194 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8195 +{
8196 + return xchg(&(v->counter), new);
8197 +}
8198 +
8199 /**
8200 * atomic64_add_unless - add unless the number is a given value
8201 * @v: pointer of type atomic64_t
8202 @@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8203
8204 __asm__ __volatile__ (
8205 PPC_ATOMIC_ENTRY_BARRIER
8206 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8207 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8208 cmpd 0,%0,%3 \n\
8209 - beq- 2f \n\
8210 - add %0,%2,%0 \n"
8211 + beq- 2f \n"
8212 +
8213 +#ifdef CONFIG_PAX_REFCOUNT
8214 +" mcrxr cr0\n"
8215 +" addo. %0,%2,%0\n"
8216 +" bf 4*cr0+so, 4f\n"
8217 +"3:.long " "0x00c00b00""\n"
8218 +"4:\n"
8219 +#else
8220 + "add %0,%2,%0 \n"
8221 +#endif
8222 +
8223 " stdcx. %0,0,%1 \n\
8224 bne- 1b \n"
8225 PPC_ATOMIC_EXIT_BARRIER
8226 +"5:"
8227 +
8228 +#ifdef CONFIG_PAX_REFCOUNT
8229 + _ASM_EXTABLE(3b, 5b)
8230 +#endif
8231 +
8232 " subf %0,%2,%0 \n\
8233 2:"
8234 : "=&r" (t)
8235 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8236 index bab79a1..4a3eabc 100644
8237 --- a/arch/powerpc/include/asm/barrier.h
8238 +++ b/arch/powerpc/include/asm/barrier.h
8239 @@ -73,7 +73,7 @@
8240 do { \
8241 compiletime_assert_atomic_type(*p); \
8242 __lwsync(); \
8243 - ACCESS_ONCE(*p) = (v); \
8244 + ACCESS_ONCE_RW(*p) = (v); \
8245 } while (0)
8246
8247 #define smp_load_acquire(p) \
8248 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8249 index 34a05a1..a1f2c67 100644
8250 --- a/arch/powerpc/include/asm/cache.h
8251 +++ b/arch/powerpc/include/asm/cache.h
8252 @@ -4,6 +4,7 @@
8253 #ifdef __KERNEL__
8254
8255 #include <asm/reg.h>
8256 +#include <linux/const.h>
8257
8258 /* bytes per L1 cache line */
8259 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8260 @@ -23,7 +24,7 @@
8261 #define L1_CACHE_SHIFT 7
8262 #endif
8263
8264 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8265 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8266
8267 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8268
8269 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8270 index 888d8f3..66f581c 100644
8271 --- a/arch/powerpc/include/asm/elf.h
8272 +++ b/arch/powerpc/include/asm/elf.h
8273 @@ -28,8 +28,19 @@
8274 the loader. We need to make sure that it is out of the way of the program
8275 that it will "exec", and that there is sufficient room for the brk. */
8276
8277 -extern unsigned long randomize_et_dyn(unsigned long base);
8278 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8279 +#define ELF_ET_DYN_BASE (0x20000000)
8280 +
8281 +#ifdef CONFIG_PAX_ASLR
8282 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8283 +
8284 +#ifdef __powerpc64__
8285 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8286 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8287 +#else
8288 +#define PAX_DELTA_MMAP_LEN 15
8289 +#define PAX_DELTA_STACK_LEN 15
8290 +#endif
8291 +#endif
8292
8293 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8294
8295 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8296 (0x7ff >> (PAGE_SHIFT - 12)) : \
8297 (0x3ffff >> (PAGE_SHIFT - 12)))
8298
8299 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8300 -#define arch_randomize_brk arch_randomize_brk
8301 -
8302 -
8303 #ifdef CONFIG_SPU_BASE
8304 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8305 #define NT_SPU 1
8306 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8307 index 8196e9c..d83a9f3 100644
8308 --- a/arch/powerpc/include/asm/exec.h
8309 +++ b/arch/powerpc/include/asm/exec.h
8310 @@ -4,6 +4,6 @@
8311 #ifndef _ASM_POWERPC_EXEC_H
8312 #define _ASM_POWERPC_EXEC_H
8313
8314 -extern unsigned long arch_align_stack(unsigned long sp);
8315 +#define arch_align_stack(x) ((x) & ~0xfUL)
8316
8317 #endif /* _ASM_POWERPC_EXEC_H */
8318 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8319 index 5acabbd..7ea14fa 100644
8320 --- a/arch/powerpc/include/asm/kmap_types.h
8321 +++ b/arch/powerpc/include/asm/kmap_types.h
8322 @@ -10,7 +10,7 @@
8323 * 2 of the License, or (at your option) any later version.
8324 */
8325
8326 -#define KM_TYPE_NR 16
8327 +#define KM_TYPE_NR 17
8328
8329 #endif /* __KERNEL__ */
8330 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8331 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8332 index b8da913..c02b593 100644
8333 --- a/arch/powerpc/include/asm/local.h
8334 +++ b/arch/powerpc/include/asm/local.h
8335 @@ -9,21 +9,65 @@ typedef struct
8336 atomic_long_t a;
8337 } local_t;
8338
8339 +typedef struct
8340 +{
8341 + atomic_long_unchecked_t a;
8342 +} local_unchecked_t;
8343 +
8344 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8345
8346 #define local_read(l) atomic_long_read(&(l)->a)
8347 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8348 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8349 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8350
8351 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8352 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8353 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8354 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8355 #define local_inc(l) atomic_long_inc(&(l)->a)
8356 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8357 #define local_dec(l) atomic_long_dec(&(l)->a)
8358 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8359
8360 static __inline__ long local_add_return(long a, local_t *l)
8361 {
8362 long t;
8363
8364 __asm__ __volatile__(
8365 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8366 +
8367 +#ifdef CONFIG_PAX_REFCOUNT
8368 +" mcrxr cr0\n"
8369 +" addo. %0,%1,%0\n"
8370 +" bf 4*cr0+so, 3f\n"
8371 +"2:.long " "0x00c00b00""\n"
8372 +#else
8373 +" add %0,%1,%0\n"
8374 +#endif
8375 +
8376 +"3:\n"
8377 + PPC405_ERR77(0,%2)
8378 + PPC_STLCX "%0,0,%2 \n\
8379 + bne- 1b"
8380 +
8381 +#ifdef CONFIG_PAX_REFCOUNT
8382 +"\n4:\n"
8383 + _ASM_EXTABLE(2b, 4b)
8384 +#endif
8385 +
8386 + : "=&r" (t)
8387 + : "r" (a), "r" (&(l->a.counter))
8388 + : "cc", "memory");
8389 +
8390 + return t;
8391 +}
8392 +
8393 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8394 +{
8395 + long t;
8396 +
8397 + __asm__ __volatile__(
8398 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8399 add %0,%1,%0\n"
8400 PPC405_ERR77(0,%2)
8401 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8402
8403 #define local_cmpxchg(l, o, n) \
8404 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8405 +#define local_cmpxchg_unchecked(l, o, n) \
8406 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8407 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8408
8409 /**
8410 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8411 index 8565c25..2865190 100644
8412 --- a/arch/powerpc/include/asm/mman.h
8413 +++ b/arch/powerpc/include/asm/mman.h
8414 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8415 }
8416 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8417
8418 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8419 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8420 {
8421 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8422 }
8423 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8424 index 26fe1ae..987ffc5 100644
8425 --- a/arch/powerpc/include/asm/page.h
8426 +++ b/arch/powerpc/include/asm/page.h
8427 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8428 * and needs to be executable. This means the whole heap ends
8429 * up being executable.
8430 */
8431 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8432 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8433 +#define VM_DATA_DEFAULT_FLAGS32 \
8434 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8435 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8436
8437 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8438 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8439 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8440 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8441 #endif
8442
8443 +#define ktla_ktva(addr) (addr)
8444 +#define ktva_ktla(addr) (addr)
8445 +
8446 #ifndef CONFIG_PPC_BOOK3S_64
8447 /*
8448 * Use the top bit of the higher-level page table entries to indicate whether
8449 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8450 index d908a46..3753f71 100644
8451 --- a/arch/powerpc/include/asm/page_64.h
8452 +++ b/arch/powerpc/include/asm/page_64.h
8453 @@ -172,15 +172,18 @@ do { \
8454 * stack by default, so in the absence of a PT_GNU_STACK program header
8455 * we turn execute permission off.
8456 */
8457 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8458 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8459 +#define VM_STACK_DEFAULT_FLAGS32 \
8460 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8461 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8462
8463 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8464 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8465
8466 +#ifndef CONFIG_PAX_PAGEEXEC
8467 #define VM_STACK_DEFAULT_FLAGS \
8468 (is_32bit_task() ? \
8469 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8470 +#endif
8471
8472 #include <asm-generic/getorder.h>
8473
8474 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8475 index 4b0be20..c15a27d 100644
8476 --- a/arch/powerpc/include/asm/pgalloc-64.h
8477 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8478 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8479 #ifndef CONFIG_PPC_64K_PAGES
8480
8481 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8482 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8483
8484 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8485 {
8486 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8487 pud_set(pud, (unsigned long)pmd);
8488 }
8489
8490 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8491 +{
8492 + pud_populate(mm, pud, pmd);
8493 +}
8494 +
8495 #define pmd_populate(mm, pmd, pte_page) \
8496 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8497 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8498 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8499 #endif
8500
8501 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8502 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8503
8504 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8505 pte_t *pte)
8506 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8507 index 316f9a5..ba05c77 100644
8508 --- a/arch/powerpc/include/asm/pgtable.h
8509 +++ b/arch/powerpc/include/asm/pgtable.h
8510 @@ -2,6 +2,7 @@
8511 #define _ASM_POWERPC_PGTABLE_H
8512 #ifdef __KERNEL__
8513
8514 +#include <linux/const.h>
8515 #ifndef __ASSEMBLY__
8516 #include <linux/mmdebug.h>
8517 #include <linux/mmzone.h>
8518 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8519 index 4aad413..85d86bf 100644
8520 --- a/arch/powerpc/include/asm/pte-hash32.h
8521 +++ b/arch/powerpc/include/asm/pte-hash32.h
8522 @@ -21,6 +21,7 @@
8523 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8524 #define _PAGE_USER 0x004 /* usermode access allowed */
8525 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8526 +#define _PAGE_EXEC _PAGE_GUARDED
8527 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8528 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8529 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8530 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8531 index a68ee15..552d213 100644
8532 --- a/arch/powerpc/include/asm/reg.h
8533 +++ b/arch/powerpc/include/asm/reg.h
8534 @@ -253,6 +253,7 @@
8535 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8536 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8537 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8538 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8539 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8540 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8541 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8542 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8543 index 5a6614a..d89995d1 100644
8544 --- a/arch/powerpc/include/asm/smp.h
8545 +++ b/arch/powerpc/include/asm/smp.h
8546 @@ -51,7 +51,7 @@ struct smp_ops_t {
8547 int (*cpu_disable)(void);
8548 void (*cpu_die)(unsigned int nr);
8549 int (*cpu_bootable)(unsigned int nr);
8550 -};
8551 +} __no_const;
8552
8553 extern void smp_send_debugger_break(void);
8554 extern void start_secondary_resume(void);
8555 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8556 index 4dbe072..b803275 100644
8557 --- a/arch/powerpc/include/asm/spinlock.h
8558 +++ b/arch/powerpc/include/asm/spinlock.h
8559 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8560 __asm__ __volatile__(
8561 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8562 __DO_SIGN_EXTEND
8563 -" addic. %0,%0,1\n\
8564 - ble- 2f\n"
8565 +
8566 +#ifdef CONFIG_PAX_REFCOUNT
8567 +" mcrxr cr0\n"
8568 +" addico. %0,%0,1\n"
8569 +" bf 4*cr0+so, 3f\n"
8570 +"2:.long " "0x00c00b00""\n"
8571 +#else
8572 +" addic. %0,%0,1\n"
8573 +#endif
8574 +
8575 +"3:\n"
8576 + "ble- 4f\n"
8577 PPC405_ERR77(0,%1)
8578 " stwcx. %0,0,%1\n\
8579 bne- 1b\n"
8580 PPC_ACQUIRE_BARRIER
8581 -"2:" : "=&r" (tmp)
8582 +"4:"
8583 +
8584 +#ifdef CONFIG_PAX_REFCOUNT
8585 + _ASM_EXTABLE(2b,4b)
8586 +#endif
8587 +
8588 + : "=&r" (tmp)
8589 : "r" (&rw->lock)
8590 : "cr0", "xer", "memory");
8591
8592 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8593 __asm__ __volatile__(
8594 "# read_unlock\n\t"
8595 PPC_RELEASE_BARRIER
8596 -"1: lwarx %0,0,%1\n\
8597 - addic %0,%0,-1\n"
8598 +"1: lwarx %0,0,%1\n"
8599 +
8600 +#ifdef CONFIG_PAX_REFCOUNT
8601 +" mcrxr cr0\n"
8602 +" addico. %0,%0,-1\n"
8603 +" bf 4*cr0+so, 3f\n"
8604 +"2:.long " "0x00c00b00""\n"
8605 +#else
8606 +" addic. %0,%0,-1\n"
8607 +#endif
8608 +
8609 +"3:\n"
8610 PPC405_ERR77(0,%1)
8611 " stwcx. %0,0,%1\n\
8612 bne- 1b"
8613 +
8614 +#ifdef CONFIG_PAX_REFCOUNT
8615 +"\n4:\n"
8616 + _ASM_EXTABLE(2b, 4b)
8617 +#endif
8618 +
8619 : "=&r"(tmp)
8620 : "r"(&rw->lock)
8621 : "cr0", "xer", "memory");
8622 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8623 index b034ecd..af7e31f 100644
8624 --- a/arch/powerpc/include/asm/thread_info.h
8625 +++ b/arch/powerpc/include/asm/thread_info.h
8626 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8627 #if defined(CONFIG_PPC64)
8628 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8629 #endif
8630 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8631 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8632
8633 /* as above, but as bit values */
8634 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8635 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8636 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8637 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8638 #define _TIF_NOHZ (1<<TIF_NOHZ)
8639 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8640 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8641 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8642 - _TIF_NOHZ)
8643 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8644
8645 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8646 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8647 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8648 index 9485b43..3bd3c16 100644
8649 --- a/arch/powerpc/include/asm/uaccess.h
8650 +++ b/arch/powerpc/include/asm/uaccess.h
8651 @@ -58,6 +58,7 @@
8652
8653 #endif
8654
8655 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8656 #define access_ok(type, addr, size) \
8657 (__chk_user_ptr(addr), \
8658 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8659 @@ -318,52 +319,6 @@ do { \
8660 extern unsigned long __copy_tofrom_user(void __user *to,
8661 const void __user *from, unsigned long size);
8662
8663 -#ifndef __powerpc64__
8664 -
8665 -static inline unsigned long copy_from_user(void *to,
8666 - const void __user *from, unsigned long n)
8667 -{
8668 - unsigned long over;
8669 -
8670 - if (access_ok(VERIFY_READ, from, n))
8671 - return __copy_tofrom_user((__force void __user *)to, from, n);
8672 - if ((unsigned long)from < TASK_SIZE) {
8673 - over = (unsigned long)from + n - TASK_SIZE;
8674 - return __copy_tofrom_user((__force void __user *)to, from,
8675 - n - over) + over;
8676 - }
8677 - return n;
8678 -}
8679 -
8680 -static inline unsigned long copy_to_user(void __user *to,
8681 - const void *from, unsigned long n)
8682 -{
8683 - unsigned long over;
8684 -
8685 - if (access_ok(VERIFY_WRITE, to, n))
8686 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8687 - if ((unsigned long)to < TASK_SIZE) {
8688 - over = (unsigned long)to + n - TASK_SIZE;
8689 - return __copy_tofrom_user(to, (__force void __user *)from,
8690 - n - over) + over;
8691 - }
8692 - return n;
8693 -}
8694 -
8695 -#else /* __powerpc64__ */
8696 -
8697 -#define __copy_in_user(to, from, size) \
8698 - __copy_tofrom_user((to), (from), (size))
8699 -
8700 -extern unsigned long copy_from_user(void *to, const void __user *from,
8701 - unsigned long n);
8702 -extern unsigned long copy_to_user(void __user *to, const void *from,
8703 - unsigned long n);
8704 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8705 - unsigned long n);
8706 -
8707 -#endif /* __powerpc64__ */
8708 -
8709 static inline unsigned long __copy_from_user_inatomic(void *to,
8710 const void __user *from, unsigned long n)
8711 {
8712 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8713 if (ret == 0)
8714 return 0;
8715 }
8716 +
8717 + if (!__builtin_constant_p(n))
8718 + check_object_size(to, n, false);
8719 +
8720 return __copy_tofrom_user((__force void __user *)to, from, n);
8721 }
8722
8723 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8724 if (ret == 0)
8725 return 0;
8726 }
8727 +
8728 + if (!__builtin_constant_p(n))
8729 + check_object_size(from, n, true);
8730 +
8731 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8732 }
8733
8734 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8735 return __copy_to_user_inatomic(to, from, size);
8736 }
8737
8738 +#ifndef __powerpc64__
8739 +
8740 +static inline unsigned long __must_check copy_from_user(void *to,
8741 + const void __user *from, unsigned long n)
8742 +{
8743 + unsigned long over;
8744 +
8745 + if ((long)n < 0)
8746 + return n;
8747 +
8748 + if (access_ok(VERIFY_READ, from, n)) {
8749 + if (!__builtin_constant_p(n))
8750 + check_object_size(to, n, false);
8751 + return __copy_tofrom_user((__force void __user *)to, from, n);
8752 + }
8753 + if ((unsigned long)from < TASK_SIZE) {
8754 + over = (unsigned long)from + n - TASK_SIZE;
8755 + if (!__builtin_constant_p(n - over))
8756 + check_object_size(to, n - over, false);
8757 + return __copy_tofrom_user((__force void __user *)to, from,
8758 + n - over) + over;
8759 + }
8760 + return n;
8761 +}
8762 +
8763 +static inline unsigned long __must_check copy_to_user(void __user *to,
8764 + const void *from, unsigned long n)
8765 +{
8766 + unsigned long over;
8767 +
8768 + if ((long)n < 0)
8769 + return n;
8770 +
8771 + if (access_ok(VERIFY_WRITE, to, n)) {
8772 + if (!__builtin_constant_p(n))
8773 + check_object_size(from, n, true);
8774 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8775 + }
8776 + if ((unsigned long)to < TASK_SIZE) {
8777 + over = (unsigned long)to + n - TASK_SIZE;
8778 + if (!__builtin_constant_p(n))
8779 + check_object_size(from, n - over, true);
8780 + return __copy_tofrom_user(to, (__force void __user *)from,
8781 + n - over) + over;
8782 + }
8783 + return n;
8784 +}
8785 +
8786 +#else /* __powerpc64__ */
8787 +
8788 +#define __copy_in_user(to, from, size) \
8789 + __copy_tofrom_user((to), (from), (size))
8790 +
8791 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8792 +{
8793 + if ((long)n < 0 || n > INT_MAX)
8794 + return n;
8795 +
8796 + if (!__builtin_constant_p(n))
8797 + check_object_size(to, n, false);
8798 +
8799 + if (likely(access_ok(VERIFY_READ, from, n)))
8800 + n = __copy_from_user(to, from, n);
8801 + else
8802 + memset(to, 0, n);
8803 + return n;
8804 +}
8805 +
8806 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8807 +{
8808 + if ((long)n < 0 || n > INT_MAX)
8809 + return n;
8810 +
8811 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8812 + if (!__builtin_constant_p(n))
8813 + check_object_size(from, n, true);
8814 + n = __copy_to_user(to, from, n);
8815 + }
8816 + return n;
8817 +}
8818 +
8819 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8820 + unsigned long n);
8821 +
8822 +#endif /* __powerpc64__ */
8823 +
8824 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8825
8826 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8827 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8828 index 502cf69..822e63b 100644
8829 --- a/arch/powerpc/kernel/Makefile
8830 +++ b/arch/powerpc/kernel/Makefile
8831 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8832 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8833 endif
8834
8835 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8836 +
8837 obj-y := cputable.o ptrace.o syscalls.o \
8838 irq.o align.o signal_32.o pmc.o vdso.o \
8839 process.o systbl.o idle.o \
8840 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8841 index 3e68d1c..72a5ee6 100644
8842 --- a/arch/powerpc/kernel/exceptions-64e.S
8843 +++ b/arch/powerpc/kernel/exceptions-64e.S
8844 @@ -1010,6 +1010,7 @@ storage_fault_common:
8845 std r14,_DAR(r1)
8846 std r15,_DSISR(r1)
8847 addi r3,r1,STACK_FRAME_OVERHEAD
8848 + bl save_nvgprs
8849 mr r4,r14
8850 mr r5,r15
8851 ld r14,PACA_EXGEN+EX_R14(r13)
8852 @@ -1018,8 +1019,7 @@ storage_fault_common:
8853 cmpdi r3,0
8854 bne- 1f
8855 b ret_from_except_lite
8856 -1: bl save_nvgprs
8857 - mr r5,r3
8858 +1: mr r5,r3
8859 addi r3,r1,STACK_FRAME_OVERHEAD
8860 ld r4,_DAR(r1)
8861 bl bad_page_fault
8862 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8863 index 72e783e..fe058e2 100644
8864 --- a/arch/powerpc/kernel/exceptions-64s.S
8865 +++ b/arch/powerpc/kernel/exceptions-64s.S
8866 @@ -1588,10 +1588,10 @@ handle_page_fault:
8867 11: ld r4,_DAR(r1)
8868 ld r5,_DSISR(r1)
8869 addi r3,r1,STACK_FRAME_OVERHEAD
8870 + bl save_nvgprs
8871 bl do_page_fault
8872 cmpdi r3,0
8873 beq+ 12f
8874 - bl save_nvgprs
8875 mr r5,r3
8876 addi r3,r1,STACK_FRAME_OVERHEAD
8877 lwz r4,_DAR(r1)
8878 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8879 index c143835..5a9697f 100644
8880 --- a/arch/powerpc/kernel/irq.c
8881 +++ b/arch/powerpc/kernel/irq.c
8882 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8883 }
8884 #endif
8885
8886 +extern void gr_handle_kernel_exploit(void);
8887 +
8888 static inline void check_stack_overflow(void)
8889 {
8890 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8891 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8892 pr_err("do_IRQ: stack overflow: %ld\n",
8893 sp - sizeof(struct thread_info));
8894 dump_stack();
8895 + gr_handle_kernel_exploit();
8896 }
8897 #endif
8898 }
8899 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8900 index c94d2e0..992a9ce 100644
8901 --- a/arch/powerpc/kernel/module_32.c
8902 +++ b/arch/powerpc/kernel/module_32.c
8903 @@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8904 me->arch.core_plt_section = i;
8905 }
8906 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8907 - pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8908 + pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8909 return -ENOEXEC;
8910 }
8911
8912 @@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8913
8914 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8915 /* Init, or core PLT? */
8916 - if (location >= mod->module_core
8917 - && location < mod->module_core + mod->core_size)
8918 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8919 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8920 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8921 - else
8922 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8923 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8924 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8925 + else {
8926 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8927 + return ~0UL;
8928 + }
8929
8930 /* Find this entry, or if that fails, the next avail. entry */
8931 while (entry->jump[0]) {
8932 @@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8933 }
8934 #ifdef CONFIG_DYNAMIC_FTRACE
8935 module->arch.tramp =
8936 - do_plt_call(module->module_core,
8937 + do_plt_call(module->module_core_rx,
8938 (unsigned long)ftrace_caller,
8939 sechdrs, module);
8940 #endif
8941 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8942 index 923cd2d..ae782a9 100644
8943 --- a/arch/powerpc/kernel/process.c
8944 +++ b/arch/powerpc/kernel/process.c
8945 @@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8946 * Lookup NIP late so we have the best change of getting the
8947 * above info out without failing
8948 */
8949 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8950 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8951 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8952 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8953 #endif
8954 show_stack(current, (unsigned long *) regs->gpr[1]);
8955 if (!user_mode(regs))
8956 @@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8957 newsp = stack[0];
8958 ip = stack[STACK_FRAME_LR_SAVE];
8959 if (!firstframe || ip != lr) {
8960 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8961 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8962 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8963 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8964 - printk(" (%pS)",
8965 + printk(" (%pA)",
8966 (void *)current->ret_stack[curr_frame].ret);
8967 curr_frame--;
8968 }
8969 @@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8970 struct pt_regs *regs = (struct pt_regs *)
8971 (sp + STACK_FRAME_OVERHEAD);
8972 lr = regs->link;
8973 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8974 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8975 regs->trap, (void *)regs->nip, (void *)lr);
8976 firstframe = 1;
8977 }
8978 @@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8979 mtspr(SPRN_CTRLT, ctrl);
8980 }
8981 #endif /* CONFIG_PPC64 */
8982 -
8983 -unsigned long arch_align_stack(unsigned long sp)
8984 -{
8985 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8986 - sp -= get_random_int() & ~PAGE_MASK;
8987 - return sp & ~0xf;
8988 -}
8989 -
8990 -static inline unsigned long brk_rnd(void)
8991 -{
8992 - unsigned long rnd = 0;
8993 -
8994 - /* 8MB for 32bit, 1GB for 64bit */
8995 - if (is_32bit_task())
8996 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8997 - else
8998 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8999 -
9000 - return rnd << PAGE_SHIFT;
9001 -}
9002 -
9003 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9004 -{
9005 - unsigned long base = mm->brk;
9006 - unsigned long ret;
9007 -
9008 -#ifdef CONFIG_PPC_STD_MMU_64
9009 - /*
9010 - * If we are using 1TB segments and we are allowed to randomise
9011 - * the heap, we can put it above 1TB so it is backed by a 1TB
9012 - * segment. Otherwise the heap will be in the bottom 1TB
9013 - * which always uses 256MB segments and this may result in a
9014 - * performance penalty.
9015 - */
9016 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9017 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9018 -#endif
9019 -
9020 - ret = PAGE_ALIGN(base + brk_rnd());
9021 -
9022 - if (ret < mm->brk)
9023 - return mm->brk;
9024 -
9025 - return ret;
9026 -}
9027 -
9028 -unsigned long randomize_et_dyn(unsigned long base)
9029 -{
9030 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9031 -
9032 - if (ret < base)
9033 - return base;
9034 -
9035 - return ret;
9036 -}
9037 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9038 index f21897b..28c0428 100644
9039 --- a/arch/powerpc/kernel/ptrace.c
9040 +++ b/arch/powerpc/kernel/ptrace.c
9041 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9042 return ret;
9043 }
9044
9045 +#ifdef CONFIG_GRKERNSEC_SETXID
9046 +extern void gr_delayed_cred_worker(void);
9047 +#endif
9048 +
9049 /*
9050 * We must return the syscall number to actually look up in the table.
9051 * This can be -1L to skip running any syscall at all.
9052 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9053
9054 secure_computing_strict(regs->gpr[0]);
9055
9056 +#ifdef CONFIG_GRKERNSEC_SETXID
9057 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9058 + gr_delayed_cred_worker();
9059 +#endif
9060 +
9061 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9062 tracehook_report_syscall_entry(regs))
9063 /*
9064 @@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9065 {
9066 int step;
9067
9068 +#ifdef CONFIG_GRKERNSEC_SETXID
9069 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9070 + gr_delayed_cred_worker();
9071 +#endif
9072 +
9073 audit_syscall_exit(regs);
9074
9075 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9076 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9077 index b171001..4ac7ac5 100644
9078 --- a/arch/powerpc/kernel/signal_32.c
9079 +++ b/arch/powerpc/kernel/signal_32.c
9080 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9081 /* Save user registers on the stack */
9082 frame = &rt_sf->uc.uc_mcontext;
9083 addr = frame;
9084 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9085 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9086 sigret = 0;
9087 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9088 } else {
9089 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9090 index 2cb0c94..c0c0bc9 100644
9091 --- a/arch/powerpc/kernel/signal_64.c
9092 +++ b/arch/powerpc/kernel/signal_64.c
9093 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9094 current->thread.fp_state.fpscr = 0;
9095
9096 /* Set up to return from userspace. */
9097 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9098 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9099 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9100 } else {
9101 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9102 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9103 index 0dc43f9..a885d33 100644
9104 --- a/arch/powerpc/kernel/traps.c
9105 +++ b/arch/powerpc/kernel/traps.c
9106 @@ -36,6 +36,7 @@
9107 #include <linux/debugfs.h>
9108 #include <linux/ratelimit.h>
9109 #include <linux/context_tracking.h>
9110 +#include <linux/uaccess.h>
9111
9112 #include <asm/emulated_ops.h>
9113 #include <asm/pgtable.h>
9114 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9115 return flags;
9116 }
9117
9118 +extern void gr_handle_kernel_exploit(void);
9119 +
9120 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9121 int signr)
9122 {
9123 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9124 panic("Fatal exception in interrupt");
9125 if (panic_on_oops)
9126 panic("Fatal exception");
9127 +
9128 + gr_handle_kernel_exploit();
9129 +
9130 do_exit(signr);
9131 }
9132
9133 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9134 enum ctx_state prev_state = exception_enter();
9135 unsigned int reason = get_reason(regs);
9136
9137 +#ifdef CONFIG_PAX_REFCOUNT
9138 + unsigned int bkpt;
9139 + const struct exception_table_entry *entry;
9140 +
9141 + if (reason & REASON_ILLEGAL) {
9142 + /* Check if PaX bad instruction */
9143 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9144 + current->thread.trap_nr = 0;
9145 + pax_report_refcount_overflow(regs);
9146 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9147 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9148 + regs->nip = entry->fixup;
9149 + return;
9150 + }
9151 + /* fixup_exception() could not handle */
9152 + goto bail;
9153 + }
9154 + }
9155 +#endif
9156 +
9157 /* We can now get here via a FP Unavailable exception if the core
9158 * has no FPU, in that case the reason flags will be 0 */
9159
9160 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9161 index f174351..5722009 100644
9162 --- a/arch/powerpc/kernel/vdso.c
9163 +++ b/arch/powerpc/kernel/vdso.c
9164 @@ -35,6 +35,7 @@
9165 #include <asm/vdso.h>
9166 #include <asm/vdso_datapage.h>
9167 #include <asm/setup.h>
9168 +#include <asm/mman.h>
9169
9170 #undef DEBUG
9171
9172 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9173 vdso_base = VDSO32_MBASE;
9174 #endif
9175
9176 - current->mm->context.vdso_base = 0;
9177 + current->mm->context.vdso_base = ~0UL;
9178
9179 /* vDSO has a problem and was disabled, just don't "enable" it for the
9180 * process
9181 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9182 vdso_base = get_unmapped_area(NULL, vdso_base,
9183 (vdso_pages << PAGE_SHIFT) +
9184 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9185 - 0, 0);
9186 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9187 if (IS_ERR_VALUE(vdso_base)) {
9188 rc = vdso_base;
9189 goto fail_mmapsem;
9190 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9191 index c1f8f53..71a3b96 100644
9192 --- a/arch/powerpc/kvm/powerpc.c
9193 +++ b/arch/powerpc/kvm/powerpc.c
9194 @@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9195 }
9196 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9197
9198 -int kvm_arch_init(void *opaque)
9199 +int kvm_arch_init(const void *opaque)
9200 {
9201 return 0;
9202 }
9203 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9204 index 5eea6f3..5d10396 100644
9205 --- a/arch/powerpc/lib/usercopy_64.c
9206 +++ b/arch/powerpc/lib/usercopy_64.c
9207 @@ -9,22 +9,6 @@
9208 #include <linux/module.h>
9209 #include <asm/uaccess.h>
9210
9211 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9212 -{
9213 - if (likely(access_ok(VERIFY_READ, from, n)))
9214 - n = __copy_from_user(to, from, n);
9215 - else
9216 - memset(to, 0, n);
9217 - return n;
9218 -}
9219 -
9220 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9221 -{
9222 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9223 - n = __copy_to_user(to, from, n);
9224 - return n;
9225 -}
9226 -
9227 unsigned long copy_in_user(void __user *to, const void __user *from,
9228 unsigned long n)
9229 {
9230 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9231 return n;
9232 }
9233
9234 -EXPORT_SYMBOL(copy_from_user);
9235 -EXPORT_SYMBOL(copy_to_user);
9236 EXPORT_SYMBOL(copy_in_user);
9237
9238 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9239 index f06b56b..ffb2fb4 100644
9240 --- a/arch/powerpc/mm/fault.c
9241 +++ b/arch/powerpc/mm/fault.c
9242 @@ -33,6 +33,10 @@
9243 #include <linux/ratelimit.h>
9244 #include <linux/context_tracking.h>
9245 #include <linux/hugetlb.h>
9246 +#include <linux/slab.h>
9247 +#include <linux/pagemap.h>
9248 +#include <linux/compiler.h>
9249 +#include <linux/unistd.h>
9250
9251 #include <asm/firmware.h>
9252 #include <asm/page.h>
9253 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9254 }
9255 #endif
9256
9257 +#ifdef CONFIG_PAX_PAGEEXEC
9258 +/*
9259 + * PaX: decide what to do with offenders (regs->nip = fault address)
9260 + *
9261 + * returns 1 when task should be killed
9262 + */
9263 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9264 +{
9265 + return 1;
9266 +}
9267 +
9268 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9269 +{
9270 + unsigned long i;
9271 +
9272 + printk(KERN_ERR "PAX: bytes at PC: ");
9273 + for (i = 0; i < 5; i++) {
9274 + unsigned int c;
9275 + if (get_user(c, (unsigned int __user *)pc+i))
9276 + printk(KERN_CONT "???????? ");
9277 + else
9278 + printk(KERN_CONT "%08x ", c);
9279 + }
9280 + printk("\n");
9281 +}
9282 +#endif
9283 +
9284 /*
9285 * Check whether the instruction at regs->nip is a store using
9286 * an update addressing form which will update r1.
9287 @@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9288 * indicate errors in DSISR but can validly be set in SRR1.
9289 */
9290 if (trap == 0x400)
9291 - error_code &= 0x48200000;
9292 + error_code &= 0x58200000;
9293 else
9294 is_write = error_code & DSISR_ISSTORE;
9295 #else
9296 @@ -390,7 +421,7 @@ good_area:
9297 * "undefined". Of those that can be set, this is the only
9298 * one which seems bad.
9299 */
9300 - if (error_code & 0x10000000)
9301 + if (error_code & DSISR_GUARDED)
9302 /* Guarded storage error. */
9303 goto bad_area;
9304 #endif /* CONFIG_8xx */
9305 @@ -405,7 +436,7 @@ good_area:
9306 * processors use the same I/D cache coherency mechanism
9307 * as embedded.
9308 */
9309 - if (error_code & DSISR_PROTFAULT)
9310 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9311 goto bad_area;
9312 #endif /* CONFIG_PPC_STD_MMU */
9313
9314 @@ -497,6 +528,23 @@ bad_area:
9315 bad_area_nosemaphore:
9316 /* User mode accesses cause a SIGSEGV */
9317 if (user_mode(regs)) {
9318 +
9319 +#ifdef CONFIG_PAX_PAGEEXEC
9320 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9321 +#ifdef CONFIG_PPC_STD_MMU
9322 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9323 +#else
9324 + if (is_exec && regs->nip == address) {
9325 +#endif
9326 + switch (pax_handle_fetch_fault(regs)) {
9327 + }
9328 +
9329 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9330 + do_group_exit(SIGKILL);
9331 + }
9332 + }
9333 +#endif
9334 +
9335 _exception(SIGSEGV, regs, code, address);
9336 goto bail;
9337 }
9338 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9339 index cb8bdbe..cde4bc7 100644
9340 --- a/arch/powerpc/mm/mmap.c
9341 +++ b/arch/powerpc/mm/mmap.c
9342 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9343 return sysctl_legacy_va_layout;
9344 }
9345
9346 -static unsigned long mmap_rnd(void)
9347 +static unsigned long mmap_rnd(struct mm_struct *mm)
9348 {
9349 unsigned long rnd = 0;
9350
9351 +#ifdef CONFIG_PAX_RANDMMAP
9352 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9353 +#endif
9354 +
9355 if (current->flags & PF_RANDOMIZE) {
9356 /* 8MB for 32bit, 1GB for 64bit */
9357 if (is_32bit_task())
9358 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9359 return rnd << PAGE_SHIFT;
9360 }
9361
9362 -static inline unsigned long mmap_base(void)
9363 +static inline unsigned long mmap_base(struct mm_struct *mm)
9364 {
9365 unsigned long gap = rlimit(RLIMIT_STACK);
9366
9367 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9368 else if (gap > MAX_GAP)
9369 gap = MAX_GAP;
9370
9371 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9372 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9373 }
9374
9375 /*
9376 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9377 */
9378 if (mmap_is_legacy()) {
9379 mm->mmap_base = TASK_UNMAPPED_BASE;
9380 +
9381 +#ifdef CONFIG_PAX_RANDMMAP
9382 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9383 + mm->mmap_base += mm->delta_mmap;
9384 +#endif
9385 +
9386 mm->get_unmapped_area = arch_get_unmapped_area;
9387 } else {
9388 - mm->mmap_base = mmap_base();
9389 + mm->mmap_base = mmap_base(mm);
9390 +
9391 +#ifdef CONFIG_PAX_RANDMMAP
9392 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9393 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9394 +#endif
9395 +
9396 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9397 }
9398 }
9399 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9400 index ded0ea1..f213a9b 100644
9401 --- a/arch/powerpc/mm/slice.c
9402 +++ b/arch/powerpc/mm/slice.c
9403 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9404 if ((mm->task_size - len) < addr)
9405 return 0;
9406 vma = find_vma(mm, addr);
9407 - return (!vma || (addr + len) <= vma->vm_start);
9408 + return check_heap_stack_gap(vma, addr, len, 0);
9409 }
9410
9411 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9412 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9413 info.align_offset = 0;
9414
9415 addr = TASK_UNMAPPED_BASE;
9416 +
9417 +#ifdef CONFIG_PAX_RANDMMAP
9418 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9419 + addr += mm->delta_mmap;
9420 +#endif
9421 +
9422 while (addr < TASK_SIZE) {
9423 info.low_limit = addr;
9424 if (!slice_scan_available(addr, available, 1, &addr))
9425 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9426 if (fixed && addr > (mm->task_size - len))
9427 return -ENOMEM;
9428
9429 +#ifdef CONFIG_PAX_RANDMMAP
9430 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9431 + addr = 0;
9432 +#endif
9433 +
9434 /* If hint, make sure it matches our alignment restrictions */
9435 if (!fixed && addr) {
9436 addr = _ALIGN_UP(addr, 1ul << pshift);
9437 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9438 index 4278acf..67fd0e6 100644
9439 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9440 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9441 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9442 }
9443
9444 static struct pci_ops scc_pciex_pci_ops = {
9445 - scc_pciex_read_config,
9446 - scc_pciex_write_config,
9447 + .read = scc_pciex_read_config,
9448 + .write = scc_pciex_write_config,
9449 };
9450
9451 static void pciex_clear_intr_all(unsigned int __iomem *base)
9452 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9453 index d966bbe..372124a 100644
9454 --- a/arch/powerpc/platforms/cell/spufs/file.c
9455 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9456 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9457 return VM_FAULT_NOPAGE;
9458 }
9459
9460 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9461 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9462 unsigned long address,
9463 - void *buf, int len, int write)
9464 + void *buf, size_t len, int write)
9465 {
9466 struct spu_context *ctx = vma->vm_file->private_data;
9467 unsigned long offset = address - vma->vm_start;
9468 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9469 index fa934fe..c296056 100644
9470 --- a/arch/s390/include/asm/atomic.h
9471 +++ b/arch/s390/include/asm/atomic.h
9472 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9473 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9474 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9475
9476 +#define atomic64_read_unchecked(v) atomic64_read(v)
9477 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9478 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9479 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9480 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9481 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9482 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9483 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9484 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9485 +
9486 #endif /* __ARCH_S390_ATOMIC__ */
9487 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9488 index b5dce65..8aca09a 100644
9489 --- a/arch/s390/include/asm/barrier.h
9490 +++ b/arch/s390/include/asm/barrier.h
9491 @@ -39,7 +39,7 @@
9492 do { \
9493 compiletime_assert_atomic_type(*p); \
9494 barrier(); \
9495 - ACCESS_ONCE(*p) = (v); \
9496 + ACCESS_ONCE_RW(*p) = (v); \
9497 } while (0)
9498
9499 #define smp_load_acquire(p) \
9500 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9501 index 4d7ccac..d03d0ad 100644
9502 --- a/arch/s390/include/asm/cache.h
9503 +++ b/arch/s390/include/asm/cache.h
9504 @@ -9,8 +9,10 @@
9505 #ifndef __ARCH_S390_CACHE_H
9506 #define __ARCH_S390_CACHE_H
9507
9508 -#define L1_CACHE_BYTES 256
9509 +#include <linux/const.h>
9510 +
9511 #define L1_CACHE_SHIFT 8
9512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9513 #define NET_SKB_PAD 32
9514
9515 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9516 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9517 index f6e43d3..5f57681 100644
9518 --- a/arch/s390/include/asm/elf.h
9519 +++ b/arch/s390/include/asm/elf.h
9520 @@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9521 the loader. We need to make sure that it is out of the way of the program
9522 that it will "exec", and that there is sufficient room for the brk. */
9523
9524 -extern unsigned long randomize_et_dyn(unsigned long base);
9525 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9526 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9527 +
9528 +#ifdef CONFIG_PAX_ASLR
9529 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9530 +
9531 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9532 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9533 +#endif
9534
9535 /* This yields a mask that user programs can use to figure out what
9536 instruction set this CPU supports. */
9537 @@ -223,9 +229,6 @@ struct linux_binprm;
9538 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9539 int arch_setup_additional_pages(struct linux_binprm *, int);
9540
9541 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9542 -#define arch_randomize_brk arch_randomize_brk
9543 -
9544 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9545
9546 #endif
9547 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9548 index c4a93d6..4d2a9b4 100644
9549 --- a/arch/s390/include/asm/exec.h
9550 +++ b/arch/s390/include/asm/exec.h
9551 @@ -7,6 +7,6 @@
9552 #ifndef __ASM_EXEC_H
9553 #define __ASM_EXEC_H
9554
9555 -extern unsigned long arch_align_stack(unsigned long sp);
9556 +#define arch_align_stack(x) ((x) & ~0xfUL)
9557
9558 #endif /* __ASM_EXEC_H */
9559 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9560 index cd4c68e..6764641 100644
9561 --- a/arch/s390/include/asm/uaccess.h
9562 +++ b/arch/s390/include/asm/uaccess.h
9563 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9564 __range_ok((unsigned long)(addr), (size)); \
9565 })
9566
9567 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9568 #define access_ok(type, addr, size) __access_ok(addr, size)
9569
9570 /*
9571 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9572 copy_to_user(void __user *to, const void *from, unsigned long n)
9573 {
9574 might_fault();
9575 +
9576 + if ((long)n < 0)
9577 + return n;
9578 +
9579 return __copy_to_user(to, from, n);
9580 }
9581
9582 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9583 static inline unsigned long __must_check
9584 copy_from_user(void *to, const void __user *from, unsigned long n)
9585 {
9586 - unsigned int sz = __compiletime_object_size(to);
9587 + size_t sz = __compiletime_object_size(to);
9588
9589 might_fault();
9590 - if (unlikely(sz != -1 && sz < n)) {
9591 +
9592 + if ((long)n < 0)
9593 + return n;
9594 +
9595 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9596 copy_from_user_overflow();
9597 return n;
9598 }
9599 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9600 index b89b591..fd9609d 100644
9601 --- a/arch/s390/kernel/module.c
9602 +++ b/arch/s390/kernel/module.c
9603 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9604
9605 /* Increase core size by size of got & plt and set start
9606 offsets for got and plt. */
9607 - me->core_size = ALIGN(me->core_size, 4);
9608 - me->arch.got_offset = me->core_size;
9609 - me->core_size += me->arch.got_size;
9610 - me->arch.plt_offset = me->core_size;
9611 - me->core_size += me->arch.plt_size;
9612 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9613 + me->arch.got_offset = me->core_size_rw;
9614 + me->core_size_rw += me->arch.got_size;
9615 + me->arch.plt_offset = me->core_size_rx;
9616 + me->core_size_rx += me->arch.plt_size;
9617 return 0;
9618 }
9619
9620 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9621 if (info->got_initialized == 0) {
9622 Elf_Addr *gotent;
9623
9624 - gotent = me->module_core + me->arch.got_offset +
9625 + gotent = me->module_core_rw + me->arch.got_offset +
9626 info->got_offset;
9627 *gotent = val;
9628 info->got_initialized = 1;
9629 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9630 rc = apply_rela_bits(loc, val, 0, 64, 0);
9631 else if (r_type == R_390_GOTENT ||
9632 r_type == R_390_GOTPLTENT) {
9633 - val += (Elf_Addr) me->module_core - loc;
9634 + val += (Elf_Addr) me->module_core_rw - loc;
9635 rc = apply_rela_bits(loc, val, 1, 32, 1);
9636 }
9637 break;
9638 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9639 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9640 if (info->plt_initialized == 0) {
9641 unsigned int *ip;
9642 - ip = me->module_core + me->arch.plt_offset +
9643 + ip = me->module_core_rx + me->arch.plt_offset +
9644 info->plt_offset;
9645 #ifndef CONFIG_64BIT
9646 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9647 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9648 val - loc + 0xffffUL < 0x1ffffeUL) ||
9649 (r_type == R_390_PLT32DBL &&
9650 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9651 - val = (Elf_Addr) me->module_core +
9652 + val = (Elf_Addr) me->module_core_rx +
9653 me->arch.plt_offset +
9654 info->plt_offset;
9655 val += rela->r_addend - loc;
9656 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9657 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9658 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9659 val = val + rela->r_addend -
9660 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9661 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9662 if (r_type == R_390_GOTOFF16)
9663 rc = apply_rela_bits(loc, val, 0, 16, 0);
9664 else if (r_type == R_390_GOTOFF32)
9665 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9666 break;
9667 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9668 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9669 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9670 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9671 rela->r_addend - loc;
9672 if (r_type == R_390_GOTPC)
9673 rc = apply_rela_bits(loc, val, 1, 32, 0);
9674 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9675 index ed84cc2..c05a9d2 100644
9676 --- a/arch/s390/kernel/process.c
9677 +++ b/arch/s390/kernel/process.c
9678 @@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9679 }
9680 return 0;
9681 }
9682 -
9683 -unsigned long arch_align_stack(unsigned long sp)
9684 -{
9685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9686 - sp -= get_random_int() & ~PAGE_MASK;
9687 - return sp & ~0xf;
9688 -}
9689 -
9690 -static inline unsigned long brk_rnd(void)
9691 -{
9692 - /* 8MB for 32bit, 1GB for 64bit */
9693 - if (is_32bit_task())
9694 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9695 - else
9696 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9697 -}
9698 -
9699 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9700 -{
9701 - unsigned long ret;
9702 -
9703 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9704 - return (ret > mm->brk) ? ret : mm->brk;
9705 -}
9706 -
9707 -unsigned long randomize_et_dyn(unsigned long base)
9708 -{
9709 - unsigned long ret;
9710 -
9711 - if (!(current->flags & PF_RANDOMIZE))
9712 - return base;
9713 - ret = PAGE_ALIGN(base + brk_rnd());
9714 - return (ret > base) ? ret : base;
9715 -}
9716 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9717 index 9b436c2..54fbf0a 100644
9718 --- a/arch/s390/mm/mmap.c
9719 +++ b/arch/s390/mm/mmap.c
9720 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9721 */
9722 if (mmap_is_legacy()) {
9723 mm->mmap_base = mmap_base_legacy();
9724 +
9725 +#ifdef CONFIG_PAX_RANDMMAP
9726 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9727 + mm->mmap_base += mm->delta_mmap;
9728 +#endif
9729 +
9730 mm->get_unmapped_area = arch_get_unmapped_area;
9731 } else {
9732 mm->mmap_base = mmap_base();
9733 +
9734 +#ifdef CONFIG_PAX_RANDMMAP
9735 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9736 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9737 +#endif
9738 +
9739 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9740 }
9741 }
9742 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9743 */
9744 if (mmap_is_legacy()) {
9745 mm->mmap_base = mmap_base_legacy();
9746 +
9747 +#ifdef CONFIG_PAX_RANDMMAP
9748 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9749 + mm->mmap_base += mm->delta_mmap;
9750 +#endif
9751 +
9752 mm->get_unmapped_area = s390_get_unmapped_area;
9753 } else {
9754 mm->mmap_base = mmap_base();
9755 +
9756 +#ifdef CONFIG_PAX_RANDMMAP
9757 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9758 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9759 +#endif
9760 +
9761 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9762 }
9763 }
9764 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9765 index ae3d59f..f65f075 100644
9766 --- a/arch/score/include/asm/cache.h
9767 +++ b/arch/score/include/asm/cache.h
9768 @@ -1,7 +1,9 @@
9769 #ifndef _ASM_SCORE_CACHE_H
9770 #define _ASM_SCORE_CACHE_H
9771
9772 +#include <linux/const.h>
9773 +
9774 #define L1_CACHE_SHIFT 4
9775 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9776 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9777
9778 #endif /* _ASM_SCORE_CACHE_H */
9779 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9780 index f9f3cd5..58ff438 100644
9781 --- a/arch/score/include/asm/exec.h
9782 +++ b/arch/score/include/asm/exec.h
9783 @@ -1,6 +1,6 @@
9784 #ifndef _ASM_SCORE_EXEC_H
9785 #define _ASM_SCORE_EXEC_H
9786
9787 -extern unsigned long arch_align_stack(unsigned long sp);
9788 +#define arch_align_stack(x) (x)
9789
9790 #endif /* _ASM_SCORE_EXEC_H */
9791 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9792 index a1519ad3..e8ac1ff 100644
9793 --- a/arch/score/kernel/process.c
9794 +++ b/arch/score/kernel/process.c
9795 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9796
9797 return task_pt_regs(task)->cp0_epc;
9798 }
9799 -
9800 -unsigned long arch_align_stack(unsigned long sp)
9801 -{
9802 - return sp;
9803 -}
9804 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9805 index ef9e555..331bd29 100644
9806 --- a/arch/sh/include/asm/cache.h
9807 +++ b/arch/sh/include/asm/cache.h
9808 @@ -9,10 +9,11 @@
9809 #define __ASM_SH_CACHE_H
9810 #ifdef __KERNEL__
9811
9812 +#include <linux/const.h>
9813 #include <linux/init.h>
9814 #include <cpu/cache.h>
9815
9816 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9817 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9818
9819 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9820
9821 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9822 index 6777177..cb5e44f 100644
9823 --- a/arch/sh/mm/mmap.c
9824 +++ b/arch/sh/mm/mmap.c
9825 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9826 struct mm_struct *mm = current->mm;
9827 struct vm_area_struct *vma;
9828 int do_colour_align;
9829 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9830 struct vm_unmapped_area_info info;
9831
9832 if (flags & MAP_FIXED) {
9833 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9834 if (filp || (flags & MAP_SHARED))
9835 do_colour_align = 1;
9836
9837 +#ifdef CONFIG_PAX_RANDMMAP
9838 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9839 +#endif
9840 +
9841 if (addr) {
9842 if (do_colour_align)
9843 addr = COLOUR_ALIGN(addr, pgoff);
9844 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9845 addr = PAGE_ALIGN(addr);
9846
9847 vma = find_vma(mm, addr);
9848 - if (TASK_SIZE - len >= addr &&
9849 - (!vma || addr + len <= vma->vm_start))
9850 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9851 return addr;
9852 }
9853
9854 info.flags = 0;
9855 info.length = len;
9856 - info.low_limit = TASK_UNMAPPED_BASE;
9857 + info.low_limit = mm->mmap_base;
9858 info.high_limit = TASK_SIZE;
9859 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9860 info.align_offset = pgoff << PAGE_SHIFT;
9861 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9862 struct mm_struct *mm = current->mm;
9863 unsigned long addr = addr0;
9864 int do_colour_align;
9865 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9866 struct vm_unmapped_area_info info;
9867
9868 if (flags & MAP_FIXED) {
9869 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9870 if (filp || (flags & MAP_SHARED))
9871 do_colour_align = 1;
9872
9873 +#ifdef CONFIG_PAX_RANDMMAP
9874 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9875 +#endif
9876 +
9877 /* requesting a specific address */
9878 if (addr) {
9879 if (do_colour_align)
9880 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9881 addr = PAGE_ALIGN(addr);
9882
9883 vma = find_vma(mm, addr);
9884 - if (TASK_SIZE - len >= addr &&
9885 - (!vma || addr + len <= vma->vm_start))
9886 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9887 return addr;
9888 }
9889
9890 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9891 VM_BUG_ON(addr != -ENOMEM);
9892 info.flags = 0;
9893 info.low_limit = TASK_UNMAPPED_BASE;
9894 +
9895 +#ifdef CONFIG_PAX_RANDMMAP
9896 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9897 + info.low_limit += mm->delta_mmap;
9898 +#endif
9899 +
9900 info.high_limit = TASK_SIZE;
9901 addr = vm_unmapped_area(&info);
9902 }
9903 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9904 index 4082749..fd97781 100644
9905 --- a/arch/sparc/include/asm/atomic_64.h
9906 +++ b/arch/sparc/include/asm/atomic_64.h
9907 @@ -15,18 +15,38 @@
9908 #define ATOMIC64_INIT(i) { (i) }
9909
9910 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9911 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9912 +{
9913 + return ACCESS_ONCE(v->counter);
9914 +}
9915 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9916 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9917 +{
9918 + return ACCESS_ONCE(v->counter);
9919 +}
9920
9921 #define atomic_set(v, i) (((v)->counter) = i)
9922 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9923 +{
9924 + v->counter = i;
9925 +}
9926 #define atomic64_set(v, i) (((v)->counter) = i)
9927 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9928 +{
9929 + v->counter = i;
9930 +}
9931
9932 -#define ATOMIC_OP(op) \
9933 -void atomic_##op(int, atomic_t *); \
9934 -void atomic64_##op(long, atomic64_t *);
9935 +#define __ATOMIC_OP(op, suffix) \
9936 +void atomic_##op##suffix(int, atomic##suffix##_t *); \
9937 +void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9938
9939 -#define ATOMIC_OP_RETURN(op) \
9940 -int atomic_##op##_return(int, atomic_t *); \
9941 -long atomic64_##op##_return(long, atomic64_t *);
9942 +#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9943 +
9944 +#define __ATOMIC_OP_RETURN(op, suffix) \
9945 +int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9946 +long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9947 +
9948 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9949
9950 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9951
9952 @@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9953
9954 #undef ATOMIC_OPS
9955 #undef ATOMIC_OP_RETURN
9956 +#undef __ATOMIC_OP_RETURN
9957 #undef ATOMIC_OP
9958 +#undef __ATOMIC_OP
9959
9960 #define atomic_dec_return(v) atomic_sub_return(1, v)
9961 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9962
9963 #define atomic_inc_return(v) atomic_add_return(1, v)
9964 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9965 +{
9966 + return atomic_add_return_unchecked(1, v);
9967 +}
9968 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9969 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9970 +{
9971 + return atomic64_add_return_unchecked(1, v);
9972 +}
9973
9974 /*
9975 * atomic_inc_and_test - increment and test
9976 @@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9977 * other cases.
9978 */
9979 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9980 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9981 +{
9982 + return atomic_inc_return_unchecked(v) == 0;
9983 +}
9984 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9985
9986 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9987 @@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9988 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9989
9990 #define atomic_inc(v) atomic_add(1, v)
9991 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9992 +{
9993 + atomic_add_unchecked(1, v);
9994 +}
9995 #define atomic64_inc(v) atomic64_add(1, v)
9996 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9997 +{
9998 + atomic64_add_unchecked(1, v);
9999 +}
10000
10001 #define atomic_dec(v) atomic_sub(1, v)
10002 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10003 +{
10004 + atomic_sub_unchecked(1, v);
10005 +}
10006 #define atomic64_dec(v) atomic64_sub(1, v)
10007 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10008 +{
10009 + atomic64_sub_unchecked(1, v);
10010 +}
10011
10012 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10013 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10014
10015 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10016 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10017 +{
10018 + return cmpxchg(&v->counter, old, new);
10019 +}
10020 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10021 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10022 +{
10023 + return xchg(&v->counter, new);
10024 +}
10025
10026 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10027 {
10028 - int c, old;
10029 + int c, old, new;
10030 c = atomic_read(v);
10031 for (;;) {
10032 - if (unlikely(c == (u)))
10033 + if (unlikely(c == u))
10034 break;
10035 - old = atomic_cmpxchg((v), c, c + (a));
10036 +
10037 + asm volatile("addcc %2, %0, %0\n"
10038 +
10039 +#ifdef CONFIG_PAX_REFCOUNT
10040 + "tvs %%icc, 6\n"
10041 +#endif
10042 +
10043 + : "=r" (new)
10044 + : "0" (c), "ir" (a)
10045 + : "cc");
10046 +
10047 + old = atomic_cmpxchg(v, c, new);
10048 if (likely(old == c))
10049 break;
10050 c = old;
10051 @@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10052 #define atomic64_cmpxchg(v, o, n) \
10053 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10054 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10055 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10056 +{
10057 + return xchg(&v->counter, new);
10058 +}
10059
10060 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10061 {
10062 - long c, old;
10063 + long c, old, new;
10064 c = atomic64_read(v);
10065 for (;;) {
10066 - if (unlikely(c == (u)))
10067 + if (unlikely(c == u))
10068 break;
10069 - old = atomic64_cmpxchg((v), c, c + (a));
10070 +
10071 + asm volatile("addcc %2, %0, %0\n"
10072 +
10073 +#ifdef CONFIG_PAX_REFCOUNT
10074 + "tvs %%xcc, 6\n"
10075 +#endif
10076 +
10077 + : "=r" (new)
10078 + : "0" (c), "ir" (a)
10079 + : "cc");
10080 +
10081 + old = atomic64_cmpxchg(v, c, new);
10082 if (likely(old == c))
10083 break;
10084 c = old;
10085 }
10086 - return c != (u);
10087 + return c != u;
10088 }
10089
10090 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10091 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10092 index 305dcc3..7835030 100644
10093 --- a/arch/sparc/include/asm/barrier_64.h
10094 +++ b/arch/sparc/include/asm/barrier_64.h
10095 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10096 do { \
10097 compiletime_assert_atomic_type(*p); \
10098 barrier(); \
10099 - ACCESS_ONCE(*p) = (v); \
10100 + ACCESS_ONCE_RW(*p) = (v); \
10101 } while (0)
10102
10103 #define smp_load_acquire(p) \
10104 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10105 index 5bb6991..5c2132e 100644
10106 --- a/arch/sparc/include/asm/cache.h
10107 +++ b/arch/sparc/include/asm/cache.h
10108 @@ -7,10 +7,12 @@
10109 #ifndef _SPARC_CACHE_H
10110 #define _SPARC_CACHE_H
10111
10112 +#include <linux/const.h>
10113 +
10114 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10115
10116 #define L1_CACHE_SHIFT 5
10117 -#define L1_CACHE_BYTES 32
10118 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10119
10120 #ifdef CONFIG_SPARC32
10121 #define SMP_CACHE_BYTES_SHIFT 5
10122 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10123 index a24e41f..47677ff 100644
10124 --- a/arch/sparc/include/asm/elf_32.h
10125 +++ b/arch/sparc/include/asm/elf_32.h
10126 @@ -114,6 +114,13 @@ typedef struct {
10127
10128 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10129
10130 +#ifdef CONFIG_PAX_ASLR
10131 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10132 +
10133 +#define PAX_DELTA_MMAP_LEN 16
10134 +#define PAX_DELTA_STACK_LEN 16
10135 +#endif
10136 +
10137 /* This yields a mask that user programs can use to figure out what
10138 instruction set this cpu supports. This can NOT be done in userspace
10139 on Sparc. */
10140 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10141 index 370ca1e..d4f4a98 100644
10142 --- a/arch/sparc/include/asm/elf_64.h
10143 +++ b/arch/sparc/include/asm/elf_64.h
10144 @@ -189,6 +189,13 @@ typedef struct {
10145 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10146 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10147
10148 +#ifdef CONFIG_PAX_ASLR
10149 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10150 +
10151 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10152 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10153 +#endif
10154 +
10155 extern unsigned long sparc64_elf_hwcap;
10156 #define ELF_HWCAP sparc64_elf_hwcap
10157
10158 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10159 index a3890da..f6a408e 100644
10160 --- a/arch/sparc/include/asm/pgalloc_32.h
10161 +++ b/arch/sparc/include/asm/pgalloc_32.h
10162 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10163 }
10164
10165 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10166 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10167
10168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10169 unsigned long address)
10170 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10171 index 5e31871..13469c6 100644
10172 --- a/arch/sparc/include/asm/pgalloc_64.h
10173 +++ b/arch/sparc/include/asm/pgalloc_64.h
10174 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10175 }
10176
10177 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10178 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10179
10180 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10181 {
10182 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10183 }
10184
10185 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10186 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10187
10188 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10189 {
10190 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10191 index 59ba6f6..4518128 100644
10192 --- a/arch/sparc/include/asm/pgtable.h
10193 +++ b/arch/sparc/include/asm/pgtable.h
10194 @@ -5,4 +5,8 @@
10195 #else
10196 #include <asm/pgtable_32.h>
10197 #endif
10198 +
10199 +#define ktla_ktva(addr) (addr)
10200 +#define ktva_ktla(addr) (addr)
10201 +
10202 #endif
10203 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10204 index b9b91ae..950b91e 100644
10205 --- a/arch/sparc/include/asm/pgtable_32.h
10206 +++ b/arch/sparc/include/asm/pgtable_32.h
10207 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10208 #define PAGE_SHARED SRMMU_PAGE_SHARED
10209 #define PAGE_COPY SRMMU_PAGE_COPY
10210 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10211 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10212 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10213 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10214 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10215
10216 /* Top-level page directory - dummy used by init-mm.
10217 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10218
10219 /* xwr */
10220 #define __P000 PAGE_NONE
10221 -#define __P001 PAGE_READONLY
10222 -#define __P010 PAGE_COPY
10223 -#define __P011 PAGE_COPY
10224 +#define __P001 PAGE_READONLY_NOEXEC
10225 +#define __P010 PAGE_COPY_NOEXEC
10226 +#define __P011 PAGE_COPY_NOEXEC
10227 #define __P100 PAGE_READONLY
10228 #define __P101 PAGE_READONLY
10229 #define __P110 PAGE_COPY
10230 #define __P111 PAGE_COPY
10231
10232 #define __S000 PAGE_NONE
10233 -#define __S001 PAGE_READONLY
10234 -#define __S010 PAGE_SHARED
10235 -#define __S011 PAGE_SHARED
10236 +#define __S001 PAGE_READONLY_NOEXEC
10237 +#define __S010 PAGE_SHARED_NOEXEC
10238 +#define __S011 PAGE_SHARED_NOEXEC
10239 #define __S100 PAGE_READONLY
10240 #define __S101 PAGE_READONLY
10241 #define __S110 PAGE_SHARED
10242 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10243 index 79da178..c2eede8 100644
10244 --- a/arch/sparc/include/asm/pgtsrmmu.h
10245 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10246 @@ -115,6 +115,11 @@
10247 SRMMU_EXEC | SRMMU_REF)
10248 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10249 SRMMU_EXEC | SRMMU_REF)
10250 +
10251 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10252 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10253 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10254 +
10255 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10256 SRMMU_DIRTY | SRMMU_REF)
10257
10258 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10259 index 29d64b1..4272fe8 100644
10260 --- a/arch/sparc/include/asm/setup.h
10261 +++ b/arch/sparc/include/asm/setup.h
10262 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10263 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10264
10265 /* init_64.c */
10266 -extern atomic_t dcpage_flushes;
10267 -extern atomic_t dcpage_flushes_xcall;
10268 +extern atomic_unchecked_t dcpage_flushes;
10269 +extern atomic_unchecked_t dcpage_flushes_xcall;
10270
10271 extern int sysctl_tsb_ratio;
10272 #endif
10273 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10274 index 9689176..63c18ea 100644
10275 --- a/arch/sparc/include/asm/spinlock_64.h
10276 +++ b/arch/sparc/include/asm/spinlock_64.h
10277 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10278
10279 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10280
10281 -static void inline arch_read_lock(arch_rwlock_t *lock)
10282 +static inline void arch_read_lock(arch_rwlock_t *lock)
10283 {
10284 unsigned long tmp1, tmp2;
10285
10286 __asm__ __volatile__ (
10287 "1: ldsw [%2], %0\n"
10288 " brlz,pn %0, 2f\n"
10289 -"4: add %0, 1, %1\n"
10290 +"4: addcc %0, 1, %1\n"
10291 +
10292 +#ifdef CONFIG_PAX_REFCOUNT
10293 +" tvs %%icc, 6\n"
10294 +#endif
10295 +
10296 " cas [%2], %0, %1\n"
10297 " cmp %0, %1\n"
10298 " bne,pn %%icc, 1b\n"
10299 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10300 " .previous"
10301 : "=&r" (tmp1), "=&r" (tmp2)
10302 : "r" (lock)
10303 - : "memory");
10304 + : "memory", "cc");
10305 }
10306
10307 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10308 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10309 {
10310 int tmp1, tmp2;
10311
10312 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10313 "1: ldsw [%2], %0\n"
10314 " brlz,a,pn %0, 2f\n"
10315 " mov 0, %0\n"
10316 -" add %0, 1, %1\n"
10317 +" addcc %0, 1, %1\n"
10318 +
10319 +#ifdef CONFIG_PAX_REFCOUNT
10320 +" tvs %%icc, 6\n"
10321 +#endif
10322 +
10323 " cas [%2], %0, %1\n"
10324 " cmp %0, %1\n"
10325 " bne,pn %%icc, 1b\n"
10326 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10327 return tmp1;
10328 }
10329
10330 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10331 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10332 {
10333 unsigned long tmp1, tmp2;
10334
10335 __asm__ __volatile__(
10336 "1: lduw [%2], %0\n"
10337 -" sub %0, 1, %1\n"
10338 +" subcc %0, 1, %1\n"
10339 +
10340 +#ifdef CONFIG_PAX_REFCOUNT
10341 +" tvs %%icc, 6\n"
10342 +#endif
10343 +
10344 " cas [%2], %0, %1\n"
10345 " cmp %0, %1\n"
10346 " bne,pn %%xcc, 1b\n"
10347 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10348 : "memory");
10349 }
10350
10351 -static void inline arch_write_lock(arch_rwlock_t *lock)
10352 +static inline void arch_write_lock(arch_rwlock_t *lock)
10353 {
10354 unsigned long mask, tmp1, tmp2;
10355
10356 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10357 : "memory");
10358 }
10359
10360 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10361 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10362 {
10363 __asm__ __volatile__(
10364 " stw %%g0, [%0]"
10365 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10366 : "memory");
10367 }
10368
10369 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10370 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10371 {
10372 unsigned long mask, tmp1, tmp2, result;
10373
10374 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10375 index 025c984..a216504 100644
10376 --- a/arch/sparc/include/asm/thread_info_32.h
10377 +++ b/arch/sparc/include/asm/thread_info_32.h
10378 @@ -49,6 +49,8 @@ struct thread_info {
10379 unsigned long w_saved;
10380
10381 struct restart_block restart_block;
10382 +
10383 + unsigned long lowest_stack;
10384 };
10385
10386 /*
10387 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10388 index 798f027..b009941 100644
10389 --- a/arch/sparc/include/asm/thread_info_64.h
10390 +++ b/arch/sparc/include/asm/thread_info_64.h
10391 @@ -63,6 +63,8 @@ struct thread_info {
10392 struct pt_regs *kern_una_regs;
10393 unsigned int kern_una_insn;
10394
10395 + unsigned long lowest_stack;
10396 +
10397 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10398 __attribute__ ((aligned(64)));
10399 };
10400 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10401 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10402 /* flag bit 4 is available */
10403 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10404 -/* flag bit 6 is available */
10405 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10406 #define TIF_32BIT 7 /* 32-bit binary */
10407 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10408 #define TIF_SECCOMP 9 /* secure computing */
10409 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10410 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10411 +
10412 /* NOTE: Thread flags >= 12 should be ones we have no interest
10413 * in using in assembly, else we can't use the mask as
10414 * an immediate value in instructions such as andcc.
10415 @@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10416 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10417 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10418 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10419 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10420
10421 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10422 _TIF_DO_NOTIFY_RESUME_MASK | \
10423 _TIF_NEED_RESCHED)
10424 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10425
10426 +#define _TIF_WORK_SYSCALL \
10427 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10428 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10429 +
10430 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10431
10432 /*
10433 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10434 index bd56c28..4b63d83 100644
10435 --- a/arch/sparc/include/asm/uaccess.h
10436 +++ b/arch/sparc/include/asm/uaccess.h
10437 @@ -1,5 +1,6 @@
10438 #ifndef ___ASM_SPARC_UACCESS_H
10439 #define ___ASM_SPARC_UACCESS_H
10440 +
10441 #if defined(__sparc__) && defined(__arch64__)
10442 #include <asm/uaccess_64.h>
10443 #else
10444 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10445 index 9634d08..f55fe4f 100644
10446 --- a/arch/sparc/include/asm/uaccess_32.h
10447 +++ b/arch/sparc/include/asm/uaccess_32.h
10448 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10449
10450 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10451 {
10452 - if (n && __access_ok((unsigned long) to, n))
10453 + if ((long)n < 0)
10454 + return n;
10455 +
10456 + if (n && __access_ok((unsigned long) to, n)) {
10457 + if (!__builtin_constant_p(n))
10458 + check_object_size(from, n, true);
10459 return __copy_user(to, (__force void __user *) from, n);
10460 - else
10461 + } else
10462 return n;
10463 }
10464
10465 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10466 {
10467 + if ((long)n < 0)
10468 + return n;
10469 +
10470 + if (!__builtin_constant_p(n))
10471 + check_object_size(from, n, true);
10472 +
10473 return __copy_user(to, (__force void __user *) from, n);
10474 }
10475
10476 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10477 {
10478 - if (n && __access_ok((unsigned long) from, n))
10479 + if ((long)n < 0)
10480 + return n;
10481 +
10482 + if (n && __access_ok((unsigned long) from, n)) {
10483 + if (!__builtin_constant_p(n))
10484 + check_object_size(to, n, false);
10485 return __copy_user((__force void __user *) to, from, n);
10486 - else
10487 + } else
10488 return n;
10489 }
10490
10491 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10492 {
10493 + if ((long)n < 0)
10494 + return n;
10495 +
10496 return __copy_user((__force void __user *) to, from, n);
10497 }
10498
10499 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10500 index c990a5e..f17b9c1 100644
10501 --- a/arch/sparc/include/asm/uaccess_64.h
10502 +++ b/arch/sparc/include/asm/uaccess_64.h
10503 @@ -10,6 +10,7 @@
10504 #include <linux/compiler.h>
10505 #include <linux/string.h>
10506 #include <linux/thread_info.h>
10507 +#include <linux/kernel.h>
10508 #include <asm/asi.h>
10509 #include <asm/spitfire.h>
10510 #include <asm-generic/uaccess-unaligned.h>
10511 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10512 static inline unsigned long __must_check
10513 copy_from_user(void *to, const void __user *from, unsigned long size)
10514 {
10515 - unsigned long ret = ___copy_from_user(to, from, size);
10516 + unsigned long ret;
10517
10518 + if ((long)size < 0 || size > INT_MAX)
10519 + return size;
10520 +
10521 + if (!__builtin_constant_p(size))
10522 + check_object_size(to, size, false);
10523 +
10524 + ret = ___copy_from_user(to, from, size);
10525 if (unlikely(ret))
10526 ret = copy_from_user_fixup(to, from, size);
10527
10528 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10529 static inline unsigned long __must_check
10530 copy_to_user(void __user *to, const void *from, unsigned long size)
10531 {
10532 - unsigned long ret = ___copy_to_user(to, from, size);
10533 + unsigned long ret;
10534
10535 + if ((long)size < 0 || size > INT_MAX)
10536 + return size;
10537 +
10538 + if (!__builtin_constant_p(size))
10539 + check_object_size(from, size, true);
10540 +
10541 + ret = ___copy_to_user(to, from, size);
10542 if (unlikely(ret))
10543 ret = copy_to_user_fixup(to, from, size);
10544 return ret;
10545 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10546 index 7cf9c6e..6206648 100644
10547 --- a/arch/sparc/kernel/Makefile
10548 +++ b/arch/sparc/kernel/Makefile
10549 @@ -4,7 +4,7 @@
10550 #
10551
10552 asflags-y := -ansi
10553 -ccflags-y := -Werror
10554 +#ccflags-y := -Werror
10555
10556 extra-y := head_$(BITS).o
10557
10558 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10559 index 50e7b62..79fae35 100644
10560 --- a/arch/sparc/kernel/process_32.c
10561 +++ b/arch/sparc/kernel/process_32.c
10562 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10563
10564 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10565 r->psr, r->pc, r->npc, r->y, print_tainted());
10566 - printk("PC: <%pS>\n", (void *) r->pc);
10567 + printk("PC: <%pA>\n", (void *) r->pc);
10568 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10569 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10570 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10571 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10572 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10573 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10574 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10575 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10576
10577 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10578 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10579 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10580 rw = (struct reg_window32 *) fp;
10581 pc = rw->ins[7];
10582 printk("[%08lx : ", pc);
10583 - printk("%pS ] ", (void *) pc);
10584 + printk("%pA ] ", (void *) pc);
10585 fp = rw->ins[6];
10586 } while (++count < 16);
10587 printk("\n");
10588 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10589 index 0be7bf9..2b1cba8 100644
10590 --- a/arch/sparc/kernel/process_64.c
10591 +++ b/arch/sparc/kernel/process_64.c
10592 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10593 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10594 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10595 if (regs->tstate & TSTATE_PRIV)
10596 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10597 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10598 }
10599
10600 void show_regs(struct pt_regs *regs)
10601 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10602
10603 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10604 regs->tpc, regs->tnpc, regs->y, print_tainted());
10605 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10606 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10607 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10608 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10609 regs->u_regs[3]);
10610 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10611 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10612 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10613 regs->u_regs[15]);
10614 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10615 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10616 show_regwindow(regs);
10617 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10618 }
10619 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10620 ((tp && tp->task) ? tp->task->pid : -1));
10621
10622 if (gp->tstate & TSTATE_PRIV) {
10623 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10624 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10625 (void *) gp->tpc,
10626 (void *) gp->o7,
10627 (void *) gp->i7,
10628 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10629 index 79cc0d1..ec62734 100644
10630 --- a/arch/sparc/kernel/prom_common.c
10631 +++ b/arch/sparc/kernel/prom_common.c
10632 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10633
10634 unsigned int prom_early_allocated __initdata;
10635
10636 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10637 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10638 .nextprop = prom_common_nextprop,
10639 .getproplen = prom_getproplen,
10640 .getproperty = prom_getproperty,
10641 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10642 index 9ddc492..27a5619 100644
10643 --- a/arch/sparc/kernel/ptrace_64.c
10644 +++ b/arch/sparc/kernel/ptrace_64.c
10645 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10646 return ret;
10647 }
10648
10649 +#ifdef CONFIG_GRKERNSEC_SETXID
10650 +extern void gr_delayed_cred_worker(void);
10651 +#endif
10652 +
10653 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10654 {
10655 int ret = 0;
10656 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10657 if (test_thread_flag(TIF_NOHZ))
10658 user_exit();
10659
10660 +#ifdef CONFIG_GRKERNSEC_SETXID
10661 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10662 + gr_delayed_cred_worker();
10663 +#endif
10664 +
10665 if (test_thread_flag(TIF_SYSCALL_TRACE))
10666 ret = tracehook_report_syscall_entry(regs);
10667
10668 @@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10669 if (test_thread_flag(TIF_NOHZ))
10670 user_exit();
10671
10672 +#ifdef CONFIG_GRKERNSEC_SETXID
10673 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10674 + gr_delayed_cred_worker();
10675 +#endif
10676 +
10677 audit_syscall_exit(regs);
10678
10679 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10680 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10681 index da6f1a7..e5dea8f 100644
10682 --- a/arch/sparc/kernel/smp_64.c
10683 +++ b/arch/sparc/kernel/smp_64.c
10684 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10685 return;
10686
10687 #ifdef CONFIG_DEBUG_DCFLUSH
10688 - atomic_inc(&dcpage_flushes);
10689 + atomic_inc_unchecked(&dcpage_flushes);
10690 #endif
10691
10692 this_cpu = get_cpu();
10693 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10694 xcall_deliver(data0, __pa(pg_addr),
10695 (u64) pg_addr, cpumask_of(cpu));
10696 #ifdef CONFIG_DEBUG_DCFLUSH
10697 - atomic_inc(&dcpage_flushes_xcall);
10698 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10699 #endif
10700 }
10701 }
10702 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10703 preempt_disable();
10704
10705 #ifdef CONFIG_DEBUG_DCFLUSH
10706 - atomic_inc(&dcpage_flushes);
10707 + atomic_inc_unchecked(&dcpage_flushes);
10708 #endif
10709 data0 = 0;
10710 pg_addr = page_address(page);
10711 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10712 xcall_deliver(data0, __pa(pg_addr),
10713 (u64) pg_addr, cpu_online_mask);
10714 #ifdef CONFIG_DEBUG_DCFLUSH
10715 - atomic_inc(&dcpage_flushes_xcall);
10716 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10717 #endif
10718 }
10719 __local_flush_dcache_page(page);
10720 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10721 index 646988d..b88905f 100644
10722 --- a/arch/sparc/kernel/sys_sparc_32.c
10723 +++ b/arch/sparc/kernel/sys_sparc_32.c
10724 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10725 if (len > TASK_SIZE - PAGE_SIZE)
10726 return -ENOMEM;
10727 if (!addr)
10728 - addr = TASK_UNMAPPED_BASE;
10729 + addr = current->mm->mmap_base;
10730
10731 info.flags = 0;
10732 info.length = len;
10733 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10734 index c85403d..6af95c9 100644
10735 --- a/arch/sparc/kernel/sys_sparc_64.c
10736 +++ b/arch/sparc/kernel/sys_sparc_64.c
10737 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10738 struct vm_area_struct * vma;
10739 unsigned long task_size = TASK_SIZE;
10740 int do_color_align;
10741 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10742 struct vm_unmapped_area_info info;
10743
10744 if (flags & MAP_FIXED) {
10745 /* We do not accept a shared mapping if it would violate
10746 * cache aliasing constraints.
10747 */
10748 - if ((flags & MAP_SHARED) &&
10749 + if ((filp || (flags & MAP_SHARED)) &&
10750 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10751 return -EINVAL;
10752 return addr;
10753 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10754 if (filp || (flags & MAP_SHARED))
10755 do_color_align = 1;
10756
10757 +#ifdef CONFIG_PAX_RANDMMAP
10758 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10759 +#endif
10760 +
10761 if (addr) {
10762 if (do_color_align)
10763 addr = COLOR_ALIGN(addr, pgoff);
10764 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10765 addr = PAGE_ALIGN(addr);
10766
10767 vma = find_vma(mm, addr);
10768 - if (task_size - len >= addr &&
10769 - (!vma || addr + len <= vma->vm_start))
10770 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10771 return addr;
10772 }
10773
10774 info.flags = 0;
10775 info.length = len;
10776 - info.low_limit = TASK_UNMAPPED_BASE;
10777 + info.low_limit = mm->mmap_base;
10778 info.high_limit = min(task_size, VA_EXCLUDE_START);
10779 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10780 info.align_offset = pgoff << PAGE_SHIFT;
10781 + info.threadstack_offset = offset;
10782 addr = vm_unmapped_area(&info);
10783
10784 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10785 VM_BUG_ON(addr != -ENOMEM);
10786 info.low_limit = VA_EXCLUDE_END;
10787 +
10788 +#ifdef CONFIG_PAX_RANDMMAP
10789 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10790 + info.low_limit += mm->delta_mmap;
10791 +#endif
10792 +
10793 info.high_limit = task_size;
10794 addr = vm_unmapped_area(&info);
10795 }
10796 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10797 unsigned long task_size = STACK_TOP32;
10798 unsigned long addr = addr0;
10799 int do_color_align;
10800 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10801 struct vm_unmapped_area_info info;
10802
10803 /* This should only ever run for 32-bit processes. */
10804 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10805 /* We do not accept a shared mapping if it would violate
10806 * cache aliasing constraints.
10807 */
10808 - if ((flags & MAP_SHARED) &&
10809 + if ((filp || (flags & MAP_SHARED)) &&
10810 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10811 return -EINVAL;
10812 return addr;
10813 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10814 if (filp || (flags & MAP_SHARED))
10815 do_color_align = 1;
10816
10817 +#ifdef CONFIG_PAX_RANDMMAP
10818 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10819 +#endif
10820 +
10821 /* requesting a specific address */
10822 if (addr) {
10823 if (do_color_align)
10824 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10825 addr = PAGE_ALIGN(addr);
10826
10827 vma = find_vma(mm, addr);
10828 - if (task_size - len >= addr &&
10829 - (!vma || addr + len <= vma->vm_start))
10830 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10831 return addr;
10832 }
10833
10834 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10835 info.high_limit = mm->mmap_base;
10836 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10837 info.align_offset = pgoff << PAGE_SHIFT;
10838 + info.threadstack_offset = offset;
10839 addr = vm_unmapped_area(&info);
10840
10841 /*
10842 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10843 VM_BUG_ON(addr != -ENOMEM);
10844 info.flags = 0;
10845 info.low_limit = TASK_UNMAPPED_BASE;
10846 +
10847 +#ifdef CONFIG_PAX_RANDMMAP
10848 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10849 + info.low_limit += mm->delta_mmap;
10850 +#endif
10851 +
10852 info.high_limit = STACK_TOP32;
10853 addr = vm_unmapped_area(&info);
10854 }
10855 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10856 EXPORT_SYMBOL(get_fb_unmapped_area);
10857
10858 /* Essentially the same as PowerPC. */
10859 -static unsigned long mmap_rnd(void)
10860 +static unsigned long mmap_rnd(struct mm_struct *mm)
10861 {
10862 unsigned long rnd = 0UL;
10863
10864 +#ifdef CONFIG_PAX_RANDMMAP
10865 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10866 +#endif
10867 +
10868 if (current->flags & PF_RANDOMIZE) {
10869 unsigned long val = get_random_int();
10870 if (test_thread_flag(TIF_32BIT))
10871 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10872
10873 void arch_pick_mmap_layout(struct mm_struct *mm)
10874 {
10875 - unsigned long random_factor = mmap_rnd();
10876 + unsigned long random_factor = mmap_rnd(mm);
10877 unsigned long gap;
10878
10879 /*
10880 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10881 gap == RLIM_INFINITY ||
10882 sysctl_legacy_va_layout) {
10883 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10884 +
10885 +#ifdef CONFIG_PAX_RANDMMAP
10886 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10887 + mm->mmap_base += mm->delta_mmap;
10888 +#endif
10889 +
10890 mm->get_unmapped_area = arch_get_unmapped_area;
10891 } else {
10892 /* We know it's 32-bit */
10893 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10894 gap = (task_size / 6 * 5);
10895
10896 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10897 +
10898 +#ifdef CONFIG_PAX_RANDMMAP
10899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10901 +#endif
10902 +
10903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10904 }
10905 }
10906 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10907 index 33a17e7..d87fb1f 100644
10908 --- a/arch/sparc/kernel/syscalls.S
10909 +++ b/arch/sparc/kernel/syscalls.S
10910 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10911 #endif
10912 .align 32
10913 1: ldx [%g6 + TI_FLAGS], %l5
10914 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10915 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10916 be,pt %icc, rtrap
10917 nop
10918 call syscall_trace_leave
10919 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10920
10921 srl %i3, 0, %o3 ! IEU0
10922 srl %i2, 0, %o2 ! IEU0 Group
10923 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10924 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10925 bne,pn %icc, linux_syscall_trace32 ! CTI
10926 mov %i0, %l5 ! IEU1
10927 5: call %l7 ! CTI Group brk forced
10928 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10929
10930 mov %i3, %o3 ! IEU1
10931 mov %i4, %o4 ! IEU0 Group
10932 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10933 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10934 bne,pn %icc, linux_syscall_trace ! CTI Group
10935 mov %i0, %l5 ! IEU0
10936 2: call %l7 ! CTI Group brk forced
10937 @@ -223,7 +223,7 @@ ret_sys_call:
10938
10939 cmp %o0, -ERESTART_RESTARTBLOCK
10940 bgeu,pn %xcc, 1f
10941 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10942 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10943 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10944
10945 2:
10946 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10947 index 6fd386c5..6907d81 100644
10948 --- a/arch/sparc/kernel/traps_32.c
10949 +++ b/arch/sparc/kernel/traps_32.c
10950 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10951 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10952 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10953
10954 +extern void gr_handle_kernel_exploit(void);
10955 +
10956 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10957 {
10958 static int die_counter;
10959 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10960 count++ < 30 &&
10961 (((unsigned long) rw) >= PAGE_OFFSET) &&
10962 !(((unsigned long) rw) & 0x7)) {
10963 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10964 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10965 (void *) rw->ins[7]);
10966 rw = (struct reg_window32 *)rw->ins[6];
10967 }
10968 }
10969 printk("Instruction DUMP:");
10970 instruction_dump ((unsigned long *) regs->pc);
10971 - if(regs->psr & PSR_PS)
10972 + if(regs->psr & PSR_PS) {
10973 + gr_handle_kernel_exploit();
10974 do_exit(SIGKILL);
10975 + }
10976 do_exit(SIGSEGV);
10977 }
10978
10979 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10980 index 981a769..d906eda 100644
10981 --- a/arch/sparc/kernel/traps_64.c
10982 +++ b/arch/sparc/kernel/traps_64.c
10983 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10984 i + 1,
10985 p->trapstack[i].tstate, p->trapstack[i].tpc,
10986 p->trapstack[i].tnpc, p->trapstack[i].tt);
10987 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10988 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10989 }
10990 }
10991
10992 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10993
10994 lvl -= 0x100;
10995 if (regs->tstate & TSTATE_PRIV) {
10996 +
10997 +#ifdef CONFIG_PAX_REFCOUNT
10998 + if (lvl == 6)
10999 + pax_report_refcount_overflow(regs);
11000 +#endif
11001 +
11002 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11003 die_if_kernel(buffer, regs);
11004 }
11005 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11006 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11007 {
11008 char buffer[32];
11009 -
11010 +
11011 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11012 0, lvl, SIGTRAP) == NOTIFY_STOP)
11013 return;
11014
11015 +#ifdef CONFIG_PAX_REFCOUNT
11016 + if (lvl == 6)
11017 + pax_report_refcount_overflow(regs);
11018 +#endif
11019 +
11020 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11021
11022 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11023 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11024 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11025 printk("%s" "ERROR(%d): ",
11026 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11027 - printk("TPC<%pS>\n", (void *) regs->tpc);
11028 + printk("TPC<%pA>\n", (void *) regs->tpc);
11029 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11030 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11031 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11032 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11033 smp_processor_id(),
11034 (type & 0x1) ? 'I' : 'D',
11035 regs->tpc);
11036 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11037 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11038 panic("Irrecoverable Cheetah+ parity error.");
11039 }
11040
11041 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11042 smp_processor_id(),
11043 (type & 0x1) ? 'I' : 'D',
11044 regs->tpc);
11045 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11046 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11047 }
11048
11049 struct sun4v_error_entry {
11050 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11051 /*0x38*/u64 reserved_5;
11052 };
11053
11054 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11055 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11056 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11057 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11058
11059 static const char *sun4v_err_type_to_str(u8 type)
11060 {
11061 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11062 }
11063
11064 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11065 - int cpu, const char *pfx, atomic_t *ocnt)
11066 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11067 {
11068 u64 *raw_ptr = (u64 *) ent;
11069 u32 attrs;
11070 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11071
11072 show_regs(regs);
11073
11074 - if ((cnt = atomic_read(ocnt)) != 0) {
11075 - atomic_set(ocnt, 0);
11076 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11077 + atomic_set_unchecked(ocnt, 0);
11078 wmb();
11079 printk("%s: Queue overflowed %d times.\n",
11080 pfx, cnt);
11081 @@ -2048,7 +2059,7 @@ out:
11082 */
11083 void sun4v_resum_overflow(struct pt_regs *regs)
11084 {
11085 - atomic_inc(&sun4v_resum_oflow_cnt);
11086 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11087 }
11088
11089 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11090 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11091 /* XXX Actually even this can make not that much sense. Perhaps
11092 * XXX we should just pull the plug and panic directly from here?
11093 */
11094 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11095 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11096 }
11097
11098 static void sun4v_tlb_error(struct pt_regs *regs)
11099 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11100
11101 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11102 regs->tpc, tl);
11103 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11104 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11105 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11106 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11107 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11108 (void *) regs->u_regs[UREG_I7]);
11109 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11110 "pte[%lx] error[%lx]\n",
11111 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11112
11113 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11114 regs->tpc, tl);
11115 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11116 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11117 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11118 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11119 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11120 (void *) regs->u_regs[UREG_I7]);
11121 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11122 "pte[%lx] error[%lx]\n",
11123 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11124 fp = (unsigned long)sf->fp + STACK_BIAS;
11125 }
11126
11127 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11128 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11129 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11130 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11131 int index = tsk->curr_ret_stack;
11132 if (tsk->ret_stack && index >= graph) {
11133 pc = tsk->ret_stack[index - graph].ret;
11134 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11135 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11136 graph++;
11137 }
11138 }
11139 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11140 return (struct reg_window *) (fp + STACK_BIAS);
11141 }
11142
11143 +extern void gr_handle_kernel_exploit(void);
11144 +
11145 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11146 {
11147 static int die_counter;
11148 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11149 while (rw &&
11150 count++ < 30 &&
11151 kstack_valid(tp, (unsigned long) rw)) {
11152 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11153 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11154 (void *) rw->ins[7]);
11155
11156 rw = kernel_stack_up(rw);
11157 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11158 }
11159 user_instruction_dump ((unsigned int __user *) regs->tpc);
11160 }
11161 - if (regs->tstate & TSTATE_PRIV)
11162 + if (regs->tstate & TSTATE_PRIV) {
11163 + gr_handle_kernel_exploit();
11164 do_exit(SIGKILL);
11165 + }
11166 do_exit(SIGSEGV);
11167 }
11168 EXPORT_SYMBOL(die_if_kernel);
11169 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11170 index 62098a8..547ab2c 100644
11171 --- a/arch/sparc/kernel/unaligned_64.c
11172 +++ b/arch/sparc/kernel/unaligned_64.c
11173 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11174 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11175
11176 if (__ratelimit(&ratelimit)) {
11177 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11178 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11179 regs->tpc, (void *) regs->tpc);
11180 }
11181 }
11182 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11183 index 3269b02..64f5231 100644
11184 --- a/arch/sparc/lib/Makefile
11185 +++ b/arch/sparc/lib/Makefile
11186 @@ -2,7 +2,7 @@
11187 #
11188
11189 asflags-y := -ansi -DST_DIV0=0x02
11190 -ccflags-y := -Werror
11191 +#ccflags-y := -Werror
11192
11193 lib-$(CONFIG_SPARC32) += ashrdi3.o
11194 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11195 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11196 index 05dac43..76f8ed4 100644
11197 --- a/arch/sparc/lib/atomic_64.S
11198 +++ b/arch/sparc/lib/atomic_64.S
11199 @@ -15,11 +15,22 @@
11200 * a value and does the barriers.
11201 */
11202
11203 -#define ATOMIC_OP(op) \
11204 -ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11205 +#ifdef CONFIG_PAX_REFCOUNT
11206 +#define __REFCOUNT_OP(op) op##cc
11207 +#define __OVERFLOW_IOP tvs %icc, 6;
11208 +#define __OVERFLOW_XOP tvs %xcc, 6;
11209 +#else
11210 +#define __REFCOUNT_OP(op) op
11211 +#define __OVERFLOW_IOP
11212 +#define __OVERFLOW_XOP
11213 +#endif
11214 +
11215 +#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11216 +ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11217 BACKOFF_SETUP(%o2); \
11218 1: lduw [%o1], %g1; \
11219 - op %g1, %o0, %g7; \
11220 + asm_op %g1, %o0, %g7; \
11221 + post_op \
11222 cas [%o1], %g1, %g7; \
11223 cmp %g1, %g7; \
11224 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11225 @@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11226 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11227 ENDPROC(atomic_##op); \
11228
11229 -#define ATOMIC_OP_RETURN(op) \
11230 -ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11231 +#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11232 + __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11233 +
11234 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11235 +ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11236 BACKOFF_SETUP(%o2); \
11237 1: lduw [%o1], %g1; \
11238 - op %g1, %o0, %g7; \
11239 + asm_op %g1, %o0, %g7; \
11240 + post_op \
11241 cas [%o1], %g1, %g7; \
11242 cmp %g1, %g7; \
11243 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11244 @@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11245 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11246 ENDPROC(atomic_##op##_return);
11247
11248 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11249 + __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11250 +
11251 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11252
11253 ATOMIC_OPS(add)
11254 @@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11255
11256 #undef ATOMIC_OPS
11257 #undef ATOMIC_OP_RETURN
11258 +#undef __ATOMIC_OP_RETURN
11259 #undef ATOMIC_OP
11260 +#undef __ATOMIC_OP
11261
11262 -#define ATOMIC64_OP(op) \
11263 -ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11264 +#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11265 +ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11266 BACKOFF_SETUP(%o2); \
11267 1: ldx [%o1], %g1; \
11268 - op %g1, %o0, %g7; \
11269 + asm_op %g1, %o0, %g7; \
11270 + post_op \
11271 casx [%o1], %g1, %g7; \
11272 cmp %g1, %g7; \
11273 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11274 @@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11275 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11276 ENDPROC(atomic64_##op); \
11277
11278 -#define ATOMIC64_OP_RETURN(op) \
11279 -ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11280 +#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11281 + __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11282 +
11283 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11284 +ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11285 BACKOFF_SETUP(%o2); \
11286 1: ldx [%o1], %g1; \
11287 - op %g1, %o0, %g7; \
11288 + asm_op %g1, %o0, %g7; \
11289 + post_op \
11290 casx [%o1], %g1, %g7; \
11291 cmp %g1, %g7; \
11292 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11293 @@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11294 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11295 ENDPROC(atomic64_##op##_return);
11296
11297 +#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11298 +i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11299 +
11300 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11301
11302 ATOMIC64_OPS(add)
11303 @@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11304
11305 #undef ATOMIC64_OPS
11306 #undef ATOMIC64_OP_RETURN
11307 +#undef __ATOMIC64_OP_RETURN
11308 #undef ATOMIC64_OP
11309 +#undef __ATOMIC64_OP
11310 +#undef __OVERFLOW_XOP
11311 +#undef __OVERFLOW_IOP
11312 +#undef __REFCOUNT_OP
11313
11314 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11315 BACKOFF_SETUP(%o2)
11316 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11317 index 1d649a9..fbc5bfc 100644
11318 --- a/arch/sparc/lib/ksyms.c
11319 +++ b/arch/sparc/lib/ksyms.c
11320 @@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11321 /* Atomic counter implementation. */
11322 #define ATOMIC_OP(op) \
11323 EXPORT_SYMBOL(atomic_##op); \
11324 -EXPORT_SYMBOL(atomic64_##op);
11325 +EXPORT_SYMBOL(atomic_##op##_unchecked); \
11326 +EXPORT_SYMBOL(atomic64_##op); \
11327 +EXPORT_SYMBOL(atomic64_##op##_unchecked);
11328
11329 #define ATOMIC_OP_RETURN(op) \
11330 EXPORT_SYMBOL(atomic_##op##_return); \
11331 @@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11332 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11333
11334 ATOMIC_OPS(add)
11335 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11336 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11337 ATOMIC_OPS(sub)
11338
11339 #undef ATOMIC_OPS
11340 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11341 index 30c3ecc..736f015 100644
11342 --- a/arch/sparc/mm/Makefile
11343 +++ b/arch/sparc/mm/Makefile
11344 @@ -2,7 +2,7 @@
11345 #
11346
11347 asflags-y := -ansi
11348 -ccflags-y := -Werror
11349 +#ccflags-y := -Werror
11350
11351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11352 obj-y += fault_$(BITS).o
11353 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11354 index 70d8171..274c6c0 100644
11355 --- a/arch/sparc/mm/fault_32.c
11356 +++ b/arch/sparc/mm/fault_32.c
11357 @@ -21,6 +21,9 @@
11358 #include <linux/perf_event.h>
11359 #include <linux/interrupt.h>
11360 #include <linux/kdebug.h>
11361 +#include <linux/slab.h>
11362 +#include <linux/pagemap.h>
11363 +#include <linux/compiler.h>
11364
11365 #include <asm/page.h>
11366 #include <asm/pgtable.h>
11367 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11368 return safe_compute_effective_address(regs, insn);
11369 }
11370
11371 +#ifdef CONFIG_PAX_PAGEEXEC
11372 +#ifdef CONFIG_PAX_DLRESOLVE
11373 +static void pax_emuplt_close(struct vm_area_struct *vma)
11374 +{
11375 + vma->vm_mm->call_dl_resolve = 0UL;
11376 +}
11377 +
11378 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11379 +{
11380 + unsigned int *kaddr;
11381 +
11382 + vmf->page = alloc_page(GFP_HIGHUSER);
11383 + if (!vmf->page)
11384 + return VM_FAULT_OOM;
11385 +
11386 + kaddr = kmap(vmf->page);
11387 + memset(kaddr, 0, PAGE_SIZE);
11388 + kaddr[0] = 0x9DE3BFA8U; /* save */
11389 + flush_dcache_page(vmf->page);
11390 + kunmap(vmf->page);
11391 + return VM_FAULT_MAJOR;
11392 +}
11393 +
11394 +static const struct vm_operations_struct pax_vm_ops = {
11395 + .close = pax_emuplt_close,
11396 + .fault = pax_emuplt_fault
11397 +};
11398 +
11399 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11400 +{
11401 + int ret;
11402 +
11403 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11404 + vma->vm_mm = current->mm;
11405 + vma->vm_start = addr;
11406 + vma->vm_end = addr + PAGE_SIZE;
11407 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11408 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11409 + vma->vm_ops = &pax_vm_ops;
11410 +
11411 + ret = insert_vm_struct(current->mm, vma);
11412 + if (ret)
11413 + return ret;
11414 +
11415 + ++current->mm->total_vm;
11416 + return 0;
11417 +}
11418 +#endif
11419 +
11420 +/*
11421 + * PaX: decide what to do with offenders (regs->pc = fault address)
11422 + *
11423 + * returns 1 when task should be killed
11424 + * 2 when patched PLT trampoline was detected
11425 + * 3 when unpatched PLT trampoline was detected
11426 + */
11427 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11428 +{
11429 +
11430 +#ifdef CONFIG_PAX_EMUPLT
11431 + int err;
11432 +
11433 + do { /* PaX: patched PLT emulation #1 */
11434 + unsigned int sethi1, sethi2, jmpl;
11435 +
11436 + err = get_user(sethi1, (unsigned int *)regs->pc);
11437 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11438 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11439 +
11440 + if (err)
11441 + break;
11442 +
11443 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11444 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11445 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11446 + {
11447 + unsigned int addr;
11448 +
11449 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11450 + addr = regs->u_regs[UREG_G1];
11451 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11452 + regs->pc = addr;
11453 + regs->npc = addr+4;
11454 + return 2;
11455 + }
11456 + } while (0);
11457 +
11458 + do { /* PaX: patched PLT emulation #2 */
11459 + unsigned int ba;
11460 +
11461 + err = get_user(ba, (unsigned int *)regs->pc);
11462 +
11463 + if (err)
11464 + break;
11465 +
11466 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11467 + unsigned int addr;
11468 +
11469 + if ((ba & 0xFFC00000U) == 0x30800000U)
11470 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11471 + else
11472 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11473 + regs->pc = addr;
11474 + regs->npc = addr+4;
11475 + return 2;
11476 + }
11477 + } while (0);
11478 +
11479 + do { /* PaX: patched PLT emulation #3 */
11480 + unsigned int sethi, bajmpl, nop;
11481 +
11482 + err = get_user(sethi, (unsigned int *)regs->pc);
11483 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11484 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11485 +
11486 + if (err)
11487 + break;
11488 +
11489 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11490 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11491 + nop == 0x01000000U)
11492 + {
11493 + unsigned int addr;
11494 +
11495 + addr = (sethi & 0x003FFFFFU) << 10;
11496 + regs->u_regs[UREG_G1] = addr;
11497 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11498 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11499 + else
11500 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11501 + regs->pc = addr;
11502 + regs->npc = addr+4;
11503 + return 2;
11504 + }
11505 + } while (0);
11506 +
11507 + do { /* PaX: unpatched PLT emulation step 1 */
11508 + unsigned int sethi, ba, nop;
11509 +
11510 + err = get_user(sethi, (unsigned int *)regs->pc);
11511 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11512 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11513 +
11514 + if (err)
11515 + break;
11516 +
11517 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519 + nop == 0x01000000U)
11520 + {
11521 + unsigned int addr, save, call;
11522 +
11523 + if ((ba & 0xFFC00000U) == 0x30800000U)
11524 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11525 + else
11526 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11527 +
11528 + err = get_user(save, (unsigned int *)addr);
11529 + err |= get_user(call, (unsigned int *)(addr+4));
11530 + err |= get_user(nop, (unsigned int *)(addr+8));
11531 + if (err)
11532 + break;
11533 +
11534 +#ifdef CONFIG_PAX_DLRESOLVE
11535 + if (save == 0x9DE3BFA8U &&
11536 + (call & 0xC0000000U) == 0x40000000U &&
11537 + nop == 0x01000000U)
11538 + {
11539 + struct vm_area_struct *vma;
11540 + unsigned long call_dl_resolve;
11541 +
11542 + down_read(&current->mm->mmap_sem);
11543 + call_dl_resolve = current->mm->call_dl_resolve;
11544 + up_read(&current->mm->mmap_sem);
11545 + if (likely(call_dl_resolve))
11546 + goto emulate;
11547 +
11548 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11549 +
11550 + down_write(&current->mm->mmap_sem);
11551 + if (current->mm->call_dl_resolve) {
11552 + call_dl_resolve = current->mm->call_dl_resolve;
11553 + up_write(&current->mm->mmap_sem);
11554 + if (vma)
11555 + kmem_cache_free(vm_area_cachep, vma);
11556 + goto emulate;
11557 + }
11558 +
11559 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11560 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11561 + up_write(&current->mm->mmap_sem);
11562 + if (vma)
11563 + kmem_cache_free(vm_area_cachep, vma);
11564 + return 1;
11565 + }
11566 +
11567 + if (pax_insert_vma(vma, call_dl_resolve)) {
11568 + up_write(&current->mm->mmap_sem);
11569 + kmem_cache_free(vm_area_cachep, vma);
11570 + return 1;
11571 + }
11572 +
11573 + current->mm->call_dl_resolve = call_dl_resolve;
11574 + up_write(&current->mm->mmap_sem);
11575 +
11576 +emulate:
11577 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11578 + regs->pc = call_dl_resolve;
11579 + regs->npc = addr+4;
11580 + return 3;
11581 + }
11582 +#endif
11583 +
11584 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11585 + if ((save & 0xFFC00000U) == 0x05000000U &&
11586 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11587 + nop == 0x01000000U)
11588 + {
11589 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11590 + regs->u_regs[UREG_G2] = addr + 4;
11591 + addr = (save & 0x003FFFFFU) << 10;
11592 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11593 + regs->pc = addr;
11594 + regs->npc = addr+4;
11595 + return 3;
11596 + }
11597 + }
11598 + } while (0);
11599 +
11600 + do { /* PaX: unpatched PLT emulation step 2 */
11601 + unsigned int save, call, nop;
11602 +
11603 + err = get_user(save, (unsigned int *)(regs->pc-4));
11604 + err |= get_user(call, (unsigned int *)regs->pc);
11605 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11606 + if (err)
11607 + break;
11608 +
11609 + if (save == 0x9DE3BFA8U &&
11610 + (call & 0xC0000000U) == 0x40000000U &&
11611 + nop == 0x01000000U)
11612 + {
11613 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11614 +
11615 + regs->u_regs[UREG_RETPC] = regs->pc;
11616 + regs->pc = dl_resolve;
11617 + regs->npc = dl_resolve+4;
11618 + return 3;
11619 + }
11620 + } while (0);
11621 +#endif
11622 +
11623 + return 1;
11624 +}
11625 +
11626 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11627 +{
11628 + unsigned long i;
11629 +
11630 + printk(KERN_ERR "PAX: bytes at PC: ");
11631 + for (i = 0; i < 8; i++) {
11632 + unsigned int c;
11633 + if (get_user(c, (unsigned int *)pc+i))
11634 + printk(KERN_CONT "???????? ");
11635 + else
11636 + printk(KERN_CONT "%08x ", c);
11637 + }
11638 + printk("\n");
11639 +}
11640 +#endif
11641 +
11642 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11643 int text_fault)
11644 {
11645 @@ -226,6 +500,24 @@ good_area:
11646 if (!(vma->vm_flags & VM_WRITE))
11647 goto bad_area;
11648 } else {
11649 +
11650 +#ifdef CONFIG_PAX_PAGEEXEC
11651 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11652 + up_read(&mm->mmap_sem);
11653 + switch (pax_handle_fetch_fault(regs)) {
11654 +
11655 +#ifdef CONFIG_PAX_EMUPLT
11656 + case 2:
11657 + case 3:
11658 + return;
11659 +#endif
11660 +
11661 + }
11662 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11663 + do_group_exit(SIGKILL);
11664 + }
11665 +#endif
11666 +
11667 /* Allow reads even for write-only mappings */
11668 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11669 goto bad_area;
11670 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11671 index 4798232..f76e3aa 100644
11672 --- a/arch/sparc/mm/fault_64.c
11673 +++ b/arch/sparc/mm/fault_64.c
11674 @@ -22,6 +22,9 @@
11675 #include <linux/kdebug.h>
11676 #include <linux/percpu.h>
11677 #include <linux/context_tracking.h>
11678 +#include <linux/slab.h>
11679 +#include <linux/pagemap.h>
11680 +#include <linux/compiler.h>
11681
11682 #include <asm/page.h>
11683 #include <asm/pgtable.h>
11684 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11685 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11686 regs->tpc);
11687 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11688 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11689 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11690 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11691 dump_stack();
11692 unhandled_fault(regs->tpc, current, regs);
11693 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11694 show_regs(regs);
11695 }
11696
11697 +#ifdef CONFIG_PAX_PAGEEXEC
11698 +#ifdef CONFIG_PAX_DLRESOLVE
11699 +static void pax_emuplt_close(struct vm_area_struct *vma)
11700 +{
11701 + vma->vm_mm->call_dl_resolve = 0UL;
11702 +}
11703 +
11704 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11705 +{
11706 + unsigned int *kaddr;
11707 +
11708 + vmf->page = alloc_page(GFP_HIGHUSER);
11709 + if (!vmf->page)
11710 + return VM_FAULT_OOM;
11711 +
11712 + kaddr = kmap(vmf->page);
11713 + memset(kaddr, 0, PAGE_SIZE);
11714 + kaddr[0] = 0x9DE3BFA8U; /* save */
11715 + flush_dcache_page(vmf->page);
11716 + kunmap(vmf->page);
11717 + return VM_FAULT_MAJOR;
11718 +}
11719 +
11720 +static const struct vm_operations_struct pax_vm_ops = {
11721 + .close = pax_emuplt_close,
11722 + .fault = pax_emuplt_fault
11723 +};
11724 +
11725 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11726 +{
11727 + int ret;
11728 +
11729 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11730 + vma->vm_mm = current->mm;
11731 + vma->vm_start = addr;
11732 + vma->vm_end = addr + PAGE_SIZE;
11733 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11734 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11735 + vma->vm_ops = &pax_vm_ops;
11736 +
11737 + ret = insert_vm_struct(current->mm, vma);
11738 + if (ret)
11739 + return ret;
11740 +
11741 + ++current->mm->total_vm;
11742 + return 0;
11743 +}
11744 +#endif
11745 +
11746 +/*
11747 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11748 + *
11749 + * returns 1 when task should be killed
11750 + * 2 when patched PLT trampoline was detected
11751 + * 3 when unpatched PLT trampoline was detected
11752 + */
11753 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11754 +{
11755 +
11756 +#ifdef CONFIG_PAX_EMUPLT
11757 + int err;
11758 +
11759 + do { /* PaX: patched PLT emulation #1 */
11760 + unsigned int sethi1, sethi2, jmpl;
11761 +
11762 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11763 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11764 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11765 +
11766 + if (err)
11767 + break;
11768 +
11769 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11770 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11771 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11772 + {
11773 + unsigned long addr;
11774 +
11775 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11776 + addr = regs->u_regs[UREG_G1];
11777 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11778 +
11779 + if (test_thread_flag(TIF_32BIT))
11780 + addr &= 0xFFFFFFFFUL;
11781 +
11782 + regs->tpc = addr;
11783 + regs->tnpc = addr+4;
11784 + return 2;
11785 + }
11786 + } while (0);
11787 +
11788 + do { /* PaX: patched PLT emulation #2 */
11789 + unsigned int ba;
11790 +
11791 + err = get_user(ba, (unsigned int *)regs->tpc);
11792 +
11793 + if (err)
11794 + break;
11795 +
11796 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11797 + unsigned long addr;
11798 +
11799 + if ((ba & 0xFFC00000U) == 0x30800000U)
11800 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11801 + else
11802 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11803 +
11804 + if (test_thread_flag(TIF_32BIT))
11805 + addr &= 0xFFFFFFFFUL;
11806 +
11807 + regs->tpc = addr;
11808 + regs->tnpc = addr+4;
11809 + return 2;
11810 + }
11811 + } while (0);
11812 +
11813 + do { /* PaX: patched PLT emulation #3 */
11814 + unsigned int sethi, bajmpl, nop;
11815 +
11816 + err = get_user(sethi, (unsigned int *)regs->tpc);
11817 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11818 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11819 +
11820 + if (err)
11821 + break;
11822 +
11823 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11824 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11825 + nop == 0x01000000U)
11826 + {
11827 + unsigned long addr;
11828 +
11829 + addr = (sethi & 0x003FFFFFU) << 10;
11830 + regs->u_regs[UREG_G1] = addr;
11831 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11832 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11833 + else
11834 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11835 +
11836 + if (test_thread_flag(TIF_32BIT))
11837 + addr &= 0xFFFFFFFFUL;
11838 +
11839 + regs->tpc = addr;
11840 + regs->tnpc = addr+4;
11841 + return 2;
11842 + }
11843 + } while (0);
11844 +
11845 + do { /* PaX: patched PLT emulation #4 */
11846 + unsigned int sethi, mov1, call, mov2;
11847 +
11848 + err = get_user(sethi, (unsigned int *)regs->tpc);
11849 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11850 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11851 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11852 +
11853 + if (err)
11854 + break;
11855 +
11856 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857 + mov1 == 0x8210000FU &&
11858 + (call & 0xC0000000U) == 0x40000000U &&
11859 + mov2 == 0x9E100001U)
11860 + {
11861 + unsigned long addr;
11862 +
11863 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11864 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11865 +
11866 + if (test_thread_flag(TIF_32BIT))
11867 + addr &= 0xFFFFFFFFUL;
11868 +
11869 + regs->tpc = addr;
11870 + regs->tnpc = addr+4;
11871 + return 2;
11872 + }
11873 + } while (0);
11874 +
11875 + do { /* PaX: patched PLT emulation #5 */
11876 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11877 +
11878 + err = get_user(sethi, (unsigned int *)regs->tpc);
11879 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11880 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11881 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11882 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11883 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11884 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11885 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11886 +
11887 + if (err)
11888 + break;
11889 +
11890 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11891 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11892 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11893 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11894 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11895 + sllx == 0x83287020U &&
11896 + jmpl == 0x81C04005U &&
11897 + nop == 0x01000000U)
11898 + {
11899 + unsigned long addr;
11900 +
11901 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11902 + regs->u_regs[UREG_G1] <<= 32;
11903 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11904 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11905 + regs->tpc = addr;
11906 + regs->tnpc = addr+4;
11907 + return 2;
11908 + }
11909 + } while (0);
11910 +
11911 + do { /* PaX: patched PLT emulation #6 */
11912 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11913 +
11914 + err = get_user(sethi, (unsigned int *)regs->tpc);
11915 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11916 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11917 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11918 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11919 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11920 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11921 +
11922 + if (err)
11923 + break;
11924 +
11925 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11926 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11927 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11928 + sllx == 0x83287020U &&
11929 + (or & 0xFFFFE000U) == 0x8A116000U &&
11930 + jmpl == 0x81C04005U &&
11931 + nop == 0x01000000U)
11932 + {
11933 + unsigned long addr;
11934 +
11935 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11936 + regs->u_regs[UREG_G1] <<= 32;
11937 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11938 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11939 + regs->tpc = addr;
11940 + regs->tnpc = addr+4;
11941 + return 2;
11942 + }
11943 + } while (0);
11944 +
11945 + do { /* PaX: unpatched PLT emulation step 1 */
11946 + unsigned int sethi, ba, nop;
11947 +
11948 + err = get_user(sethi, (unsigned int *)regs->tpc);
11949 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11950 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11951 +
11952 + if (err)
11953 + break;
11954 +
11955 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11956 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11957 + nop == 0x01000000U)
11958 + {
11959 + unsigned long addr;
11960 + unsigned int save, call;
11961 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11962 +
11963 + if ((ba & 0xFFC00000U) == 0x30800000U)
11964 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11965 + else
11966 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11967 +
11968 + if (test_thread_flag(TIF_32BIT))
11969 + addr &= 0xFFFFFFFFUL;
11970 +
11971 + err = get_user(save, (unsigned int *)addr);
11972 + err |= get_user(call, (unsigned int *)(addr+4));
11973 + err |= get_user(nop, (unsigned int *)(addr+8));
11974 + if (err)
11975 + break;
11976 +
11977 +#ifdef CONFIG_PAX_DLRESOLVE
11978 + if (save == 0x9DE3BFA8U &&
11979 + (call & 0xC0000000U) == 0x40000000U &&
11980 + nop == 0x01000000U)
11981 + {
11982 + struct vm_area_struct *vma;
11983 + unsigned long call_dl_resolve;
11984 +
11985 + down_read(&current->mm->mmap_sem);
11986 + call_dl_resolve = current->mm->call_dl_resolve;
11987 + up_read(&current->mm->mmap_sem);
11988 + if (likely(call_dl_resolve))
11989 + goto emulate;
11990 +
11991 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11992 +
11993 + down_write(&current->mm->mmap_sem);
11994 + if (current->mm->call_dl_resolve) {
11995 + call_dl_resolve = current->mm->call_dl_resolve;
11996 + up_write(&current->mm->mmap_sem);
11997 + if (vma)
11998 + kmem_cache_free(vm_area_cachep, vma);
11999 + goto emulate;
12000 + }
12001 +
12002 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12003 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12004 + up_write(&current->mm->mmap_sem);
12005 + if (vma)
12006 + kmem_cache_free(vm_area_cachep, vma);
12007 + return 1;
12008 + }
12009 +
12010 + if (pax_insert_vma(vma, call_dl_resolve)) {
12011 + up_write(&current->mm->mmap_sem);
12012 + kmem_cache_free(vm_area_cachep, vma);
12013 + return 1;
12014 + }
12015 +
12016 + current->mm->call_dl_resolve = call_dl_resolve;
12017 + up_write(&current->mm->mmap_sem);
12018 +
12019 +emulate:
12020 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12021 + regs->tpc = call_dl_resolve;
12022 + regs->tnpc = addr+4;
12023 + return 3;
12024 + }
12025 +#endif
12026 +
12027 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12028 + if ((save & 0xFFC00000U) == 0x05000000U &&
12029 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12030 + nop == 0x01000000U)
12031 + {
12032 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033 + regs->u_regs[UREG_G2] = addr + 4;
12034 + addr = (save & 0x003FFFFFU) << 10;
12035 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12036 +
12037 + if (test_thread_flag(TIF_32BIT))
12038 + addr &= 0xFFFFFFFFUL;
12039 +
12040 + regs->tpc = addr;
12041 + regs->tnpc = addr+4;
12042 + return 3;
12043 + }
12044 +
12045 + /* PaX: 64-bit PLT stub */
12046 + err = get_user(sethi1, (unsigned int *)addr);
12047 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12048 + err |= get_user(or1, (unsigned int *)(addr+8));
12049 + err |= get_user(or2, (unsigned int *)(addr+12));
12050 + err |= get_user(sllx, (unsigned int *)(addr+16));
12051 + err |= get_user(add, (unsigned int *)(addr+20));
12052 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12053 + err |= get_user(nop, (unsigned int *)(addr+28));
12054 + if (err)
12055 + break;
12056 +
12057 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12058 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12059 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12060 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12061 + sllx == 0x89293020U &&
12062 + add == 0x8A010005U &&
12063 + jmpl == 0x89C14000U &&
12064 + nop == 0x01000000U)
12065 + {
12066 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12067 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12068 + regs->u_regs[UREG_G4] <<= 32;
12069 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12070 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12071 + regs->u_regs[UREG_G4] = addr + 24;
12072 + addr = regs->u_regs[UREG_G5];
12073 + regs->tpc = addr;
12074 + regs->tnpc = addr+4;
12075 + return 3;
12076 + }
12077 + }
12078 + } while (0);
12079 +
12080 +#ifdef CONFIG_PAX_DLRESOLVE
12081 + do { /* PaX: unpatched PLT emulation step 2 */
12082 + unsigned int save, call, nop;
12083 +
12084 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12085 + err |= get_user(call, (unsigned int *)regs->tpc);
12086 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12087 + if (err)
12088 + break;
12089 +
12090 + if (save == 0x9DE3BFA8U &&
12091 + (call & 0xC0000000U) == 0x40000000U &&
12092 + nop == 0x01000000U)
12093 + {
12094 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12095 +
12096 + if (test_thread_flag(TIF_32BIT))
12097 + dl_resolve &= 0xFFFFFFFFUL;
12098 +
12099 + regs->u_regs[UREG_RETPC] = regs->tpc;
12100 + regs->tpc = dl_resolve;
12101 + regs->tnpc = dl_resolve+4;
12102 + return 3;
12103 + }
12104 + } while (0);
12105 +#endif
12106 +
12107 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12108 + unsigned int sethi, ba, nop;
12109 +
12110 + err = get_user(sethi, (unsigned int *)regs->tpc);
12111 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12112 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12113 +
12114 + if (err)
12115 + break;
12116 +
12117 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12118 + (ba & 0xFFF00000U) == 0x30600000U &&
12119 + nop == 0x01000000U)
12120 + {
12121 + unsigned long addr;
12122 +
12123 + addr = (sethi & 0x003FFFFFU) << 10;
12124 + regs->u_regs[UREG_G1] = addr;
12125 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12126 +
12127 + if (test_thread_flag(TIF_32BIT))
12128 + addr &= 0xFFFFFFFFUL;
12129 +
12130 + regs->tpc = addr;
12131 + regs->tnpc = addr+4;
12132 + return 2;
12133 + }
12134 + } while (0);
12135 +
12136 +#endif
12137 +
12138 + return 1;
12139 +}
12140 +
12141 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12142 +{
12143 + unsigned long i;
12144 +
12145 + printk(KERN_ERR "PAX: bytes at PC: ");
12146 + for (i = 0; i < 8; i++) {
12147 + unsigned int c;
12148 + if (get_user(c, (unsigned int *)pc+i))
12149 + printk(KERN_CONT "???????? ");
12150 + else
12151 + printk(KERN_CONT "%08x ", c);
12152 + }
12153 + printk("\n");
12154 +}
12155 +#endif
12156 +
12157 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12158 {
12159 enum ctx_state prev_state = exception_enter();
12160 @@ -353,6 +816,29 @@ retry:
12161 if (!vma)
12162 goto bad_area;
12163
12164 +#ifdef CONFIG_PAX_PAGEEXEC
12165 + /* PaX: detect ITLB misses on non-exec pages */
12166 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12167 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12168 + {
12169 + if (address != regs->tpc)
12170 + goto good_area;
12171 +
12172 + up_read(&mm->mmap_sem);
12173 + switch (pax_handle_fetch_fault(regs)) {
12174 +
12175 +#ifdef CONFIG_PAX_EMUPLT
12176 + case 2:
12177 + case 3:
12178 + return;
12179 +#endif
12180 +
12181 + }
12182 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12183 + do_group_exit(SIGKILL);
12184 + }
12185 +#endif
12186 +
12187 /* Pure DTLB misses do not tell us whether the fault causing
12188 * load/store/atomic was a write or not, it only says that there
12189 * was no match. So in such a case we (carefully) read the
12190 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12191 index d329537..2c3746a 100644
12192 --- a/arch/sparc/mm/hugetlbpage.c
12193 +++ b/arch/sparc/mm/hugetlbpage.c
12194 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12195 unsigned long addr,
12196 unsigned long len,
12197 unsigned long pgoff,
12198 - unsigned long flags)
12199 + unsigned long flags,
12200 + unsigned long offset)
12201 {
12202 + struct mm_struct *mm = current->mm;
12203 unsigned long task_size = TASK_SIZE;
12204 struct vm_unmapped_area_info info;
12205
12206 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12207
12208 info.flags = 0;
12209 info.length = len;
12210 - info.low_limit = TASK_UNMAPPED_BASE;
12211 + info.low_limit = mm->mmap_base;
12212 info.high_limit = min(task_size, VA_EXCLUDE_START);
12213 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12214 info.align_offset = 0;
12215 + info.threadstack_offset = offset;
12216 addr = vm_unmapped_area(&info);
12217
12218 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12219 VM_BUG_ON(addr != -ENOMEM);
12220 info.low_limit = VA_EXCLUDE_END;
12221 +
12222 +#ifdef CONFIG_PAX_RANDMMAP
12223 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12224 + info.low_limit += mm->delta_mmap;
12225 +#endif
12226 +
12227 info.high_limit = task_size;
12228 addr = vm_unmapped_area(&info);
12229 }
12230 @@ -55,7 +64,8 @@ static unsigned long
12231 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12232 const unsigned long len,
12233 const unsigned long pgoff,
12234 - const unsigned long flags)
12235 + const unsigned long flags,
12236 + const unsigned long offset)
12237 {
12238 struct mm_struct *mm = current->mm;
12239 unsigned long addr = addr0;
12240 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12241 info.high_limit = mm->mmap_base;
12242 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12243 info.align_offset = 0;
12244 + info.threadstack_offset = offset;
12245 addr = vm_unmapped_area(&info);
12246
12247 /*
12248 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12249 VM_BUG_ON(addr != -ENOMEM);
12250 info.flags = 0;
12251 info.low_limit = TASK_UNMAPPED_BASE;
12252 +
12253 +#ifdef CONFIG_PAX_RANDMMAP
12254 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12255 + info.low_limit += mm->delta_mmap;
12256 +#endif
12257 +
12258 info.high_limit = STACK_TOP32;
12259 addr = vm_unmapped_area(&info);
12260 }
12261 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12262 struct mm_struct *mm = current->mm;
12263 struct vm_area_struct *vma;
12264 unsigned long task_size = TASK_SIZE;
12265 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12266
12267 if (test_thread_flag(TIF_32BIT))
12268 task_size = STACK_TOP32;
12269 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12270 return addr;
12271 }
12272
12273 +#ifdef CONFIG_PAX_RANDMMAP
12274 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12275 +#endif
12276 +
12277 if (addr) {
12278 addr = ALIGN(addr, HPAGE_SIZE);
12279 vma = find_vma(mm, addr);
12280 - if (task_size - len >= addr &&
12281 - (!vma || addr + len <= vma->vm_start))
12282 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12283 return addr;
12284 }
12285 if (mm->get_unmapped_area == arch_get_unmapped_area)
12286 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12287 - pgoff, flags);
12288 + pgoff, flags, offset);
12289 else
12290 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12291 - pgoff, flags);
12292 + pgoff, flags, offset);
12293 }
12294
12295 pte_t *huge_pte_alloc(struct mm_struct *mm,
12296 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12297 index 2d91c62..17a8fff 100644
12298 --- a/arch/sparc/mm/init_64.c
12299 +++ b/arch/sparc/mm/init_64.c
12300 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12301 int num_kernel_image_mappings;
12302
12303 #ifdef CONFIG_DEBUG_DCFLUSH
12304 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12305 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12306 #ifdef CONFIG_SMP
12307 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12308 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12309 #endif
12310 #endif
12311
12312 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12313 {
12314 BUG_ON(tlb_type == hypervisor);
12315 #ifdef CONFIG_DEBUG_DCFLUSH
12316 - atomic_inc(&dcpage_flushes);
12317 + atomic_inc_unchecked(&dcpage_flushes);
12318 #endif
12319
12320 #ifdef DCACHE_ALIASING_POSSIBLE
12321 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12322
12323 #ifdef CONFIG_DEBUG_DCFLUSH
12324 seq_printf(m, "DCPageFlushes\t: %d\n",
12325 - atomic_read(&dcpage_flushes));
12326 + atomic_read_unchecked(&dcpage_flushes));
12327 #ifdef CONFIG_SMP
12328 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12329 - atomic_read(&dcpage_flushes_xcall));
12330 + atomic_read_unchecked(&dcpage_flushes_xcall));
12331 #endif /* CONFIG_SMP */
12332 #endif /* CONFIG_DEBUG_DCFLUSH */
12333 }
12334 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12335 index 7cca418..53fc030 100644
12336 --- a/arch/tile/Kconfig
12337 +++ b/arch/tile/Kconfig
12338 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12339
12340 config KEXEC
12341 bool "kexec system call"
12342 + depends on !GRKERNSEC_KMEM
12343 ---help---
12344 kexec is a system call that implements the ability to shutdown your
12345 current kernel, and to start another kernel. It is like a reboot
12346 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12347 index 7b11c5f..755a026 100644
12348 --- a/arch/tile/include/asm/atomic_64.h
12349 +++ b/arch/tile/include/asm/atomic_64.h
12350 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12351
12352 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12353
12354 +#define atomic64_read_unchecked(v) atomic64_read(v)
12355 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12356 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12357 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12358 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12359 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12360 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12361 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12362 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12363 +
12364 /* Define this to indicate that cmpxchg is an efficient operation. */
12365 #define __HAVE_ARCH_CMPXCHG
12366
12367 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12368 index 6160761..00cac88 100644
12369 --- a/arch/tile/include/asm/cache.h
12370 +++ b/arch/tile/include/asm/cache.h
12371 @@ -15,11 +15,12 @@
12372 #ifndef _ASM_TILE_CACHE_H
12373 #define _ASM_TILE_CACHE_H
12374
12375 +#include <linux/const.h>
12376 #include <arch/chip.h>
12377
12378 /* bytes per L1 data cache line */
12379 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12380 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12381 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12382
12383 /* bytes per L2 cache line */
12384 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12385 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12386 index b6cde32..c0cb736 100644
12387 --- a/arch/tile/include/asm/uaccess.h
12388 +++ b/arch/tile/include/asm/uaccess.h
12389 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12390 const void __user *from,
12391 unsigned long n)
12392 {
12393 - int sz = __compiletime_object_size(to);
12394 + size_t sz = __compiletime_object_size(to);
12395
12396 - if (likely(sz == -1 || sz >= n))
12397 + if (likely(sz == (size_t)-1 || sz >= n))
12398 n = _copy_from_user(to, from, n);
12399 else
12400 copy_from_user_overflow();
12401 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12402 index e514899..f8743c4 100644
12403 --- a/arch/tile/mm/hugetlbpage.c
12404 +++ b/arch/tile/mm/hugetlbpage.c
12405 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12406 info.high_limit = TASK_SIZE;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409 + info.threadstack_offset = 0;
12410 return vm_unmapped_area(&info);
12411 }
12412
12413 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12414 info.high_limit = current->mm->mmap_base;
12415 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12416 info.align_offset = 0;
12417 + info.threadstack_offset = 0;
12418 addr = vm_unmapped_area(&info);
12419
12420 /*
12421 diff --git a/arch/um/Makefile b/arch/um/Makefile
12422 index e4b1a96..16162f8 100644
12423 --- a/arch/um/Makefile
12424 +++ b/arch/um/Makefile
12425 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12428
12429 +ifdef CONSTIFY_PLUGIN
12430 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12431 +endif
12432 +
12433 #This will adjust *FLAGS accordingly to the platform.
12434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12435
12436 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12437 index 19e1bdd..3665b77 100644
12438 --- a/arch/um/include/asm/cache.h
12439 +++ b/arch/um/include/asm/cache.h
12440 @@ -1,6 +1,7 @@
12441 #ifndef __UM_CACHE_H
12442 #define __UM_CACHE_H
12443
12444 +#include <linux/const.h>
12445
12446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12448 @@ -12,6 +13,6 @@
12449 # define L1_CACHE_SHIFT 5
12450 #endif
12451
12452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12454
12455 #endif
12456 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12457 index 2e0a6b1..a64d0f5 100644
12458 --- a/arch/um/include/asm/kmap_types.h
12459 +++ b/arch/um/include/asm/kmap_types.h
12460 @@ -8,6 +8,6 @@
12461
12462 /* No more #include "asm/arch/kmap_types.h" ! */
12463
12464 -#define KM_TYPE_NR 14
12465 +#define KM_TYPE_NR 15
12466
12467 #endif
12468 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12469 index 71c5d13..4c7b9f1 100644
12470 --- a/arch/um/include/asm/page.h
12471 +++ b/arch/um/include/asm/page.h
12472 @@ -14,6 +14,9 @@
12473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12474 #define PAGE_MASK (~(PAGE_SIZE-1))
12475
12476 +#define ktla_ktva(addr) (addr)
12477 +#define ktva_ktla(addr) (addr)
12478 +
12479 #ifndef __ASSEMBLY__
12480
12481 struct page;
12482 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12483 index 0032f92..cd151e0 100644
12484 --- a/arch/um/include/asm/pgtable-3level.h
12485 +++ b/arch/um/include/asm/pgtable-3level.h
12486 @@ -58,6 +58,7 @@
12487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12488 #define pud_populate(mm, pud, pmd) \
12489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12490 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12491
12492 #ifdef CONFIG_64BIT
12493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12494 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12495 index f17bca8..48adb87 100644
12496 --- a/arch/um/kernel/process.c
12497 +++ b/arch/um/kernel/process.c
12498 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12499 return 2;
12500 }
12501
12502 -/*
12503 - * Only x86 and x86_64 have an arch_align_stack().
12504 - * All other arches have "#define arch_align_stack(x) (x)"
12505 - * in their asm/exec.h
12506 - * As this is included in UML from asm-um/system-generic.h,
12507 - * we can use it to behave as the subarch does.
12508 - */
12509 -#ifndef arch_align_stack
12510 -unsigned long arch_align_stack(unsigned long sp)
12511 -{
12512 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12513 - sp -= get_random_int() % 8192;
12514 - return sp & ~0xf;
12515 -}
12516 -#endif
12517 -
12518 unsigned long get_wchan(struct task_struct *p)
12519 {
12520 unsigned long stack_page, sp, ip;
12521 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12522 index ad8f795..2c7eec6 100644
12523 --- a/arch/unicore32/include/asm/cache.h
12524 +++ b/arch/unicore32/include/asm/cache.h
12525 @@ -12,8 +12,10 @@
12526 #ifndef __UNICORE_CACHE_H__
12527 #define __UNICORE_CACHE_H__
12528
12529 -#define L1_CACHE_SHIFT (5)
12530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531 +#include <linux/const.h>
12532 +
12533 +#define L1_CACHE_SHIFT 5
12534 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12535
12536 /*
12537 * Memory returned by kmalloc() may be used for DMA, so we must make
12538 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12539 index 3635fff..c1f9fab 100644
12540 --- a/arch/x86/Kconfig
12541 +++ b/arch/x86/Kconfig
12542 @@ -129,7 +129,7 @@ config X86
12543 select RTC_LIB
12544 select HAVE_DEBUG_STACKOVERFLOW
12545 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12546 - select HAVE_CC_STACKPROTECTOR
12547 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12548 select GENERIC_CPU_AUTOPROBE
12549 select HAVE_ARCH_AUDITSYSCALL
12550 select ARCH_SUPPORTS_ATOMIC_RMW
12551 @@ -262,7 +262,7 @@ config X86_HT
12552
12553 config X86_32_LAZY_GS
12554 def_bool y
12555 - depends on X86_32 && !CC_STACKPROTECTOR
12556 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12557
12558 config ARCH_HWEIGHT_CFLAGS
12559 string
12560 @@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12561
12562 menuconfig HYPERVISOR_GUEST
12563 bool "Linux guest support"
12564 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12565 ---help---
12566 Say Y here to enable options for running Linux under various hyper-
12567 visors. This option enables basic hypervisor detection and platform
12568 @@ -977,6 +978,7 @@ config VM86
12569
12570 config X86_16BIT
12571 bool "Enable support for 16-bit segments" if EXPERT
12572 + depends on !GRKERNSEC
12573 default y
12574 ---help---
12575 This option is required by programs like Wine to run 16-bit
12576 @@ -1132,6 +1134,7 @@ choice
12577
12578 config NOHIGHMEM
12579 bool "off"
12580 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12581 ---help---
12582 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12583 However, the address space of 32-bit x86 processors is only 4
12584 @@ -1168,6 +1171,7 @@ config NOHIGHMEM
12585
12586 config HIGHMEM4G
12587 bool "4GB"
12588 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12589 ---help---
12590 Select this if you have a 32-bit processor and between 1 and 4
12591 gigabytes of physical RAM.
12592 @@ -1220,7 +1224,7 @@ config PAGE_OFFSET
12593 hex
12594 default 0xB0000000 if VMSPLIT_3G_OPT
12595 default 0x80000000 if VMSPLIT_2G
12596 - default 0x78000000 if VMSPLIT_2G_OPT
12597 + default 0x70000000 if VMSPLIT_2G_OPT
12598 default 0x40000000 if VMSPLIT_1G
12599 default 0xC0000000
12600 depends on X86_32
12601 @@ -1635,6 +1639,7 @@ source kernel/Kconfig.hz
12602
12603 config KEXEC
12604 bool "kexec system call"
12605 + depends on !GRKERNSEC_KMEM
12606 ---help---
12607 kexec is a system call that implements the ability to shutdown your
12608 current kernel, and to start another kernel. It is like a reboot
12609 @@ -1820,7 +1825,9 @@ config X86_NEED_RELOCS
12610
12611 config PHYSICAL_ALIGN
12612 hex "Alignment value to which kernel should be aligned"
12613 - default "0x200000"
12614 + default "0x1000000"
12615 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12616 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12617 range 0x2000 0x1000000 if X86_32
12618 range 0x200000 0x1000000 if X86_64
12619 ---help---
12620 @@ -1903,6 +1910,7 @@ config COMPAT_VDSO
12621 def_bool n
12622 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12623 depends on X86_32 || IA32_EMULATION
12624 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12625 ---help---
12626 Certain buggy versions of glibc will crash if they are
12627 presented with a 32-bit vDSO that is not mapped at the address
12628 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12629 index 6983314..54ad7e8 100644
12630 --- a/arch/x86/Kconfig.cpu
12631 +++ b/arch/x86/Kconfig.cpu
12632 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12633
12634 config X86_F00F_BUG
12635 def_bool y
12636 - depends on M586MMX || M586TSC || M586 || M486
12637 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12638
12639 config X86_INVD_BUG
12640 def_bool y
12641 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12642
12643 config X86_ALIGNMENT_16
12644 def_bool y
12645 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12646 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12647
12648 config X86_INTEL_USERCOPY
12649 def_bool y
12650 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12651 # generates cmov.
12652 config X86_CMOV
12653 def_bool y
12654 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12655 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12656
12657 config X86_MINIMUM_CPU_FAMILY
12658 int
12659 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12660 index 61bd2ad..50b625d 100644
12661 --- a/arch/x86/Kconfig.debug
12662 +++ b/arch/x86/Kconfig.debug
12663 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12664 config DEBUG_RODATA
12665 bool "Write protect kernel read-only data structures"
12666 default y
12667 - depends on DEBUG_KERNEL
12668 + depends on DEBUG_KERNEL && BROKEN
12669 ---help---
12670 Mark the kernel read-only data as write-protected in the pagetables,
12671 in order to catch accidental (and incorrect) writes to such const
12672 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12673
12674 config DEBUG_SET_MODULE_RONX
12675 bool "Set loadable kernel module data as NX and text as RO"
12676 - depends on MODULES
12677 + depends on MODULES && BROKEN
12678 ---help---
12679 This option helps catch unintended modifications to loadable
12680 kernel module's text and read-only data. It also prevents execution
12681 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12682 index 920e616..ac3d4df 100644
12683 --- a/arch/x86/Makefile
12684 +++ b/arch/x86/Makefile
12685 @@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12686 # CPU-specific tuning. Anything which can be shared with UML should go here.
12687 include $(srctree)/arch/x86/Makefile_32.cpu
12688 KBUILD_CFLAGS += $(cflags-y)
12689 -
12690 - # temporary until string.h is fixed
12691 - KBUILD_CFLAGS += -ffreestanding
12692 else
12693 BITS := 64
12694 UTS_MACHINE := x86_64
12695 @@ -107,6 +104,9 @@ else
12696 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12697 endif
12698
12699 +# temporary until string.h is fixed
12700 +KBUILD_CFLAGS += -ffreestanding
12701 +
12702 # Make sure compiler does not have buggy stack-protector support.
12703 ifdef CONFIG_CC_STACKPROTECTOR
12704 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12705 @@ -180,6 +180,7 @@ archheaders:
12706 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12707
12708 archprepare:
12709 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12710 ifeq ($(CONFIG_KEXEC_FILE),y)
12711 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12712 endif
12713 @@ -263,3 +264,9 @@ define archhelp
12714 echo ' FDARGS="..." arguments for the booted kernel'
12715 echo ' FDINITRD=file initrd for the booted kernel'
12716 endef
12717 +
12718 +define OLD_LD
12719 +
12720 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12721 +*** Please upgrade your binutils to 2.18 or newer
12722 +endef
12723 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12724 index 3db07f3..9d81d0f 100644
12725 --- a/arch/x86/boot/Makefile
12726 +++ b/arch/x86/boot/Makefile
12727 @@ -56,6 +56,9 @@ clean-files += cpustr.h
12728 # ---------------------------------------------------------------------------
12729
12730 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12731 +ifdef CONSTIFY_PLUGIN
12732 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12733 +endif
12734 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12735 GCOV_PROFILE := n
12736
12737 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12738 index 878e4b9..20537ab 100644
12739 --- a/arch/x86/boot/bitops.h
12740 +++ b/arch/x86/boot/bitops.h
12741 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12742 u8 v;
12743 const u32 *p = (const u32 *)addr;
12744
12745 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12746 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12747 return v;
12748 }
12749
12750 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12751
12752 static inline void set_bit(int nr, void *addr)
12753 {
12754 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12755 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12756 }
12757
12758 #endif /* BOOT_BITOPS_H */
12759 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12760 index bd49ec6..94c7f58 100644
12761 --- a/arch/x86/boot/boot.h
12762 +++ b/arch/x86/boot/boot.h
12763 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12764 static inline u16 ds(void)
12765 {
12766 u16 seg;
12767 - asm("movw %%ds,%0" : "=rm" (seg));
12768 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12769 return seg;
12770 }
12771
12772 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12773 index 6a1a845..0ad2dae 100644
12774 --- a/arch/x86/boot/compressed/Makefile
12775 +++ b/arch/x86/boot/compressed/Makefile
12776 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12777 KBUILD_CFLAGS += -mno-mmx -mno-sse
12778 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12779 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12780 +ifdef CONSTIFY_PLUGIN
12781 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12782 +endif
12783
12784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12785 GCOV_PROFILE := n
12786 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12787 index a53440e..c3dbf1e 100644
12788 --- a/arch/x86/boot/compressed/efi_stub_32.S
12789 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12790 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12791 * parameter 2, ..., param n. To make things easy, we save the return
12792 * address of efi_call_phys in a global variable.
12793 */
12794 - popl %ecx
12795 - movl %ecx, saved_return_addr(%edx)
12796 - /* get the function pointer into ECX*/
12797 - popl %ecx
12798 - movl %ecx, efi_rt_function_ptr(%edx)
12799 + popl saved_return_addr(%edx)
12800 + popl efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 3. Call the physical function.
12804 */
12805 - call *%ecx
12806 + call *efi_rt_function_ptr(%edx)
12807
12808 /*
12809 * 4. Balance the stack. And because EAX contain the return value,
12810 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12811 1: popl %edx
12812 subl $1b, %edx
12813
12814 - movl efi_rt_function_ptr(%edx), %ecx
12815 - pushl %ecx
12816 + pushl efi_rt_function_ptr(%edx)
12817
12818 /*
12819 * 10. Push the saved return address onto the stack and return.
12820 */
12821 - movl saved_return_addr(%edx), %ecx
12822 - pushl %ecx
12823 - ret
12824 + jmpl *saved_return_addr(%edx)
12825 ENDPROC(efi_call_phys)
12826 .previous
12827
12828 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12829 index 1d7fbbc..36ecd58 100644
12830 --- a/arch/x86/boot/compressed/head_32.S
12831 +++ b/arch/x86/boot/compressed/head_32.S
12832 @@ -140,10 +140,10 @@ preferred_addr:
12833 addl %eax, %ebx
12834 notl %eax
12835 andl %eax, %ebx
12836 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12837 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12838 jge 1f
12839 #endif
12840 - movl $LOAD_PHYSICAL_ADDR, %ebx
12841 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12842 1:
12843
12844 /* Target address to relocate to for decompression */
12845 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12846 index 6b1766c..ad465c9 100644
12847 --- a/arch/x86/boot/compressed/head_64.S
12848 +++ b/arch/x86/boot/compressed/head_64.S
12849 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12850 addl %eax, %ebx
12851 notl %eax
12852 andl %eax, %ebx
12853 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12854 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12855 jge 1f
12856 #endif
12857 - movl $LOAD_PHYSICAL_ADDR, %ebx
12858 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12859 1:
12860
12861 /* Target address to relocate to for decompression */
12862 @@ -322,10 +322,10 @@ preferred_addr:
12863 addq %rax, %rbp
12864 notq %rax
12865 andq %rax, %rbp
12866 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12867 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12868 jge 1f
12869 #endif
12870 - movq $LOAD_PHYSICAL_ADDR, %rbp
12871 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12872 1:
12873
12874 /* Target address to relocate to for decompression */
12875 @@ -434,8 +434,8 @@ gdt:
12876 .long gdt
12877 .word 0
12878 .quad 0x0000000000000000 /* NULL descriptor */
12879 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12880 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12881 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12882 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12883 .quad 0x0080890000000000 /* TS descriptor */
12884 .quad 0x0000000000000000 /* TS continued */
12885 gdt_end:
12886 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12887 index 0c33a7c..be226ed 100644
12888 --- a/arch/x86/boot/compressed/misc.c
12889 +++ b/arch/x86/boot/compressed/misc.c
12890 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12891 * Calculate the delta between where vmlinux was linked to load
12892 * and where it was actually loaded.
12893 */
12894 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12895 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12896 if (!delta) {
12897 debug_putstr("No relocation needed... ");
12898 return;
12899 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12900 Elf32_Ehdr ehdr;
12901 Elf32_Phdr *phdrs, *phdr;
12902 #endif
12903 - void *dest;
12904 + void *dest, *prev;
12905 int i;
12906
12907 memcpy(&ehdr, output, sizeof(ehdr));
12908 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12909 case PT_LOAD:
12910 #ifdef CONFIG_RELOCATABLE
12911 dest = output;
12912 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12913 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12914 #else
12915 dest = (void *)(phdr->p_paddr);
12916 #endif
12917 memcpy(dest,
12918 output + phdr->p_offset,
12919 phdr->p_filesz);
12920 + if (i)
12921 + memset(prev, 0xff, dest - prev);
12922 + prev = dest + phdr->p_filesz;
12923 break;
12924 default: /* Ignore other PT_* */ break;
12925 }
12926 @@ -404,7 +407,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12927 error("Destination address too large");
12928 #endif
12929 #ifndef CONFIG_RELOCATABLE
12930 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12931 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12932 error("Wrong destination address");
12933 #endif
12934
12935 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12936 index 1fd7d57..0f7d096 100644
12937 --- a/arch/x86/boot/cpucheck.c
12938 +++ b/arch/x86/boot/cpucheck.c
12939 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12940 u32 ecx = MSR_K7_HWCR;
12941 u32 eax, edx;
12942
12943 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12944 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12945 eax &= ~(1 << 15);
12946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12948
12949 get_cpuflags(); /* Make sure it really did something */
12950 err = check_cpuflags();
12951 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12952 u32 ecx = MSR_VIA_FCR;
12953 u32 eax, edx;
12954
12955 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12956 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12957 eax |= (1<<1)|(1<<7);
12958 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12959 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12960
12961 set_bit(X86_FEATURE_CX8, cpu.flags);
12962 err = check_cpuflags();
12963 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12964 u32 eax, edx;
12965 u32 level = 1;
12966
12967 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12968 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12969 - asm("cpuid"
12970 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972 + asm volatile("cpuid"
12973 : "+a" (level), "=d" (cpu.flags[0])
12974 : : "ecx", "ebx");
12975 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12976 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12977
12978 err = check_cpuflags();
12979 } else if (err == 0x01 &&
12980 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12981 index 16ef025..91e033b 100644
12982 --- a/arch/x86/boot/header.S
12983 +++ b/arch/x86/boot/header.S
12984 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12985 # single linked list of
12986 # struct setup_data
12987
12988 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12989 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12990
12991 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12992 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12993 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12994 +#else
12995 #define VO_INIT_SIZE (VO__end - VO__text)
12996 +#endif
12997 #if ZO_INIT_SIZE > VO_INIT_SIZE
12998 #define INIT_SIZE ZO_INIT_SIZE
12999 #else
13000 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13001 index db75d07..8e6d0af 100644
13002 --- a/arch/x86/boot/memory.c
13003 +++ b/arch/x86/boot/memory.c
13004 @@ -19,7 +19,7 @@
13005
13006 static int detect_memory_e820(void)
13007 {
13008 - int count = 0;
13009 + unsigned int count = 0;
13010 struct biosregs ireg, oreg;
13011 struct e820entry *desc = boot_params.e820_map;
13012 static struct e820entry buf; /* static so it is zeroed */
13013 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13014 index ba3e100..6501b8f 100644
13015 --- a/arch/x86/boot/video-vesa.c
13016 +++ b/arch/x86/boot/video-vesa.c
13017 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13018
13019 boot_params.screen_info.vesapm_seg = oreg.es;
13020 boot_params.screen_info.vesapm_off = oreg.di;
13021 + boot_params.screen_info.vesapm_size = oreg.cx;
13022 }
13023
13024 /*
13025 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13026 index 43eda28..5ab5fdb 100644
13027 --- a/arch/x86/boot/video.c
13028 +++ b/arch/x86/boot/video.c
13029 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13030 static unsigned int get_entry(void)
13031 {
13032 char entry_buf[4];
13033 - int i, len = 0;
13034 + unsigned int i, len = 0;
13035 int key;
13036 unsigned int v;
13037
13038 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13039 index 9105655..41779c1 100644
13040 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13041 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13042 @@ -8,6 +8,8 @@
13043 * including this sentence is retained in full.
13044 */
13045
13046 +#include <asm/alternative-asm.h>
13047 +
13048 .extern crypto_ft_tab
13049 .extern crypto_it_tab
13050 .extern crypto_fl_tab
13051 @@ -70,6 +72,8 @@
13052 je B192; \
13053 leaq 32(r9),r9;
13054
13055 +#define ret pax_force_retaddr; ret
13056 +
13057 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13058 movq r1,r2; \
13059 movq r3,r4; \
13060 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13061 index 477e9d7..c92c7d8 100644
13062 --- a/arch/x86/crypto/aesni-intel_asm.S
13063 +++ b/arch/x86/crypto/aesni-intel_asm.S
13064 @@ -31,6 +31,7 @@
13065
13066 #include <linux/linkage.h>
13067 #include <asm/inst.h>
13068 +#include <asm/alternative-asm.h>
13069
13070 #ifdef __x86_64__
13071 .data
13072 @@ -205,7 +206,7 @@ enc: .octa 0x2
13073 * num_initial_blocks = b mod 4
13074 * encrypt the initial num_initial_blocks blocks and apply ghash on
13075 * the ciphertext
13076 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13077 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13078 * are clobbered
13079 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13080 */
13081 @@ -214,8 +215,8 @@ enc: .octa 0x2
13082 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13083 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13084 mov arg7, %r10 # %r10 = AAD
13085 - mov arg8, %r12 # %r12 = aadLen
13086 - mov %r12, %r11
13087 + mov arg8, %r15 # %r15 = aadLen
13088 + mov %r15, %r11
13089 pxor %xmm\i, %xmm\i
13090 _get_AAD_loop\num_initial_blocks\operation:
13091 movd (%r10), \TMP1
13092 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13093 psrldq $4, %xmm\i
13094 pxor \TMP1, %xmm\i
13095 add $4, %r10
13096 - sub $4, %r12
13097 + sub $4, %r15
13098 jne _get_AAD_loop\num_initial_blocks\operation
13099 cmp $16, %r11
13100 je _get_AAD_loop2_done\num_initial_blocks\operation
13101 - mov $16, %r12
13102 + mov $16, %r15
13103 _get_AAD_loop2\num_initial_blocks\operation:
13104 psrldq $4, %xmm\i
13105 - sub $4, %r12
13106 - cmp %r11, %r12
13107 + sub $4, %r15
13108 + cmp %r11, %r15
13109 jne _get_AAD_loop2\num_initial_blocks\operation
13110 _get_AAD_loop2_done\num_initial_blocks\operation:
13111 movdqa SHUF_MASK(%rip), %xmm14
13112 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13113 * num_initial_blocks = b mod 4
13114 * encrypt the initial num_initial_blocks blocks and apply ghash on
13115 * the ciphertext
13116 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13117 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13118 * are clobbered
13119 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13120 */
13121 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13122 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13123 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13124 mov arg7, %r10 # %r10 = AAD
13125 - mov arg8, %r12 # %r12 = aadLen
13126 - mov %r12, %r11
13127 + mov arg8, %r15 # %r15 = aadLen
13128 + mov %r15, %r11
13129 pxor %xmm\i, %xmm\i
13130 _get_AAD_loop\num_initial_blocks\operation:
13131 movd (%r10), \TMP1
13132 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13133 psrldq $4, %xmm\i
13134 pxor \TMP1, %xmm\i
13135 add $4, %r10
13136 - sub $4, %r12
13137 + sub $4, %r15
13138 jne _get_AAD_loop\num_initial_blocks\operation
13139 cmp $16, %r11
13140 je _get_AAD_loop2_done\num_initial_blocks\operation
13141 - mov $16, %r12
13142 + mov $16, %r15
13143 _get_AAD_loop2\num_initial_blocks\operation:
13144 psrldq $4, %xmm\i
13145 - sub $4, %r12
13146 - cmp %r11, %r12
13147 + sub $4, %r15
13148 + cmp %r11, %r15
13149 jne _get_AAD_loop2\num_initial_blocks\operation
13150 _get_AAD_loop2_done\num_initial_blocks\operation:
13151 movdqa SHUF_MASK(%rip), %xmm14
13152 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13153 *
13154 *****************************************************************************/
13155 ENTRY(aesni_gcm_dec)
13156 - push %r12
13157 + push %r15
13158 push %r13
13159 push %r14
13160 mov %rsp, %r14
13161 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13162 */
13163 sub $VARIABLE_OFFSET, %rsp
13164 and $~63, %rsp # align rsp to 64 bytes
13165 - mov %arg6, %r12
13166 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13167 + mov %arg6, %r15
13168 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13169 movdqa SHUF_MASK(%rip), %xmm2
13170 PSHUFB_XMM %xmm2, %xmm13
13171
13172 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13173 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13174 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13175 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13176 - mov %r13, %r12
13177 - and $(3<<4), %r12
13178 + mov %r13, %r15
13179 + and $(3<<4), %r15
13180 jz _initial_num_blocks_is_0_decrypt
13181 - cmp $(2<<4), %r12
13182 + cmp $(2<<4), %r15
13183 jb _initial_num_blocks_is_1_decrypt
13184 je _initial_num_blocks_is_2_decrypt
13185 _initial_num_blocks_is_3_decrypt:
13186 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13187 sub $16, %r11
13188 add %r13, %r11
13189 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13190 - lea SHIFT_MASK+16(%rip), %r12
13191 - sub %r13, %r12
13192 + lea SHIFT_MASK+16(%rip), %r15
13193 + sub %r13, %r15
13194 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13195 # (%r13 is the number of bytes in plaintext mod 16)
13196 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13197 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13198 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13199
13200 movdqa %xmm1, %xmm2
13201 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13202 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13203 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13204 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13205 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13206 pand %xmm1, %xmm2
13207 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13208 sub $1, %r13
13209 jne _less_than_8_bytes_left_decrypt
13210 _multiple_of_16_bytes_decrypt:
13211 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13212 - shl $3, %r12 # convert into number of bits
13213 - movd %r12d, %xmm15 # len(A) in %xmm15
13214 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13215 + shl $3, %r15 # convert into number of bits
13216 + movd %r15d, %xmm15 # len(A) in %xmm15
13217 shl $3, %arg4 # len(C) in bits (*128)
13218 MOVQ_R64_XMM %arg4, %xmm1
13219 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13220 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13221 mov %r14, %rsp
13222 pop %r14
13223 pop %r13
13224 - pop %r12
13225 + pop %r15
13226 + pax_force_retaddr
13227 ret
13228 ENDPROC(aesni_gcm_dec)
13229
13230 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13231 * poly = x^128 + x^127 + x^126 + x^121 + 1
13232 ***************************************************************************/
13233 ENTRY(aesni_gcm_enc)
13234 - push %r12
13235 + push %r15
13236 push %r13
13237 push %r14
13238 mov %rsp, %r14
13239 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13240 #
13241 sub $VARIABLE_OFFSET, %rsp
13242 and $~63, %rsp
13243 - mov %arg6, %r12
13244 - movdqu (%r12), %xmm13
13245 + mov %arg6, %r15
13246 + movdqu (%r15), %xmm13
13247 movdqa SHUF_MASK(%rip), %xmm2
13248 PSHUFB_XMM %xmm2, %xmm13
13249
13250 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13251 movdqa %xmm13, HashKey(%rsp)
13252 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13253 and $-16, %r13
13254 - mov %r13, %r12
13255 + mov %r13, %r15
13256
13257 # Encrypt first few blocks
13258
13259 - and $(3<<4), %r12
13260 + and $(3<<4), %r15
13261 jz _initial_num_blocks_is_0_encrypt
13262 - cmp $(2<<4), %r12
13263 + cmp $(2<<4), %r15
13264 jb _initial_num_blocks_is_1_encrypt
13265 je _initial_num_blocks_is_2_encrypt
13266 _initial_num_blocks_is_3_encrypt:
13267 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13268 sub $16, %r11
13269 add %r13, %r11
13270 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13271 - lea SHIFT_MASK+16(%rip), %r12
13272 - sub %r13, %r12
13273 + lea SHIFT_MASK+16(%rip), %r15
13274 + sub %r13, %r15
13275 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13276 # (%r13 is the number of bytes in plaintext mod 16)
13277 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13278 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13279 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13280 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13281 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13282 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13283 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13284 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13285 movdqa SHUF_MASK(%rip), %xmm10
13286 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13287 sub $1, %r13
13288 jne _less_than_8_bytes_left_encrypt
13289 _multiple_of_16_bytes_encrypt:
13290 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13291 - shl $3, %r12
13292 - movd %r12d, %xmm15 # len(A) in %xmm15
13293 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13294 + shl $3, %r15
13295 + movd %r15d, %xmm15 # len(A) in %xmm15
13296 shl $3, %arg4 # len(C) in bits (*128)
13297 MOVQ_R64_XMM %arg4, %xmm1
13298 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13299 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13300 mov %r14, %rsp
13301 pop %r14
13302 pop %r13
13303 - pop %r12
13304 + pop %r15
13305 + pax_force_retaddr
13306 ret
13307 ENDPROC(aesni_gcm_enc)
13308
13309 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13310 pxor %xmm1, %xmm0
13311 movaps %xmm0, (TKEYP)
13312 add $0x10, TKEYP
13313 + pax_force_retaddr
13314 ret
13315 ENDPROC(_key_expansion_128)
13316 ENDPROC(_key_expansion_256a)
13317 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13318 shufps $0b01001110, %xmm2, %xmm1
13319 movaps %xmm1, 0x10(TKEYP)
13320 add $0x20, TKEYP
13321 + pax_force_retaddr
13322 ret
13323 ENDPROC(_key_expansion_192a)
13324
13325 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13326
13327 movaps %xmm0, (TKEYP)
13328 add $0x10, TKEYP
13329 + pax_force_retaddr
13330 ret
13331 ENDPROC(_key_expansion_192b)
13332
13333 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13334 pxor %xmm1, %xmm2
13335 movaps %xmm2, (TKEYP)
13336 add $0x10, TKEYP
13337 + pax_force_retaddr
13338 ret
13339 ENDPROC(_key_expansion_256b)
13340
13341 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13342 #ifndef __x86_64__
13343 popl KEYP
13344 #endif
13345 + pax_force_retaddr
13346 ret
13347 ENDPROC(aesni_set_key)
13348
13349 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13350 popl KLEN
13351 popl KEYP
13352 #endif
13353 + pax_force_retaddr
13354 ret
13355 ENDPROC(aesni_enc)
13356
13357 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13358 AESENC KEY STATE
13359 movaps 0x70(TKEYP), KEY
13360 AESENCLAST KEY STATE
13361 + pax_force_retaddr
13362 ret
13363 ENDPROC(_aesni_enc1)
13364
13365 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13366 AESENCLAST KEY STATE2
13367 AESENCLAST KEY STATE3
13368 AESENCLAST KEY STATE4
13369 + pax_force_retaddr
13370 ret
13371 ENDPROC(_aesni_enc4)
13372
13373 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13374 popl KLEN
13375 popl KEYP
13376 #endif
13377 + pax_force_retaddr
13378 ret
13379 ENDPROC(aesni_dec)
13380
13381 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13382 AESDEC KEY STATE
13383 movaps 0x70(TKEYP), KEY
13384 AESDECLAST KEY STATE
13385 + pax_force_retaddr
13386 ret
13387 ENDPROC(_aesni_dec1)
13388
13389 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13390 AESDECLAST KEY STATE2
13391 AESDECLAST KEY STATE3
13392 AESDECLAST KEY STATE4
13393 + pax_force_retaddr
13394 ret
13395 ENDPROC(_aesni_dec4)
13396
13397 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13398 popl KEYP
13399 popl LEN
13400 #endif
13401 + pax_force_retaddr
13402 ret
13403 ENDPROC(aesni_ecb_enc)
13404
13405 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13406 popl KEYP
13407 popl LEN
13408 #endif
13409 + pax_force_retaddr
13410 ret
13411 ENDPROC(aesni_ecb_dec)
13412
13413 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13414 popl LEN
13415 popl IVP
13416 #endif
13417 + pax_force_retaddr
13418 ret
13419 ENDPROC(aesni_cbc_enc)
13420
13421 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13422 popl LEN
13423 popl IVP
13424 #endif
13425 + pax_force_retaddr
13426 ret
13427 ENDPROC(aesni_cbc_dec)
13428
13429 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13430 mov $1, TCTR_LOW
13431 MOVQ_R64_XMM TCTR_LOW INC
13432 MOVQ_R64_XMM CTR TCTR_LOW
13433 + pax_force_retaddr
13434 ret
13435 ENDPROC(_aesni_inc_init)
13436
13437 @@ -2579,6 +2598,7 @@ _aesni_inc:
13438 .Linc_low:
13439 movaps CTR, IV
13440 PSHUFB_XMM BSWAP_MASK IV
13441 + pax_force_retaddr
13442 ret
13443 ENDPROC(_aesni_inc)
13444
13445 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13446 .Lctr_enc_ret:
13447 movups IV, (IVP)
13448 .Lctr_enc_just_ret:
13449 + pax_force_retaddr
13450 ret
13451 ENDPROC(aesni_ctr_enc)
13452
13453 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13454 pxor INC, STATE4
13455 movdqu STATE4, 0x70(OUTP)
13456
13457 + pax_force_retaddr
13458 ret
13459 ENDPROC(aesni_xts_crypt8)
13460
13461 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13462 index 246c670..466e2d6 100644
13463 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13464 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465 @@ -21,6 +21,7 @@
13466 */
13467
13468 #include <linux/linkage.h>
13469 +#include <asm/alternative-asm.h>
13470
13471 .file "blowfish-x86_64-asm.S"
13472 .text
13473 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13474 jnz .L__enc_xor;
13475
13476 write_block();
13477 + pax_force_retaddr
13478 ret;
13479 .L__enc_xor:
13480 xor_block();
13481 + pax_force_retaddr
13482 ret;
13483 ENDPROC(__blowfish_enc_blk)
13484
13485 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13486
13487 movq %r11, %rbp;
13488
13489 + pax_force_retaddr
13490 ret;
13491 ENDPROC(blowfish_dec_blk)
13492
13493 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13494
13495 popq %rbx;
13496 popq %rbp;
13497 + pax_force_retaddr
13498 ret;
13499
13500 .L__enc_xor4:
13501 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13502
13503 popq %rbx;
13504 popq %rbp;
13505 + pax_force_retaddr
13506 ret;
13507 ENDPROC(__blowfish_enc_blk_4way)
13508
13509 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13510 popq %rbx;
13511 popq %rbp;
13512
13513 + pax_force_retaddr
13514 ret;
13515 ENDPROC(blowfish_dec_blk_4way)
13516 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13517 index ce71f92..1dce7ec 100644
13518 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13519 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520 @@ -16,6 +16,7 @@
13521 */
13522
13523 #include <linux/linkage.h>
13524 +#include <asm/alternative-asm.h>
13525
13526 #define CAMELLIA_TABLE_BYTE_LEN 272
13527
13528 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13529 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13530 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13531 %rcx, (%r9));
13532 + pax_force_retaddr
13533 ret;
13534 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13535
13536 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13537 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13538 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13539 %rax, (%r9));
13540 + pax_force_retaddr
13541 ret;
13542 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13543
13544 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13545 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13546 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13547
13548 + pax_force_retaddr
13549 ret;
13550
13551 .align 8
13552 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13553 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13554 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13555
13556 + pax_force_retaddr
13557 ret;
13558
13559 .align 8
13560 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13561 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13562 %xmm8, %rsi);
13563
13564 + pax_force_retaddr
13565 ret;
13566 ENDPROC(camellia_ecb_enc_16way)
13567
13568 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13569 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13570 %xmm8, %rsi);
13571
13572 + pax_force_retaddr
13573 ret;
13574 ENDPROC(camellia_ecb_dec_16way)
13575
13576 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13577 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13578 %xmm8, %rsi);
13579
13580 + pax_force_retaddr
13581 ret;
13582 ENDPROC(camellia_cbc_dec_16way)
13583
13584 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13585 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13586 %xmm8, %rsi);
13587
13588 + pax_force_retaddr
13589 ret;
13590 ENDPROC(camellia_ctr_16way)
13591
13592 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13593 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13594 %xmm8, %rsi);
13595
13596 + pax_force_retaddr
13597 ret;
13598 ENDPROC(camellia_xts_crypt_16way)
13599
13600 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13601 index 0e0b886..5a3123c 100644
13602 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13603 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604 @@ -11,6 +11,7 @@
13605 */
13606
13607 #include <linux/linkage.h>
13608 +#include <asm/alternative-asm.h>
13609
13610 #define CAMELLIA_TABLE_BYTE_LEN 272
13611
13612 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13613 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13614 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13615 %rcx, (%r9));
13616 + pax_force_retaddr
13617 ret;
13618 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13619
13620 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13621 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13622 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13623 %rax, (%r9));
13624 + pax_force_retaddr
13625 ret;
13626 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13627
13628 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13629 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13630 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13631
13632 + pax_force_retaddr
13633 ret;
13634
13635 .align 8
13636 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13637 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13638 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13639
13640 + pax_force_retaddr
13641 ret;
13642
13643 .align 8
13644 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13645
13646 vzeroupper;
13647
13648 + pax_force_retaddr
13649 ret;
13650 ENDPROC(camellia_ecb_enc_32way)
13651
13652 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13653
13654 vzeroupper;
13655
13656 + pax_force_retaddr
13657 ret;
13658 ENDPROC(camellia_ecb_dec_32way)
13659
13660 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13661
13662 vzeroupper;
13663
13664 + pax_force_retaddr
13665 ret;
13666 ENDPROC(camellia_cbc_dec_32way)
13667
13668 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13669
13670 vzeroupper;
13671
13672 + pax_force_retaddr
13673 ret;
13674 ENDPROC(camellia_ctr_32way)
13675
13676 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13677
13678 vzeroupper;
13679
13680 + pax_force_retaddr
13681 ret;
13682 ENDPROC(camellia_xts_crypt_32way)
13683
13684 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13685 index 310319c..db3d7b5 100644
13686 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13687 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688 @@ -21,6 +21,7 @@
13689 */
13690
13691 #include <linux/linkage.h>
13692 +#include <asm/alternative-asm.h>
13693
13694 .file "camellia-x86_64-asm_64.S"
13695 .text
13696 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13697 enc_outunpack(mov, RT1);
13698
13699 movq RRBP, %rbp;
13700 + pax_force_retaddr
13701 ret;
13702
13703 .L__enc_xor:
13704 enc_outunpack(xor, RT1);
13705
13706 movq RRBP, %rbp;
13707 + pax_force_retaddr
13708 ret;
13709 ENDPROC(__camellia_enc_blk)
13710
13711 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13712 dec_outunpack();
13713
13714 movq RRBP, %rbp;
13715 + pax_force_retaddr
13716 ret;
13717 ENDPROC(camellia_dec_blk)
13718
13719 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13720
13721 movq RRBP, %rbp;
13722 popq %rbx;
13723 + pax_force_retaddr
13724 ret;
13725
13726 .L__enc2_xor:
13727 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13728
13729 movq RRBP, %rbp;
13730 popq %rbx;
13731 + pax_force_retaddr
13732 ret;
13733 ENDPROC(__camellia_enc_blk_2way)
13734
13735 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13736
13737 movq RRBP, %rbp;
13738 movq RXOR, %rbx;
13739 + pax_force_retaddr
13740 ret;
13741 ENDPROC(camellia_dec_blk_2way)
13742 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13743 index c35fd5d..2d8c7db 100644
13744 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13745 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746 @@ -24,6 +24,7 @@
13747 */
13748
13749 #include <linux/linkage.h>
13750 +#include <asm/alternative-asm.h>
13751
13752 .file "cast5-avx-x86_64-asm_64.S"
13753
13754 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13755 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13756 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13757
13758 + pax_force_retaddr
13759 ret;
13760 ENDPROC(__cast5_enc_blk16)
13761
13762 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13763 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13764 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13765
13766 + pax_force_retaddr
13767 ret;
13768
13769 .L__skip_dec:
13770 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13771 vmovdqu RR4, (6*4*4)(%r11);
13772 vmovdqu RL4, (7*4*4)(%r11);
13773
13774 + pax_force_retaddr
13775 ret;
13776 ENDPROC(cast5_ecb_enc_16way)
13777
13778 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13779 vmovdqu RR4, (6*4*4)(%r11);
13780 vmovdqu RL4, (7*4*4)(%r11);
13781
13782 + pax_force_retaddr
13783 ret;
13784 ENDPROC(cast5_ecb_dec_16way)
13785
13786 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13787 * %rdx: src
13788 */
13789
13790 - pushq %r12;
13791 + pushq %r14;
13792
13793 movq %rsi, %r11;
13794 - movq %rdx, %r12;
13795 + movq %rdx, %r14;
13796
13797 vmovdqu (0*16)(%rdx), RL1;
13798 vmovdqu (1*16)(%rdx), RR1;
13799 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13800 call __cast5_dec_blk16;
13801
13802 /* xor with src */
13803 - vmovq (%r12), RX;
13804 + vmovq (%r14), RX;
13805 vpshufd $0x4f, RX, RX;
13806 vpxor RX, RR1, RR1;
13807 - vpxor 0*16+8(%r12), RL1, RL1;
13808 - vpxor 1*16+8(%r12), RR2, RR2;
13809 - vpxor 2*16+8(%r12), RL2, RL2;
13810 - vpxor 3*16+8(%r12), RR3, RR3;
13811 - vpxor 4*16+8(%r12), RL3, RL3;
13812 - vpxor 5*16+8(%r12), RR4, RR4;
13813 - vpxor 6*16+8(%r12), RL4, RL4;
13814 + vpxor 0*16+8(%r14), RL1, RL1;
13815 + vpxor 1*16+8(%r14), RR2, RR2;
13816 + vpxor 2*16+8(%r14), RL2, RL2;
13817 + vpxor 3*16+8(%r14), RR3, RR3;
13818 + vpxor 4*16+8(%r14), RL3, RL3;
13819 + vpxor 5*16+8(%r14), RR4, RR4;
13820 + vpxor 6*16+8(%r14), RL4, RL4;
13821
13822 vmovdqu RR1, (0*16)(%r11);
13823 vmovdqu RL1, (1*16)(%r11);
13824 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13825 vmovdqu RR4, (6*16)(%r11);
13826 vmovdqu RL4, (7*16)(%r11);
13827
13828 - popq %r12;
13829 + popq %r14;
13830
13831 + pax_force_retaddr
13832 ret;
13833 ENDPROC(cast5_cbc_dec_16way)
13834
13835 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13836 * %rcx: iv (big endian, 64bit)
13837 */
13838
13839 - pushq %r12;
13840 + pushq %r14;
13841
13842 movq %rsi, %r11;
13843 - movq %rdx, %r12;
13844 + movq %rdx, %r14;
13845
13846 vpcmpeqd RTMP, RTMP, RTMP;
13847 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13848 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13849 call __cast5_enc_blk16;
13850
13851 /* dst = src ^ iv */
13852 - vpxor (0*16)(%r12), RR1, RR1;
13853 - vpxor (1*16)(%r12), RL1, RL1;
13854 - vpxor (2*16)(%r12), RR2, RR2;
13855 - vpxor (3*16)(%r12), RL2, RL2;
13856 - vpxor (4*16)(%r12), RR3, RR3;
13857 - vpxor (5*16)(%r12), RL3, RL3;
13858 - vpxor (6*16)(%r12), RR4, RR4;
13859 - vpxor (7*16)(%r12), RL4, RL4;
13860 + vpxor (0*16)(%r14), RR1, RR1;
13861 + vpxor (1*16)(%r14), RL1, RL1;
13862 + vpxor (2*16)(%r14), RR2, RR2;
13863 + vpxor (3*16)(%r14), RL2, RL2;
13864 + vpxor (4*16)(%r14), RR3, RR3;
13865 + vpxor (5*16)(%r14), RL3, RL3;
13866 + vpxor (6*16)(%r14), RR4, RR4;
13867 + vpxor (7*16)(%r14), RL4, RL4;
13868 vmovdqu RR1, (0*16)(%r11);
13869 vmovdqu RL1, (1*16)(%r11);
13870 vmovdqu RR2, (2*16)(%r11);
13871 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13872 vmovdqu RR4, (6*16)(%r11);
13873 vmovdqu RL4, (7*16)(%r11);
13874
13875 - popq %r12;
13876 + popq %r14;
13877
13878 + pax_force_retaddr
13879 ret;
13880 ENDPROC(cast5_ctr_16way)
13881 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13882 index e3531f8..e123f35 100644
13883 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13884 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885 @@ -24,6 +24,7 @@
13886 */
13887
13888 #include <linux/linkage.h>
13889 +#include <asm/alternative-asm.h>
13890 #include "glue_helper-asm-avx.S"
13891
13892 .file "cast6-avx-x86_64-asm_64.S"
13893 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13894 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13895 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13896
13897 + pax_force_retaddr
13898 ret;
13899 ENDPROC(__cast6_enc_blk8)
13900
13901 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13902 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13903 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13904
13905 + pax_force_retaddr
13906 ret;
13907 ENDPROC(__cast6_dec_blk8)
13908
13909 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13910
13911 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13912
13913 + pax_force_retaddr
13914 ret;
13915 ENDPROC(cast6_ecb_enc_8way)
13916
13917 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13918
13919 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13920
13921 + pax_force_retaddr
13922 ret;
13923 ENDPROC(cast6_ecb_dec_8way)
13924
13925 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13926 * %rdx: src
13927 */
13928
13929 - pushq %r12;
13930 + pushq %r14;
13931
13932 movq %rsi, %r11;
13933 - movq %rdx, %r12;
13934 + movq %rdx, %r14;
13935
13936 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13937
13938 call __cast6_dec_blk8;
13939
13940 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13941 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942
13943 - popq %r12;
13944 + popq %r14;
13945
13946 + pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_cbc_dec_8way)
13949
13950 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13951 * %rcx: iv (little endian, 128bit)
13952 */
13953
13954 - pushq %r12;
13955 + pushq %r14;
13956
13957 movq %rsi, %r11;
13958 - movq %rdx, %r12;
13959 + movq %rdx, %r14;
13960
13961 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13962 RD2, RX, RKR, RKM);
13963
13964 call __cast6_enc_blk8;
13965
13966 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13967 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968
13969 - popq %r12;
13970 + popq %r14;
13971
13972 + pax_force_retaddr
13973 ret;
13974 ENDPROC(cast6_ctr_8way)
13975
13976 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13977 /* dst <= regs xor IVs(in dst) */
13978 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13979
13980 + pax_force_retaddr
13981 ret;
13982 ENDPROC(cast6_xts_enc_8way)
13983
13984 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13985 /* dst <= regs xor IVs(in dst) */
13986 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13987
13988 + pax_force_retaddr
13989 ret;
13990 ENDPROC(cast6_xts_dec_8way)
13991 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13992 index 26d49eb..c0a8c84 100644
13993 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13994 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995 @@ -45,6 +45,7 @@
13996
13997 #include <asm/inst.h>
13998 #include <linux/linkage.h>
13999 +#include <asm/alternative-asm.h>
14000
14001 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14002
14003 @@ -309,6 +310,7 @@ do_return:
14004 popq %rsi
14005 popq %rdi
14006 popq %rbx
14007 + pax_force_retaddr
14008 ret
14009
14010 ################################################################
14011 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14012 index 5d1e007..098cb4f 100644
14013 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14014 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015 @@ -18,6 +18,7 @@
14016
14017 #include <linux/linkage.h>
14018 #include <asm/inst.h>
14019 +#include <asm/alternative-asm.h>
14020
14021 .data
14022
14023 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14024 psrlq $1, T2
14025 pxor T2, T1
14026 pxor T1, DATA
14027 + pax_force_retaddr
14028 ret
14029 ENDPROC(__clmul_gf128mul_ble)
14030
14031 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14032 call __clmul_gf128mul_ble
14033 PSHUFB_XMM BSWAP DATA
14034 movups DATA, (%rdi)
14035 + pax_force_retaddr
14036 ret
14037 ENDPROC(clmul_ghash_mul)
14038
14039 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14040 PSHUFB_XMM BSWAP DATA
14041 movups DATA, (%rdi)
14042 .Lupdate_just_ret:
14043 + pax_force_retaddr
14044 ret
14045 ENDPROC(clmul_ghash_update)
14046 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14047 index 9279e0b..c4b3d2c 100644
14048 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14049 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050 @@ -1,4 +1,5 @@
14051 #include <linux/linkage.h>
14052 +#include <asm/alternative-asm.h>
14053
14054 # enter salsa20_encrypt_bytes
14055 ENTRY(salsa20_encrypt_bytes)
14056 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14057 add %r11,%rsp
14058 mov %rdi,%rax
14059 mov %rsi,%rdx
14060 + pax_force_retaddr
14061 ret
14062 # bytesatleast65:
14063 ._bytesatleast65:
14064 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14065 add %r11,%rsp
14066 mov %rdi,%rax
14067 mov %rsi,%rdx
14068 + pax_force_retaddr
14069 ret
14070 ENDPROC(salsa20_keysetup)
14071
14072 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14073 add %r11,%rsp
14074 mov %rdi,%rax
14075 mov %rsi,%rdx
14076 + pax_force_retaddr
14077 ret
14078 ENDPROC(salsa20_ivsetup)
14079 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14080 index 2f202f4..d9164d6 100644
14081 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14082 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083 @@ -24,6 +24,7 @@
14084 */
14085
14086 #include <linux/linkage.h>
14087 +#include <asm/alternative-asm.h>
14088 #include "glue_helper-asm-avx.S"
14089
14090 .file "serpent-avx-x86_64-asm_64.S"
14091 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14092 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14093 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14094
14095 + pax_force_retaddr
14096 ret;
14097 ENDPROC(__serpent_enc_blk8_avx)
14098
14099 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14100 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14101 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14102
14103 + pax_force_retaddr
14104 ret;
14105 ENDPROC(__serpent_dec_blk8_avx)
14106
14107 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14108
14109 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14110
14111 + pax_force_retaddr
14112 ret;
14113 ENDPROC(serpent_ecb_enc_8way_avx)
14114
14115 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14116
14117 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14118
14119 + pax_force_retaddr
14120 ret;
14121 ENDPROC(serpent_ecb_dec_8way_avx)
14122
14123 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14124
14125 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14126
14127 + pax_force_retaddr
14128 ret;
14129 ENDPROC(serpent_cbc_dec_8way_avx)
14130
14131 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14132
14133 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14134
14135 + pax_force_retaddr
14136 ret;
14137 ENDPROC(serpent_ctr_8way_avx)
14138
14139 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14140 /* dst <= regs xor IVs(in dst) */
14141 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142
14143 + pax_force_retaddr
14144 ret;
14145 ENDPROC(serpent_xts_enc_8way_avx)
14146
14147 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14150
14151 + pax_force_retaddr
14152 ret;
14153 ENDPROC(serpent_xts_dec_8way_avx)
14154 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14155 index b222085..abd483c 100644
14156 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14157 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14158 @@ -15,6 +15,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162 +#include <asm/alternative-asm.h>
14163 #include "glue_helper-asm-avx2.S"
14164
14165 .file "serpent-avx2-asm_64.S"
14166 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14167 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14168 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14169
14170 + pax_force_retaddr
14171 ret;
14172 ENDPROC(__serpent_enc_blk16)
14173
14174 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14175 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14176 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14177
14178 + pax_force_retaddr
14179 ret;
14180 ENDPROC(__serpent_dec_blk16)
14181
14182 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14183
14184 vzeroupper;
14185
14186 + pax_force_retaddr
14187 ret;
14188 ENDPROC(serpent_ecb_enc_16way)
14189
14190 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14191
14192 vzeroupper;
14193
14194 + pax_force_retaddr
14195 ret;
14196 ENDPROC(serpent_ecb_dec_16way)
14197
14198 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14199
14200 vzeroupper;
14201
14202 + pax_force_retaddr
14203 ret;
14204 ENDPROC(serpent_cbc_dec_16way)
14205
14206 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14207
14208 vzeroupper;
14209
14210 + pax_force_retaddr
14211 ret;
14212 ENDPROC(serpent_ctr_16way)
14213
14214 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14215
14216 vzeroupper;
14217
14218 + pax_force_retaddr
14219 ret;
14220 ENDPROC(serpent_xts_enc_16way)
14221
14222 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14223
14224 vzeroupper;
14225
14226 + pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_xts_dec_16way)
14229 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14230 index acc066c..1559cc4 100644
14231 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14232 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233 @@ -25,6 +25,7 @@
14234 */
14235
14236 #include <linux/linkage.h>
14237 +#include <asm/alternative-asm.h>
14238
14239 .file "serpent-sse2-x86_64-asm_64.S"
14240 .text
14241 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14242 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14243 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14244
14245 + pax_force_retaddr
14246 ret;
14247
14248 .L__enc_xor8:
14249 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14250 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14251
14252 + pax_force_retaddr
14253 ret;
14254 ENDPROC(__serpent_enc_blk_8way)
14255
14256 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14257 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14258 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14259
14260 + pax_force_retaddr
14261 ret;
14262 ENDPROC(serpent_dec_blk_8way)
14263 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14264 index a410950..9dfe7ad 100644
14265 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14266 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14267 @@ -29,6 +29,7 @@
14268 */
14269
14270 #include <linux/linkage.h>
14271 +#include <asm/alternative-asm.h>
14272
14273 #define CTX %rdi // arg1
14274 #define BUF %rsi // arg2
14275 @@ -75,9 +76,9 @@
14276
14277 push %rbx
14278 push %rbp
14279 - push %r12
14280 + push %r14
14281
14282 - mov %rsp, %r12
14283 + mov %rsp, %r14
14284 sub $64, %rsp # allocate workspace
14285 and $~15, %rsp # align stack
14286
14287 @@ -99,11 +100,12 @@
14288 xor %rax, %rax
14289 rep stosq
14290
14291 - mov %r12, %rsp # deallocate workspace
14292 + mov %r14, %rsp # deallocate workspace
14293
14294 - pop %r12
14295 + pop %r14
14296 pop %rbp
14297 pop %rbx
14298 + pax_force_retaddr
14299 ret
14300
14301 ENDPROC(\name)
14302 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14303 index 642f156..51a513c 100644
14304 --- a/arch/x86/crypto/sha256-avx-asm.S
14305 +++ b/arch/x86/crypto/sha256-avx-asm.S
14306 @@ -49,6 +49,7 @@
14307
14308 #ifdef CONFIG_AS_AVX
14309 #include <linux/linkage.h>
14310 +#include <asm/alternative-asm.h>
14311
14312 ## assume buffers not aligned
14313 #define VMOVDQ vmovdqu
14314 @@ -460,6 +461,7 @@ done_hash:
14315 popq %r13
14316 popq %rbp
14317 popq %rbx
14318 + pax_force_retaddr
14319 ret
14320 ENDPROC(sha256_transform_avx)
14321
14322 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14323 index 9e86944..3795e6a 100644
14324 --- a/arch/x86/crypto/sha256-avx2-asm.S
14325 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14326 @@ -50,6 +50,7 @@
14327
14328 #ifdef CONFIG_AS_AVX2
14329 #include <linux/linkage.h>
14330 +#include <asm/alternative-asm.h>
14331
14332 ## assume buffers not aligned
14333 #define VMOVDQ vmovdqu
14334 @@ -720,6 +721,7 @@ done_hash:
14335 popq %r12
14336 popq %rbp
14337 popq %rbx
14338 + pax_force_retaddr
14339 ret
14340 ENDPROC(sha256_transform_rorx)
14341
14342 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14343 index f833b74..8c62a9e 100644
14344 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14345 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14346 @@ -47,6 +47,7 @@
14347 ########################################################################
14348
14349 #include <linux/linkage.h>
14350 +#include <asm/alternative-asm.h>
14351
14352 ## assume buffers not aligned
14353 #define MOVDQ movdqu
14354 @@ -471,6 +472,7 @@ done_hash:
14355 popq %rbp
14356 popq %rbx
14357
14358 + pax_force_retaddr
14359 ret
14360 ENDPROC(sha256_transform_ssse3)
14361
14362 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14363 index 974dde9..a823ff9 100644
14364 --- a/arch/x86/crypto/sha512-avx-asm.S
14365 +++ b/arch/x86/crypto/sha512-avx-asm.S
14366 @@ -49,6 +49,7 @@
14367
14368 #ifdef CONFIG_AS_AVX
14369 #include <linux/linkage.h>
14370 +#include <asm/alternative-asm.h>
14371
14372 .text
14373
14374 @@ -364,6 +365,7 @@ updateblock:
14375 mov frame_RSPSAVE(%rsp), %rsp
14376
14377 nowork:
14378 + pax_force_retaddr
14379 ret
14380 ENDPROC(sha512_transform_avx)
14381
14382 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14383 index 568b961..ed20c37 100644
14384 --- a/arch/x86/crypto/sha512-avx2-asm.S
14385 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14386 @@ -51,6 +51,7 @@
14387
14388 #ifdef CONFIG_AS_AVX2
14389 #include <linux/linkage.h>
14390 +#include <asm/alternative-asm.h>
14391
14392 .text
14393
14394 @@ -678,6 +679,7 @@ done_hash:
14395
14396 # Restore Stack Pointer
14397 mov frame_RSPSAVE(%rsp), %rsp
14398 + pax_force_retaddr
14399 ret
14400 ENDPROC(sha512_transform_rorx)
14401
14402 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14403 index fb56855..6edd768 100644
14404 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14405 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14406 @@ -48,6 +48,7 @@
14407 ########################################################################
14408
14409 #include <linux/linkage.h>
14410 +#include <asm/alternative-asm.h>
14411
14412 .text
14413
14414 @@ -363,6 +364,7 @@ updateblock:
14415 mov frame_RSPSAVE(%rsp), %rsp
14416
14417 nowork:
14418 + pax_force_retaddr
14419 ret
14420 ENDPROC(sha512_transform_ssse3)
14421
14422 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14423 index 0505813..b067311 100644
14424 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14425 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426 @@ -24,6 +24,7 @@
14427 */
14428
14429 #include <linux/linkage.h>
14430 +#include <asm/alternative-asm.h>
14431 #include "glue_helper-asm-avx.S"
14432
14433 .file "twofish-avx-x86_64-asm_64.S"
14434 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14435 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14436 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14437
14438 + pax_force_retaddr
14439 ret;
14440 ENDPROC(__twofish_enc_blk8)
14441
14442 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14443 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14444 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14445
14446 + pax_force_retaddr
14447 ret;
14448 ENDPROC(__twofish_dec_blk8)
14449
14450 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14451
14452 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14453
14454 + pax_force_retaddr
14455 ret;
14456 ENDPROC(twofish_ecb_enc_8way)
14457
14458 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14459
14460 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14461
14462 + pax_force_retaddr
14463 ret;
14464 ENDPROC(twofish_ecb_dec_8way)
14465
14466 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14467 * %rdx: src
14468 */
14469
14470 - pushq %r12;
14471 + pushq %r14;
14472
14473 movq %rsi, %r11;
14474 - movq %rdx, %r12;
14475 + movq %rdx, %r14;
14476
14477 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14478
14479 call __twofish_dec_blk8;
14480
14481 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14482 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483
14484 - popq %r12;
14485 + popq %r14;
14486
14487 + pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_cbc_dec_8way)
14490
14491 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14492 * %rcx: iv (little endian, 128bit)
14493 */
14494
14495 - pushq %r12;
14496 + pushq %r14;
14497
14498 movq %rsi, %r11;
14499 - movq %rdx, %r12;
14500 + movq %rdx, %r14;
14501
14502 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14503 RD2, RX0, RX1, RY0);
14504
14505 call __twofish_enc_blk8;
14506
14507 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14508 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14509
14510 - popq %r12;
14511 + popq %r14;
14512
14513 + pax_force_retaddr
14514 ret;
14515 ENDPROC(twofish_ctr_8way)
14516
14517 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14518 /* dst <= regs xor IVs(in dst) */
14519 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14520
14521 + pax_force_retaddr
14522 ret;
14523 ENDPROC(twofish_xts_enc_8way)
14524
14525 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14526 /* dst <= regs xor IVs(in dst) */
14527 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14528
14529 + pax_force_retaddr
14530 ret;
14531 ENDPROC(twofish_xts_dec_8way)
14532 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14533 index 1c3b7ce..02f578d 100644
14534 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14535 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536 @@ -21,6 +21,7 @@
14537 */
14538
14539 #include <linux/linkage.h>
14540 +#include <asm/alternative-asm.h>
14541
14542 .file "twofish-x86_64-asm-3way.S"
14543 .text
14544 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14545 popq %r13;
14546 popq %r14;
14547 popq %r15;
14548 + pax_force_retaddr
14549 ret;
14550
14551 .L__enc_xor3:
14552 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14553 popq %r13;
14554 popq %r14;
14555 popq %r15;
14556 + pax_force_retaddr
14557 ret;
14558 ENDPROC(__twofish_enc_blk_3way)
14559
14560 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14561 popq %r13;
14562 popq %r14;
14563 popq %r15;
14564 + pax_force_retaddr
14565 ret;
14566 ENDPROC(twofish_dec_blk_3way)
14567 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14568 index a039d21..524b8b2 100644
14569 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14570 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571 @@ -22,6 +22,7 @@
14572
14573 #include <linux/linkage.h>
14574 #include <asm/asm-offsets.h>
14575 +#include <asm/alternative-asm.h>
14576
14577 #define a_offset 0
14578 #define b_offset 4
14579 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14580
14581 popq R1
14582 movq $1,%rax
14583 + pax_force_retaddr
14584 ret
14585 ENDPROC(twofish_enc_blk)
14586
14587 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14588
14589 popq R1
14590 movq $1,%rax
14591 + pax_force_retaddr
14592 ret
14593 ENDPROC(twofish_dec_blk)
14594 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14595 index df91466..74b31cb 100644
14596 --- a/arch/x86/ia32/ia32_aout.c
14597 +++ b/arch/x86/ia32/ia32_aout.c
14598 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14599 unsigned long dump_start, dump_size;
14600 struct user32 dump;
14601
14602 + memset(&dump, 0, sizeof(dump));
14603 +
14604 fs = get_fs();
14605 set_fs(KERNEL_DS);
14606 has_dumped = 1;
14607 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14608 index f9e181a..300544c 100644
14609 --- a/arch/x86/ia32/ia32_signal.c
14610 +++ b/arch/x86/ia32/ia32_signal.c
14611 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14612 if (__get_user(set.sig[0], &frame->sc.oldmask)
14613 || (_COMPAT_NSIG_WORDS > 1
14614 && __copy_from_user((((char *) &set.sig) + 4),
14615 - &frame->extramask,
14616 + frame->extramask,
14617 sizeof(frame->extramask))))
14618 goto badframe;
14619
14620 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14621 sp -= frame_size;
14622 /* Align the stack pointer according to the i386 ABI,
14623 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14624 - sp = ((sp + 4) & -16ul) - 4;
14625 + sp = ((sp - 12) & -16ul) - 4;
14626 return (void __user *) sp;
14627 }
14628
14629 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14630 } else {
14631 /* Return stub is in 32bit vsyscall page */
14632 if (current->mm->context.vdso)
14633 - restorer = current->mm->context.vdso +
14634 - selected_vdso32->sym___kernel_sigreturn;
14635 + restorer = (void __force_user *)(current->mm->context.vdso +
14636 + selected_vdso32->sym___kernel_sigreturn);
14637 else
14638 - restorer = &frame->retcode;
14639 + restorer = frame->retcode;
14640 }
14641
14642 put_user_try {
14643 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14644 * These are actually not used anymore, but left because some
14645 * gdb versions depend on them as a marker.
14646 */
14647 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14648 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14649 } put_user_catch(err);
14650
14651 if (err)
14652 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14653 0xb8,
14654 __NR_ia32_rt_sigreturn,
14655 0x80cd,
14656 - 0,
14657 + 0
14658 };
14659
14660 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14661 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14662
14663 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14664 restorer = ksig->ka.sa.sa_restorer;
14665 + else if (current->mm->context.vdso)
14666 + /* Return stub is in 32bit vsyscall page */
14667 + restorer = (void __force_user *)(current->mm->context.vdso +
14668 + selected_vdso32->sym___kernel_rt_sigreturn);
14669 else
14670 - restorer = current->mm->context.vdso +
14671 - selected_vdso32->sym___kernel_rt_sigreturn;
14672 + restorer = frame->retcode;
14673 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14674
14675 /*
14676 * Not actually used anymore, but left because some gdb
14677 * versions need it.
14678 */
14679 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14680 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14681 } put_user_catch(err);
14682
14683 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14684 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14685 index ffe7122..899bad3 100644
14686 --- a/arch/x86/ia32/ia32entry.S
14687 +++ b/arch/x86/ia32/ia32entry.S
14688 @@ -15,8 +15,10 @@
14689 #include <asm/irqflags.h>
14690 #include <asm/asm.h>
14691 #include <asm/smap.h>
14692 +#include <asm/pgtable.h>
14693 #include <linux/linkage.h>
14694 #include <linux/err.h>
14695 +#include <asm/alternative-asm.h>
14696
14697 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14698 #include <linux/elf-em.h>
14699 @@ -62,12 +64,12 @@
14700 */
14701 .macro LOAD_ARGS32 offset, _r9=0
14702 .if \_r9
14703 - movl \offset+16(%rsp),%r9d
14704 + movl \offset+R9(%rsp),%r9d
14705 .endif
14706 - movl \offset+40(%rsp),%ecx
14707 - movl \offset+48(%rsp),%edx
14708 - movl \offset+56(%rsp),%esi
14709 - movl \offset+64(%rsp),%edi
14710 + movl \offset+RCX(%rsp),%ecx
14711 + movl \offset+RDX(%rsp),%edx
14712 + movl \offset+RSI(%rsp),%esi
14713 + movl \offset+RDI(%rsp),%edi
14714 movl %eax,%eax /* zero extension */
14715 .endm
14716
14717 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14718 ENDPROC(native_irq_enable_sysexit)
14719 #endif
14720
14721 + .macro pax_enter_kernel_user
14722 + pax_set_fptr_mask
14723 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14724 + call pax_enter_kernel_user
14725 +#endif
14726 + .endm
14727 +
14728 + .macro pax_exit_kernel_user
14729 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14730 + call pax_exit_kernel_user
14731 +#endif
14732 +#ifdef CONFIG_PAX_RANDKSTACK
14733 + pushq %rax
14734 + pushq %r11
14735 + call pax_randomize_kstack
14736 + popq %r11
14737 + popq %rax
14738 +#endif
14739 + .endm
14740 +
14741 + .macro pax_erase_kstack
14742 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14743 + call pax_erase_kstack
14744 +#endif
14745 + .endm
14746 +
14747 /*
14748 * 32bit SYSENTER instruction entry.
14749 *
14750 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14751 CFI_REGISTER rsp,rbp
14752 SWAPGS_UNSAFE_STACK
14753 movq PER_CPU_VAR(kernel_stack), %rsp
14754 - addq $(KERNEL_STACK_OFFSET),%rsp
14755 - /*
14756 - * No need to follow this irqs on/off section: the syscall
14757 - * disabled irqs, here we enable it straight after entry:
14758 - */
14759 - ENABLE_INTERRUPTS(CLBR_NONE)
14760 movl %ebp,%ebp /* zero extension */
14761 pushq_cfi $__USER32_DS
14762 /*CFI_REL_OFFSET ss,0*/
14763 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14764 CFI_REL_OFFSET rsp,0
14765 pushfq_cfi
14766 /*CFI_REL_OFFSET rflags,0*/
14767 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14768 - CFI_REGISTER rip,r10
14769 + orl $X86_EFLAGS_IF,(%rsp)
14770 + GET_THREAD_INFO(%r11)
14771 + movl TI_sysenter_return(%r11), %r11d
14772 + CFI_REGISTER rip,r11
14773 pushq_cfi $__USER32_CS
14774 /*CFI_REL_OFFSET cs,0*/
14775 movl %eax, %eax
14776 - pushq_cfi %r10
14777 + pushq_cfi %r11
14778 CFI_REL_OFFSET rip,0
14779 pushq_cfi %rax
14780 cld
14781 SAVE_ARGS 0,1,0
14782 + pax_enter_kernel_user
14783 +
14784 +#ifdef CONFIG_PAX_RANDKSTACK
14785 + pax_erase_kstack
14786 +#endif
14787 +
14788 + /*
14789 + * No need to follow this irqs on/off section: the syscall
14790 + * disabled irqs, here we enable it straight after entry:
14791 + */
14792 + ENABLE_INTERRUPTS(CLBR_NONE)
14793 /* no need to do an access_ok check here because rbp has been
14794 32bit zero extended */
14795 +
14796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14797 + addq pax_user_shadow_base,%rbp
14798 + ASM_PAX_OPEN_USERLAND
14799 +#endif
14800 +
14801 ASM_STAC
14802 1: movl (%rbp),%ebp
14803 _ASM_EXTABLE(1b,ia32_badarg)
14804 ASM_CLAC
14805
14806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14807 + ASM_PAX_CLOSE_USERLAND
14808 +#endif
14809 +
14810 /*
14811 * Sysenter doesn't filter flags, so we need to clear NT
14812 * ourselves. To save a few cycles, we can check whether
14813 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14814 jnz sysenter_fix_flags
14815 sysenter_flags_fixed:
14816
14817 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14818 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14819 + GET_THREAD_INFO(%r11)
14820 + orl $TS_COMPAT,TI_status(%r11)
14821 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14822 CFI_REMEMBER_STATE
14823 jnz sysenter_tracesys
14824 cmpq $(IA32_NR_syscalls-1),%rax
14825 @@ -172,15 +218,18 @@ sysenter_do_call:
14826 sysenter_dispatch:
14827 call *ia32_sys_call_table(,%rax,8)
14828 movq %rax,RAX-ARGOFFSET(%rsp)
14829 + GET_THREAD_INFO(%r11)
14830 DISABLE_INTERRUPTS(CLBR_NONE)
14831 TRACE_IRQS_OFF
14832 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14833 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14834 jnz sysexit_audit
14835 sysexit_from_sys_call:
14836 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14837 + pax_exit_kernel_user
14838 + pax_erase_kstack
14839 + andl $~TS_COMPAT,TI_status(%r11)
14840 /* clear IF, that popfq doesn't enable interrupts early */
14841 - andl $~0x200,EFLAGS-R11(%rsp)
14842 - movl RIP-R11(%rsp),%edx /* User %eip */
14843 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14844 + movl RIP(%rsp),%edx /* User %eip */
14845 CFI_REGISTER rip,rdx
14846 RESTORE_ARGS 0,24,0,0,0,0
14847 xorq %r8,%r8
14848 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
14849 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14850 movl %eax,%edi /* 1st arg: syscall number */
14851 call __audit_syscall_entry
14852 +
14853 + pax_erase_kstack
14854 +
14855 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14856 cmpq $(IA32_NR_syscalls-1),%rax
14857 ja ia32_badsys
14858 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
14859 .endm
14860
14861 .macro auditsys_exit exit
14862 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14863 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14864 jnz ia32_ret_from_sys_call
14865 TRACE_IRQS_ON
14866 ENABLE_INTERRUPTS(CLBR_NONE)
14867 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
14868 1: setbe %al /* 1 if error, 0 if not */
14869 movzbl %al,%edi /* zero-extend that into %edi */
14870 call __audit_syscall_exit
14871 + GET_THREAD_INFO(%r11)
14872 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14873 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14874 DISABLE_INTERRUPTS(CLBR_NONE)
14875 TRACE_IRQS_OFF
14876 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14877 + testl %edi,TI_flags(%r11)
14878 jz \exit
14879 CLEAR_RREGS -ARGOFFSET
14880 jmp int_with_check
14881 @@ -253,7 +306,7 @@ sysenter_fix_flags:
14882
14883 sysenter_tracesys:
14884 #ifdef CONFIG_AUDITSYSCALL
14885 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14886 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14887 jz sysenter_auditsys
14888 #endif
14889 SAVE_REST
14890 @@ -265,6 +318,9 @@ sysenter_tracesys:
14891 RESTORE_REST
14892 cmpq $(IA32_NR_syscalls-1),%rax
14893 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14894 +
14895 + pax_erase_kstack
14896 +
14897 jmp sysenter_do_call
14898 CFI_ENDPROC
14899 ENDPROC(ia32_sysenter_target)
14900 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14901 ENTRY(ia32_cstar_target)
14902 CFI_STARTPROC32 simple
14903 CFI_SIGNAL_FRAME
14904 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14905 + CFI_DEF_CFA rsp,0
14906 CFI_REGISTER rip,rcx
14907 /*CFI_REGISTER rflags,r11*/
14908 SWAPGS_UNSAFE_STACK
14909 movl %esp,%r8d
14910 CFI_REGISTER rsp,r8
14911 movq PER_CPU_VAR(kernel_stack),%rsp
14912 + SAVE_ARGS 8*6,0,0
14913 + pax_enter_kernel_user
14914 +
14915 +#ifdef CONFIG_PAX_RANDKSTACK
14916 + pax_erase_kstack
14917 +#endif
14918 +
14919 /*
14920 * No need to follow this irqs on/off section: the syscall
14921 * disabled irqs and here we enable it straight after entry:
14922 */
14923 ENABLE_INTERRUPTS(CLBR_NONE)
14924 - SAVE_ARGS 8,0,0
14925 movl %eax,%eax /* zero extension */
14926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14927 movq %rcx,RIP-ARGOFFSET(%rsp)
14928 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14929 /* no need to do an access_ok check here because r8 has been
14930 32bit zero extended */
14931 /* hardware stack frame is complete now */
14932 +
14933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14934 + ASM_PAX_OPEN_USERLAND
14935 + movq pax_user_shadow_base,%r8
14936 + addq RSP-ARGOFFSET(%rsp),%r8
14937 +#endif
14938 +
14939 ASM_STAC
14940 1: movl (%r8),%r9d
14941 _ASM_EXTABLE(1b,ia32_badarg)
14942 ASM_CLAC
14943 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14944 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14945 +
14946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14947 + ASM_PAX_CLOSE_USERLAND
14948 +#endif
14949 +
14950 + GET_THREAD_INFO(%r11)
14951 + orl $TS_COMPAT,TI_status(%r11)
14952 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14953 CFI_REMEMBER_STATE
14954 jnz cstar_tracesys
14955 cmpq $IA32_NR_syscalls-1,%rax
14956 @@ -335,13 +410,16 @@ cstar_do_call:
14957 cstar_dispatch:
14958 call *ia32_sys_call_table(,%rax,8)
14959 movq %rax,RAX-ARGOFFSET(%rsp)
14960 + GET_THREAD_INFO(%r11)
14961 DISABLE_INTERRUPTS(CLBR_NONE)
14962 TRACE_IRQS_OFF
14963 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14964 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14965 jnz sysretl_audit
14966 sysretl_from_sys_call:
14967 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14968 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14969 + pax_exit_kernel_user
14970 + pax_erase_kstack
14971 + andl $~TS_COMPAT,TI_status(%r11)
14972 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14973 movl RIP-ARGOFFSET(%rsp),%ecx
14974 CFI_REGISTER rip,rcx
14975 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14976 @@ -368,7 +446,7 @@ sysretl_audit:
14977
14978 cstar_tracesys:
14979 #ifdef CONFIG_AUDITSYSCALL
14980 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14981 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14982 jz cstar_auditsys
14983 #endif
14984 xchgl %r9d,%ebp
14985 @@ -382,11 +460,19 @@ cstar_tracesys:
14986 xchgl %ebp,%r9d
14987 cmpq $(IA32_NR_syscalls-1),%rax
14988 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14989 +
14990 + pax_erase_kstack
14991 +
14992 jmp cstar_do_call
14993 END(ia32_cstar_target)
14994
14995 ia32_badarg:
14996 ASM_CLAC
14997 +
14998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14999 + ASM_PAX_CLOSE_USERLAND
15000 +#endif
15001 +
15002 movq $-EFAULT,%rax
15003 jmp ia32_sysret
15004 CFI_ENDPROC
15005 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15006 CFI_REL_OFFSET rip,RIP-RIP
15007 PARAVIRT_ADJUST_EXCEPTION_FRAME
15008 SWAPGS
15009 - /*
15010 - * No need to follow this irqs on/off section: the syscall
15011 - * disabled irqs and here we enable it straight after entry:
15012 - */
15013 - ENABLE_INTERRUPTS(CLBR_NONE)
15014 movl %eax,%eax
15015 pushq_cfi %rax
15016 cld
15017 /* note the registers are not zero extended to the sf.
15018 this could be a problem. */
15019 SAVE_ARGS 0,1,0
15020 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15021 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15022 + pax_enter_kernel_user
15023 +
15024 +#ifdef CONFIG_PAX_RANDKSTACK
15025 + pax_erase_kstack
15026 +#endif
15027 +
15028 + /*
15029 + * No need to follow this irqs on/off section: the syscall
15030 + * disabled irqs and here we enable it straight after entry:
15031 + */
15032 + ENABLE_INTERRUPTS(CLBR_NONE)
15033 + GET_THREAD_INFO(%r11)
15034 + orl $TS_COMPAT,TI_status(%r11)
15035 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15036 jnz ia32_tracesys
15037 cmpq $(IA32_NR_syscalls-1),%rax
15038 ja ia32_badsys
15039 @@ -458,6 +551,9 @@ ia32_tracesys:
15040 RESTORE_REST
15041 cmpq $(IA32_NR_syscalls-1),%rax
15042 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15043 +
15044 + pax_erase_kstack
15045 +
15046 jmp ia32_do_call
15047 END(ia32_syscall)
15048
15049 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15050 index 8e0ceec..af13504 100644
15051 --- a/arch/x86/ia32/sys_ia32.c
15052 +++ b/arch/x86/ia32/sys_ia32.c
15053 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15054 */
15055 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15056 {
15057 - typeof(ubuf->st_uid) uid = 0;
15058 - typeof(ubuf->st_gid) gid = 0;
15059 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15060 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15061 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15062 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15063 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15064 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15065 index 372231c..51b537d 100644
15066 --- a/arch/x86/include/asm/alternative-asm.h
15067 +++ b/arch/x86/include/asm/alternative-asm.h
15068 @@ -18,6 +18,45 @@
15069 .endm
15070 #endif
15071
15072 +#ifdef KERNEXEC_PLUGIN
15073 + .macro pax_force_retaddr_bts rip=0
15074 + btsq $63,\rip(%rsp)
15075 + .endm
15076 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15077 + .macro pax_force_retaddr rip=0, reload=0
15078 + btsq $63,\rip(%rsp)
15079 + .endm
15080 + .macro pax_force_fptr ptr
15081 + btsq $63,\ptr
15082 + .endm
15083 + .macro pax_set_fptr_mask
15084 + .endm
15085 +#endif
15086 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15087 + .macro pax_force_retaddr rip=0, reload=0
15088 + .if \reload
15089 + pax_set_fptr_mask
15090 + .endif
15091 + orq %r12,\rip(%rsp)
15092 + .endm
15093 + .macro pax_force_fptr ptr
15094 + orq %r12,\ptr
15095 + .endm
15096 + .macro pax_set_fptr_mask
15097 + movabs $0x8000000000000000,%r12
15098 + .endm
15099 +#endif
15100 +#else
15101 + .macro pax_force_retaddr rip=0, reload=0
15102 + .endm
15103 + .macro pax_force_fptr ptr
15104 + .endm
15105 + .macro pax_force_retaddr_bts rip=0
15106 + .endm
15107 + .macro pax_set_fptr_mask
15108 + .endm
15109 +#endif
15110 +
15111 .macro altinstruction_entry orig alt feature orig_len alt_len
15112 .long \orig - .
15113 .long \alt - .
15114 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15115 index 473bdbe..b1e3377 100644
15116 --- a/arch/x86/include/asm/alternative.h
15117 +++ b/arch/x86/include/asm/alternative.h
15118 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15119 ".pushsection .discard,\"aw\",@progbits\n" \
15120 DISCARD_ENTRY(1) \
15121 ".popsection\n" \
15122 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15123 + ".pushsection .altinstr_replacement, \"a\"\n" \
15124 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15125 ".popsection"
15126
15127 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15128 DISCARD_ENTRY(1) \
15129 DISCARD_ENTRY(2) \
15130 ".popsection\n" \
15131 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15132 + ".pushsection .altinstr_replacement, \"a\"\n" \
15133 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15134 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15135 ".popsection"
15136 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15137 index 465b309..ab7e51f 100644
15138 --- a/arch/x86/include/asm/apic.h
15139 +++ b/arch/x86/include/asm/apic.h
15140 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15141
15142 #ifdef CONFIG_X86_LOCAL_APIC
15143
15144 -extern unsigned int apic_verbosity;
15145 +extern int apic_verbosity;
15146 extern int local_apic_timer_c2_ok;
15147
15148 extern int disable_apic;
15149 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15150 index 20370c6..a2eb9b0 100644
15151 --- a/arch/x86/include/asm/apm.h
15152 +++ b/arch/x86/include/asm/apm.h
15153 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15154 __asm__ __volatile__(APM_DO_ZERO_SEGS
15155 "pushl %%edi\n\t"
15156 "pushl %%ebp\n\t"
15157 - "lcall *%%cs:apm_bios_entry\n\t"
15158 + "lcall *%%ss:apm_bios_entry\n\t"
15159 "setc %%al\n\t"
15160 "popl %%ebp\n\t"
15161 "popl %%edi\n\t"
15162 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15163 __asm__ __volatile__(APM_DO_ZERO_SEGS
15164 "pushl %%edi\n\t"
15165 "pushl %%ebp\n\t"
15166 - "lcall *%%cs:apm_bios_entry\n\t"
15167 + "lcall *%%ss:apm_bios_entry\n\t"
15168 "setc %%bl\n\t"
15169 "popl %%ebp\n\t"
15170 "popl %%edi\n\t"
15171 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15172 index 5e5cd12..3d18208 100644
15173 --- a/arch/x86/include/asm/atomic.h
15174 +++ b/arch/x86/include/asm/atomic.h
15175 @@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15176 }
15177
15178 /**
15179 + * atomic_read_unchecked - read atomic variable
15180 + * @v: pointer of type atomic_unchecked_t
15181 + *
15182 + * Atomically reads the value of @v.
15183 + */
15184 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15185 +{
15186 + return ACCESS_ONCE((v)->counter);
15187 +}
15188 +
15189 +/**
15190 * atomic_set - set atomic variable
15191 * @v: pointer of type atomic_t
15192 * @i: required value
15193 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15194 }
15195
15196 /**
15197 + * atomic_set_unchecked - set atomic variable
15198 + * @v: pointer of type atomic_unchecked_t
15199 + * @i: required value
15200 + *
15201 + * Atomically sets the value of @v to @i.
15202 + */
15203 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15204 +{
15205 + v->counter = i;
15206 +}
15207 +
15208 +/**
15209 * atomic_add - add integer to atomic variable
15210 * @i: integer value to add
15211 * @v: pointer of type atomic_t
15212 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15213 */
15214 static inline void atomic_add(int i, atomic_t *v)
15215 {
15216 - asm volatile(LOCK_PREFIX "addl %1,%0"
15217 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15218 +
15219 +#ifdef CONFIG_PAX_REFCOUNT
15220 + "jno 0f\n"
15221 + LOCK_PREFIX "subl %1,%0\n"
15222 + "int $4\n0:\n"
15223 + _ASM_EXTABLE(0b, 0b)
15224 +#endif
15225 +
15226 + : "+m" (v->counter)
15227 + : "ir" (i));
15228 +}
15229 +
15230 +/**
15231 + * atomic_add_unchecked - add integer to atomic variable
15232 + * @i: integer value to add
15233 + * @v: pointer of type atomic_unchecked_t
15234 + *
15235 + * Atomically adds @i to @v.
15236 + */
15237 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15238 +{
15239 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15240 : "+m" (v->counter)
15241 : "ir" (i));
15242 }
15243 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15244 */
15245 static inline void atomic_sub(int i, atomic_t *v)
15246 {
15247 - asm volatile(LOCK_PREFIX "subl %1,%0"
15248 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15249 +
15250 +#ifdef CONFIG_PAX_REFCOUNT
15251 + "jno 0f\n"
15252 + LOCK_PREFIX "addl %1,%0\n"
15253 + "int $4\n0:\n"
15254 + _ASM_EXTABLE(0b, 0b)
15255 +#endif
15256 +
15257 + : "+m" (v->counter)
15258 + : "ir" (i));
15259 +}
15260 +
15261 +/**
15262 + * atomic_sub_unchecked - subtract integer from atomic variable
15263 + * @i: integer value to subtract
15264 + * @v: pointer of type atomic_unchecked_t
15265 + *
15266 + * Atomically subtracts @i from @v.
15267 + */
15268 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15269 +{
15270 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15271 : "+m" (v->counter)
15272 : "ir" (i));
15273 }
15274 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15275 */
15276 static inline int atomic_sub_and_test(int i, atomic_t *v)
15277 {
15278 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15279 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15280 }
15281
15282 /**
15283 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15284 */
15285 static inline void atomic_inc(atomic_t *v)
15286 {
15287 - asm volatile(LOCK_PREFIX "incl %0"
15288 + asm volatile(LOCK_PREFIX "incl %0\n"
15289 +
15290 +#ifdef CONFIG_PAX_REFCOUNT
15291 + "jno 0f\n"
15292 + LOCK_PREFIX "decl %0\n"
15293 + "int $4\n0:\n"
15294 + _ASM_EXTABLE(0b, 0b)
15295 +#endif
15296 +
15297 + : "+m" (v->counter));
15298 +}
15299 +
15300 +/**
15301 + * atomic_inc_unchecked - increment atomic variable
15302 + * @v: pointer of type atomic_unchecked_t
15303 + *
15304 + * Atomically increments @v by 1.
15305 + */
15306 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15307 +{
15308 + asm volatile(LOCK_PREFIX "incl %0\n"
15309 : "+m" (v->counter));
15310 }
15311
15312 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15313 */
15314 static inline void atomic_dec(atomic_t *v)
15315 {
15316 - asm volatile(LOCK_PREFIX "decl %0"
15317 + asm volatile(LOCK_PREFIX "decl %0\n"
15318 +
15319 +#ifdef CONFIG_PAX_REFCOUNT
15320 + "jno 0f\n"
15321 + LOCK_PREFIX "incl %0\n"
15322 + "int $4\n0:\n"
15323 + _ASM_EXTABLE(0b, 0b)
15324 +#endif
15325 +
15326 + : "+m" (v->counter));
15327 +}
15328 +
15329 +/**
15330 + * atomic_dec_unchecked - decrement atomic variable
15331 + * @v: pointer of type atomic_unchecked_t
15332 + *
15333 + * Atomically decrements @v by 1.
15334 + */
15335 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15336 +{
15337 + asm volatile(LOCK_PREFIX "decl %0\n"
15338 : "+m" (v->counter));
15339 }
15340
15341 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15342 */
15343 static inline int atomic_dec_and_test(atomic_t *v)
15344 {
15345 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15346 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15347 }
15348
15349 /**
15350 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15351 */
15352 static inline int atomic_inc_and_test(atomic_t *v)
15353 {
15354 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15355 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15356 +}
15357 +
15358 +/**
15359 + * atomic_inc_and_test_unchecked - increment and test
15360 + * @v: pointer of type atomic_unchecked_t
15361 + *
15362 + * Atomically increments @v by 1
15363 + * and returns true if the result is zero, or false for all
15364 + * other cases.
15365 + */
15366 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15367 +{
15368 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15369 }
15370
15371 /**
15372 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15373 */
15374 static inline int atomic_add_negative(int i, atomic_t *v)
15375 {
15376 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15377 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15378 }
15379
15380 /**
15381 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15382 *
15383 * Atomically adds @i to @v and returns @i + @v
15384 */
15385 -static inline int atomic_add_return(int i, atomic_t *v)
15386 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15387 +{
15388 + return i + xadd_check_overflow(&v->counter, i);
15389 +}
15390 +
15391 +/**
15392 + * atomic_add_return_unchecked - add integer and return
15393 + * @i: integer value to add
15394 + * @v: pointer of type atomic_unchecked_t
15395 + *
15396 + * Atomically adds @i to @v and returns @i + @v
15397 + */
15398 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15399 {
15400 return i + xadd(&v->counter, i);
15401 }
15402 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15403 *
15404 * Atomically subtracts @i from @v and returns @v - @i
15405 */
15406 -static inline int atomic_sub_return(int i, atomic_t *v)
15407 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15408 {
15409 return atomic_add_return(-i, v);
15410 }
15411
15412 #define atomic_inc_return(v) (atomic_add_return(1, v))
15413 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15414 +{
15415 + return atomic_add_return_unchecked(1, v);
15416 +}
15417 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15418
15419 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15420 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15421 +{
15422 + return cmpxchg(&v->counter, old, new);
15423 +}
15424 +
15425 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15426 {
15427 return cmpxchg(&v->counter, old, new);
15428 }
15429 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15430 return xchg(&v->counter, new);
15431 }
15432
15433 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15434 +{
15435 + return xchg(&v->counter, new);
15436 +}
15437 +
15438 /**
15439 * __atomic_add_unless - add unless the number is already a given value
15440 * @v: pointer of type atomic_t
15441 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15442 * Atomically adds @a to @v, so long as @v was not already @u.
15443 * Returns the old value of @v.
15444 */
15445 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15446 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15447 {
15448 - int c, old;
15449 + int c, old, new;
15450 c = atomic_read(v);
15451 for (;;) {
15452 - if (unlikely(c == (u)))
15453 + if (unlikely(c == u))
15454 break;
15455 - old = atomic_cmpxchg((v), c, c + (a));
15456 +
15457 + asm volatile("addl %2,%0\n"
15458 +
15459 +#ifdef CONFIG_PAX_REFCOUNT
15460 + "jno 0f\n"
15461 + "subl %2,%0\n"
15462 + "int $4\n0:\n"
15463 + _ASM_EXTABLE(0b, 0b)
15464 +#endif
15465 +
15466 + : "=r" (new)
15467 + : "0" (c), "ir" (a));
15468 +
15469 + old = atomic_cmpxchg(v, c, new);
15470 if (likely(old == c))
15471 break;
15472 c = old;
15473 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15474 }
15475
15476 /**
15477 + * atomic_inc_not_zero_hint - increment if not null
15478 + * @v: pointer of type atomic_t
15479 + * @hint: probable value of the atomic before the increment
15480 + *
15481 + * This version of atomic_inc_not_zero() gives a hint of probable
15482 + * value of the atomic. This helps processor to not read the memory
15483 + * before doing the atomic read/modify/write cycle, lowering
15484 + * number of bus transactions on some arches.
15485 + *
15486 + * Returns: 0 if increment was not done, 1 otherwise.
15487 + */
15488 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15489 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15490 +{
15491 + int val, c = hint, new;
15492 +
15493 + /* sanity test, should be removed by compiler if hint is a constant */
15494 + if (!hint)
15495 + return __atomic_add_unless(v, 1, 0);
15496 +
15497 + do {
15498 + asm volatile("incl %0\n"
15499 +
15500 +#ifdef CONFIG_PAX_REFCOUNT
15501 + "jno 0f\n"
15502 + "decl %0\n"
15503 + "int $4\n0:\n"
15504 + _ASM_EXTABLE(0b, 0b)
15505 +#endif
15506 +
15507 + : "=r" (new)
15508 + : "0" (c));
15509 +
15510 + val = atomic_cmpxchg(v, c, new);
15511 + if (val == c)
15512 + return 1;
15513 + c = val;
15514 + } while (c);
15515 +
15516 + return 0;
15517 +}
15518 +
15519 +/**
15520 * atomic_inc_short - increment of a short integer
15521 * @v: pointer to type int
15522 *
15523 @@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15524 }
15525
15526 /* These are x86-specific, used by some header files */
15527 -#define atomic_clear_mask(mask, addr) \
15528 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15529 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15530 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15531 +{
15532 + asm volatile(LOCK_PREFIX "andl %1,%0"
15533 + : "+m" (v->counter)
15534 + : "r" (~(mask))
15535 + : "memory");
15536 +}
15537
15538 -#define atomic_set_mask(mask, addr) \
15539 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15540 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15541 - : "memory")
15542 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15543 +{
15544 + asm volatile(LOCK_PREFIX "andl %1,%0"
15545 + : "+m" (v->counter)
15546 + : "r" (~(mask))
15547 + : "memory");
15548 +}
15549 +
15550 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15551 +{
15552 + asm volatile(LOCK_PREFIX "orl %1,%0"
15553 + : "+m" (v->counter)
15554 + : "r" (mask)
15555 + : "memory");
15556 +}
15557 +
15558 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15559 +{
15560 + asm volatile(LOCK_PREFIX "orl %1,%0"
15561 + : "+m" (v->counter)
15562 + : "r" (mask)
15563 + : "memory");
15564 +}
15565
15566 #ifdef CONFIG_X86_32
15567 # include <asm/atomic64_32.h>
15568 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15569 index b154de7..bf18a5a 100644
15570 --- a/arch/x86/include/asm/atomic64_32.h
15571 +++ b/arch/x86/include/asm/atomic64_32.h
15572 @@ -12,6 +12,14 @@ typedef struct {
15573 u64 __aligned(8) counter;
15574 } atomic64_t;
15575
15576 +#ifdef CONFIG_PAX_REFCOUNT
15577 +typedef struct {
15578 + u64 __aligned(8) counter;
15579 +} atomic64_unchecked_t;
15580 +#else
15581 +typedef atomic64_t atomic64_unchecked_t;
15582 +#endif
15583 +
15584 #define ATOMIC64_INIT(val) { (val) }
15585
15586 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15587 @@ -37,21 +45,31 @@ typedef struct {
15588 ATOMIC64_DECL_ONE(sym##_386)
15589
15590 ATOMIC64_DECL_ONE(add_386);
15591 +ATOMIC64_DECL_ONE(add_unchecked_386);
15592 ATOMIC64_DECL_ONE(sub_386);
15593 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15594 ATOMIC64_DECL_ONE(inc_386);
15595 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15596 ATOMIC64_DECL_ONE(dec_386);
15597 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15598 #endif
15599
15600 #define alternative_atomic64(f, out, in...) \
15601 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15602
15603 ATOMIC64_DECL(read);
15604 +ATOMIC64_DECL(read_unchecked);
15605 ATOMIC64_DECL(set);
15606 +ATOMIC64_DECL(set_unchecked);
15607 ATOMIC64_DECL(xchg);
15608 ATOMIC64_DECL(add_return);
15609 +ATOMIC64_DECL(add_return_unchecked);
15610 ATOMIC64_DECL(sub_return);
15611 +ATOMIC64_DECL(sub_return_unchecked);
15612 ATOMIC64_DECL(inc_return);
15613 +ATOMIC64_DECL(inc_return_unchecked);
15614 ATOMIC64_DECL(dec_return);
15615 +ATOMIC64_DECL(dec_return_unchecked);
15616 ATOMIC64_DECL(dec_if_positive);
15617 ATOMIC64_DECL(inc_not_zero);
15618 ATOMIC64_DECL(add_unless);
15619 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15620 }
15621
15622 /**
15623 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15624 + * @p: pointer to type atomic64_unchecked_t
15625 + * @o: expected value
15626 + * @n: new value
15627 + *
15628 + * Atomically sets @v to @n if it was equal to @o and returns
15629 + * the old value.
15630 + */
15631 +
15632 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15633 +{
15634 + return cmpxchg64(&v->counter, o, n);
15635 +}
15636 +
15637 +/**
15638 * atomic64_xchg - xchg atomic64 variable
15639 * @v: pointer to type atomic64_t
15640 * @n: value to assign
15641 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15642 }
15643
15644 /**
15645 + * atomic64_set_unchecked - set atomic64 variable
15646 + * @v: pointer to type atomic64_unchecked_t
15647 + * @n: value to assign
15648 + *
15649 + * Atomically sets the value of @v to @n.
15650 + */
15651 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15652 +{
15653 + unsigned high = (unsigned)(i >> 32);
15654 + unsigned low = (unsigned)i;
15655 + alternative_atomic64(set, /* no output */,
15656 + "S" (v), "b" (low), "c" (high)
15657 + : "eax", "edx", "memory");
15658 +}
15659 +
15660 +/**
15661 * atomic64_read - read atomic64 variable
15662 * @v: pointer to type atomic64_t
15663 *
15664 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15665 }
15666
15667 /**
15668 + * atomic64_read_unchecked - read atomic64 variable
15669 + * @v: pointer to type atomic64_unchecked_t
15670 + *
15671 + * Atomically reads the value of @v and returns it.
15672 + */
15673 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15674 +{
15675 + long long r;
15676 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15677 + return r;
15678 + }
15679 +
15680 +/**
15681 * atomic64_add_return - add and return
15682 * @i: integer value to add
15683 * @v: pointer to type atomic64_t
15684 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15685 return i;
15686 }
15687
15688 +/**
15689 + * atomic64_add_return_unchecked - add and return
15690 + * @i: integer value to add
15691 + * @v: pointer to type atomic64_unchecked_t
15692 + *
15693 + * Atomically adds @i to @v and returns @i + *@v
15694 + */
15695 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15696 +{
15697 + alternative_atomic64(add_return_unchecked,
15698 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15699 + ASM_NO_INPUT_CLOBBER("memory"));
15700 + return i;
15701 +}
15702 +
15703 /*
15704 * Other variants with different arithmetic operators:
15705 */
15706 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15707 return a;
15708 }
15709
15710 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15711 +{
15712 + long long a;
15713 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15714 + "S" (v) : "memory", "ecx");
15715 + return a;
15716 +}
15717 +
15718 static inline long long atomic64_dec_return(atomic64_t *v)
15719 {
15720 long long a;
15721 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15722 }
15723
15724 /**
15725 + * atomic64_add_unchecked - add integer to atomic64 variable
15726 + * @i: integer value to add
15727 + * @v: pointer to type atomic64_unchecked_t
15728 + *
15729 + * Atomically adds @i to @v.
15730 + */
15731 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15732 +{
15733 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15734 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15735 + ASM_NO_INPUT_CLOBBER("memory"));
15736 + return i;
15737 +}
15738 +
15739 +/**
15740 * atomic64_sub - subtract the atomic64 variable
15741 * @i: integer value to subtract
15742 * @v: pointer to type atomic64_t
15743 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15744 index f8d273e..02f39f3 100644
15745 --- a/arch/x86/include/asm/atomic64_64.h
15746 +++ b/arch/x86/include/asm/atomic64_64.h
15747 @@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15748 }
15749
15750 /**
15751 + * atomic64_read_unchecked - read atomic64 variable
15752 + * @v: pointer of type atomic64_unchecked_t
15753 + *
15754 + * Atomically reads the value of @v.
15755 + * Doesn't imply a read memory barrier.
15756 + */
15757 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15758 +{
15759 + return ACCESS_ONCE((v)->counter);
15760 +}
15761 +
15762 +/**
15763 * atomic64_set - set atomic64 variable
15764 * @v: pointer to type atomic64_t
15765 * @i: required value
15766 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15767 }
15768
15769 /**
15770 + * atomic64_set_unchecked - set atomic64 variable
15771 + * @v: pointer to type atomic64_unchecked_t
15772 + * @i: required value
15773 + *
15774 + * Atomically sets the value of @v to @i.
15775 + */
15776 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15777 +{
15778 + v->counter = i;
15779 +}
15780 +
15781 +/**
15782 * atomic64_add - add integer to atomic64 variable
15783 * @i: integer value to add
15784 * @v: pointer to type atomic64_t
15785 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15786 */
15787 static inline void atomic64_add(long i, atomic64_t *v)
15788 {
15789 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15790 +
15791 +#ifdef CONFIG_PAX_REFCOUNT
15792 + "jno 0f\n"
15793 + LOCK_PREFIX "subq %1,%0\n"
15794 + "int $4\n0:\n"
15795 + _ASM_EXTABLE(0b, 0b)
15796 +#endif
15797 +
15798 + : "=m" (v->counter)
15799 + : "er" (i), "m" (v->counter));
15800 +}
15801 +
15802 +/**
15803 + * atomic64_add_unchecked - add integer to atomic64 variable
15804 + * @i: integer value to add
15805 + * @v: pointer to type atomic64_unchecked_t
15806 + *
15807 + * Atomically adds @i to @v.
15808 + */
15809 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15810 +{
15811 asm volatile(LOCK_PREFIX "addq %1,%0"
15812 : "=m" (v->counter)
15813 : "er" (i), "m" (v->counter));
15814 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15815 */
15816 static inline void atomic64_sub(long i, atomic64_t *v)
15817 {
15818 - asm volatile(LOCK_PREFIX "subq %1,%0"
15819 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15820 +
15821 +#ifdef CONFIG_PAX_REFCOUNT
15822 + "jno 0f\n"
15823 + LOCK_PREFIX "addq %1,%0\n"
15824 + "int $4\n0:\n"
15825 + _ASM_EXTABLE(0b, 0b)
15826 +#endif
15827 +
15828 + : "=m" (v->counter)
15829 + : "er" (i), "m" (v->counter));
15830 +}
15831 +
15832 +/**
15833 + * atomic64_sub_unchecked - subtract the atomic64 variable
15834 + * @i: integer value to subtract
15835 + * @v: pointer to type atomic64_unchecked_t
15836 + *
15837 + * Atomically subtracts @i from @v.
15838 + */
15839 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15840 +{
15841 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15842 : "=m" (v->counter)
15843 : "er" (i), "m" (v->counter));
15844 }
15845 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15846 */
15847 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15848 {
15849 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15850 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15851 }
15852
15853 /**
15854 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15855 */
15856 static inline void atomic64_inc(atomic64_t *v)
15857 {
15858 + asm volatile(LOCK_PREFIX "incq %0\n"
15859 +
15860 +#ifdef CONFIG_PAX_REFCOUNT
15861 + "jno 0f\n"
15862 + LOCK_PREFIX "decq %0\n"
15863 + "int $4\n0:\n"
15864 + _ASM_EXTABLE(0b, 0b)
15865 +#endif
15866 +
15867 + : "=m" (v->counter)
15868 + : "m" (v->counter));
15869 +}
15870 +
15871 +/**
15872 + * atomic64_inc_unchecked - increment atomic64 variable
15873 + * @v: pointer to type atomic64_unchecked_t
15874 + *
15875 + * Atomically increments @v by 1.
15876 + */
15877 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15878 +{
15879 asm volatile(LOCK_PREFIX "incq %0"
15880 : "=m" (v->counter)
15881 : "m" (v->counter));
15882 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15883 */
15884 static inline void atomic64_dec(atomic64_t *v)
15885 {
15886 - asm volatile(LOCK_PREFIX "decq %0"
15887 + asm volatile(LOCK_PREFIX "decq %0\n"
15888 +
15889 +#ifdef CONFIG_PAX_REFCOUNT
15890 + "jno 0f\n"
15891 + LOCK_PREFIX "incq %0\n"
15892 + "int $4\n0:\n"
15893 + _ASM_EXTABLE(0b, 0b)
15894 +#endif
15895 +
15896 + : "=m" (v->counter)
15897 + : "m" (v->counter));
15898 +}
15899 +
15900 +/**
15901 + * atomic64_dec_unchecked - decrement atomic64 variable
15902 + * @v: pointer to type atomic64_t
15903 + *
15904 + * Atomically decrements @v by 1.
15905 + */
15906 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15907 +{
15908 + asm volatile(LOCK_PREFIX "decq %0\n"
15909 : "=m" (v->counter)
15910 : "m" (v->counter));
15911 }
15912 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15913 */
15914 static inline int atomic64_dec_and_test(atomic64_t *v)
15915 {
15916 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15917 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15918 }
15919
15920 /**
15921 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15922 */
15923 static inline int atomic64_inc_and_test(atomic64_t *v)
15924 {
15925 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15926 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15927 }
15928
15929 /**
15930 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15931 */
15932 static inline int atomic64_add_negative(long i, atomic64_t *v)
15933 {
15934 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15935 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15936 }
15937
15938 /**
15939 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15940 */
15941 static inline long atomic64_add_return(long i, atomic64_t *v)
15942 {
15943 + return i + xadd_check_overflow(&v->counter, i);
15944 +}
15945 +
15946 +/**
15947 + * atomic64_add_return_unchecked - add and return
15948 + * @i: integer value to add
15949 + * @v: pointer to type atomic64_unchecked_t
15950 + *
15951 + * Atomically adds @i to @v and returns @i + @v
15952 + */
15953 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15954 +{
15955 return i + xadd(&v->counter, i);
15956 }
15957
15958 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15959 }
15960
15961 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15962 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15963 +{
15964 + return atomic64_add_return_unchecked(1, v);
15965 +}
15966 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15967
15968 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15969 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15970 return cmpxchg(&v->counter, old, new);
15971 }
15972
15973 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15974 +{
15975 + return cmpxchg(&v->counter, old, new);
15976 +}
15977 +
15978 static inline long atomic64_xchg(atomic64_t *v, long new)
15979 {
15980 return xchg(&v->counter, new);
15981 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15982 */
15983 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15984 {
15985 - long c, old;
15986 + long c, old, new;
15987 c = atomic64_read(v);
15988 for (;;) {
15989 - if (unlikely(c == (u)))
15990 + if (unlikely(c == u))
15991 break;
15992 - old = atomic64_cmpxchg((v), c, c + (a));
15993 +
15994 + asm volatile("add %2,%0\n"
15995 +
15996 +#ifdef CONFIG_PAX_REFCOUNT
15997 + "jno 0f\n"
15998 + "sub %2,%0\n"
15999 + "int $4\n0:\n"
16000 + _ASM_EXTABLE(0b, 0b)
16001 +#endif
16002 +
16003 + : "=r" (new)
16004 + : "0" (c), "ir" (a));
16005 +
16006 + old = atomic64_cmpxchg(v, c, new);
16007 if (likely(old == c))
16008 break;
16009 c = old;
16010 }
16011 - return c != (u);
16012 + return c != u;
16013 }
16014
16015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16016 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16017 index 0f4460b..fa1ee19 100644
16018 --- a/arch/x86/include/asm/barrier.h
16019 +++ b/arch/x86/include/asm/barrier.h
16020 @@ -107,7 +107,7 @@
16021 do { \
16022 compiletime_assert_atomic_type(*p); \
16023 smp_mb(); \
16024 - ACCESS_ONCE(*p) = (v); \
16025 + ACCESS_ONCE_RW(*p) = (v); \
16026 } while (0)
16027
16028 #define smp_load_acquire(p) \
16029 @@ -124,7 +124,7 @@ do { \
16030 do { \
16031 compiletime_assert_atomic_type(*p); \
16032 barrier(); \
16033 - ACCESS_ONCE(*p) = (v); \
16034 + ACCESS_ONCE_RW(*p) = (v); \
16035 } while (0)
16036
16037 #define smp_load_acquire(p) \
16038 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16039 index cfe3b95..d01b118 100644
16040 --- a/arch/x86/include/asm/bitops.h
16041 +++ b/arch/x86/include/asm/bitops.h
16042 @@ -50,7 +50,7 @@
16043 * a mask operation on a byte.
16044 */
16045 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16046 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16047 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16048 #define CONST_MASK(nr) (1 << ((nr) & 7))
16049
16050 /**
16051 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16052 */
16053 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16054 {
16055 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16056 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16057 }
16058
16059 /**
16060 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16061 */
16062 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16063 {
16064 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16065 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16066 }
16067
16068 /**
16069 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16070 */
16071 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16072 {
16073 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16074 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16075 }
16076
16077 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16078 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16079 *
16080 * Undefined if no bit exists, so code should check against 0 first.
16081 */
16082 -static inline unsigned long __ffs(unsigned long word)
16083 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16084 {
16085 asm("rep; bsf %1,%0"
16086 : "=r" (word)
16087 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16088 *
16089 * Undefined if no zero exists, so code should check against ~0UL first.
16090 */
16091 -static inline unsigned long ffz(unsigned long word)
16092 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16093 {
16094 asm("rep; bsf %1,%0"
16095 : "=r" (word)
16096 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16097 *
16098 * Undefined if no set bit exists, so code should check against 0 first.
16099 */
16100 -static inline unsigned long __fls(unsigned long word)
16101 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16102 {
16103 asm("bsr %1,%0"
16104 : "=r" (word)
16105 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16106 * set bit if value is nonzero. The last (most significant) bit is
16107 * at position 32.
16108 */
16109 -static inline int fls(int x)
16110 +static inline int __intentional_overflow(-1) fls(int x)
16111 {
16112 int r;
16113
16114 @@ -476,7 +476,7 @@ static inline int fls(int x)
16115 * at position 64.
16116 */
16117 #ifdef CONFIG_X86_64
16118 -static __always_inline int fls64(__u64 x)
16119 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16120 {
16121 int bitpos = -1;
16122 /*
16123 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16124 index 4fa687a..60f2d39 100644
16125 --- a/arch/x86/include/asm/boot.h
16126 +++ b/arch/x86/include/asm/boot.h
16127 @@ -6,10 +6,15 @@
16128 #include <uapi/asm/boot.h>
16129
16130 /* Physical address where kernel should be loaded. */
16131 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16132 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16133 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16134 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16135
16136 +#ifndef __ASSEMBLY__
16137 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16138 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16139 +#endif
16140 +
16141 /* Minimum kernel alignment, as a power of two */
16142 #ifdef CONFIG_X86_64
16143 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16144 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16145 index 48f99f1..d78ebf9 100644
16146 --- a/arch/x86/include/asm/cache.h
16147 +++ b/arch/x86/include/asm/cache.h
16148 @@ -5,12 +5,13 @@
16149
16150 /* L1 cache line size */
16151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16152 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16153 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16154
16155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16156 +#define __read_only __attribute__((__section__(".data..read_only")))
16157
16158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16159 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16160 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16161
16162 #ifdef CONFIG_X86_VSMP
16163 #ifdef CONFIG_SMP
16164 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16165 index 9863ee3..4a1f8e1 100644
16166 --- a/arch/x86/include/asm/cacheflush.h
16167 +++ b/arch/x86/include/asm/cacheflush.h
16168 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16169 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16170
16171 if (pg_flags == _PGMT_DEFAULT)
16172 - return -1;
16173 + return ~0UL;
16174 else if (pg_flags == _PGMT_WC)
16175 return _PAGE_CACHE_WC;
16176 else if (pg_flags == _PGMT_UC_MINUS)
16177 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16178 index 76659b6..72b8439 100644
16179 --- a/arch/x86/include/asm/calling.h
16180 +++ b/arch/x86/include/asm/calling.h
16181 @@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16182 #define RSP 152
16183 #define SS 160
16184
16185 -#define ARGOFFSET R11
16186 -#define SWFRAME ORIG_RAX
16187 +#define ARGOFFSET R15
16188
16189 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16190 - subq $9*8+\addskip, %rsp
16191 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16192 - movq_cfi rdi, 8*8
16193 - movq_cfi rsi, 7*8
16194 - movq_cfi rdx, 6*8
16195 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16196 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16197 + movq_cfi rdi, RDI
16198 + movq_cfi rsi, RSI
16199 + movq_cfi rdx, RDX
16200
16201 .if \save_rcx
16202 - movq_cfi rcx, 5*8
16203 + movq_cfi rcx, RCX
16204 .endif
16205
16206 .if \rax_enosys
16207 - movq $-ENOSYS, 4*8(%rsp)
16208 + movq $-ENOSYS, RAX(%rsp)
16209 .else
16210 - movq_cfi rax, 4*8
16211 + movq_cfi rax, RAX
16212 .endif
16213
16214 .if \save_r891011
16215 - movq_cfi r8, 3*8
16216 - movq_cfi r9, 2*8
16217 - movq_cfi r10, 1*8
16218 - movq_cfi r11, 0*8
16219 + movq_cfi r8, R8
16220 + movq_cfi r9, R9
16221 + movq_cfi r10, R10
16222 + movq_cfi r11, R11
16223 .endif
16224
16225 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16226 + movq_cfi r12, R12
16227 +#endif
16228 +
16229 .endm
16230
16231 -#define ARG_SKIP (9*8)
16232 +#define ARG_SKIP ORIG_RAX
16233
16234 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16235 rstor_r8910=1, rstor_rdx=1
16236 +
16237 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16238 + movq_cfi_restore R12, r12
16239 +#endif
16240 +
16241 .if \rstor_r11
16242 - movq_cfi_restore 0*8, r11
16243 + movq_cfi_restore R11, r11
16244 .endif
16245
16246 .if \rstor_r8910
16247 - movq_cfi_restore 1*8, r10
16248 - movq_cfi_restore 2*8, r9
16249 - movq_cfi_restore 3*8, r8
16250 + movq_cfi_restore R10, r10
16251 + movq_cfi_restore R9, r9
16252 + movq_cfi_restore R8, r8
16253 .endif
16254
16255 .if \rstor_rax
16256 - movq_cfi_restore 4*8, rax
16257 + movq_cfi_restore RAX, rax
16258 .endif
16259
16260 .if \rstor_rcx
16261 - movq_cfi_restore 5*8, rcx
16262 + movq_cfi_restore RCX, rcx
16263 .endif
16264
16265 .if \rstor_rdx
16266 - movq_cfi_restore 6*8, rdx
16267 + movq_cfi_restore RDX, rdx
16268 .endif
16269
16270 - movq_cfi_restore 7*8, rsi
16271 - movq_cfi_restore 8*8, rdi
16272 + movq_cfi_restore RSI, rsi
16273 + movq_cfi_restore RDI, rdi
16274
16275 - .if ARG_SKIP+\addskip > 0
16276 - addq $ARG_SKIP+\addskip, %rsp
16277 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16278 + .if ORIG_RAX+\addskip > 0
16279 + addq $ORIG_RAX+\addskip, %rsp
16280 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16281 .endif
16282 .endm
16283
16284 - .macro LOAD_ARGS offset, skiprax=0
16285 - movq \offset(%rsp), %r11
16286 - movq \offset+8(%rsp), %r10
16287 - movq \offset+16(%rsp), %r9
16288 - movq \offset+24(%rsp), %r8
16289 - movq \offset+40(%rsp), %rcx
16290 - movq \offset+48(%rsp), %rdx
16291 - movq \offset+56(%rsp), %rsi
16292 - movq \offset+64(%rsp), %rdi
16293 + .macro LOAD_ARGS skiprax=0
16294 + movq R11(%rsp), %r11
16295 + movq R10(%rsp), %r10
16296 + movq R9(%rsp), %r9
16297 + movq R8(%rsp), %r8
16298 + movq RCX(%rsp), %rcx
16299 + movq RDX(%rsp), %rdx
16300 + movq RSI(%rsp), %rsi
16301 + movq RDI(%rsp), %rdi
16302 .if \skiprax
16303 .else
16304 - movq \offset+72(%rsp), %rax
16305 + movq ORIG_RAX(%rsp), %rax
16306 .endif
16307 .endm
16308
16309 -#define REST_SKIP (6*8)
16310 -
16311 .macro SAVE_REST
16312 - subq $REST_SKIP, %rsp
16313 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16314 - movq_cfi rbx, 5*8
16315 - movq_cfi rbp, 4*8
16316 - movq_cfi r12, 3*8
16317 - movq_cfi r13, 2*8
16318 - movq_cfi r14, 1*8
16319 - movq_cfi r15, 0*8
16320 + movq_cfi rbx, RBX
16321 + movq_cfi rbp, RBP
16322 +
16323 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16324 + movq_cfi r12, R12
16325 +#endif
16326 +
16327 + movq_cfi r13, R13
16328 + movq_cfi r14, R14
16329 + movq_cfi r15, R15
16330 .endm
16331
16332 .macro RESTORE_REST
16333 - movq_cfi_restore 0*8, r15
16334 - movq_cfi_restore 1*8, r14
16335 - movq_cfi_restore 2*8, r13
16336 - movq_cfi_restore 3*8, r12
16337 - movq_cfi_restore 4*8, rbp
16338 - movq_cfi_restore 5*8, rbx
16339 - addq $REST_SKIP, %rsp
16340 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16341 + movq_cfi_restore R15, r15
16342 + movq_cfi_restore R14, r14
16343 + movq_cfi_restore R13, r13
16344 +
16345 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16346 + movq_cfi_restore R12, r12
16347 +#endif
16348 +
16349 + movq_cfi_restore RBP, rbp
16350 + movq_cfi_restore RBX, rbx
16351 .endm
16352
16353 .macro SAVE_ALL
16354 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16355 index f50de69..2b0a458 100644
16356 --- a/arch/x86/include/asm/checksum_32.h
16357 +++ b/arch/x86/include/asm/checksum_32.h
16358 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16359 int len, __wsum sum,
16360 int *src_err_ptr, int *dst_err_ptr);
16361
16362 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16363 + int len, __wsum sum,
16364 + int *src_err_ptr, int *dst_err_ptr);
16365 +
16366 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16367 + int len, __wsum sum,
16368 + int *src_err_ptr, int *dst_err_ptr);
16369 +
16370 /*
16371 * Note: when you get a NULL pointer exception here this means someone
16372 * passed in an incorrect kernel address to one of these functions.
16373 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16374
16375 might_sleep();
16376 stac();
16377 - ret = csum_partial_copy_generic((__force void *)src, dst,
16378 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16379 len, sum, err_ptr, NULL);
16380 clac();
16381
16382 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16383 might_sleep();
16384 if (access_ok(VERIFY_WRITE, dst, len)) {
16385 stac();
16386 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16387 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16388 len, sum, NULL, err_ptr);
16389 clac();
16390 return ret;
16391 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16392 index 99c105d7..2f667ac 100644
16393 --- a/arch/x86/include/asm/cmpxchg.h
16394 +++ b/arch/x86/include/asm/cmpxchg.h
16395 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16396 __compiletime_error("Bad argument size for cmpxchg");
16397 extern void __xadd_wrong_size(void)
16398 __compiletime_error("Bad argument size for xadd");
16399 +extern void __xadd_check_overflow_wrong_size(void)
16400 + __compiletime_error("Bad argument size for xadd_check_overflow");
16401 extern void __add_wrong_size(void)
16402 __compiletime_error("Bad argument size for add");
16403 +extern void __add_check_overflow_wrong_size(void)
16404 + __compiletime_error("Bad argument size for add_check_overflow");
16405
16406 /*
16407 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16408 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16409 __ret; \
16410 })
16411
16412 +#ifdef CONFIG_PAX_REFCOUNT
16413 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16414 + ({ \
16415 + __typeof__ (*(ptr)) __ret = (arg); \
16416 + switch (sizeof(*(ptr))) { \
16417 + case __X86_CASE_L: \
16418 + asm volatile (lock #op "l %0, %1\n" \
16419 + "jno 0f\n" \
16420 + "mov %0,%1\n" \
16421 + "int $4\n0:\n" \
16422 + _ASM_EXTABLE(0b, 0b) \
16423 + : "+r" (__ret), "+m" (*(ptr)) \
16424 + : : "memory", "cc"); \
16425 + break; \
16426 + case __X86_CASE_Q: \
16427 + asm volatile (lock #op "q %q0, %1\n" \
16428 + "jno 0f\n" \
16429 + "mov %0,%1\n" \
16430 + "int $4\n0:\n" \
16431 + _ASM_EXTABLE(0b, 0b) \
16432 + : "+r" (__ret), "+m" (*(ptr)) \
16433 + : : "memory", "cc"); \
16434 + break; \
16435 + default: \
16436 + __ ## op ## _check_overflow_wrong_size(); \
16437 + } \
16438 + __ret; \
16439 + })
16440 +#else
16441 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16442 +#endif
16443 +
16444 /*
16445 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16446 * Since this is generally used to protect other memory information, we
16447 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16448 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16449 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16450
16451 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16452 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16453 +
16454 #define __add(ptr, inc, lock) \
16455 ({ \
16456 __typeof__ (*(ptr)) __ret = (inc); \
16457 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16458 index 59c6c40..5e0b22c 100644
16459 --- a/arch/x86/include/asm/compat.h
16460 +++ b/arch/x86/include/asm/compat.h
16461 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16462 typedef u32 compat_uint_t;
16463 typedef u32 compat_ulong_t;
16464 typedef u64 __attribute__((aligned(4))) compat_u64;
16465 -typedef u32 compat_uptr_t;
16466 +typedef u32 __user compat_uptr_t;
16467
16468 struct compat_timespec {
16469 compat_time_t tv_sec;
16470 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16471 index 0bb1335..8f1aec7 100644
16472 --- a/arch/x86/include/asm/cpufeature.h
16473 +++ b/arch/x86/include/asm/cpufeature.h
16474 @@ -207,7 +207,7 @@
16475 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16476 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16477 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16478 -
16479 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16480
16481 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16482 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16483 @@ -215,7 +215,7 @@
16484 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16485 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16486 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16487 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16488 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16489 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16490 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16491 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16492 @@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16493 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16494 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16495 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16496 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16497
16498 #if __GNUC__ >= 4
16499 extern void warn_pre_alternatives(void);
16500 @@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16501
16502 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16503 t_warn:
16504 - warn_pre_alternatives();
16505 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16506 + warn_pre_alternatives();
16507 return false;
16508 #endif
16509
16510 @@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16511 ".section .discard,\"aw\",@progbits\n"
16512 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16513 ".previous\n"
16514 - ".section .altinstr_replacement,\"ax\"\n"
16515 + ".section .altinstr_replacement,\"a\"\n"
16516 "3: movb $1,%0\n"
16517 "4:\n"
16518 ".previous\n"
16519 @@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16520 " .byte 2b - 1b\n" /* src len */
16521 " .byte 4f - 3f\n" /* repl len */
16522 ".previous\n"
16523 - ".section .altinstr_replacement,\"ax\"\n"
16524 + ".section .altinstr_replacement,\"a\"\n"
16525 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16526 "4:\n"
16527 ".previous\n"
16528 @@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16529 ".section .discard,\"aw\",@progbits\n"
16530 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16531 ".previous\n"
16532 - ".section .altinstr_replacement,\"ax\"\n"
16533 + ".section .altinstr_replacement,\"a\"\n"
16534 "3: movb $0,%0\n"
16535 "4:\n"
16536 ".previous\n"
16537 @@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16538 ".section .discard,\"aw\",@progbits\n"
16539 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16540 ".previous\n"
16541 - ".section .altinstr_replacement,\"ax\"\n"
16542 + ".section .altinstr_replacement,\"a\"\n"
16543 "5: movb $1,%0\n"
16544 "6:\n"
16545 ".previous\n"
16546 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16547 index a94b82e..59ecefa 100644
16548 --- a/arch/x86/include/asm/desc.h
16549 +++ b/arch/x86/include/asm/desc.h
16550 @@ -4,6 +4,7 @@
16551 #include <asm/desc_defs.h>
16552 #include <asm/ldt.h>
16553 #include <asm/mmu.h>
16554 +#include <asm/pgtable.h>
16555
16556 #include <linux/smp.h>
16557 #include <linux/percpu.h>
16558 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16559
16560 desc->type = (info->read_exec_only ^ 1) << 1;
16561 desc->type |= info->contents << 2;
16562 + desc->type |= info->seg_not_present ^ 1;
16563
16564 desc->s = 1;
16565 desc->dpl = 0x3;
16566 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16567 }
16568
16569 extern struct desc_ptr idt_descr;
16570 -extern gate_desc idt_table[];
16571 -extern struct desc_ptr debug_idt_descr;
16572 -extern gate_desc debug_idt_table[];
16573 -
16574 -struct gdt_page {
16575 - struct desc_struct gdt[GDT_ENTRIES];
16576 -} __attribute__((aligned(PAGE_SIZE)));
16577 -
16578 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16579 +extern gate_desc idt_table[IDT_ENTRIES];
16580 +extern const struct desc_ptr debug_idt_descr;
16581 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16582
16583 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16584 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16585 {
16586 - return per_cpu(gdt_page, cpu).gdt;
16587 + return cpu_gdt_table[cpu];
16588 }
16589
16590 #ifdef CONFIG_X86_64
16591 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16592 unsigned long base, unsigned dpl, unsigned flags,
16593 unsigned short seg)
16594 {
16595 - gate->a = (seg << 16) | (base & 0xffff);
16596 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16597 + gate->gate.offset_low = base;
16598 + gate->gate.seg = seg;
16599 + gate->gate.reserved = 0;
16600 + gate->gate.type = type;
16601 + gate->gate.s = 0;
16602 + gate->gate.dpl = dpl;
16603 + gate->gate.p = 1;
16604 + gate->gate.offset_high = base >> 16;
16605 }
16606
16607 #endif
16608 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16609
16610 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16611 {
16612 + pax_open_kernel();
16613 memcpy(&idt[entry], gate, sizeof(*gate));
16614 + pax_close_kernel();
16615 }
16616
16617 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16618 {
16619 + pax_open_kernel();
16620 memcpy(&ldt[entry], desc, 8);
16621 + pax_close_kernel();
16622 }
16623
16624 static inline void
16625 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16626 default: size = sizeof(*gdt); break;
16627 }
16628
16629 + pax_open_kernel();
16630 memcpy(&gdt[entry], desc, size);
16631 + pax_close_kernel();
16632 }
16633
16634 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16635 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16636
16637 static inline void native_load_tr_desc(void)
16638 {
16639 + pax_open_kernel();
16640 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16641 + pax_close_kernel();
16642 }
16643
16644 static inline void native_load_gdt(const struct desc_ptr *dtr)
16645 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16646 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16647 unsigned int i;
16648
16649 + pax_open_kernel();
16650 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16651 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16652 + pax_close_kernel();
16653 }
16654
16655 /* This intentionally ignores lm, since 32-bit apps don't have that field. */
16656 @@ -295,7 +308,7 @@ static inline void load_LDT(mm_context_t *pc)
16657 preempt_enable();
16658 }
16659
16660 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16661 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16662 {
16663 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16664 }
16665 @@ -319,7 +332,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16666 }
16667
16668 #ifdef CONFIG_X86_64
16669 -static inline void set_nmi_gate(int gate, void *addr)
16670 +static inline void set_nmi_gate(int gate, const void *addr)
16671 {
16672 gate_desc s;
16673
16674 @@ -329,14 +342,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16675 #endif
16676
16677 #ifdef CONFIG_TRACING
16678 -extern struct desc_ptr trace_idt_descr;
16679 -extern gate_desc trace_idt_table[];
16680 +extern const struct desc_ptr trace_idt_descr;
16681 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16682 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16683 {
16684 write_idt_entry(trace_idt_table, entry, gate);
16685 }
16686
16687 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16688 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16689 unsigned dpl, unsigned ist, unsigned seg)
16690 {
16691 gate_desc s;
16692 @@ -356,7 +369,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16693 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16694 #endif
16695
16696 -static inline void _set_gate(int gate, unsigned type, void *addr,
16697 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16698 unsigned dpl, unsigned ist, unsigned seg)
16699 {
16700 gate_desc s;
16701 @@ -379,9 +392,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16702 #define set_intr_gate(n, addr) \
16703 do { \
16704 BUG_ON((unsigned)n > 0xFF); \
16705 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16706 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16707 __KERNEL_CS); \
16708 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16709 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16710 0, 0, __KERNEL_CS); \
16711 } while (0)
16712
16713 @@ -409,19 +422,19 @@ static inline void alloc_system_vector(int vector)
16714 /*
16715 * This routine sets up an interrupt gate at directory privilege level 3.
16716 */
16717 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16718 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16719 {
16720 BUG_ON((unsigned)n > 0xFF);
16721 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16722 }
16723
16724 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16725 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16726 {
16727 BUG_ON((unsigned)n > 0xFF);
16728 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16729 }
16730
16731 -static inline void set_trap_gate(unsigned int n, void *addr)
16732 +static inline void set_trap_gate(unsigned int n, const void *addr)
16733 {
16734 BUG_ON((unsigned)n > 0xFF);
16735 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16736 @@ -430,16 +443,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16737 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16738 {
16739 BUG_ON((unsigned)n > 0xFF);
16740 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16741 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16742 }
16743
16744 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16745 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16746 {
16747 BUG_ON((unsigned)n > 0xFF);
16748 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16749 }
16750
16751 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16752 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16753 {
16754 BUG_ON((unsigned)n > 0xFF);
16755 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16756 @@ -511,4 +524,17 @@ static inline void load_current_idt(void)
16757 else
16758 load_idt((const struct desc_ptr *)&idt_descr);
16759 }
16760 +
16761 +#ifdef CONFIG_X86_32
16762 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16763 +{
16764 + struct desc_struct d;
16765 +
16766 + if (likely(limit))
16767 + limit = (limit - 1UL) >> PAGE_SHIFT;
16768 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16769 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16770 +}
16771 +#endif
16772 +
16773 #endif /* _ASM_X86_DESC_H */
16774 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16775 index 278441f..b95a174 100644
16776 --- a/arch/x86/include/asm/desc_defs.h
16777 +++ b/arch/x86/include/asm/desc_defs.h
16778 @@ -31,6 +31,12 @@ struct desc_struct {
16779 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16780 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16781 };
16782 + struct {
16783 + u16 offset_low;
16784 + u16 seg;
16785 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16786 + unsigned offset_high: 16;
16787 + } gate;
16788 };
16789 } __attribute__((packed));
16790
16791 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16792 index ced283a..ffe04cc 100644
16793 --- a/arch/x86/include/asm/div64.h
16794 +++ b/arch/x86/include/asm/div64.h
16795 @@ -39,7 +39,7 @@
16796 __mod; \
16797 })
16798
16799 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16800 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16801 {
16802 union {
16803 u64 v64;
16804 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16805 index ca3347a..1a5082a 100644
16806 --- a/arch/x86/include/asm/elf.h
16807 +++ b/arch/x86/include/asm/elf.h
16808 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16809
16810 #include <asm/vdso.h>
16811
16812 -#ifdef CONFIG_X86_64
16813 -extern unsigned int vdso64_enabled;
16814 -#endif
16815 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16816 extern unsigned int vdso32_enabled;
16817 #endif
16818 @@ -249,7 +246,25 @@ extern int force_personality32;
16819 the loader. We need to make sure that it is out of the way of the program
16820 that it will "exec", and that there is sufficient room for the brk. */
16821
16822 +#ifdef CONFIG_PAX_SEGMEXEC
16823 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16824 +#else
16825 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16826 +#endif
16827 +
16828 +#ifdef CONFIG_PAX_ASLR
16829 +#ifdef CONFIG_X86_32
16830 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16831 +
16832 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16833 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16834 +#else
16835 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16836 +
16837 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16838 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16839 +#endif
16840 +#endif
16841
16842 /* This yields a mask that user programs can use to figure out what
16843 instruction set this CPU supports. This could be done in user space,
16844 @@ -298,17 +313,13 @@ do { \
16845
16846 #define ARCH_DLINFO \
16847 do { \
16848 - if (vdso64_enabled) \
16849 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16850 - (unsigned long __force)current->mm->context.vdso); \
16851 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16852 } while (0)
16853
16854 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16855 #define ARCH_DLINFO_X32 \
16856 do { \
16857 - if (vdso64_enabled) \
16858 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16859 - (unsigned long __force)current->mm->context.vdso); \
16860 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16861 } while (0)
16862
16863 #define AT_SYSINFO 32
16864 @@ -323,10 +334,10 @@ else \
16865
16866 #endif /* !CONFIG_X86_32 */
16867
16868 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16869 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16870
16871 #define VDSO_ENTRY \
16872 - ((unsigned long)current->mm->context.vdso + \
16873 + (current->mm->context.vdso + \
16874 selected_vdso32->sym___kernel_vsyscall)
16875
16876 struct linux_binprm;
16877 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16878 int uses_interp);
16879 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16880
16881 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16882 -#define arch_randomize_brk arch_randomize_brk
16883 -
16884 /*
16885 * True on X86_32 or when emulating IA32 on X86_64
16886 */
16887 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16888 index 77a99ac..39ff7f5 100644
16889 --- a/arch/x86/include/asm/emergency-restart.h
16890 +++ b/arch/x86/include/asm/emergency-restart.h
16891 @@ -1,6 +1,6 @@
16892 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16893 #define _ASM_X86_EMERGENCY_RESTART_H
16894
16895 -extern void machine_emergency_restart(void);
16896 +extern void machine_emergency_restart(void) __noreturn;
16897
16898 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16899 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16900 index 1c7eefe..d0e4702 100644
16901 --- a/arch/x86/include/asm/floppy.h
16902 +++ b/arch/x86/include/asm/floppy.h
16903 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16904 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16905 } fd_routine[] = {
16906 {
16907 - request_dma,
16908 - free_dma,
16909 - get_dma_residue,
16910 - dma_mem_alloc,
16911 - hard_dma_setup
16912 + ._request_dma = request_dma,
16913 + ._free_dma = free_dma,
16914 + ._get_dma_residue = get_dma_residue,
16915 + ._dma_mem_alloc = dma_mem_alloc,
16916 + ._dma_setup = hard_dma_setup
16917 },
16918 {
16919 - vdma_request_dma,
16920 - vdma_nop,
16921 - vdma_get_dma_residue,
16922 - vdma_mem_alloc,
16923 - vdma_dma_setup
16924 + ._request_dma = vdma_request_dma,
16925 + ._free_dma = vdma_nop,
16926 + ._get_dma_residue = vdma_get_dma_residue,
16927 + ._dma_mem_alloc = vdma_mem_alloc,
16928 + ._dma_setup = vdma_dma_setup
16929 }
16930 };
16931
16932 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16933 index e97622f..d0ba77a 100644
16934 --- a/arch/x86/include/asm/fpu-internal.h
16935 +++ b/arch/x86/include/asm/fpu-internal.h
16936 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16937 #define user_insn(insn, output, input...) \
16938 ({ \
16939 int err; \
16940 + pax_open_userland(); \
16941 asm volatile(ASM_STAC "\n" \
16942 - "1:" #insn "\n\t" \
16943 + "1:" \
16944 + __copyuser_seg \
16945 + #insn "\n\t" \
16946 "2: " ASM_CLAC "\n" \
16947 ".section .fixup,\"ax\"\n" \
16948 "3: movl $-1,%[err]\n" \
16949 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16950 _ASM_EXTABLE(1b, 3b) \
16951 : [err] "=r" (err), output \
16952 : "0"(0), input); \
16953 + pax_close_userland(); \
16954 err; \
16955 })
16956
16957 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16958 "fnclex\n\t"
16959 "emms\n\t"
16960 "fildl %P[addr]" /* set F?P to defined value */
16961 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16962 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16963 }
16964
16965 return fpu_restore_checking(&tsk->thread.fpu);
16966 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16967 index b4c1f54..e290c08 100644
16968 --- a/arch/x86/include/asm/futex.h
16969 +++ b/arch/x86/include/asm/futex.h
16970 @@ -12,6 +12,7 @@
16971 #include <asm/smap.h>
16972
16973 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16974 + typecheck(u32 __user *, uaddr); \
16975 asm volatile("\t" ASM_STAC "\n" \
16976 "1:\t" insn "\n" \
16977 "2:\t" ASM_CLAC "\n" \
16978 @@ -20,15 +21,16 @@
16979 "\tjmp\t2b\n" \
16980 "\t.previous\n" \
16981 _ASM_EXTABLE(1b, 3b) \
16982 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16983 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16984 : "i" (-EFAULT), "0" (oparg), "1" (0))
16985
16986 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16987 + typecheck(u32 __user *, uaddr); \
16988 asm volatile("\t" ASM_STAC "\n" \
16989 "1:\tmovl %2, %0\n" \
16990 "\tmovl\t%0, %3\n" \
16991 "\t" insn "\n" \
16992 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16993 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16994 "\tjnz\t1b\n" \
16995 "3:\t" ASM_CLAC "\n" \
16996 "\t.section .fixup,\"ax\"\n" \
16997 @@ -38,7 +40,7 @@
16998 _ASM_EXTABLE(1b, 4b) \
16999 _ASM_EXTABLE(2b, 4b) \
17000 : "=&a" (oldval), "=&r" (ret), \
17001 - "+m" (*uaddr), "=&r" (tem) \
17002 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17003 : "r" (oparg), "i" (-EFAULT), "1" (0))
17004
17005 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17006 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17007
17008 pagefault_disable();
17009
17010 + pax_open_userland();
17011 switch (op) {
17012 case FUTEX_OP_SET:
17013 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17014 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17015 break;
17016 case FUTEX_OP_ADD:
17017 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17018 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17019 uaddr, oparg);
17020 break;
17021 case FUTEX_OP_OR:
17022 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17023 default:
17024 ret = -ENOSYS;
17025 }
17026 + pax_close_userland();
17027
17028 pagefault_enable();
17029
17030 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17031 index 4615906..788c817 100644
17032 --- a/arch/x86/include/asm/hw_irq.h
17033 +++ b/arch/x86/include/asm/hw_irq.h
17034 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17035 extern void enable_IO_APIC(void);
17036
17037 /* Statistics */
17038 -extern atomic_t irq_err_count;
17039 -extern atomic_t irq_mis_count;
17040 +extern atomic_unchecked_t irq_err_count;
17041 +extern atomic_unchecked_t irq_mis_count;
17042
17043 /* EISA */
17044 extern void eisa_set_level_irq(unsigned int irq);
17045 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17046 index ccffa53..3c90c87 100644
17047 --- a/arch/x86/include/asm/i8259.h
17048 +++ b/arch/x86/include/asm/i8259.h
17049 @@ -62,7 +62,7 @@ struct legacy_pic {
17050 void (*init)(int auto_eoi);
17051 int (*irq_pending)(unsigned int irq);
17052 void (*make_irq)(unsigned int irq);
17053 -};
17054 +} __do_const;
17055
17056 extern struct legacy_pic *legacy_pic;
17057 extern struct legacy_pic null_legacy_pic;
17058 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17059 index b8237d8..3e8864e 100644
17060 --- a/arch/x86/include/asm/io.h
17061 +++ b/arch/x86/include/asm/io.h
17062 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17063 "m" (*(volatile type __force *)addr) barrier); }
17064
17065 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17066 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17067 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17068 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17069 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17070
17071 build_mmio_read(__readb, "b", unsigned char, "=q", )
17072 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17073 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17074 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17075 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17076
17077 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17078 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17079 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17080 * this function
17081 */
17082
17083 -static inline phys_addr_t virt_to_phys(volatile void *address)
17084 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17085 {
17086 return __pa(address);
17087 }
17088 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17089 return ioremap_nocache(offset, size);
17090 }
17091
17092 -extern void iounmap(volatile void __iomem *addr);
17093 +extern void iounmap(const volatile void __iomem *addr);
17094
17095 extern void set_iounmap_nonlazy(void);
17096
17097 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17098
17099 #include <linux/vmalloc.h>
17100
17101 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17102 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17103 +{
17104 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17105 +}
17106 +
17107 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17108 +{
17109 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17110 +}
17111 +
17112 /*
17113 * Convert a virtual cached pointer to an uncached pointer
17114 */
17115 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17116 index 0a8b519..80e7d5b 100644
17117 --- a/arch/x86/include/asm/irqflags.h
17118 +++ b/arch/x86/include/asm/irqflags.h
17119 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17120 sti; \
17121 sysexit
17122
17123 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17124 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17125 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17126 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17127 +
17128 #else
17129 #define INTERRUPT_RETURN iret
17130 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17131 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17132 index 4421b5d..8543006 100644
17133 --- a/arch/x86/include/asm/kprobes.h
17134 +++ b/arch/x86/include/asm/kprobes.h
17135 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17136 #define RELATIVEJUMP_SIZE 5
17137 #define RELATIVECALL_OPCODE 0xe8
17138 #define RELATIVE_ADDR_SIZE 4
17139 -#define MAX_STACK_SIZE 64
17140 -#define MIN_STACK_SIZE(ADDR) \
17141 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17142 - THREAD_SIZE - (unsigned long)(ADDR))) \
17143 - ? (MAX_STACK_SIZE) \
17144 - : (((unsigned long)current_thread_info()) + \
17145 - THREAD_SIZE - (unsigned long)(ADDR)))
17146 +#define MAX_STACK_SIZE 64UL
17147 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17148
17149 #define flush_insn_slot(p) do { } while (0)
17150
17151 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17152 index 6ed0c30..74fb6c3 100644
17153 --- a/arch/x86/include/asm/kvm_host.h
17154 +++ b/arch/x86/include/asm/kvm_host.h
17155 @@ -51,6 +51,7 @@
17156 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17157
17158 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17159 +#define CR3_PCID_INVD (1UL << 63)
17160 #define CR4_RESERVED_BITS \
17161 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17162 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17163 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17164 index 4ad6560..75c7bdd 100644
17165 --- a/arch/x86/include/asm/local.h
17166 +++ b/arch/x86/include/asm/local.h
17167 @@ -10,33 +10,97 @@ typedef struct {
17168 atomic_long_t a;
17169 } local_t;
17170
17171 +typedef struct {
17172 + atomic_long_unchecked_t a;
17173 +} local_unchecked_t;
17174 +
17175 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17176
17177 #define local_read(l) atomic_long_read(&(l)->a)
17178 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17179 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17180 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17181
17182 static inline void local_inc(local_t *l)
17183 {
17184 - asm volatile(_ASM_INC "%0"
17185 + asm volatile(_ASM_INC "%0\n"
17186 +
17187 +#ifdef CONFIG_PAX_REFCOUNT
17188 + "jno 0f\n"
17189 + _ASM_DEC "%0\n"
17190 + "int $4\n0:\n"
17191 + _ASM_EXTABLE(0b, 0b)
17192 +#endif
17193 +
17194 + : "+m" (l->a.counter));
17195 +}
17196 +
17197 +static inline void local_inc_unchecked(local_unchecked_t *l)
17198 +{
17199 + asm volatile(_ASM_INC "%0\n"
17200 : "+m" (l->a.counter));
17201 }
17202
17203 static inline void local_dec(local_t *l)
17204 {
17205 - asm volatile(_ASM_DEC "%0"
17206 + asm volatile(_ASM_DEC "%0\n"
17207 +
17208 +#ifdef CONFIG_PAX_REFCOUNT
17209 + "jno 0f\n"
17210 + _ASM_INC "%0\n"
17211 + "int $4\n0:\n"
17212 + _ASM_EXTABLE(0b, 0b)
17213 +#endif
17214 +
17215 + : "+m" (l->a.counter));
17216 +}
17217 +
17218 +static inline void local_dec_unchecked(local_unchecked_t *l)
17219 +{
17220 + asm volatile(_ASM_DEC "%0\n"
17221 : "+m" (l->a.counter));
17222 }
17223
17224 static inline void local_add(long i, local_t *l)
17225 {
17226 - asm volatile(_ASM_ADD "%1,%0"
17227 + asm volatile(_ASM_ADD "%1,%0\n"
17228 +
17229 +#ifdef CONFIG_PAX_REFCOUNT
17230 + "jno 0f\n"
17231 + _ASM_SUB "%1,%0\n"
17232 + "int $4\n0:\n"
17233 + _ASM_EXTABLE(0b, 0b)
17234 +#endif
17235 +
17236 + : "+m" (l->a.counter)
17237 + : "ir" (i));
17238 +}
17239 +
17240 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17241 +{
17242 + asm volatile(_ASM_ADD "%1,%0\n"
17243 : "+m" (l->a.counter)
17244 : "ir" (i));
17245 }
17246
17247 static inline void local_sub(long i, local_t *l)
17248 {
17249 - asm volatile(_ASM_SUB "%1,%0"
17250 + asm volatile(_ASM_SUB "%1,%0\n"
17251 +
17252 +#ifdef CONFIG_PAX_REFCOUNT
17253 + "jno 0f\n"
17254 + _ASM_ADD "%1,%0\n"
17255 + "int $4\n0:\n"
17256 + _ASM_EXTABLE(0b, 0b)
17257 +#endif
17258 +
17259 + : "+m" (l->a.counter)
17260 + : "ir" (i));
17261 +}
17262 +
17263 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17264 +{
17265 + asm volatile(_ASM_SUB "%1,%0\n"
17266 : "+m" (l->a.counter)
17267 : "ir" (i));
17268 }
17269 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17270 */
17271 static inline int local_sub_and_test(long i, local_t *l)
17272 {
17273 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17274 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17275 }
17276
17277 /**
17278 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17279 */
17280 static inline int local_dec_and_test(local_t *l)
17281 {
17282 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17283 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17284 }
17285
17286 /**
17287 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17288 */
17289 static inline int local_inc_and_test(local_t *l)
17290 {
17291 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17292 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17293 }
17294
17295 /**
17296 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17297 */
17298 static inline int local_add_negative(long i, local_t *l)
17299 {
17300 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17301 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17302 }
17303
17304 /**
17305 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17306 static inline long local_add_return(long i, local_t *l)
17307 {
17308 long __i = i;
17309 + asm volatile(_ASM_XADD "%0, %1\n"
17310 +
17311 +#ifdef CONFIG_PAX_REFCOUNT
17312 + "jno 0f\n"
17313 + _ASM_MOV "%0,%1\n"
17314 + "int $4\n0:\n"
17315 + _ASM_EXTABLE(0b, 0b)
17316 +#endif
17317 +
17318 + : "+r" (i), "+m" (l->a.counter)
17319 + : : "memory");
17320 + return i + __i;
17321 +}
17322 +
17323 +/**
17324 + * local_add_return_unchecked - add and return
17325 + * @i: integer value to add
17326 + * @l: pointer to type local_unchecked_t
17327 + *
17328 + * Atomically adds @i to @l and returns @i + @l
17329 + */
17330 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17331 +{
17332 + long __i = i;
17333 asm volatile(_ASM_XADD "%0, %1;"
17334 : "+r" (i), "+m" (l->a.counter)
17335 : : "memory");
17336 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17337
17338 #define local_cmpxchg(l, o, n) \
17339 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17340 +#define local_cmpxchg_unchecked(l, o, n) \
17341 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17342 /* Always has a lock prefix */
17343 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17344
17345 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17346 new file mode 100644
17347 index 0000000..2bfd3ba
17348 --- /dev/null
17349 +++ b/arch/x86/include/asm/mman.h
17350 @@ -0,0 +1,15 @@
17351 +#ifndef _X86_MMAN_H
17352 +#define _X86_MMAN_H
17353 +
17354 +#include <uapi/asm/mman.h>
17355 +
17356 +#ifdef __KERNEL__
17357 +#ifndef __ASSEMBLY__
17358 +#ifdef CONFIG_X86_32
17359 +#define arch_mmap_check i386_mmap_check
17360 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17361 +#endif
17362 +#endif
17363 +#endif
17364 +
17365 +#endif /* X86_MMAN_H */
17366 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17367 index 876e74e..e20bfb1 100644
17368 --- a/arch/x86/include/asm/mmu.h
17369 +++ b/arch/x86/include/asm/mmu.h
17370 @@ -9,7 +9,7 @@
17371 * we put the segment information here.
17372 */
17373 typedef struct {
17374 - void *ldt;
17375 + struct desc_struct *ldt;
17376 int size;
17377
17378 #ifdef CONFIG_X86_64
17379 @@ -18,7 +18,19 @@ typedef struct {
17380 #endif
17381
17382 struct mutex lock;
17383 - void __user *vdso;
17384 + unsigned long vdso;
17385 +
17386 +#ifdef CONFIG_X86_32
17387 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17388 + unsigned long user_cs_base;
17389 + unsigned long user_cs_limit;
17390 +
17391 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17392 + cpumask_t cpu_user_cs_mask;
17393 +#endif
17394 +
17395 +#endif
17396 +#endif
17397 } mm_context_t;
17398
17399 #ifdef CONFIG_SMP
17400 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17401 index 166af2a..648c200 100644
17402 --- a/arch/x86/include/asm/mmu_context.h
17403 +++ b/arch/x86/include/asm/mmu_context.h
17404 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17405
17406 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17407 {
17408 +
17409 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17410 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17411 + unsigned int i;
17412 + pgd_t *pgd;
17413 +
17414 + pax_open_kernel();
17415 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17416 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17417 + set_pgd_batched(pgd+i, native_make_pgd(0));
17418 + pax_close_kernel();
17419 + }
17420 +#endif
17421 +
17422 #ifdef CONFIG_SMP
17423 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17424 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17425 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17426 struct task_struct *tsk)
17427 {
17428 unsigned cpu = smp_processor_id();
17429 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17430 + int tlbstate = TLBSTATE_OK;
17431 +#endif
17432
17433 if (likely(prev != next)) {
17434 #ifdef CONFIG_SMP
17435 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17436 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17437 +#endif
17438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17439 this_cpu_write(cpu_tlbstate.active_mm, next);
17440 #endif
17441 cpumask_set_cpu(cpu, mm_cpumask(next));
17442
17443 /* Re-load page tables */
17444 +#ifdef CONFIG_PAX_PER_CPU_PGD
17445 + pax_open_kernel();
17446 +
17447 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17448 + if (static_cpu_has(X86_FEATURE_PCID))
17449 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17450 + else
17451 +#endif
17452 +
17453 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17454 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17455 + pax_close_kernel();
17456 + 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));
17457 +
17458 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17459 + if (static_cpu_has(X86_FEATURE_PCID)) {
17460 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17461 + u64 descriptor[2];
17462 + descriptor[0] = PCID_USER;
17463 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17464 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17465 + descriptor[0] = PCID_KERNEL;
17466 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17467 + }
17468 + } else {
17469 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17470 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17471 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17472 + else
17473 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17474 + }
17475 + } else
17476 +#endif
17477 +
17478 + load_cr3(get_cpu_pgd(cpu, kernel));
17479 +#else
17480 load_cr3(next->pgd);
17481 +#endif
17482 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17483
17484 /* Stop flush ipis for the previous mm */
17485 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17486 /* Load the LDT, if the LDT is different: */
17487 if (unlikely(prev->context.ldt != next->context.ldt))
17488 load_LDT_nolock(&next->context);
17489 +
17490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17491 + if (!(__supported_pte_mask & _PAGE_NX)) {
17492 + smp_mb__before_atomic();
17493 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17494 + smp_mb__after_atomic();
17495 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17496 + }
17497 +#endif
17498 +
17499 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17500 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17501 + prev->context.user_cs_limit != next->context.user_cs_limit))
17502 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17503 +#ifdef CONFIG_SMP
17504 + else if (unlikely(tlbstate != TLBSTATE_OK))
17505 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17506 +#endif
17507 +#endif
17508 +
17509 }
17510 + else {
17511 +
17512 +#ifdef CONFIG_PAX_PER_CPU_PGD
17513 + pax_open_kernel();
17514 +
17515 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17516 + if (static_cpu_has(X86_FEATURE_PCID))
17517 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17518 + else
17519 +#endif
17520 +
17521 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17522 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17523 + pax_close_kernel();
17524 + 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));
17525 +
17526 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17527 + if (static_cpu_has(X86_FEATURE_PCID)) {
17528 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17529 + u64 descriptor[2];
17530 + descriptor[0] = PCID_USER;
17531 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17532 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17533 + descriptor[0] = PCID_KERNEL;
17534 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17535 + }
17536 + } else {
17537 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17538 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17539 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17540 + else
17541 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17542 + }
17543 + } else
17544 +#endif
17545 +
17546 + load_cr3(get_cpu_pgd(cpu, kernel));
17547 +#endif
17548 +
17549 #ifdef CONFIG_SMP
17550 - else {
17551 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17552 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17553
17554 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17555 * tlb flush IPI delivery. We must reload CR3
17556 * to make sure to use no freed page tables.
17557 */
17558 +
17559 +#ifndef CONFIG_PAX_PER_CPU_PGD
17560 load_cr3(next->pgd);
17561 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17562 +#endif
17563 +
17564 load_LDT_nolock(&next->context);
17565 +
17566 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17567 + if (!(__supported_pte_mask & _PAGE_NX))
17568 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17569 +#endif
17570 +
17571 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17572 +#ifdef CONFIG_PAX_PAGEEXEC
17573 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17574 +#endif
17575 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17576 +#endif
17577 +
17578 }
17579 +#endif
17580 }
17581 -#endif
17582 }
17583
17584 #define activate_mm(prev, next) \
17585 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17586 index e3b7819..b257c64 100644
17587 --- a/arch/x86/include/asm/module.h
17588 +++ b/arch/x86/include/asm/module.h
17589 @@ -5,6 +5,7 @@
17590
17591 #ifdef CONFIG_X86_64
17592 /* X86_64 does not define MODULE_PROC_FAMILY */
17593 +#define MODULE_PROC_FAMILY ""
17594 #elif defined CONFIG_M486
17595 #define MODULE_PROC_FAMILY "486 "
17596 #elif defined CONFIG_M586
17597 @@ -57,8 +58,20 @@
17598 #error unknown processor family
17599 #endif
17600
17601 -#ifdef CONFIG_X86_32
17602 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17603 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17604 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17605 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17606 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17607 +#else
17608 +#define MODULE_PAX_KERNEXEC ""
17609 #endif
17610
17611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17612 +#define MODULE_PAX_UDEREF "UDEREF "
17613 +#else
17614 +#define MODULE_PAX_UDEREF ""
17615 +#endif
17616 +
17617 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17618 +
17619 #endif /* _ASM_X86_MODULE_H */
17620 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17621 index 5f2fc44..106caa6 100644
17622 --- a/arch/x86/include/asm/nmi.h
17623 +++ b/arch/x86/include/asm/nmi.h
17624 @@ -36,26 +36,35 @@ enum {
17625
17626 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17627
17628 +struct nmiaction;
17629 +
17630 +struct nmiwork {
17631 + const struct nmiaction *action;
17632 + u64 max_duration;
17633 + struct irq_work irq_work;
17634 +};
17635 +
17636 struct nmiaction {
17637 struct list_head list;
17638 nmi_handler_t handler;
17639 - u64 max_duration;
17640 - struct irq_work irq_work;
17641 unsigned long flags;
17642 const char *name;
17643 -};
17644 + struct nmiwork *work;
17645 +} __do_const;
17646
17647 #define register_nmi_handler(t, fn, fg, n, init...) \
17648 ({ \
17649 - static struct nmiaction init fn##_na = { \
17650 + static struct nmiwork fn##_nw; \
17651 + static const struct nmiaction init fn##_na = { \
17652 .handler = (fn), \
17653 .name = (n), \
17654 .flags = (fg), \
17655 + .work = &fn##_nw, \
17656 }; \
17657 __register_nmi_handler((t), &fn##_na); \
17658 })
17659
17660 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17661 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17662
17663 void unregister_nmi_handler(unsigned int, const char *);
17664
17665 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17666 index 802dde3..9183e68 100644
17667 --- a/arch/x86/include/asm/page.h
17668 +++ b/arch/x86/include/asm/page.h
17669 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17670 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17671
17672 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17673 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17674
17675 #define __boot_va(x) __va(x)
17676 #define __boot_pa(x) __pa(x)
17677 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17678 * virt_to_page(kaddr) returns a valid pointer if and only if
17679 * virt_addr_valid(kaddr) returns true.
17680 */
17681 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17682 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17683 extern bool __virt_addr_valid(unsigned long kaddr);
17684 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17685
17686 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17687 +#define virt_to_page(kaddr) \
17688 + ({ \
17689 + const void *__kaddr = (const void *)(kaddr); \
17690 + BUG_ON(!virt_addr_valid(__kaddr)); \
17691 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17692 + })
17693 +#else
17694 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17695 +#endif
17696 +
17697 #endif /* __ASSEMBLY__ */
17698
17699 #include <asm-generic/memory_model.h>
17700 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17701 index f408caf..4a0455e 100644
17702 --- a/arch/x86/include/asm/page_64.h
17703 +++ b/arch/x86/include/asm/page_64.h
17704 @@ -7,9 +7,9 @@
17705
17706 /* duplicated to the one in bootmem.h */
17707 extern unsigned long max_pfn;
17708 -extern unsigned long phys_base;
17709 +extern const unsigned long phys_base;
17710
17711 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17712 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17713 {
17714 unsigned long y = x - __START_KERNEL_map;
17715
17716 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17717 index cd6e1610..70f4418 100644
17718 --- a/arch/x86/include/asm/paravirt.h
17719 +++ b/arch/x86/include/asm/paravirt.h
17720 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17721 return (pmd_t) { ret };
17722 }
17723
17724 -static inline pmdval_t pmd_val(pmd_t pmd)
17725 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17726 {
17727 pmdval_t ret;
17728
17729 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17730 val);
17731 }
17732
17733 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17734 +{
17735 + pgdval_t val = native_pgd_val(pgd);
17736 +
17737 + if (sizeof(pgdval_t) > sizeof(long))
17738 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17739 + val, (u64)val >> 32);
17740 + else
17741 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17742 + val);
17743 +}
17744 +
17745 static inline void pgd_clear(pgd_t *pgdp)
17746 {
17747 set_pgd(pgdp, __pgd(0));
17748 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17749 pv_mmu_ops.set_fixmap(idx, phys, flags);
17750 }
17751
17752 +#ifdef CONFIG_PAX_KERNEXEC
17753 +static inline unsigned long pax_open_kernel(void)
17754 +{
17755 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17756 +}
17757 +
17758 +static inline unsigned long pax_close_kernel(void)
17759 +{
17760 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17761 +}
17762 +#else
17763 +static inline unsigned long pax_open_kernel(void) { return 0; }
17764 +static inline unsigned long pax_close_kernel(void) { return 0; }
17765 +#endif
17766 +
17767 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17768
17769 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17770 @@ -906,7 +933,7 @@ extern void default_banner(void);
17771
17772 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17773 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17774 -#define PARA_INDIRECT(addr) *%cs:addr
17775 +#define PARA_INDIRECT(addr) *%ss:addr
17776 #endif
17777
17778 #define INTERRUPT_RETURN \
17779 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17780 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17781 CLBR_NONE, \
17782 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17783 +
17784 +#define GET_CR0_INTO_RDI \
17785 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17786 + mov %rax,%rdi
17787 +
17788 +#define SET_RDI_INTO_CR0 \
17789 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17790 +
17791 +#define GET_CR3_INTO_RDI \
17792 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17793 + mov %rax,%rdi
17794 +
17795 +#define SET_RDI_INTO_CR3 \
17796 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17797 +
17798 #endif /* CONFIG_X86_32 */
17799
17800 #endif /* __ASSEMBLY__ */
17801 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17802 index 7549b8b..f0edfda 100644
17803 --- a/arch/x86/include/asm/paravirt_types.h
17804 +++ b/arch/x86/include/asm/paravirt_types.h
17805 @@ -84,7 +84,7 @@ struct pv_init_ops {
17806 */
17807 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17808 unsigned long addr, unsigned len);
17809 -};
17810 +} __no_const __no_randomize_layout;
17811
17812
17813 struct pv_lazy_ops {
17814 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17815 void (*enter)(void);
17816 void (*leave)(void);
17817 void (*flush)(void);
17818 -};
17819 +} __no_randomize_layout;
17820
17821 struct pv_time_ops {
17822 unsigned long long (*sched_clock)(void);
17823 unsigned long long (*steal_clock)(int cpu);
17824 unsigned long (*get_tsc_khz)(void);
17825 -};
17826 +} __no_const __no_randomize_layout;
17827
17828 struct pv_cpu_ops {
17829 /* hooks for various privileged instructions */
17830 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17831
17832 void (*start_context_switch)(struct task_struct *prev);
17833 void (*end_context_switch)(struct task_struct *next);
17834 -};
17835 +} __no_const __no_randomize_layout;
17836
17837 struct pv_irq_ops {
17838 /*
17839 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17840 #ifdef CONFIG_X86_64
17841 void (*adjust_exception_frame)(void);
17842 #endif
17843 -};
17844 +} __no_randomize_layout;
17845
17846 struct pv_apic_ops {
17847 #ifdef CONFIG_X86_LOCAL_APIC
17848 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17849 unsigned long start_eip,
17850 unsigned long start_esp);
17851 #endif
17852 -};
17853 +} __no_const __no_randomize_layout;
17854
17855 struct pv_mmu_ops {
17856 unsigned long (*read_cr2)(void);
17857 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17858 struct paravirt_callee_save make_pud;
17859
17860 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17861 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17862 #endif /* PAGETABLE_LEVELS == 4 */
17863 #endif /* PAGETABLE_LEVELS >= 3 */
17864
17865 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17866 an mfn. We can tell which is which from the index. */
17867 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17868 phys_addr_t phys, pgprot_t flags);
17869 -};
17870 +
17871 +#ifdef CONFIG_PAX_KERNEXEC
17872 + unsigned long (*pax_open_kernel)(void);
17873 + unsigned long (*pax_close_kernel)(void);
17874 +#endif
17875 +
17876 +} __no_randomize_layout;
17877
17878 struct arch_spinlock;
17879 #ifdef CONFIG_SMP
17880 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17881 struct pv_lock_ops {
17882 struct paravirt_callee_save lock_spinning;
17883 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17884 -};
17885 +} __no_randomize_layout;
17886
17887 /* This contains all the paravirt structures: we get a convenient
17888 * number for each function using the offset which we use to indicate
17889 - * what to patch. */
17890 + * what to patch.
17891 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17892 + */
17893 +
17894 struct paravirt_patch_template {
17895 struct pv_init_ops pv_init_ops;
17896 struct pv_time_ops pv_time_ops;
17897 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17898 struct pv_apic_ops pv_apic_ops;
17899 struct pv_mmu_ops pv_mmu_ops;
17900 struct pv_lock_ops pv_lock_ops;
17901 -};
17902 +} __no_randomize_layout;
17903
17904 extern struct pv_info pv_info;
17905 extern struct pv_init_ops pv_init_ops;
17906 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17907 index c4412e9..90e88c5 100644
17908 --- a/arch/x86/include/asm/pgalloc.h
17909 +++ b/arch/x86/include/asm/pgalloc.h
17910 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17911 pmd_t *pmd, pte_t *pte)
17912 {
17913 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17914 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17915 +}
17916 +
17917 +static inline void pmd_populate_user(struct mm_struct *mm,
17918 + pmd_t *pmd, pte_t *pte)
17919 +{
17920 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17921 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17922 }
17923
17924 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17925
17926 #ifdef CONFIG_X86_PAE
17927 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17928 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17929 +{
17930 + pud_populate(mm, pudp, pmd);
17931 +}
17932 #else /* !CONFIG_X86_PAE */
17933 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17934 {
17935 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17936 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17937 }
17938 +
17939 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17940 +{
17941 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17942 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17943 +}
17944 #endif /* CONFIG_X86_PAE */
17945
17946 #if PAGETABLE_LEVELS > 3
17947 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17948 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17949 }
17950
17951 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17952 +{
17953 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17954 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17955 +}
17956 +
17957 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17958 {
17959 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17960 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17961 index 206a87f..1623b06 100644
17962 --- a/arch/x86/include/asm/pgtable-2level.h
17963 +++ b/arch/x86/include/asm/pgtable-2level.h
17964 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17965
17966 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17967 {
17968 + pax_open_kernel();
17969 *pmdp = pmd;
17970 + pax_close_kernel();
17971 }
17972
17973 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17974 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17975 index 81bb91b..9392125 100644
17976 --- a/arch/x86/include/asm/pgtable-3level.h
17977 +++ b/arch/x86/include/asm/pgtable-3level.h
17978 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17979
17980 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17981 {
17982 + pax_open_kernel();
17983 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17984 + pax_close_kernel();
17985 }
17986
17987 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17988 {
17989 + pax_open_kernel();
17990 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17991 + pax_close_kernel();
17992 }
17993
17994 /*
17995 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17996 index aa97a07..5c53c32 100644
17997 --- a/arch/x86/include/asm/pgtable.h
17998 +++ b/arch/x86/include/asm/pgtable.h
17999 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18000
18001 #ifndef __PAGETABLE_PUD_FOLDED
18002 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18003 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18004 #define pgd_clear(pgd) native_pgd_clear(pgd)
18005 #endif
18006
18007 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18008
18009 #define arch_end_context_switch(prev) do {} while(0)
18010
18011 +#define pax_open_kernel() native_pax_open_kernel()
18012 +#define pax_close_kernel() native_pax_close_kernel()
18013 #endif /* CONFIG_PARAVIRT */
18014
18015 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18016 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18017 +
18018 +#ifdef CONFIG_PAX_KERNEXEC
18019 +static inline unsigned long native_pax_open_kernel(void)
18020 +{
18021 + unsigned long cr0;
18022 +
18023 + preempt_disable();
18024 + barrier();
18025 + cr0 = read_cr0() ^ X86_CR0_WP;
18026 + BUG_ON(cr0 & X86_CR0_WP);
18027 + write_cr0(cr0);
18028 + barrier();
18029 + return cr0 ^ X86_CR0_WP;
18030 +}
18031 +
18032 +static inline unsigned long native_pax_close_kernel(void)
18033 +{
18034 + unsigned long cr0;
18035 +
18036 + barrier();
18037 + cr0 = read_cr0() ^ X86_CR0_WP;
18038 + BUG_ON(!(cr0 & X86_CR0_WP));
18039 + write_cr0(cr0);
18040 + barrier();
18041 + preempt_enable_no_resched();
18042 + return cr0 ^ X86_CR0_WP;
18043 +}
18044 +#else
18045 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18046 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18047 +#endif
18048 +
18049 /*
18050 * The following only work if pte_present() is true.
18051 * Undefined behaviour if not..
18052 */
18053 +static inline int pte_user(pte_t pte)
18054 +{
18055 + return pte_val(pte) & _PAGE_USER;
18056 +}
18057 +
18058 static inline int pte_dirty(pte_t pte)
18059 {
18060 return pte_flags(pte) & _PAGE_DIRTY;
18061 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18062 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18063 }
18064
18065 +static inline unsigned long pgd_pfn(pgd_t pgd)
18066 +{
18067 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18068 +}
18069 +
18070 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18071
18072 static inline int pmd_large(pmd_t pte)
18073 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18074 return pte_clear_flags(pte, _PAGE_RW);
18075 }
18076
18077 +static inline pte_t pte_mkread(pte_t pte)
18078 +{
18079 + return __pte(pte_val(pte) | _PAGE_USER);
18080 +}
18081 +
18082 static inline pte_t pte_mkexec(pte_t pte)
18083 {
18084 - return pte_clear_flags(pte, _PAGE_NX);
18085 +#ifdef CONFIG_X86_PAE
18086 + if (__supported_pte_mask & _PAGE_NX)
18087 + return pte_clear_flags(pte, _PAGE_NX);
18088 + else
18089 +#endif
18090 + return pte_set_flags(pte, _PAGE_USER);
18091 +}
18092 +
18093 +static inline pte_t pte_exprotect(pte_t pte)
18094 +{
18095 +#ifdef CONFIG_X86_PAE
18096 + if (__supported_pte_mask & _PAGE_NX)
18097 + return pte_set_flags(pte, _PAGE_NX);
18098 + else
18099 +#endif
18100 + return pte_clear_flags(pte, _PAGE_USER);
18101 }
18102
18103 static inline pte_t pte_mkdirty(pte_t pte)
18104 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18105 #endif
18106
18107 #ifndef __ASSEMBLY__
18108 +
18109 +#ifdef CONFIG_PAX_PER_CPU_PGD
18110 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18111 +enum cpu_pgd_type {kernel = 0, user = 1};
18112 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18113 +{
18114 + return cpu_pgd[cpu][type];
18115 +}
18116 +#endif
18117 +
18118 #include <linux/mm_types.h>
18119 #include <linux/mmdebug.h>
18120 #include <linux/log2.h>
18121 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18122 * Currently stuck as a macro due to indirect forward reference to
18123 * linux/mmzone.h's __section_mem_map_addr() definition:
18124 */
18125 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18126 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18127
18128 /* Find an entry in the second-level page table.. */
18129 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18130 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18131 * Currently stuck as a macro due to indirect forward reference to
18132 * linux/mmzone.h's __section_mem_map_addr() definition:
18133 */
18134 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18135 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18136
18137 /* to find an entry in a page-table-directory. */
18138 static inline unsigned long pud_index(unsigned long address)
18139 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18140
18141 static inline int pgd_bad(pgd_t pgd)
18142 {
18143 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18144 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18145 }
18146
18147 static inline int pgd_none(pgd_t pgd)
18148 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18149 * pgd_offset() returns a (pgd_t *)
18150 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18151 */
18152 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18153 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18154 +
18155 +#ifdef CONFIG_PAX_PER_CPU_PGD
18156 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18157 +#endif
18158 +
18159 /*
18160 * a shortcut which implies the use of the kernel's pgd, instead
18161 * of a process's
18162 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18163 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18164 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18165
18166 +#ifdef CONFIG_X86_32
18167 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18168 +#else
18169 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18170 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18171 +
18172 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18173 +#ifdef __ASSEMBLY__
18174 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18175 +#else
18176 +extern unsigned long pax_user_shadow_base;
18177 +extern pgdval_t clone_pgd_mask;
18178 +#endif
18179 +#endif
18180 +
18181 +#endif
18182 +
18183 #ifndef __ASSEMBLY__
18184
18185 extern int direct_gbpages;
18186 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18187 * dst and src can be on the same page, but the range must not overlap,
18188 * and must not cross a page boundary.
18189 */
18190 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18191 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18192 {
18193 - memcpy(dst, src, count * sizeof(pgd_t));
18194 + pax_open_kernel();
18195 + while (count--)
18196 + *dst++ = *src++;
18197 + pax_close_kernel();
18198 }
18199
18200 +#ifdef CONFIG_PAX_PER_CPU_PGD
18201 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18202 +#endif
18203 +
18204 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18205 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18206 +#else
18207 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18208 +#endif
18209 +
18210 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18211 static inline int page_level_shift(enum pg_level level)
18212 {
18213 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18214 index b6c0b40..3535d47 100644
18215 --- a/arch/x86/include/asm/pgtable_32.h
18216 +++ b/arch/x86/include/asm/pgtable_32.h
18217 @@ -25,9 +25,6 @@
18218 struct mm_struct;
18219 struct vm_area_struct;
18220
18221 -extern pgd_t swapper_pg_dir[1024];
18222 -extern pgd_t initial_page_table[1024];
18223 -
18224 static inline void pgtable_cache_init(void) { }
18225 static inline void check_pgt_cache(void) { }
18226 void paging_init(void);
18227 @@ -45,6 +42,12 @@ void paging_init(void);
18228 # include <asm/pgtable-2level.h>
18229 #endif
18230
18231 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18232 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18233 +#ifdef CONFIG_X86_PAE
18234 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18235 +#endif
18236 +
18237 #if defined(CONFIG_HIGHPTE)
18238 #define pte_offset_map(dir, address) \
18239 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18240 @@ -59,12 +62,17 @@ void paging_init(void);
18241 /* Clear a kernel PTE and flush it from the TLB */
18242 #define kpte_clear_flush(ptep, vaddr) \
18243 do { \
18244 + pax_open_kernel(); \
18245 pte_clear(&init_mm, (vaddr), (ptep)); \
18246 + pax_close_kernel(); \
18247 __flush_tlb_one((vaddr)); \
18248 } while (0)
18249
18250 #endif /* !__ASSEMBLY__ */
18251
18252 +#define HAVE_ARCH_UNMAPPED_AREA
18253 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18254 +
18255 /*
18256 * kern_addr_valid() is (1) for FLATMEM and (0) for
18257 * SPARSEMEM and DISCONTIGMEM
18258 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18259 index ed5903b..c7fe163 100644
18260 --- a/arch/x86/include/asm/pgtable_32_types.h
18261 +++ b/arch/x86/include/asm/pgtable_32_types.h
18262 @@ -8,7 +8,7 @@
18263 */
18264 #ifdef CONFIG_X86_PAE
18265 # include <asm/pgtable-3level_types.h>
18266 -# define PMD_SIZE (1UL << PMD_SHIFT)
18267 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18268 # define PMD_MASK (~(PMD_SIZE - 1))
18269 #else
18270 # include <asm/pgtable-2level_types.h>
18271 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18272 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18273 #endif
18274
18275 +#ifdef CONFIG_PAX_KERNEXEC
18276 +#ifndef __ASSEMBLY__
18277 +extern unsigned char MODULES_EXEC_VADDR[];
18278 +extern unsigned char MODULES_EXEC_END[];
18279 +#endif
18280 +#include <asm/boot.h>
18281 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18282 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18283 +#else
18284 +#define ktla_ktva(addr) (addr)
18285 +#define ktva_ktla(addr) (addr)
18286 +#endif
18287 +
18288 #define MODULES_VADDR VMALLOC_START
18289 #define MODULES_END VMALLOC_END
18290 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18291 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18292 index 4572b2f..4430113 100644
18293 --- a/arch/x86/include/asm/pgtable_64.h
18294 +++ b/arch/x86/include/asm/pgtable_64.h
18295 @@ -16,11 +16,16 @@
18296
18297 extern pud_t level3_kernel_pgt[512];
18298 extern pud_t level3_ident_pgt[512];
18299 +extern pud_t level3_vmalloc_start_pgt[512];
18300 +extern pud_t level3_vmalloc_end_pgt[512];
18301 +extern pud_t level3_vmemmap_pgt[512];
18302 +extern pud_t level2_vmemmap_pgt[512];
18303 extern pmd_t level2_kernel_pgt[512];
18304 extern pmd_t level2_fixmap_pgt[512];
18305 -extern pmd_t level2_ident_pgt[512];
18306 +extern pmd_t level2_ident_pgt[512*2];
18307 extern pte_t level1_fixmap_pgt[512];
18308 -extern pgd_t init_level4_pgt[];
18309 +extern pte_t level1_vsyscall_pgt[512];
18310 +extern pgd_t init_level4_pgt[512];
18311
18312 #define swapper_pg_dir init_level4_pgt
18313
18314 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18315
18316 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18317 {
18318 + pax_open_kernel();
18319 *pmdp = pmd;
18320 + pax_close_kernel();
18321 }
18322
18323 static inline void native_pmd_clear(pmd_t *pmd)
18324 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18325
18326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18327 {
18328 + pax_open_kernel();
18329 *pudp = pud;
18330 + pax_close_kernel();
18331 }
18332
18333 static inline void native_pud_clear(pud_t *pud)
18334 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18335
18336 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18337 {
18338 + pax_open_kernel();
18339 + *pgdp = pgd;
18340 + pax_close_kernel();
18341 +}
18342 +
18343 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18344 +{
18345 *pgdp = pgd;
18346 }
18347
18348 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18349 index 7166e25..baaa6fe 100644
18350 --- a/arch/x86/include/asm/pgtable_64_types.h
18351 +++ b/arch/x86/include/asm/pgtable_64_types.h
18352 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18353 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18354 #define MODULES_END _AC(0xffffffffff000000, UL)
18355 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18356 +#define MODULES_EXEC_VADDR MODULES_VADDR
18357 +#define MODULES_EXEC_END MODULES_END
18358 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18359 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18360
18361 +#define ktla_ktva(addr) (addr)
18362 +#define ktva_ktla(addr) (addr)
18363 +
18364 #define EARLY_DYNAMIC_PAGE_TABLES 64
18365
18366 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18367 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18368 index 0778964..0e94758 100644
18369 --- a/arch/x86/include/asm/pgtable_types.h
18370 +++ b/arch/x86/include/asm/pgtable_types.h
18371 @@ -110,8 +110,10 @@
18372
18373 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18374 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18375 -#else
18376 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18377 #define _PAGE_NX (_AT(pteval_t, 0))
18378 +#else
18379 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18380 #endif
18381
18382 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18383 @@ -150,6 +152,9 @@
18384 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18385 _PAGE_ACCESSED)
18386
18387 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18388 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18389 +
18390 #define __PAGE_KERNEL_EXEC \
18391 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18392 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18393 @@ -160,7 +165,7 @@
18394 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18395 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18396 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18397 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18398 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18399 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18400 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18401 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18402 @@ -217,7 +222,7 @@
18403 #ifdef CONFIG_X86_64
18404 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18405 #else
18406 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18407 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18408 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18409 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18410 #endif
18411 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18412 {
18413 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18414 }
18415 +#endif
18416
18417 +#if PAGETABLE_LEVELS == 3
18418 +#include <asm-generic/pgtable-nopud.h>
18419 +#endif
18420 +
18421 +#if PAGETABLE_LEVELS == 2
18422 +#include <asm-generic/pgtable-nopmd.h>
18423 +#endif
18424 +
18425 +#ifndef __ASSEMBLY__
18426 #if PAGETABLE_LEVELS > 3
18427 typedef struct { pudval_t pud; } pud_t;
18428
18429 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18430 return pud.pud;
18431 }
18432 #else
18433 -#include <asm-generic/pgtable-nopud.h>
18434 -
18435 static inline pudval_t native_pud_val(pud_t pud)
18436 {
18437 return native_pgd_val(pud.pgd);
18438 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18439 return pmd.pmd;
18440 }
18441 #else
18442 -#include <asm-generic/pgtable-nopmd.h>
18443 -
18444 static inline pmdval_t native_pmd_val(pmd_t pmd)
18445 {
18446 return native_pgd_val(pmd.pud.pgd);
18447 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18448
18449 extern pteval_t __supported_pte_mask;
18450 extern void set_nx(void);
18451 -extern int nx_enabled;
18452
18453 #define pgprot_writecombine pgprot_writecombine
18454 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18455 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18456 index 4008734..48f0d81 100644
18457 --- a/arch/x86/include/asm/preempt.h
18458 +++ b/arch/x86/include/asm/preempt.h
18459 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18460 */
18461 static __always_inline bool __preempt_count_dec_and_test(void)
18462 {
18463 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18464 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18465 }
18466
18467 /*
18468 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18469 index eb71ec7..f06532a 100644
18470 --- a/arch/x86/include/asm/processor.h
18471 +++ b/arch/x86/include/asm/processor.h
18472 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18473 /* Index into per_cpu list: */
18474 u16 cpu_index;
18475 u32 microcode;
18476 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18477 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18478
18479 #define X86_VENDOR_INTEL 0
18480 #define X86_VENDOR_CYRIX 1
18481 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18482 : "memory");
18483 }
18484
18485 +/* invpcid (%rdx),%rax */
18486 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18487 +
18488 +#define INVPCID_SINGLE_ADDRESS 0UL
18489 +#define INVPCID_SINGLE_CONTEXT 1UL
18490 +#define INVPCID_ALL_GLOBAL 2UL
18491 +#define INVPCID_ALL_NONGLOBAL 3UL
18492 +
18493 +#define PCID_KERNEL 0UL
18494 +#define PCID_USER 1UL
18495 +#define PCID_NOFLUSH (1UL << 63)
18496 +
18497 static inline void load_cr3(pgd_t *pgdir)
18498 {
18499 - write_cr3(__pa(pgdir));
18500 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18501 }
18502
18503 #ifdef CONFIG_X86_32
18504 @@ -282,7 +294,7 @@ struct tss_struct {
18505
18506 } ____cacheline_aligned;
18507
18508 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18509 +extern struct tss_struct init_tss[NR_CPUS];
18510
18511 /*
18512 * Save the original ist values for checking stack pointers during debugging
18513 @@ -478,6 +490,7 @@ struct thread_struct {
18514 unsigned short ds;
18515 unsigned short fsindex;
18516 unsigned short gsindex;
18517 + unsigned short ss;
18518 #endif
18519 #ifdef CONFIG_X86_32
18520 unsigned long ip;
18521 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18522 extern unsigned long mmu_cr4_features;
18523 extern u32 *trampoline_cr4_features;
18524
18525 -static inline void set_in_cr4(unsigned long mask)
18526 -{
18527 - unsigned long cr4;
18528 -
18529 - mmu_cr4_features |= mask;
18530 - if (trampoline_cr4_features)
18531 - *trampoline_cr4_features = mmu_cr4_features;
18532 - cr4 = read_cr4();
18533 - cr4 |= mask;
18534 - write_cr4(cr4);
18535 -}
18536 -
18537 -static inline void clear_in_cr4(unsigned long mask)
18538 -{
18539 - unsigned long cr4;
18540 -
18541 - mmu_cr4_features &= ~mask;
18542 - if (trampoline_cr4_features)
18543 - *trampoline_cr4_features = mmu_cr4_features;
18544 - cr4 = read_cr4();
18545 - cr4 &= ~mask;
18546 - write_cr4(cr4);
18547 -}
18548 +extern void set_in_cr4(unsigned long mask);
18549 +extern void clear_in_cr4(unsigned long mask);
18550
18551 typedef struct {
18552 unsigned long seg;
18553 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18554 */
18555 #define TASK_SIZE PAGE_OFFSET
18556 #define TASK_SIZE_MAX TASK_SIZE
18557 +
18558 +#ifdef CONFIG_PAX_SEGMEXEC
18559 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18560 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18561 +#else
18562 #define STACK_TOP TASK_SIZE
18563 -#define STACK_TOP_MAX STACK_TOP
18564 +#endif
18565 +
18566 +#define STACK_TOP_MAX TASK_SIZE
18567
18568 #define INIT_THREAD { \
18569 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18570 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18571 .vm86_info = NULL, \
18572 .sysenter_cs = __KERNEL_CS, \
18573 .io_bitmap_ptr = NULL, \
18574 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18575 */
18576 #define INIT_TSS { \
18577 .x86_tss = { \
18578 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18579 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18580 .ss0 = __KERNEL_DS, \
18581 .ss1 = __KERNEL_CS, \
18582 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18583 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18584 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18585
18586 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18587 -#define KSTK_TOP(info) \
18588 -({ \
18589 - unsigned long *__ptr = (unsigned long *)(info); \
18590 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18591 -})
18592 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18593
18594 /*
18595 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18596 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18597 #define task_pt_regs(task) \
18598 ({ \
18599 struct pt_regs *__regs__; \
18600 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18601 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18602 __regs__ - 1; \
18603 })
18604
18605 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18606 /*
18607 * User space process size. 47bits minus one guard page.
18608 */
18609 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18610 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18611
18612 /* This decides where the kernel will search for a free chunk of vm
18613 * space during mmap's.
18614 */
18615 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18616 - 0xc0000000 : 0xFFFFe000)
18617 + 0xc0000000 : 0xFFFFf000)
18618
18619 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18620 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18621 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18622 #define STACK_TOP_MAX TASK_SIZE_MAX
18623
18624 #define INIT_THREAD { \
18625 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18626 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18627 }
18628
18629 #define INIT_TSS { \
18630 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18631 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18632 }
18633
18634 /*
18635 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18636 */
18637 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18638
18639 +#ifdef CONFIG_PAX_SEGMEXEC
18640 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18641 +#endif
18642 +
18643 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18644
18645 /* Get/set a process' ability to use the timestamp counter instruction */
18646 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18647 return 0;
18648 }
18649
18650 -extern unsigned long arch_align_stack(unsigned long sp);
18651 +#define arch_align_stack(x) ((x) & ~0xfUL)
18652 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18653
18654 void default_idle(void);
18655 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18656 #define xen_set_default_idle 0
18657 #endif
18658
18659 -void stop_this_cpu(void *dummy);
18660 +void stop_this_cpu(void *dummy) __noreturn;
18661 void df_debug(struct pt_regs *regs, long error_code);
18662 #endif /* _ASM_X86_PROCESSOR_H */
18663 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18664 index 86fc2bb..bd5049a 100644
18665 --- a/arch/x86/include/asm/ptrace.h
18666 +++ b/arch/x86/include/asm/ptrace.h
18667 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18668 }
18669
18670 /*
18671 - * user_mode_vm(regs) determines whether a register set came from user mode.
18672 + * user_mode(regs) determines whether a register set came from user mode.
18673 * This is true if V8086 mode was enabled OR if the register set was from
18674 * protected mode with RPL-3 CS value. This tricky test checks that with
18675 * one comparison. Many places in the kernel can bypass this full check
18676 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18677 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18678 + * be used.
18679 */
18680 -static inline int user_mode(struct pt_regs *regs)
18681 +static inline int user_mode_novm(struct pt_regs *regs)
18682 {
18683 #ifdef CONFIG_X86_32
18684 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18685 #else
18686 - return !!(regs->cs & 3);
18687 + return !!(regs->cs & SEGMENT_RPL_MASK);
18688 #endif
18689 }
18690
18691 -static inline int user_mode_vm(struct pt_regs *regs)
18692 +static inline int user_mode(struct pt_regs *regs)
18693 {
18694 #ifdef CONFIG_X86_32
18695 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18696 USER_RPL;
18697 #else
18698 - return user_mode(regs);
18699 + return user_mode_novm(regs);
18700 #endif
18701 }
18702
18703 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18704 #ifdef CONFIG_X86_64
18705 static inline bool user_64bit_mode(struct pt_regs *regs)
18706 {
18707 + unsigned long cs = regs->cs & 0xffff;
18708 #ifndef CONFIG_PARAVIRT
18709 /*
18710 * On non-paravirt systems, this is the only long mode CPL 3
18711 * selector. We do not allow long mode selectors in the LDT.
18712 */
18713 - return regs->cs == __USER_CS;
18714 + return cs == __USER_CS;
18715 #else
18716 /* Headers are too twisted for this to go in paravirt.h. */
18717 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18718 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18719 #endif
18720 }
18721
18722 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18723 * Traps from the kernel do not save sp and ss.
18724 * Use the helper function to retrieve sp.
18725 */
18726 - if (offset == offsetof(struct pt_regs, sp) &&
18727 - regs->cs == __KERNEL_CS)
18728 - return kernel_stack_pointer(regs);
18729 + if (offset == offsetof(struct pt_regs, sp)) {
18730 + unsigned long cs = regs->cs & 0xffff;
18731 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18732 + return kernel_stack_pointer(regs);
18733 + }
18734 #endif
18735 return *(unsigned long *)((unsigned long)regs + offset);
18736 }
18737 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18738 index ae0e241..e80b10b 100644
18739 --- a/arch/x86/include/asm/qrwlock.h
18740 +++ b/arch/x86/include/asm/qrwlock.h
18741 @@ -7,8 +7,8 @@
18742 #define queue_write_unlock queue_write_unlock
18743 static inline void queue_write_unlock(struct qrwlock *lock)
18744 {
18745 - barrier();
18746 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18747 + barrier();
18748 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18749 }
18750 #endif
18751
18752 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18753 index 9c6b890..5305f53 100644
18754 --- a/arch/x86/include/asm/realmode.h
18755 +++ b/arch/x86/include/asm/realmode.h
18756 @@ -22,16 +22,14 @@ struct real_mode_header {
18757 #endif
18758 /* APM/BIOS reboot */
18759 u32 machine_real_restart_asm;
18760 -#ifdef CONFIG_X86_64
18761 u32 machine_real_restart_seg;
18762 -#endif
18763 };
18764
18765 /* This must match data at trampoline_32/64.S */
18766 struct trampoline_header {
18767 #ifdef CONFIG_X86_32
18768 u32 start;
18769 - u16 gdt_pad;
18770 + u16 boot_cs;
18771 u16 gdt_limit;
18772 u32 gdt_base;
18773 #else
18774 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18775 index a82c4f1..ac45053 100644
18776 --- a/arch/x86/include/asm/reboot.h
18777 +++ b/arch/x86/include/asm/reboot.h
18778 @@ -6,13 +6,13 @@
18779 struct pt_regs;
18780
18781 struct machine_ops {
18782 - void (*restart)(char *cmd);
18783 - void (*halt)(void);
18784 - void (*power_off)(void);
18785 + void (* __noreturn restart)(char *cmd);
18786 + void (* __noreturn halt)(void);
18787 + void (* __noreturn power_off)(void);
18788 void (*shutdown)(void);
18789 void (*crash_shutdown)(struct pt_regs *);
18790 - void (*emergency_restart)(void);
18791 -};
18792 + void (* __noreturn emergency_restart)(void);
18793 +} __no_const;
18794
18795 extern struct machine_ops machine_ops;
18796
18797 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18798 index 8f7866a..e442f20 100644
18799 --- a/arch/x86/include/asm/rmwcc.h
18800 +++ b/arch/x86/include/asm/rmwcc.h
18801 @@ -3,7 +3,34 @@
18802
18803 #ifdef CC_HAVE_ASM_GOTO
18804
18805 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18806 +#ifdef CONFIG_PAX_REFCOUNT
18807 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18808 +do { \
18809 + asm_volatile_goto (fullop \
18810 + ";jno 0f\n" \
18811 + fullantiop \
18812 + ";int $4\n0:\n" \
18813 + _ASM_EXTABLE(0b, 0b) \
18814 + ";j" cc " %l[cc_label]" \
18815 + : : "m" (var), ## __VA_ARGS__ \
18816 + : "memory" : cc_label); \
18817 + return 0; \
18818 +cc_label: \
18819 + return 1; \
18820 +} while (0)
18821 +#else
18822 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18823 +do { \
18824 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18825 + : : "m" (var), ## __VA_ARGS__ \
18826 + : "memory" : cc_label); \
18827 + return 0; \
18828 +cc_label: \
18829 + return 1; \
18830 +} while (0)
18831 +#endif
18832 +
18833 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18834 do { \
18835 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18836 : : "m" (var), ## __VA_ARGS__ \
18837 @@ -13,15 +40,46 @@ cc_label: \
18838 return 1; \
18839 } while (0)
18840
18841 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18842 - __GEN_RMWcc(op " " arg0, var, cc)
18843 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18844 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18845
18846 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18847 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18848 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18849 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18850 +
18851 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18852 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18853 +
18854 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18855 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18856
18857 #else /* !CC_HAVE_ASM_GOTO */
18858
18859 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18860 +#ifdef CONFIG_PAX_REFCOUNT
18861 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18862 +do { \
18863 + char c; \
18864 + asm volatile (fullop \
18865 + ";jno 0f\n" \
18866 + fullantiop \
18867 + ";int $4\n0:\n" \
18868 + _ASM_EXTABLE(0b, 0b) \
18869 + "; set" cc " %1" \
18870 + : "+m" (var), "=qm" (c) \
18871 + : __VA_ARGS__ : "memory"); \
18872 + return c != 0; \
18873 +} while (0)
18874 +#else
18875 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18876 +do { \
18877 + char c; \
18878 + asm volatile (fullop "; set" cc " %1" \
18879 + : "+m" (var), "=qm" (c) \
18880 + : __VA_ARGS__ : "memory"); \
18881 + return c != 0; \
18882 +} while (0)
18883 +#endif
18884 +
18885 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18886 do { \
18887 char c; \
18888 asm volatile (fullop "; set" cc " %1" \
18889 @@ -30,11 +88,17 @@ do { \
18890 return c != 0; \
18891 } while (0)
18892
18893 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18894 - __GEN_RMWcc(op " " arg0, var, cc)
18895 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18896 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18897 +
18898 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18899 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18900 +
18901 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18902 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18903
18904 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18905 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18906 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18907 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18908
18909 #endif /* CC_HAVE_ASM_GOTO */
18910
18911 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18912 index cad82c9..2e5c5c1 100644
18913 --- a/arch/x86/include/asm/rwsem.h
18914 +++ b/arch/x86/include/asm/rwsem.h
18915 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18916 {
18917 asm volatile("# beginning down_read\n\t"
18918 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18919 +
18920 +#ifdef CONFIG_PAX_REFCOUNT
18921 + "jno 0f\n"
18922 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18923 + "int $4\n0:\n"
18924 + _ASM_EXTABLE(0b, 0b)
18925 +#endif
18926 +
18927 /* adds 0x00000001 */
18928 " jns 1f\n"
18929 " call call_rwsem_down_read_failed\n"
18930 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18931 "1:\n\t"
18932 " mov %1,%2\n\t"
18933 " add %3,%2\n\t"
18934 +
18935 +#ifdef CONFIG_PAX_REFCOUNT
18936 + "jno 0f\n"
18937 + "sub %3,%2\n"
18938 + "int $4\n0:\n"
18939 + _ASM_EXTABLE(0b, 0b)
18940 +#endif
18941 +
18942 " jle 2f\n\t"
18943 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18944 " jnz 1b\n\t"
18945 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18946 long tmp;
18947 asm volatile("# beginning down_write\n\t"
18948 LOCK_PREFIX " xadd %1,(%2)\n\t"
18949 +
18950 +#ifdef CONFIG_PAX_REFCOUNT
18951 + "jno 0f\n"
18952 + "mov %1,(%2)\n"
18953 + "int $4\n0:\n"
18954 + _ASM_EXTABLE(0b, 0b)
18955 +#endif
18956 +
18957 /* adds 0xffff0001, returns the old value */
18958 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18959 /* was the active mask 0 before? */
18960 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18961 long tmp;
18962 asm volatile("# beginning __up_read\n\t"
18963 LOCK_PREFIX " xadd %1,(%2)\n\t"
18964 +
18965 +#ifdef CONFIG_PAX_REFCOUNT
18966 + "jno 0f\n"
18967 + "mov %1,(%2)\n"
18968 + "int $4\n0:\n"
18969 + _ASM_EXTABLE(0b, 0b)
18970 +#endif
18971 +
18972 /* subtracts 1, returns the old value */
18973 " jns 1f\n\t"
18974 " call call_rwsem_wake\n" /* expects old value in %edx */
18975 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18976 long tmp;
18977 asm volatile("# beginning __up_write\n\t"
18978 LOCK_PREFIX " xadd %1,(%2)\n\t"
18979 +
18980 +#ifdef CONFIG_PAX_REFCOUNT
18981 + "jno 0f\n"
18982 + "mov %1,(%2)\n"
18983 + "int $4\n0:\n"
18984 + _ASM_EXTABLE(0b, 0b)
18985 +#endif
18986 +
18987 /* subtracts 0xffff0001, returns the old value */
18988 " jns 1f\n\t"
18989 " call call_rwsem_wake\n" /* expects old value in %edx */
18990 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18991 {
18992 asm volatile("# beginning __downgrade_write\n\t"
18993 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18994 +
18995 +#ifdef CONFIG_PAX_REFCOUNT
18996 + "jno 0f\n"
18997 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18998 + "int $4\n0:\n"
18999 + _ASM_EXTABLE(0b, 0b)
19000 +#endif
19001 +
19002 /*
19003 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19004 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19005 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19006 */
19007 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19008 {
19009 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19010 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19011 +
19012 +#ifdef CONFIG_PAX_REFCOUNT
19013 + "jno 0f\n"
19014 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19015 + "int $4\n0:\n"
19016 + _ASM_EXTABLE(0b, 0b)
19017 +#endif
19018 +
19019 : "+m" (sem->count)
19020 : "er" (delta));
19021 }
19022 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19023 */
19024 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19025 {
19026 - return delta + xadd(&sem->count, delta);
19027 + return delta + xadd_check_overflow(&sem->count, delta);
19028 }
19029
19030 #endif /* __KERNEL__ */
19031 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19032 index 6f1c3a8..7744f19 100644
19033 --- a/arch/x86/include/asm/segment.h
19034 +++ b/arch/x86/include/asm/segment.h
19035 @@ -64,10 +64,15 @@
19036 * 26 - ESPFIX small SS
19037 * 27 - per-cpu [ offset to per-cpu data area ]
19038 * 28 - stack_canary-20 [ for stack protector ]
19039 - * 29 - unused
19040 - * 30 - unused
19041 + * 29 - PCI BIOS CS
19042 + * 30 - PCI BIOS DS
19043 * 31 - TSS for double fault handler
19044 */
19045 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19046 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19047 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19048 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19049 +
19050 #define GDT_ENTRY_TLS_MIN 6
19051 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19052
19053 @@ -79,6 +84,8 @@
19054
19055 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19056
19057 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19058 +
19059 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19060
19061 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19062 @@ -104,6 +111,12 @@
19063 #define __KERNEL_STACK_CANARY 0
19064 #endif
19065
19066 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19067 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19068 +
19069 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19070 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19071 +
19072 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19073
19074 /*
19075 @@ -141,7 +154,7 @@
19076 */
19077
19078 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19079 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19080 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19081
19082
19083 #else
19084 @@ -165,6 +178,8 @@
19085 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19086 #define __USER32_DS __USER_DS
19087
19088 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19089 +
19090 #define GDT_ENTRY_TSS 8 /* needs two entries */
19091 #define GDT_ENTRY_LDT 10 /* needs two entries */
19092 #define GDT_ENTRY_TLS_MIN 12
19093 @@ -173,6 +188,8 @@
19094 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19095 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19096
19097 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19098 +
19099 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19100 #define FS_TLS 0
19101 #define GS_TLS 1
19102 @@ -180,12 +197,14 @@
19103 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19104 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19105
19106 -#define GDT_ENTRIES 16
19107 +#define GDT_ENTRIES 17
19108
19109 #endif
19110
19111 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19112 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19113 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19114 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19115 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19116 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19117 #ifndef CONFIG_PARAVIRT
19118 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19119 {
19120 unsigned long __limit;
19121 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19122 - return __limit + 1;
19123 + return __limit;
19124 }
19125
19126 #endif /* !__ASSEMBLY__ */
19127 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19128 index 8d3120f..352b440 100644
19129 --- a/arch/x86/include/asm/smap.h
19130 +++ b/arch/x86/include/asm/smap.h
19131 @@ -25,11 +25,40 @@
19132
19133 #include <asm/alternative-asm.h>
19134
19135 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19136 +#define ASM_PAX_OPEN_USERLAND \
19137 + 661: jmp 663f; \
19138 + .pushsection .altinstr_replacement, "a" ; \
19139 + 662: pushq %rax; nop; \
19140 + .popsection ; \
19141 + .pushsection .altinstructions, "a" ; \
19142 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19143 + .popsection ; \
19144 + call __pax_open_userland; \
19145 + popq %rax; \
19146 + 663:
19147 +
19148 +#define ASM_PAX_CLOSE_USERLAND \
19149 + 661: jmp 663f; \
19150 + .pushsection .altinstr_replacement, "a" ; \
19151 + 662: pushq %rax; nop; \
19152 + .popsection; \
19153 + .pushsection .altinstructions, "a" ; \
19154 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19155 + .popsection; \
19156 + call __pax_close_userland; \
19157 + popq %rax; \
19158 + 663:
19159 +#else
19160 +#define ASM_PAX_OPEN_USERLAND
19161 +#define ASM_PAX_CLOSE_USERLAND
19162 +#endif
19163 +
19164 #ifdef CONFIG_X86_SMAP
19165
19166 #define ASM_CLAC \
19167 661: ASM_NOP3 ; \
19168 - .pushsection .altinstr_replacement, "ax" ; \
19169 + .pushsection .altinstr_replacement, "a" ; \
19170 662: __ASM_CLAC ; \
19171 .popsection ; \
19172 .pushsection .altinstructions, "a" ; \
19173 @@ -38,7 +67,7 @@
19174
19175 #define ASM_STAC \
19176 661: ASM_NOP3 ; \
19177 - .pushsection .altinstr_replacement, "ax" ; \
19178 + .pushsection .altinstr_replacement, "a" ; \
19179 662: __ASM_STAC ; \
19180 .popsection ; \
19181 .pushsection .altinstructions, "a" ; \
19182 @@ -56,6 +85,37 @@
19183
19184 #include <asm/alternative.h>
19185
19186 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19187 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19188 +
19189 +extern void __pax_open_userland(void);
19190 +static __always_inline unsigned long pax_open_userland(void)
19191 +{
19192 +
19193 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19194 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19195 + :
19196 + : [open] "i" (__pax_open_userland)
19197 + : "memory", "rax");
19198 +#endif
19199 +
19200 + return 0;
19201 +}
19202 +
19203 +extern void __pax_close_userland(void);
19204 +static __always_inline unsigned long pax_close_userland(void)
19205 +{
19206 +
19207 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19208 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19209 + :
19210 + : [close] "i" (__pax_close_userland)
19211 + : "memory", "rax");
19212 +#endif
19213 +
19214 + return 0;
19215 +}
19216 +
19217 #ifdef CONFIG_X86_SMAP
19218
19219 static __always_inline void clac(void)
19220 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19221 index 8cd1cc3..827e09e 100644
19222 --- a/arch/x86/include/asm/smp.h
19223 +++ b/arch/x86/include/asm/smp.h
19224 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19225 /* cpus sharing the last level cache: */
19226 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19227 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19228 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19229 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19230
19231 static inline struct cpumask *cpu_sibling_mask(int cpu)
19232 {
19233 @@ -78,7 +78,7 @@ struct smp_ops {
19234
19235 void (*send_call_func_ipi)(const struct cpumask *mask);
19236 void (*send_call_func_single_ipi)(int cpu);
19237 -};
19238 +} __no_const;
19239
19240 /* Globals due to paravirt */
19241 extern void set_cpu_sibling_map(int cpu);
19242 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19243 extern int safe_smp_processor_id(void);
19244
19245 #elif defined(CONFIG_X86_64_SMP)
19246 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19247 -
19248 -#define stack_smp_processor_id() \
19249 -({ \
19250 - struct thread_info *ti; \
19251 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19252 - ti->cpu; \
19253 -})
19254 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19255 +#define stack_smp_processor_id() raw_smp_processor_id()
19256 #define safe_smp_processor_id() smp_processor_id()
19257
19258 #endif
19259 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19260 index 6a99859..03cb807 100644
19261 --- a/arch/x86/include/asm/stackprotector.h
19262 +++ b/arch/x86/include/asm/stackprotector.h
19263 @@ -47,7 +47,7 @@
19264 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19265 */
19266 #define GDT_STACK_CANARY_INIT \
19267 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19268 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19269
19270 /*
19271 * Initialize the stackprotector canary value.
19272 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19273
19274 static inline void load_stack_canary_segment(void)
19275 {
19276 -#ifdef CONFIG_X86_32
19277 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19278 asm volatile ("mov %0, %%gs" : : "r" (0));
19279 #endif
19280 }
19281 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19282 index 70bbe39..4ae2bd4 100644
19283 --- a/arch/x86/include/asm/stacktrace.h
19284 +++ b/arch/x86/include/asm/stacktrace.h
19285 @@ -11,28 +11,20 @@
19286
19287 extern int kstack_depth_to_print;
19288
19289 -struct thread_info;
19290 +struct task_struct;
19291 struct stacktrace_ops;
19292
19293 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19294 - unsigned long *stack,
19295 - unsigned long bp,
19296 - const struct stacktrace_ops *ops,
19297 - void *data,
19298 - unsigned long *end,
19299 - int *graph);
19300 +typedef unsigned long walk_stack_t(struct task_struct *task,
19301 + void *stack_start,
19302 + unsigned long *stack,
19303 + unsigned long bp,
19304 + const struct stacktrace_ops *ops,
19305 + void *data,
19306 + unsigned long *end,
19307 + int *graph);
19308
19309 -extern unsigned long
19310 -print_context_stack(struct thread_info *tinfo,
19311 - unsigned long *stack, unsigned long bp,
19312 - const struct stacktrace_ops *ops, void *data,
19313 - unsigned long *end, int *graph);
19314 -
19315 -extern unsigned long
19316 -print_context_stack_bp(struct thread_info *tinfo,
19317 - unsigned long *stack, unsigned long bp,
19318 - const struct stacktrace_ops *ops, void *data,
19319 - unsigned long *end, int *graph);
19320 +extern walk_stack_t print_context_stack;
19321 +extern walk_stack_t print_context_stack_bp;
19322
19323 /* Generic stack tracer with callbacks */
19324
19325 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19326 void (*address)(void *data, unsigned long address, int reliable);
19327 /* On negative return stop dumping */
19328 int (*stack)(void *data, char *name);
19329 - walk_stack_t walk_stack;
19330 + walk_stack_t *walk_stack;
19331 };
19332
19333 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19334 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19335 index d7f3b3b..3cc39f1 100644
19336 --- a/arch/x86/include/asm/switch_to.h
19337 +++ b/arch/x86/include/asm/switch_to.h
19338 @@ -108,7 +108,7 @@ do { \
19339 "call __switch_to\n\t" \
19340 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19341 __switch_canary \
19342 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19343 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19344 "movq %%rax,%%rdi\n\t" \
19345 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19346 "jnz ret_from_fork\n\t" \
19347 @@ -119,7 +119,7 @@ do { \
19348 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19349 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19350 [_tif_fork] "i" (_TIF_FORK), \
19351 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19352 + [thread_info] "m" (current_tinfo), \
19353 [current_task] "m" (current_task) \
19354 __switch_canary_iparam \
19355 : "memory", "cc" __EXTRA_CLOBBER)
19356 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19357 index 547e344..6be1175 100644
19358 --- a/arch/x86/include/asm/thread_info.h
19359 +++ b/arch/x86/include/asm/thread_info.h
19360 @@ -24,7 +24,6 @@ struct exec_domain;
19361 #include <linux/atomic.h>
19362
19363 struct thread_info {
19364 - struct task_struct *task; /* main task structure */
19365 struct exec_domain *exec_domain; /* execution domain */
19366 __u32 flags; /* low level flags */
19367 __u32 status; /* thread synchronous flags */
19368 @@ -33,13 +32,13 @@ struct thread_info {
19369 mm_segment_t addr_limit;
19370 struct restart_block restart_block;
19371 void __user *sysenter_return;
19372 + unsigned long lowest_stack;
19373 unsigned int sig_on_uaccess_error:1;
19374 unsigned int uaccess_err:1; /* uaccess failed */
19375 };
19376
19377 -#define INIT_THREAD_INFO(tsk) \
19378 +#define INIT_THREAD_INFO \
19379 { \
19380 - .task = &tsk, \
19381 .exec_domain = &default_exec_domain, \
19382 .flags = 0, \
19383 .cpu = 0, \
19384 @@ -50,7 +49,7 @@ struct thread_info {
19385 }, \
19386 }
19387
19388 -#define init_thread_info (init_thread_union.thread_info)
19389 +#define init_thread_info (init_thread_union.stack)
19390 #define init_stack (init_thread_union.stack)
19391
19392 #else /* !__ASSEMBLY__ */
19393 @@ -91,6 +90,7 @@ struct thread_info {
19394 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19395 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19396 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19397 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19398
19399 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19400 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19401 @@ -115,17 +115,18 @@ struct thread_info {
19402 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19403 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19404 #define _TIF_X32 (1 << TIF_X32)
19405 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19406
19407 /* work to do in syscall_trace_enter() */
19408 #define _TIF_WORK_SYSCALL_ENTRY \
19409 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19410 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19411 - _TIF_NOHZ)
19412 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19413
19414 /* work to do in syscall_trace_leave() */
19415 #define _TIF_WORK_SYSCALL_EXIT \
19416 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19417 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19418 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19419
19420 /* work to do on interrupt/exception return */
19421 #define _TIF_WORK_MASK \
19422 @@ -136,7 +137,7 @@ struct thread_info {
19423 /* work to do on any return to user space */
19424 #define _TIF_ALLWORK_MASK \
19425 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19426 - _TIF_NOHZ)
19427 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19428
19429 /* Only used for 64 bit */
19430 #define _TIF_DO_NOTIFY_MASK \
19431 @@ -151,7 +152,6 @@ struct thread_info {
19432 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19433
19434 #define STACK_WARN (THREAD_SIZE/8)
19435 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19436
19437 /*
19438 * macros/functions for gaining access to the thread information structure
19439 @@ -162,26 +162,18 @@ struct thread_info {
19440
19441 DECLARE_PER_CPU(unsigned long, kernel_stack);
19442
19443 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19444 +
19445 static inline struct thread_info *current_thread_info(void)
19446 {
19447 - struct thread_info *ti;
19448 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19449 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19450 - return ti;
19451 + return this_cpu_read_stable(current_tinfo);
19452 }
19453
19454 #else /* !__ASSEMBLY__ */
19455
19456 /* how to get the thread information struct from ASM */
19457 #define GET_THREAD_INFO(reg) \
19458 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19459 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19460 -
19461 -/*
19462 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19463 - * a certain register (to be used in assembler memory operands).
19464 - */
19465 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19466 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19467
19468 #endif
19469
19470 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19471 extern void arch_task_cache_init(void);
19472 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19473 extern void arch_release_task_struct(struct task_struct *tsk);
19474 +
19475 +#define __HAVE_THREAD_FUNCTIONS
19476 +#define task_thread_info(task) (&(task)->tinfo)
19477 +#define task_stack_page(task) ((task)->stack)
19478 +#define setup_thread_stack(p, org) do {} while (0)
19479 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19480 +
19481 #endif
19482 #endif /* _ASM_X86_THREAD_INFO_H */
19483 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19484 index 04905bf..1178cdf 100644
19485 --- a/arch/x86/include/asm/tlbflush.h
19486 +++ b/arch/x86/include/asm/tlbflush.h
19487 @@ -17,18 +17,44 @@
19488
19489 static inline void __native_flush_tlb(void)
19490 {
19491 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19492 + u64 descriptor[2];
19493 +
19494 + descriptor[0] = PCID_KERNEL;
19495 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19496 + return;
19497 + }
19498 +
19499 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19500 + if (static_cpu_has(X86_FEATURE_PCID)) {
19501 + unsigned int cpu = raw_get_cpu();
19502 +
19503 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19504 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19505 + raw_put_cpu_no_resched();
19506 + return;
19507 + }
19508 +#endif
19509 +
19510 native_write_cr3(native_read_cr3());
19511 }
19512
19513 static inline void __native_flush_tlb_global_irq_disabled(void)
19514 {
19515 - unsigned long cr4;
19516 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19517 + u64 descriptor[2];
19518
19519 - cr4 = native_read_cr4();
19520 - /* clear PGE */
19521 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19522 - /* write old PGE again and flush TLBs */
19523 - native_write_cr4(cr4);
19524 + descriptor[0] = PCID_KERNEL;
19525 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19526 + } else {
19527 + unsigned long cr4;
19528 +
19529 + cr4 = native_read_cr4();
19530 + /* clear PGE */
19531 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19532 + /* write old PGE again and flush TLBs */
19533 + native_write_cr4(cr4);
19534 + }
19535 }
19536
19537 static inline void __native_flush_tlb_global(void)
19538 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19539
19540 static inline void __native_flush_tlb_single(unsigned long addr)
19541 {
19542 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19543 + u64 descriptor[2];
19544 +
19545 + descriptor[0] = PCID_KERNEL;
19546 + descriptor[1] = addr;
19547 +
19548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19549 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19550 + if (addr < TASK_SIZE_MAX)
19551 + descriptor[1] += pax_user_shadow_base;
19552 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19553 + }
19554 +
19555 + descriptor[0] = PCID_USER;
19556 + descriptor[1] = addr;
19557 +#endif
19558 +
19559 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19560 + return;
19561 + }
19562 +
19563 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19564 + if (static_cpu_has(X86_FEATURE_PCID)) {
19565 + unsigned int cpu = raw_get_cpu();
19566 +
19567 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19568 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19569 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19570 + raw_put_cpu_no_resched();
19571 +
19572 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19573 + addr += pax_user_shadow_base;
19574 + }
19575 +#endif
19576 +
19577 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19578 }
19579
19580 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19581 index 0d592e0..526f797 100644
19582 --- a/arch/x86/include/asm/uaccess.h
19583 +++ b/arch/x86/include/asm/uaccess.h
19584 @@ -7,6 +7,7 @@
19585 #include <linux/compiler.h>
19586 #include <linux/thread_info.h>
19587 #include <linux/string.h>
19588 +#include <linux/spinlock.h>
19589 #include <asm/asm.h>
19590 #include <asm/page.h>
19591 #include <asm/smap.h>
19592 @@ -29,7 +30,12 @@
19593
19594 #define get_ds() (KERNEL_DS)
19595 #define get_fs() (current_thread_info()->addr_limit)
19596 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19597 +void __set_fs(mm_segment_t x);
19598 +void set_fs(mm_segment_t x);
19599 +#else
19600 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19601 +#endif
19602
19603 #define segment_eq(a, b) ((a).seg == (b).seg)
19604
19605 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19606 * checks that the pointer is in the user space range - after calling
19607 * this function, memory access functions may still return -EFAULT.
19608 */
19609 -#define access_ok(type, addr, size) \
19610 - likely(!__range_not_ok(addr, size, user_addr_max()))
19611 +extern int _cond_resched(void);
19612 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19613 +#define access_ok(type, addr, size) \
19614 +({ \
19615 + unsigned long __size = size; \
19616 + unsigned long __addr = (unsigned long)addr; \
19617 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19618 + if (__ret_ao && __size) { \
19619 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19620 + unsigned long __end_ao = __addr + __size - 1; \
19621 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19622 + while (__addr_ao <= __end_ao) { \
19623 + char __c_ao; \
19624 + __addr_ao += PAGE_SIZE; \
19625 + if (__size > PAGE_SIZE) \
19626 + _cond_resched(); \
19627 + if (__get_user(__c_ao, (char __user *)__addr)) \
19628 + break; \
19629 + if (type != VERIFY_WRITE) { \
19630 + __addr = __addr_ao; \
19631 + continue; \
19632 + } \
19633 + if (__put_user(__c_ao, (char __user *)__addr)) \
19634 + break; \
19635 + __addr = __addr_ao; \
19636 + } \
19637 + } \
19638 + } \
19639 + __ret_ao; \
19640 +})
19641
19642 /*
19643 * The exception table consists of pairs of addresses relative to the
19644 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19645 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19646 __chk_user_ptr(ptr); \
19647 might_fault(); \
19648 + pax_open_userland(); \
19649 asm volatile("call __get_user_%P3" \
19650 : "=a" (__ret_gu), "=r" (__val_gu) \
19651 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19652 (x) = (__typeof__(*(ptr))) __val_gu; \
19653 + pax_close_userland(); \
19654 __ret_gu; \
19655 })
19656
19657 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19658 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19659 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19660
19661 -
19662 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19663 +#define __copyuser_seg "gs;"
19664 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19665 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19666 +#else
19667 +#define __copyuser_seg
19668 +#define __COPYUSER_SET_ES
19669 +#define __COPYUSER_RESTORE_ES
19670 +#endif
19671
19672 #ifdef CONFIG_X86_32
19673 #define __put_user_asm_u64(x, addr, err, errret) \
19674 asm volatile(ASM_STAC "\n" \
19675 - "1: movl %%eax,0(%2)\n" \
19676 - "2: movl %%edx,4(%2)\n" \
19677 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19678 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19679 "3: " ASM_CLAC "\n" \
19680 ".section .fixup,\"ax\"\n" \
19681 "4: movl %3,%0\n" \
19682 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19683
19684 #define __put_user_asm_ex_u64(x, addr) \
19685 asm volatile(ASM_STAC "\n" \
19686 - "1: movl %%eax,0(%1)\n" \
19687 - "2: movl %%edx,4(%1)\n" \
19688 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19689 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19690 "3: " ASM_CLAC "\n" \
19691 _ASM_EXTABLE_EX(1b, 2b) \
19692 _ASM_EXTABLE_EX(2b, 3b) \
19693 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19694 __typeof__(*(ptr)) __pu_val; \
19695 __chk_user_ptr(ptr); \
19696 might_fault(); \
19697 - __pu_val = x; \
19698 + __pu_val = (x); \
19699 + pax_open_userland(); \
19700 switch (sizeof(*(ptr))) { \
19701 case 1: \
19702 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19703 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19704 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19705 break; \
19706 } \
19707 + pax_close_userland(); \
19708 __ret_pu; \
19709 })
19710
19711 @@ -355,8 +401,10 @@ do { \
19712 } while (0)
19713
19714 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19715 +do { \
19716 + pax_open_userland(); \
19717 asm volatile(ASM_STAC "\n" \
19718 - "1: mov"itype" %2,%"rtype"1\n" \
19719 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19720 "2: " ASM_CLAC "\n" \
19721 ".section .fixup,\"ax\"\n" \
19722 "3: mov %3,%0\n" \
19723 @@ -364,8 +412,10 @@ do { \
19724 " jmp 2b\n" \
19725 ".previous\n" \
19726 _ASM_EXTABLE(1b, 3b) \
19727 - : "=r" (err), ltype(x) \
19728 - : "m" (__m(addr)), "i" (errret), "0" (err))
19729 + : "=r" (err), ltype (x) \
19730 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19731 + pax_close_userland(); \
19732 +} while (0)
19733
19734 #define __get_user_size_ex(x, ptr, size) \
19735 do { \
19736 @@ -389,7 +439,7 @@ do { \
19737 } while (0)
19738
19739 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19740 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19741 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19742 "2:\n" \
19743 _ASM_EXTABLE_EX(1b, 2b) \
19744 : ltype(x) : "m" (__m(addr)))
19745 @@ -406,13 +456,24 @@ do { \
19746 int __gu_err; \
19747 unsigned long __gu_val; \
19748 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19749 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19750 + (x) = (__typeof__(*(ptr)))__gu_val; \
19751 __gu_err; \
19752 })
19753
19754 /* FIXME: this hack is definitely wrong -AK */
19755 struct __large_struct { unsigned long buf[100]; };
19756 -#define __m(x) (*(struct __large_struct __user *)(x))
19757 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19758 +#define ____m(x) \
19759 +({ \
19760 + unsigned long ____x = (unsigned long)(x); \
19761 + if (____x < pax_user_shadow_base) \
19762 + ____x += pax_user_shadow_base; \
19763 + (typeof(x))____x; \
19764 +})
19765 +#else
19766 +#define ____m(x) (x)
19767 +#endif
19768 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19769
19770 /*
19771 * Tell gcc we read from memory instead of writing: this is because
19772 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19773 * aliasing issues.
19774 */
19775 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19776 +do { \
19777 + pax_open_userland(); \
19778 asm volatile(ASM_STAC "\n" \
19779 - "1: mov"itype" %"rtype"1,%2\n" \
19780 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19781 "2: " ASM_CLAC "\n" \
19782 ".section .fixup,\"ax\"\n" \
19783 "3: mov %3,%0\n" \
19784 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19785 ".previous\n" \
19786 _ASM_EXTABLE(1b, 3b) \
19787 : "=r"(err) \
19788 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19789 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19790 + pax_close_userland(); \
19791 +} while (0)
19792
19793 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19794 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19795 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19796 "2:\n" \
19797 _ASM_EXTABLE_EX(1b, 2b) \
19798 : : ltype(x), "m" (__m(addr)))
19799 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19800 */
19801 #define uaccess_try do { \
19802 current_thread_info()->uaccess_err = 0; \
19803 + pax_open_userland(); \
19804 stac(); \
19805 barrier();
19806
19807 #define uaccess_catch(err) \
19808 clac(); \
19809 + pax_close_userland(); \
19810 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19811 } while (0)
19812
19813 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19814 * On error, the variable @x is set to zero.
19815 */
19816
19817 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19818 +#define __get_user(x, ptr) get_user((x), (ptr))
19819 +#else
19820 #define __get_user(x, ptr) \
19821 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19822 +#endif
19823
19824 /**
19825 * __put_user: - Write a simple value into user space, with less checking.
19826 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19827 * Returns zero on success, or -EFAULT on error.
19828 */
19829
19830 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19831 +#define __put_user(x, ptr) put_user((x), (ptr))
19832 +#else
19833 #define __put_user(x, ptr) \
19834 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19835 +#endif
19836
19837 #define __get_user_unaligned __get_user
19838 #define __put_user_unaligned __put_user
19839 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19840 #define get_user_ex(x, ptr) do { \
19841 unsigned long __gue_val; \
19842 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19843 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19844 + (x) = (__typeof__(*(ptr)))__gue_val; \
19845 } while (0)
19846
19847 #define put_user_try uaccess_try
19848 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19849 __typeof__(ptr) __uval = (uval); \
19850 __typeof__(*(ptr)) __old = (old); \
19851 __typeof__(*(ptr)) __new = (new); \
19852 + pax_open_userland(); \
19853 switch (size) { \
19854 case 1: \
19855 { \
19856 asm volatile("\t" ASM_STAC "\n" \
19857 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19858 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19859 "2:\t" ASM_CLAC "\n" \
19860 "\t.section .fixup, \"ax\"\n" \
19861 "3:\tmov %3, %0\n" \
19862 "\tjmp 2b\n" \
19863 "\t.previous\n" \
19864 _ASM_EXTABLE(1b, 3b) \
19865 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19866 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19867 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19868 : "memory" \
19869 ); \
19870 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19871 case 2: \
19872 { \
19873 asm volatile("\t" ASM_STAC "\n" \
19874 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19875 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19876 "2:\t" ASM_CLAC "\n" \
19877 "\t.section .fixup, \"ax\"\n" \
19878 "3:\tmov %3, %0\n" \
19879 "\tjmp 2b\n" \
19880 "\t.previous\n" \
19881 _ASM_EXTABLE(1b, 3b) \
19882 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19883 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19884 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19885 : "memory" \
19886 ); \
19887 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19888 case 4: \
19889 { \
19890 asm volatile("\t" ASM_STAC "\n" \
19891 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19892 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19893 "2:\t" ASM_CLAC "\n" \
19894 "\t.section .fixup, \"ax\"\n" \
19895 "3:\tmov %3, %0\n" \
19896 "\tjmp 2b\n" \
19897 "\t.previous\n" \
19898 _ASM_EXTABLE(1b, 3b) \
19899 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19900 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19901 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19902 : "memory" \
19903 ); \
19904 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19905 __cmpxchg_wrong_size(); \
19906 \
19907 asm volatile("\t" ASM_STAC "\n" \
19908 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19909 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19910 "2:\t" ASM_CLAC "\n" \
19911 "\t.section .fixup, \"ax\"\n" \
19912 "3:\tmov %3, %0\n" \
19913 "\tjmp 2b\n" \
19914 "\t.previous\n" \
19915 _ASM_EXTABLE(1b, 3b) \
19916 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19917 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19918 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19919 : "memory" \
19920 ); \
19921 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19922 default: \
19923 __cmpxchg_wrong_size(); \
19924 } \
19925 + pax_close_userland(); \
19926 *__uval = __old; \
19927 __ret; \
19928 })
19929 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19930
19931 #define ARCH_HAS_NOCACHE_UACCESS 1
19932
19933 -#ifdef CONFIG_X86_32
19934 -# include <asm/uaccess_32.h>
19935 -#else
19936 -# include <asm/uaccess_64.h>
19937 -#endif
19938 -
19939 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19940 - unsigned n);
19941 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19942 - unsigned n);
19943 -
19944 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19945 # define copy_user_diag __compiletime_error
19946 #else
19947 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19948 extern void copy_user_diag("copy_from_user() buffer size is too small")
19949 copy_from_user_overflow(void);
19950 extern void copy_user_diag("copy_to_user() buffer size is too small")
19951 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19952 +copy_to_user_overflow(void);
19953
19954 #undef copy_user_diag
19955
19956 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19957
19958 extern void
19959 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19960 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19961 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19962 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19963
19964 #else
19965 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19966
19967 #endif
19968
19969 +#ifdef CONFIG_X86_32
19970 +# include <asm/uaccess_32.h>
19971 +#else
19972 +# include <asm/uaccess_64.h>
19973 +#endif
19974 +
19975 static inline unsigned long __must_check
19976 copy_from_user(void *to, const void __user *from, unsigned long n)
19977 {
19978 - int sz = __compiletime_object_size(to);
19979 + size_t sz = __compiletime_object_size(to);
19980
19981 might_fault();
19982
19983 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19984 * case, and do only runtime checking for non-constant sizes.
19985 */
19986
19987 - if (likely(sz < 0 || sz >= n))
19988 - n = _copy_from_user(to, from, n);
19989 - else if(__builtin_constant_p(n))
19990 - copy_from_user_overflow();
19991 - else
19992 - __copy_from_user_overflow(sz, n);
19993 + if (likely(sz != (size_t)-1 && sz < n)) {
19994 + if(__builtin_constant_p(n))
19995 + copy_from_user_overflow();
19996 + else
19997 + __copy_from_user_overflow(sz, n);
19998 + } else if (access_ok(VERIFY_READ, from, n))
19999 + n = __copy_from_user(to, from, n);
20000 + else if ((long)n > 0)
20001 + memset(to, 0, n);
20002
20003 return n;
20004 }
20005 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 static inline unsigned long __must_check
20007 copy_to_user(void __user *to, const void *from, unsigned long n)
20008 {
20009 - int sz = __compiletime_object_size(from);
20010 + size_t sz = __compiletime_object_size(from);
20011
20012 might_fault();
20013
20014 /* See the comment in copy_from_user() above. */
20015 - if (likely(sz < 0 || sz >= n))
20016 - n = _copy_to_user(to, from, n);
20017 - else if(__builtin_constant_p(n))
20018 - copy_to_user_overflow();
20019 - else
20020 - __copy_to_user_overflow(sz, n);
20021 + if (likely(sz != (size_t)-1 && sz < n)) {
20022 + if(__builtin_constant_p(n))
20023 + copy_to_user_overflow();
20024 + else
20025 + __copy_to_user_overflow(sz, n);
20026 + } else if (access_ok(VERIFY_WRITE, to, n))
20027 + n = __copy_to_user(to, from, n);
20028
20029 return n;
20030 }
20031 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20032 index 3c03a5d..1071638 100644
20033 --- a/arch/x86/include/asm/uaccess_32.h
20034 +++ b/arch/x86/include/asm/uaccess_32.h
20035 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20036 static __always_inline unsigned long __must_check
20037 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20038 {
20039 + if ((long)n < 0)
20040 + return n;
20041 +
20042 + check_object_size(from, n, true);
20043 +
20044 if (__builtin_constant_p(n)) {
20045 unsigned long ret;
20046
20047 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20048 __copy_to_user(void __user *to, const void *from, unsigned long n)
20049 {
20050 might_fault();
20051 +
20052 return __copy_to_user_inatomic(to, from, n);
20053 }
20054
20055 static __always_inline unsigned long
20056 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20057 {
20058 + if ((long)n < 0)
20059 + return n;
20060 +
20061 /* Avoid zeroing the tail if the copy fails..
20062 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20063 * but as the zeroing behaviour is only significant when n is not
20064 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20065 __copy_from_user(void *to, const void __user *from, unsigned long n)
20066 {
20067 might_fault();
20068 +
20069 + if ((long)n < 0)
20070 + return n;
20071 +
20072 + check_object_size(to, n, false);
20073 +
20074 if (__builtin_constant_p(n)) {
20075 unsigned long ret;
20076
20077 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20078 const void __user *from, unsigned long n)
20079 {
20080 might_fault();
20081 +
20082 + if ((long)n < 0)
20083 + return n;
20084 +
20085 if (__builtin_constant_p(n)) {
20086 unsigned long ret;
20087
20088 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20089 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20090 unsigned long n)
20091 {
20092 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20093 + if ((long)n < 0)
20094 + return n;
20095 +
20096 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20097 }
20098
20099 #endif /* _ASM_X86_UACCESS_32_H */
20100 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20101 index 12a26b9..206c200 100644
20102 --- a/arch/x86/include/asm/uaccess_64.h
20103 +++ b/arch/x86/include/asm/uaccess_64.h
20104 @@ -10,6 +10,9 @@
20105 #include <asm/alternative.h>
20106 #include <asm/cpufeature.h>
20107 #include <asm/page.h>
20108 +#include <asm/pgtable.h>
20109 +
20110 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20111
20112 /*
20113 * Copy To/From Userspace
20114 @@ -17,14 +20,14 @@
20115
20116 /* Handles exceptions in both to and from, but doesn't do access_ok */
20117 __must_check unsigned long
20118 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20119 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20120 __must_check unsigned long
20121 -copy_user_generic_string(void *to, const void *from, unsigned len);
20122 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20123 __must_check unsigned long
20124 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20125 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20126
20127 static __always_inline __must_check unsigned long
20128 -copy_user_generic(void *to, const void *from, unsigned len)
20129 +copy_user_generic(void *to, const void *from, unsigned long len)
20130 {
20131 unsigned ret;
20132
20133 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20134 }
20135
20136 __must_check unsigned long
20137 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20138 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20139
20140 static __always_inline __must_check
20141 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20142 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20143 {
20144 - int ret = 0;
20145 + size_t sz = __compiletime_object_size(dst);
20146 + unsigned ret = 0;
20147 +
20148 + if (size > INT_MAX)
20149 + return size;
20150 +
20151 + check_object_size(dst, size, false);
20152 +
20153 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20154 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20155 + return size;
20156 +#endif
20157 +
20158 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20159 + if(__builtin_constant_p(size))
20160 + copy_from_user_overflow();
20161 + else
20162 + __copy_from_user_overflow(sz, size);
20163 + return size;
20164 + }
20165
20166 if (!__builtin_constant_p(size))
20167 - return copy_user_generic(dst, (__force void *)src, size);
20168 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20169 switch (size) {
20170 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20171 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20172 ret, "b", "b", "=q", 1);
20173 return ret;
20174 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20175 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20176 ret, "w", "w", "=r", 2);
20177 return ret;
20178 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20179 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20180 ret, "l", "k", "=r", 4);
20181 return ret;
20182 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20183 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20184 ret, "q", "", "=r", 8);
20185 return ret;
20186 case 10:
20187 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20188 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20189 ret, "q", "", "=r", 10);
20190 if (unlikely(ret))
20191 return ret;
20192 __get_user_asm(*(u16 *)(8 + (char *)dst),
20193 - (u16 __user *)(8 + (char __user *)src),
20194 + (const u16 __user *)(8 + (const char __user *)src),
20195 ret, "w", "w", "=r", 2);
20196 return ret;
20197 case 16:
20198 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20199 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20200 ret, "q", "", "=r", 16);
20201 if (unlikely(ret))
20202 return ret;
20203 __get_user_asm(*(u64 *)(8 + (char *)dst),
20204 - (u64 __user *)(8 + (char __user *)src),
20205 + (const u64 __user *)(8 + (const char __user *)src),
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 default:
20209 - return copy_user_generic(dst, (__force void *)src, size);
20210 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20211 }
20212 }
20213
20214 static __always_inline __must_check
20215 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20216 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20217 {
20218 might_fault();
20219 return __copy_from_user_nocheck(dst, src, size);
20220 }
20221
20222 static __always_inline __must_check
20223 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20224 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20225 {
20226 - int ret = 0;
20227 + size_t sz = __compiletime_object_size(src);
20228 + unsigned ret = 0;
20229 +
20230 + if (size > INT_MAX)
20231 + return size;
20232 +
20233 + check_object_size(src, size, true);
20234 +
20235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20236 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20237 + return size;
20238 +#endif
20239 +
20240 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20241 + if(__builtin_constant_p(size))
20242 + copy_to_user_overflow();
20243 + else
20244 + __copy_to_user_overflow(sz, size);
20245 + return size;
20246 + }
20247
20248 if (!__builtin_constant_p(size))
20249 - return copy_user_generic((__force void *)dst, src, size);
20250 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20251 switch (size) {
20252 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20253 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20254 ret, "b", "b", "iq", 1);
20255 return ret;
20256 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20257 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20258 ret, "w", "w", "ir", 2);
20259 return ret;
20260 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20261 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20262 ret, "l", "k", "ir", 4);
20263 return ret;
20264 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20265 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20266 ret, "q", "", "er", 8);
20267 return ret;
20268 case 10:
20269 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20270 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20271 ret, "q", "", "er", 10);
20272 if (unlikely(ret))
20273 return ret;
20274 asm("":::"memory");
20275 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20276 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20277 ret, "w", "w", "ir", 2);
20278 return ret;
20279 case 16:
20280 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20281 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20282 ret, "q", "", "er", 16);
20283 if (unlikely(ret))
20284 return ret;
20285 asm("":::"memory");
20286 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20287 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 default:
20291 - return copy_user_generic((__force void *)dst, src, size);
20292 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20293 }
20294 }
20295
20296 static __always_inline __must_check
20297 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20298 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20299 {
20300 might_fault();
20301 return __copy_to_user_nocheck(dst, src, size);
20302 }
20303
20304 static __always_inline __must_check
20305 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20306 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20307 {
20308 - int ret = 0;
20309 + unsigned ret = 0;
20310
20311 might_fault();
20312 +
20313 + if (size > INT_MAX)
20314 + return size;
20315 +
20316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20317 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20318 + return size;
20319 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20320 + return size;
20321 +#endif
20322 +
20323 if (!__builtin_constant_p(size))
20324 - return copy_user_generic((__force void *)dst,
20325 - (__force void *)src, size);
20326 + return copy_user_generic((__force_kernel void *)____m(dst),
20327 + (__force_kernel const void *)____m(src), size);
20328 switch (size) {
20329 case 1: {
20330 u8 tmp;
20331 - __get_user_asm(tmp, (u8 __user *)src,
20332 + __get_user_asm(tmp, (const u8 __user *)src,
20333 ret, "b", "b", "=q", 1);
20334 if (likely(!ret))
20335 __put_user_asm(tmp, (u8 __user *)dst,
20336 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20337 }
20338 case 2: {
20339 u16 tmp;
20340 - __get_user_asm(tmp, (u16 __user *)src,
20341 + __get_user_asm(tmp, (const u16 __user *)src,
20342 ret, "w", "w", "=r", 2);
20343 if (likely(!ret))
20344 __put_user_asm(tmp, (u16 __user *)dst,
20345 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20346
20347 case 4: {
20348 u32 tmp;
20349 - __get_user_asm(tmp, (u32 __user *)src,
20350 + __get_user_asm(tmp, (const u32 __user *)src,
20351 ret, "l", "k", "=r", 4);
20352 if (likely(!ret))
20353 __put_user_asm(tmp, (u32 __user *)dst,
20354 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20355 }
20356 case 8: {
20357 u64 tmp;
20358 - __get_user_asm(tmp, (u64 __user *)src,
20359 + __get_user_asm(tmp, (const u64 __user *)src,
20360 ret, "q", "", "=r", 8);
20361 if (likely(!ret))
20362 __put_user_asm(tmp, (u64 __user *)dst,
20363 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20364 return ret;
20365 }
20366 default:
20367 - return copy_user_generic((__force void *)dst,
20368 - (__force void *)src, size);
20369 + return copy_user_generic((__force_kernel void *)____m(dst),
20370 + (__force_kernel const void *)____m(src), size);
20371 }
20372 }
20373
20374 -static __must_check __always_inline int
20375 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20376 +static __must_check __always_inline unsigned long
20377 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20378 {
20379 return __copy_from_user_nocheck(dst, src, size);
20380 }
20381
20382 -static __must_check __always_inline int
20383 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20384 +static __must_check __always_inline unsigned long
20385 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20386 {
20387 return __copy_to_user_nocheck(dst, src, size);
20388 }
20389
20390 -extern long __copy_user_nocache(void *dst, const void __user *src,
20391 - unsigned size, int zerorest);
20392 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20393 + unsigned long size, int zerorest);
20394
20395 -static inline int
20396 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20397 +static inline unsigned long
20398 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20399 {
20400 might_fault();
20401 +
20402 + if (size > INT_MAX)
20403 + return size;
20404 +
20405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20406 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20407 + return size;
20408 +#endif
20409 +
20410 return __copy_user_nocache(dst, src, size, 1);
20411 }
20412
20413 -static inline int
20414 +static inline unsigned long
20415 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20416 - unsigned size)
20417 + unsigned long size)
20418 {
20419 + if (size > INT_MAX)
20420 + return size;
20421 +
20422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20423 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20424 + return size;
20425 +#endif
20426 +
20427 return __copy_user_nocache(dst, src, size, 0);
20428 }
20429
20430 unsigned long
20431 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20432 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20433
20434 #endif /* _ASM_X86_UACCESS_64_H */
20435 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20436 index 5b238981..77fdd78 100644
20437 --- a/arch/x86/include/asm/word-at-a-time.h
20438 +++ b/arch/x86/include/asm/word-at-a-time.h
20439 @@ -11,7 +11,7 @@
20440 * and shift, for example.
20441 */
20442 struct word_at_a_time {
20443 - const unsigned long one_bits, high_bits;
20444 + unsigned long one_bits, high_bits;
20445 };
20446
20447 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20448 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20449 index e45e4da..44e8572 100644
20450 --- a/arch/x86/include/asm/x86_init.h
20451 +++ b/arch/x86/include/asm/x86_init.h
20452 @@ -129,7 +129,7 @@ struct x86_init_ops {
20453 struct x86_init_timers timers;
20454 struct x86_init_iommu iommu;
20455 struct x86_init_pci pci;
20456 -};
20457 +} __no_const;
20458
20459 /**
20460 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20461 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20462 void (*setup_percpu_clockev)(void);
20463 void (*early_percpu_clock_init)(void);
20464 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20465 -};
20466 +} __no_const;
20467
20468 struct timespec;
20469
20470 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20471 void (*save_sched_clock_state)(void);
20472 void (*restore_sched_clock_state)(void);
20473 void (*apic_post_init)(void);
20474 -};
20475 +} __no_const;
20476
20477 struct pci_dev;
20478 struct msi_msg;
20479 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20480 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20481 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20482 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20483 -};
20484 +} __no_const;
20485
20486 struct IO_APIC_route_entry;
20487 struct io_apic_irq_attr;
20488 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20489 unsigned int destination, int vector,
20490 struct io_apic_irq_attr *attr);
20491 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20492 -};
20493 +} __no_const;
20494
20495 extern struct x86_init_ops x86_init;
20496 extern struct x86_cpuinit_ops x86_cpuinit;
20497 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20498 index f58ef6c..a2abc78 100644
20499 --- a/arch/x86/include/asm/xen/page.h
20500 +++ b/arch/x86/include/asm/xen/page.h
20501 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20502 extern struct page *m2p_find_override(unsigned long mfn);
20503 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20504
20505 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20506 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20507 {
20508 unsigned long mfn;
20509
20510 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20511 index 7e7a79a..0824666 100644
20512 --- a/arch/x86/include/asm/xsave.h
20513 +++ b/arch/x86/include/asm/xsave.h
20514 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20515 if (unlikely(err))
20516 return -EFAULT;
20517
20518 + pax_open_userland();
20519 __asm__ __volatile__(ASM_STAC "\n"
20520 - "1:"XSAVE"\n"
20521 + "1:"
20522 + __copyuser_seg
20523 + XSAVE"\n"
20524 "2: " ASM_CLAC "\n"
20525 xstate_fault
20526 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20527 : "memory");
20528 + pax_close_userland();
20529 return err;
20530 }
20531
20532 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20533 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20534 {
20535 int err = 0;
20536 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20537 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20538 u32 lmask = mask;
20539 u32 hmask = mask >> 32;
20540
20541 + pax_open_userland();
20542 __asm__ __volatile__(ASM_STAC "\n"
20543 - "1:"XRSTOR"\n"
20544 + "1:"
20545 + __copyuser_seg
20546 + XRSTOR"\n"
20547 "2: " ASM_CLAC "\n"
20548 xstate_fault
20549 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20550 : "memory"); /* memory required? */
20551 + pax_close_userland();
20552 return err;
20553 }
20554
20555 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20556 index d993e33..8db1b18 100644
20557 --- a/arch/x86/include/uapi/asm/e820.h
20558 +++ b/arch/x86/include/uapi/asm/e820.h
20559 @@ -58,7 +58,7 @@ struct e820map {
20560 #define ISA_START_ADDRESS 0xa0000
20561 #define ISA_END_ADDRESS 0x100000
20562
20563 -#define BIOS_BEGIN 0x000a0000
20564 +#define BIOS_BEGIN 0x000c0000
20565 #define BIOS_END 0x00100000
20566
20567 #define BIOS_ROM_BASE 0xffe00000
20568 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20569 index 7b0a55a..ad115bf 100644
20570 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20571 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20572 @@ -49,7 +49,6 @@
20573 #define EFLAGS 144
20574 #define RSP 152
20575 #define SS 160
20576 -#define ARGOFFSET R11
20577 #endif /* __ASSEMBLY__ */
20578
20579 /* top of stack page */
20580 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20581 index 8f1e774..9b4c381 100644
20582 --- a/arch/x86/kernel/Makefile
20583 +++ b/arch/x86/kernel/Makefile
20584 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20585 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20586 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20587 obj-y += probe_roms.o
20588 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20589 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20590 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20591 obj-$(CONFIG_X86_64) += mcount_64.o
20592 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20593 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20594 index a142e77..6222cdd 100644
20595 --- a/arch/x86/kernel/acpi/boot.c
20596 +++ b/arch/x86/kernel/acpi/boot.c
20597 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20598 * If your system is blacklisted here, but you find that acpi=force
20599 * works for you, please contact linux-acpi@vger.kernel.org
20600 */
20601 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20602 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20603 /*
20604 * Boxes that need ACPI disabled
20605 */
20606 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20607 };
20608
20609 /* second table for DMI checks that should run after early-quirks */
20610 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20611 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20612 /*
20613 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20614 * which includes some code which overrides all temperature
20615 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20616 index 3136820..e2c6577 100644
20617 --- a/arch/x86/kernel/acpi/sleep.c
20618 +++ b/arch/x86/kernel/acpi/sleep.c
20619 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20620 #else /* CONFIG_64BIT */
20621 #ifdef CONFIG_SMP
20622 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20623 +
20624 + pax_open_kernel();
20625 early_gdt_descr.address =
20626 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20627 + pax_close_kernel();
20628 +
20629 initial_gs = per_cpu_offset(smp_processor_id());
20630 #endif
20631 initial_code = (unsigned long)wakeup_long64;
20632 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20633 index 665c6b7..eae4d56 100644
20634 --- a/arch/x86/kernel/acpi/wakeup_32.S
20635 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20636 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20637 # and restore the stack ... but you need gdt for this to work
20638 movl saved_context_esp, %esp
20639
20640 - movl %cs:saved_magic, %eax
20641 - cmpl $0x12345678, %eax
20642 + cmpl $0x12345678, saved_magic
20643 jne bogus_magic
20644
20645 # jump to place where we left off
20646 - movl saved_eip, %eax
20647 - jmp *%eax
20648 + jmp *(saved_eip)
20649
20650 bogus_magic:
20651 jmp bogus_magic
20652 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20653 index 703130f..27a155d 100644
20654 --- a/arch/x86/kernel/alternative.c
20655 +++ b/arch/x86/kernel/alternative.c
20656 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20657 */
20658 for (a = start; a < end; a++) {
20659 instr = (u8 *)&a->instr_offset + a->instr_offset;
20660 +
20661 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20662 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20663 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20664 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20665 +#endif
20666 +
20667 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20668 BUG_ON(a->replacementlen > a->instrlen);
20669 BUG_ON(a->instrlen > sizeof(insnbuf));
20670 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20671 add_nops(insnbuf + a->replacementlen,
20672 a->instrlen - a->replacementlen);
20673
20674 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20675 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20676 + instr = ktva_ktla(instr);
20677 +#endif
20678 +
20679 text_poke_early(instr, insnbuf, a->instrlen);
20680 }
20681 }
20682 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20683 for (poff = start; poff < end; poff++) {
20684 u8 *ptr = (u8 *)poff + *poff;
20685
20686 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20687 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20688 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20689 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690 +#endif
20691 +
20692 if (!*poff || ptr < text || ptr >= text_end)
20693 continue;
20694 /* turn DS segment override prefix into lock prefix */
20695 - if (*ptr == 0x3e)
20696 + if (*ktla_ktva(ptr) == 0x3e)
20697 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20698 }
20699 mutex_unlock(&text_mutex);
20700 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20701 for (poff = start; poff < end; poff++) {
20702 u8 *ptr = (u8 *)poff + *poff;
20703
20704 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20705 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20706 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20707 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20708 +#endif
20709 +
20710 if (!*poff || ptr < text || ptr >= text_end)
20711 continue;
20712 /* turn lock prefix into DS segment override prefix */
20713 - if (*ptr == 0xf0)
20714 + if (*ktla_ktva(ptr) == 0xf0)
20715 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20716 }
20717 mutex_unlock(&text_mutex);
20718 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20719
20720 BUG_ON(p->len > MAX_PATCH_LEN);
20721 /* prep the buffer with the original instructions */
20722 - memcpy(insnbuf, p->instr, p->len);
20723 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20724 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20725 (unsigned long)p->instr, p->len);
20726
20727 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20728 if (!uniproc_patched || num_possible_cpus() == 1)
20729 free_init_pages("SMP alternatives",
20730 (unsigned long)__smp_locks,
20731 - (unsigned long)__smp_locks_end);
20732 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20733 #endif
20734
20735 apply_paravirt(__parainstructions, __parainstructions_end);
20736 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20737 * instructions. And on the local CPU you need to be protected again NMI or MCE
20738 * handlers seeing an inconsistent instruction while you patch.
20739 */
20740 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20741 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20742 size_t len)
20743 {
20744 unsigned long flags;
20745 local_irq_save(flags);
20746 - memcpy(addr, opcode, len);
20747 +
20748 + pax_open_kernel();
20749 + memcpy(ktla_ktva(addr), opcode, len);
20750 sync_core();
20751 + pax_close_kernel();
20752 +
20753 local_irq_restore(flags);
20754 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20755 that causes hangs on some VIA CPUs. */
20756 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20757 */
20758 void *text_poke(void *addr, const void *opcode, size_t len)
20759 {
20760 - unsigned long flags;
20761 - char *vaddr;
20762 + unsigned char *vaddr = ktla_ktva(addr);
20763 struct page *pages[2];
20764 - int i;
20765 + size_t i;
20766
20767 if (!core_kernel_text((unsigned long)addr)) {
20768 - pages[0] = vmalloc_to_page(addr);
20769 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20770 + pages[0] = vmalloc_to_page(vaddr);
20771 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20772 } else {
20773 - pages[0] = virt_to_page(addr);
20774 + pages[0] = virt_to_page(vaddr);
20775 WARN_ON(!PageReserved(pages[0]));
20776 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20777 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20778 }
20779 BUG_ON(!pages[0]);
20780 - local_irq_save(flags);
20781 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20782 - if (pages[1])
20783 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20784 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20785 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20786 - clear_fixmap(FIX_TEXT_POKE0);
20787 - if (pages[1])
20788 - clear_fixmap(FIX_TEXT_POKE1);
20789 - local_flush_tlb();
20790 - sync_core();
20791 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20792 - that causes hangs on some VIA CPUs. */
20793 + text_poke_early(addr, opcode, len);
20794 for (i = 0; i < len; i++)
20795 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20796 - local_irq_restore(flags);
20797 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20798 return addr;
20799 }
20800
20801 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20802 if (likely(!bp_patching_in_progress))
20803 return 0;
20804
20805 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20806 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20807 return 0;
20808
20809 /* set up the specified breakpoint handler */
20810 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20811 */
20812 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20813 {
20814 - unsigned char int3 = 0xcc;
20815 + const unsigned char int3 = 0xcc;
20816
20817 bp_int3_handler = handler;
20818 bp_int3_addr = (u8 *)addr + sizeof(int3);
20819 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20820 index ba6cc04..06fd971 100644
20821 --- a/arch/x86/kernel/apic/apic.c
20822 +++ b/arch/x86/kernel/apic/apic.c
20823 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20824 /*
20825 * Debug level, exported for io_apic.c
20826 */
20827 -unsigned int apic_verbosity;
20828 +int apic_verbosity;
20829
20830 int pic_mode;
20831
20832 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20833 apic_write(APIC_ESR, 0);
20834 v = apic_read(APIC_ESR);
20835 ack_APIC_irq();
20836 - atomic_inc(&irq_err_count);
20837 + atomic_inc_unchecked(&irq_err_count);
20838
20839 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20840 smp_processor_id(), v);
20841 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20842 index de918c4..32eed23 100644
20843 --- a/arch/x86/kernel/apic/apic_flat_64.c
20844 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20845 @@ -154,7 +154,7 @@ static int flat_probe(void)
20846 return 1;
20847 }
20848
20849 -static struct apic apic_flat = {
20850 +static struct apic apic_flat __read_only = {
20851 .name = "flat",
20852 .probe = flat_probe,
20853 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20854 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20855 return 0;
20856 }
20857
20858 -static struct apic apic_physflat = {
20859 +static struct apic apic_physflat __read_only = {
20860
20861 .name = "physical flat",
20862 .probe = physflat_probe,
20863 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20864 index b205cdb..d8503ff 100644
20865 --- a/arch/x86/kernel/apic/apic_noop.c
20866 +++ b/arch/x86/kernel/apic/apic_noop.c
20867 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20868 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20869 }
20870
20871 -struct apic apic_noop = {
20872 +struct apic apic_noop __read_only = {
20873 .name = "noop",
20874 .probe = noop_probe,
20875 .acpi_madt_oem_check = NULL,
20876 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20877 index c4a8d63..fe893ac 100644
20878 --- a/arch/x86/kernel/apic/bigsmp_32.c
20879 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20880 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20881 return dmi_bigsmp;
20882 }
20883
20884 -static struct apic apic_bigsmp = {
20885 +static struct apic apic_bigsmp __read_only = {
20886
20887 .name = "bigsmp",
20888 .probe = probe_bigsmp,
20889 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20890 index 1183d54..6158e47 100644
20891 --- a/arch/x86/kernel/apic/io_apic.c
20892 +++ b/arch/x86/kernel/apic/io_apic.c
20893 @@ -1230,7 +1230,7 @@ out:
20894 }
20895 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20896
20897 -void lock_vector_lock(void)
20898 +void lock_vector_lock(void) __acquires(vector_lock)
20899 {
20900 /* Used to the online set of cpus does not change
20901 * during assign_irq_vector.
20902 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20903 raw_spin_lock(&vector_lock);
20904 }
20905
20906 -void unlock_vector_lock(void)
20907 +void unlock_vector_lock(void) __releases(vector_lock)
20908 {
20909 raw_spin_unlock(&vector_lock);
20910 }
20911 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20912 ack_APIC_irq();
20913 }
20914
20915 -atomic_t irq_mis_count;
20916 +atomic_unchecked_t irq_mis_count;
20917
20918 #ifdef CONFIG_GENERIC_PENDING_IRQ
20919 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20920 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20921 * at the cpu.
20922 */
20923 if (!(v & (1 << (i & 0x1f)))) {
20924 - atomic_inc(&irq_mis_count);
20925 + atomic_inc_unchecked(&irq_mis_count);
20926
20927 eoi_ioapic_irq(irq, cfg);
20928 }
20929 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20930 index bda4886..f9c7195 100644
20931 --- a/arch/x86/kernel/apic/probe_32.c
20932 +++ b/arch/x86/kernel/apic/probe_32.c
20933 @@ -72,7 +72,7 @@ static int probe_default(void)
20934 return 1;
20935 }
20936
20937 -static struct apic apic_default = {
20938 +static struct apic apic_default __read_only = {
20939
20940 .name = "default",
20941 .probe = probe_default,
20942 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20943 index e658f21..b695a1a 100644
20944 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20945 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20946 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20947 return notifier_from_errno(err);
20948 }
20949
20950 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20951 +static struct notifier_block x2apic_cpu_notifier = {
20952 .notifier_call = update_clusterinfo,
20953 };
20954
20955 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20956 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20957 }
20958
20959 -static struct apic apic_x2apic_cluster = {
20960 +static struct apic apic_x2apic_cluster __read_only = {
20961
20962 .name = "cluster x2apic",
20963 .probe = x2apic_cluster_probe,
20964 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20965 index 6fae733..5ca17af 100644
20966 --- a/arch/x86/kernel/apic/x2apic_phys.c
20967 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20968 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20969 return apic == &apic_x2apic_phys;
20970 }
20971
20972 -static struct apic apic_x2apic_phys = {
20973 +static struct apic apic_x2apic_phys __read_only = {
20974
20975 .name = "physical x2apic",
20976 .probe = x2apic_phys_probe,
20977 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20978 index 8e9dcfd..c61b3e4 100644
20979 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20980 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20981 @@ -348,7 +348,7 @@ static int uv_probe(void)
20982 return apic == &apic_x2apic_uv_x;
20983 }
20984
20985 -static struct apic __refdata apic_x2apic_uv_x = {
20986 +static struct apic apic_x2apic_uv_x __read_only = {
20987
20988 .name = "UV large system",
20989 .probe = uv_probe,
20990 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20991 index 5848744..56cb598 100644
20992 --- a/arch/x86/kernel/apm_32.c
20993 +++ b/arch/x86/kernel/apm_32.c
20994 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20995 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20996 * even though they are called in protected mode.
20997 */
20998 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20999 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21000 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21001
21002 static const char driver_version[] = "1.16ac"; /* no spaces */
21003 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21004 BUG_ON(cpu != 0);
21005 gdt = get_cpu_gdt_table(cpu);
21006 save_desc_40 = gdt[0x40 / 8];
21007 +
21008 + pax_open_kernel();
21009 gdt[0x40 / 8] = bad_bios_desc;
21010 + pax_close_kernel();
21011
21012 apm_irq_save(flags);
21013 APM_DO_SAVE_SEGS;
21014 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21015 &call->esi);
21016 APM_DO_RESTORE_SEGS;
21017 apm_irq_restore(flags);
21018 +
21019 + pax_open_kernel();
21020 gdt[0x40 / 8] = save_desc_40;
21021 + pax_close_kernel();
21022 +
21023 put_cpu();
21024
21025 return call->eax & 0xff;
21026 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21027 BUG_ON(cpu != 0);
21028 gdt = get_cpu_gdt_table(cpu);
21029 save_desc_40 = gdt[0x40 / 8];
21030 +
21031 + pax_open_kernel();
21032 gdt[0x40 / 8] = bad_bios_desc;
21033 + pax_close_kernel();
21034
21035 apm_irq_save(flags);
21036 APM_DO_SAVE_SEGS;
21037 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21038 &call->eax);
21039 APM_DO_RESTORE_SEGS;
21040 apm_irq_restore(flags);
21041 +
21042 + pax_open_kernel();
21043 gdt[0x40 / 8] = save_desc_40;
21044 + pax_close_kernel();
21045 +
21046 put_cpu();
21047 return error;
21048 }
21049 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21050 * code to that CPU.
21051 */
21052 gdt = get_cpu_gdt_table(0);
21053 +
21054 + pax_open_kernel();
21055 set_desc_base(&gdt[APM_CS >> 3],
21056 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21057 set_desc_base(&gdt[APM_CS_16 >> 3],
21058 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21059 set_desc_base(&gdt[APM_DS >> 3],
21060 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21061 + pax_close_kernel();
21062
21063 proc_create("apm", 0, NULL, &apm_file_ops);
21064
21065 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21066 index 9f6b934..cf5ffb3 100644
21067 --- a/arch/x86/kernel/asm-offsets.c
21068 +++ b/arch/x86/kernel/asm-offsets.c
21069 @@ -32,6 +32,8 @@ void common(void) {
21070 OFFSET(TI_flags, thread_info, flags);
21071 OFFSET(TI_status, thread_info, status);
21072 OFFSET(TI_addr_limit, thread_info, addr_limit);
21073 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21074 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21075
21076 BLANK();
21077 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21078 @@ -52,8 +54,26 @@ void common(void) {
21079 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21080 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21081 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21082 +
21083 +#ifdef CONFIG_PAX_KERNEXEC
21084 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21085 #endif
21086
21087 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21088 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21089 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21090 +#ifdef CONFIG_X86_64
21091 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21092 +#endif
21093 +#endif
21094 +
21095 +#endif
21096 +
21097 + BLANK();
21098 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21099 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21100 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21101 +
21102 #ifdef CONFIG_XEN
21103 BLANK();
21104 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21105 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21106 index e7c798b..2b2019b 100644
21107 --- a/arch/x86/kernel/asm-offsets_64.c
21108 +++ b/arch/x86/kernel/asm-offsets_64.c
21109 @@ -77,6 +77,7 @@ int main(void)
21110 BLANK();
21111 #undef ENTRY
21112
21113 + DEFINE(TSS_size, sizeof(struct tss_struct));
21114 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21115 BLANK();
21116
21117 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21118 index 80091ae..0c5184f 100644
21119 --- a/arch/x86/kernel/cpu/Makefile
21120 +++ b/arch/x86/kernel/cpu/Makefile
21121 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21122 CFLAGS_REMOVE_perf_event.o = -pg
21123 endif
21124
21125 -# Make sure load_percpu_segment has no stackprotector
21126 -nostackp := $(call cc-option, -fno-stack-protector)
21127 -CFLAGS_common.o := $(nostackp)
21128 -
21129 obj-y := intel_cacheinfo.o scattered.o topology.o
21130 obj-y += common.o
21131 obj-y += rdrand.o
21132 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21133 index 813d29d..6e542d4 100644
21134 --- a/arch/x86/kernel/cpu/amd.c
21135 +++ b/arch/x86/kernel/cpu/amd.c
21136 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21137 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21138 {
21139 /* AMD errata T13 (order #21922) */
21140 - if ((c->x86 == 6)) {
21141 + if (c->x86 == 6) {
21142 /* Duron Rev A0 */
21143 if (c->x86_model == 3 && c->x86_mask == 0)
21144 size = 64;
21145 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21146 index cfa9b5b..19b5084 100644
21147 --- a/arch/x86/kernel/cpu/common.c
21148 +++ b/arch/x86/kernel/cpu/common.c
21149 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21150
21151 static const struct cpu_dev *this_cpu = &default_cpu;
21152
21153 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21154 -#ifdef CONFIG_X86_64
21155 - /*
21156 - * We need valid kernel segments for data and code in long mode too
21157 - * IRET will check the segment types kkeil 2000/10/28
21158 - * Also sysret mandates a special GDT layout
21159 - *
21160 - * TLS descriptors are currently at a different place compared to i386.
21161 - * Hopefully nobody expects them at a fixed place (Wine?)
21162 - */
21163 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21164 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21165 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21166 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21167 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21168 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21169 -#else
21170 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21171 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21172 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21173 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21174 - /*
21175 - * Segments used for calling PnP BIOS have byte granularity.
21176 - * They code segments and data segments have fixed 64k limits,
21177 - * the transfer segment sizes are set at run time.
21178 - */
21179 - /* 32-bit code */
21180 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21181 - /* 16-bit code */
21182 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21183 - /* 16-bit data */
21184 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21185 - /* 16-bit data */
21186 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21187 - /* 16-bit data */
21188 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21189 - /*
21190 - * The APM segments have byte granularity and their bases
21191 - * are set at run time. All have 64k limits.
21192 - */
21193 - /* 32-bit code */
21194 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21195 - /* 16-bit code */
21196 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21197 - /* data */
21198 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21199 -
21200 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21201 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21202 - GDT_STACK_CANARY_INIT
21203 -#endif
21204 -} };
21205 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21206 -
21207 static int __init x86_xsave_setup(char *s)
21208 {
21209 if (strlen(s))
21210 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21211 }
21212 }
21213
21214 +#ifdef CONFIG_X86_64
21215 +static __init int setup_disable_pcid(char *arg)
21216 +{
21217 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21218 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21219 +
21220 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21221 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21222 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21223 +#endif
21224 +
21225 + return 1;
21226 +}
21227 +__setup("nopcid", setup_disable_pcid);
21228 +
21229 +static void setup_pcid(struct cpuinfo_x86 *c)
21230 +{
21231 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21232 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21233 +
21234 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21235 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21236 + pax_open_kernel();
21237 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21238 + pax_close_kernel();
21239 + printk("PAX: slow and weak UDEREF enabled\n");
21240 + } else
21241 + printk("PAX: UDEREF disabled\n");
21242 +#endif
21243 +
21244 + return;
21245 + }
21246 +
21247 + printk("PAX: PCID detected\n");
21248 + set_in_cr4(X86_CR4_PCIDE);
21249 +
21250 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21251 + pax_open_kernel();
21252 + clone_pgd_mask = ~(pgdval_t)0UL;
21253 + pax_close_kernel();
21254 + if (pax_user_shadow_base)
21255 + printk("PAX: weak UDEREF enabled\n");
21256 + else {
21257 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21258 + printk("PAX: strong UDEREF enabled\n");
21259 + }
21260 +#endif
21261 +
21262 + if (cpu_has(c, X86_FEATURE_INVPCID))
21263 + printk("PAX: INVPCID detected\n");
21264 +}
21265 +#endif
21266 +
21267 /*
21268 * Some CPU features depend on higher CPUID levels, which may not always
21269 * be available due to CPUID level capping or broken virtualization
21270 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21271 {
21272 struct desc_ptr gdt_descr;
21273
21274 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21275 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21276 gdt_descr.size = GDT_SIZE - 1;
21277 load_gdt(&gdt_descr);
21278 /* Reload the per-cpu base */
21279 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21280 setup_smep(c);
21281 setup_smap(c);
21282
21283 +#ifdef CONFIG_X86_64
21284 + setup_pcid(c);
21285 +#endif
21286 +
21287 /*
21288 * The vendor-specific functions might have changed features.
21289 * Now we do "generic changes."
21290 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21291 /* Filter out anything that depends on CPUID levels we don't have */
21292 filter_cpuid_features(c, true);
21293
21294 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21295 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21296 +#endif
21297 +
21298 /* If the model name is still unset, do table lookup. */
21299 if (!c->x86_model_id[0]) {
21300 const char *p;
21301 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21302 void enable_sep_cpu(void)
21303 {
21304 int cpu = get_cpu();
21305 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21306 + struct tss_struct *tss = init_tss + cpu;
21307
21308 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21309 put_cpu();
21310 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21311 }
21312 __setup("clearcpuid=", setup_disablecpuid);
21313
21314 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21315 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21316 +
21317 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21318 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21319 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21320 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21321
21322 #ifdef CONFIG_X86_64
21323 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21324 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21325 - (unsigned long) debug_idt_table };
21326 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21327 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21328
21329 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21330 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21331 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21332 */
21333 load_ucode_ap();
21334
21335 - t = &per_cpu(init_tss, cpu);
21336 + t = init_tss + cpu;
21337 oist = &per_cpu(orig_ist, cpu);
21338
21339 #ifdef CONFIG_NUMA
21340 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21341 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21342 barrier();
21343
21344 - x86_configure_nx();
21345 enable_x2apic();
21346
21347 /*
21348 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21349 {
21350 int cpu = smp_processor_id();
21351 struct task_struct *curr = current;
21352 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21353 + struct tss_struct *t = init_tss + cpu;
21354 struct thread_struct *thread = &curr->thread;
21355
21356 wait_for_master_cpu(cpu);
21357 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21358 index c703507..28535e3 100644
21359 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21360 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21361 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21362 };
21363
21364 #ifdef CONFIG_AMD_NB
21365 +static struct attribute *default_attrs_amd_nb[] = {
21366 + &type.attr,
21367 + &level.attr,
21368 + &coherency_line_size.attr,
21369 + &physical_line_partition.attr,
21370 + &ways_of_associativity.attr,
21371 + &number_of_sets.attr,
21372 + &size.attr,
21373 + &shared_cpu_map.attr,
21374 + &shared_cpu_list.attr,
21375 + NULL,
21376 + NULL,
21377 + NULL,
21378 + NULL
21379 +};
21380 +
21381 static struct attribute **amd_l3_attrs(void)
21382 {
21383 static struct attribute **attrs;
21384 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21385
21386 n = ARRAY_SIZE(default_attrs);
21387
21388 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21389 - n += 2;
21390 -
21391 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21392 - n += 1;
21393 -
21394 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21395 - if (attrs == NULL)
21396 - return attrs = default_attrs;
21397 -
21398 - for (n = 0; default_attrs[n]; n++)
21399 - attrs[n] = default_attrs[n];
21400 + attrs = default_attrs_amd_nb;
21401
21402 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21403 attrs[n++] = &cache_disable_0.attr;
21404 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21405 .default_attrs = default_attrs,
21406 };
21407
21408 +#ifdef CONFIG_AMD_NB
21409 +static struct kobj_type ktype_cache_amd_nb = {
21410 + .sysfs_ops = &sysfs_ops,
21411 + .default_attrs = default_attrs_amd_nb,
21412 +};
21413 +#endif
21414 +
21415 static struct kobj_type ktype_percpu_entry = {
21416 .sysfs_ops = &sysfs_ops,
21417 };
21418 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21419 return retval;
21420 }
21421
21422 +#ifdef CONFIG_AMD_NB
21423 + amd_l3_attrs();
21424 +#endif
21425 +
21426 for (i = 0; i < num_cache_leaves; i++) {
21427 + struct kobj_type *ktype;
21428 +
21429 this_object = INDEX_KOBJECT_PTR(cpu, i);
21430 this_object->cpu = cpu;
21431 this_object->index = i;
21432
21433 this_leaf = CPUID4_INFO_IDX(cpu, i);
21434
21435 - ktype_cache.default_attrs = default_attrs;
21436 + ktype = &ktype_cache;
21437 #ifdef CONFIG_AMD_NB
21438 if (this_leaf->base.nb)
21439 - ktype_cache.default_attrs = amd_l3_attrs();
21440 + ktype = &ktype_cache_amd_nb;
21441 #endif
21442 retval = kobject_init_and_add(&(this_object->kobj),
21443 - &ktype_cache,
21444 + ktype,
21445 per_cpu(ici_cache_kobject, cpu),
21446 "index%1lu", i);
21447 if (unlikely(retval)) {
21448 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21449 index 61a9668ce..b446a37 100644
21450 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21451 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21452 @@ -45,6 +45,7 @@
21453 #include <asm/processor.h>
21454 #include <asm/mce.h>
21455 #include <asm/msr.h>
21456 +#include <asm/local.h>
21457
21458 #include "mce-internal.h"
21459
21460 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21461 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21462 m->cs, m->ip);
21463
21464 - if (m->cs == __KERNEL_CS)
21465 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21466 print_symbol("{%s}", m->ip);
21467 pr_cont("\n");
21468 }
21469 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21470
21471 #define PANIC_TIMEOUT 5 /* 5 seconds */
21472
21473 -static atomic_t mce_paniced;
21474 +static atomic_unchecked_t mce_paniced;
21475
21476 static int fake_panic;
21477 -static atomic_t mce_fake_paniced;
21478 +static atomic_unchecked_t mce_fake_paniced;
21479
21480 /* Panic in progress. Enable interrupts and wait for final IPI */
21481 static void wait_for_panic(void)
21482 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21483 /*
21484 * Make sure only one CPU runs in machine check panic
21485 */
21486 - if (atomic_inc_return(&mce_paniced) > 1)
21487 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21488 wait_for_panic();
21489 barrier();
21490
21491 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21492 console_verbose();
21493 } else {
21494 /* Don't log too much for fake panic */
21495 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21496 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21497 return;
21498 }
21499 /* First print corrected ones that are still unlogged */
21500 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21501 if (!fake_panic) {
21502 if (panic_timeout == 0)
21503 panic_timeout = mca_cfg.panic_timeout;
21504 - panic(msg);
21505 + panic("%s", msg);
21506 } else
21507 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21508 }
21509 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21510 * might have been modified by someone else.
21511 */
21512 rmb();
21513 - if (atomic_read(&mce_paniced))
21514 + if (atomic_read_unchecked(&mce_paniced))
21515 wait_for_panic();
21516 if (!mca_cfg.monarch_timeout)
21517 goto out;
21518 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21519 }
21520
21521 /* Call the installed machine check handler for this CPU setup. */
21522 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21523 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21524 unexpected_machine_check;
21525
21526 /*
21527 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21528 return;
21529 }
21530
21531 + pax_open_kernel();
21532 machine_check_vector = do_machine_check;
21533 + pax_close_kernel();
21534
21535 __mcheck_cpu_init_generic();
21536 __mcheck_cpu_init_vendor(c);
21537 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21538 */
21539
21540 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21541 -static int mce_chrdev_open_count; /* #times opened */
21542 +static local_t mce_chrdev_open_count; /* #times opened */
21543 static int mce_chrdev_open_exclu; /* already open exclusive? */
21544
21545 static int mce_chrdev_open(struct inode *inode, struct file *file)
21546 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21547 spin_lock(&mce_chrdev_state_lock);
21548
21549 if (mce_chrdev_open_exclu ||
21550 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21551 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21552 spin_unlock(&mce_chrdev_state_lock);
21553
21554 return -EBUSY;
21555 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21556
21557 if (file->f_flags & O_EXCL)
21558 mce_chrdev_open_exclu = 1;
21559 - mce_chrdev_open_count++;
21560 + local_inc(&mce_chrdev_open_count);
21561
21562 spin_unlock(&mce_chrdev_state_lock);
21563
21564 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21565 {
21566 spin_lock(&mce_chrdev_state_lock);
21567
21568 - mce_chrdev_open_count--;
21569 + local_dec(&mce_chrdev_open_count);
21570 mce_chrdev_open_exclu = 0;
21571
21572 spin_unlock(&mce_chrdev_state_lock);
21573 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21574
21575 for (i = 0; i < mca_cfg.banks; i++) {
21576 struct mce_bank *b = &mce_banks[i];
21577 - struct device_attribute *a = &b->attr;
21578 + device_attribute_no_const *a = &b->attr;
21579
21580 sysfs_attr_init(&a->attr);
21581 a->attr.name = b->attrname;
21582 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21583 static void mce_reset(void)
21584 {
21585 cpu_missing = 0;
21586 - atomic_set(&mce_fake_paniced, 0);
21587 + atomic_set_unchecked(&mce_fake_paniced, 0);
21588 atomic_set(&mce_executing, 0);
21589 atomic_set(&mce_callin, 0);
21590 atomic_set(&global_nwo, 0);
21591 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21592 index a304298..49b6d06 100644
21593 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21594 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21595 @@ -10,6 +10,7 @@
21596 #include <asm/processor.h>
21597 #include <asm/mce.h>
21598 #include <asm/msr.h>
21599 +#include <asm/pgtable.h>
21600
21601 /* By default disabled */
21602 int mce_p5_enabled __read_mostly;
21603 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21604 if (!cpu_has(c, X86_FEATURE_MCE))
21605 return;
21606
21607 + pax_open_kernel();
21608 machine_check_vector = pentium_machine_check;
21609 + pax_close_kernel();
21610 /* Make sure the vector pointer is visible before we enable MCEs: */
21611 wmb();
21612
21613 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21614 index 7dc5564..1273569 100644
21615 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21616 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21617 @@ -9,6 +9,7 @@
21618 #include <asm/processor.h>
21619 #include <asm/mce.h>
21620 #include <asm/msr.h>
21621 +#include <asm/pgtable.h>
21622
21623 /* Machine check handler for WinChip C6: */
21624 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21625 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21626 {
21627 u32 lo, hi;
21628
21629 + pax_open_kernel();
21630 machine_check_vector = winchip_machine_check;
21631 + pax_close_kernel();
21632 /* Make sure the vector pointer is visible before we enable MCEs: */
21633 wmb();
21634
21635 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21636 index 36a8361..e7058c2 100644
21637 --- a/arch/x86/kernel/cpu/microcode/core.c
21638 +++ b/arch/x86/kernel/cpu/microcode/core.c
21639 @@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21640 return NOTIFY_OK;
21641 }
21642
21643 -static struct notifier_block __refdata mc_cpu_notifier = {
21644 +static struct notifier_block mc_cpu_notifier = {
21645 .notifier_call = mc_cpu_callback,
21646 };
21647
21648 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21649 index c6826d1..ad18e14a 100644
21650 --- a/arch/x86/kernel/cpu/microcode/intel.c
21651 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21652 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21653
21654 static int get_ucode_user(void *to, const void *from, size_t n)
21655 {
21656 - return copy_from_user(to, from, n);
21657 + return copy_from_user(to, (const void __force_user *)from, n);
21658 }
21659
21660 static enum ucode_state
21661 request_microcode_user(int cpu, const void __user *buf, size_t size)
21662 {
21663 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21664 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21665 }
21666
21667 static void microcode_fini_cpu(int cpu)
21668 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21669 index ea5f363..cb0e905 100644
21670 --- a/arch/x86/kernel/cpu/mtrr/main.c
21671 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21672 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21673 u64 size_or_mask, size_and_mask;
21674 static bool mtrr_aps_delayed_init;
21675
21676 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21677 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21678
21679 const struct mtrr_ops *mtrr_if;
21680
21681 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21682 index df5e41f..816c719 100644
21683 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21684 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21685 @@ -25,7 +25,7 @@ struct mtrr_ops {
21686 int (*validate_add_page)(unsigned long base, unsigned long size,
21687 unsigned int type);
21688 int (*have_wrcomb)(void);
21689 -};
21690 +} __do_const;
21691
21692 extern int generic_get_free_region(unsigned long base, unsigned long size,
21693 int replace_reg);
21694 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21695 index 143e5f5..5825081 100644
21696 --- a/arch/x86/kernel/cpu/perf_event.c
21697 +++ b/arch/x86/kernel/cpu/perf_event.c
21698 @@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21699
21700 }
21701
21702 -static struct attribute_group x86_pmu_format_group = {
21703 +static attribute_group_no_const x86_pmu_format_group = {
21704 .name = "format",
21705 .attrs = NULL,
21706 };
21707 @@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21708 NULL,
21709 };
21710
21711 -static struct attribute_group x86_pmu_events_group = {
21712 +static attribute_group_no_const x86_pmu_events_group = {
21713 .name = "events",
21714 .attrs = events_attr,
21715 };
21716 @@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21717 if (idx > GDT_ENTRIES)
21718 return 0;
21719
21720 - desc = raw_cpu_ptr(gdt_page.gdt);
21721 + desc = get_cpu_gdt_table(smp_processor_id());
21722 }
21723
21724 return get_desc_base(desc + idx);
21725 @@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21726 break;
21727
21728 perf_callchain_store(entry, frame.return_address);
21729 - fp = frame.next_frame;
21730 + fp = (const void __force_user *)frame.next_frame;
21731 }
21732 }
21733
21734 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21735 index 639d128..e92d7e5 100644
21736 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21737 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21738 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21739 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21740 {
21741 struct attribute **attrs;
21742 - struct attribute_group *attr_group;
21743 + attribute_group_no_const *attr_group;
21744 int i = 0, j;
21745
21746 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21747 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21748 index 498b6d9..4126515 100644
21749 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21750 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21751 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21752 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21753
21754 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21755 - u64 capabilities;
21756 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21757
21758 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21759 - x86_pmu.intel_cap.capabilities = capabilities;
21760 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21761 + x86_pmu.intel_cap.capabilities = capabilities;
21762 }
21763
21764 intel_ds_init();
21765 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21766 index 8c25674..30aa32e 100644
21767 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21768 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21769 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21770 NULL,
21771 };
21772
21773 -static struct attribute_group rapl_pmu_events_group = {
21774 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21775 .name = "events",
21776 .attrs = NULL, /* patched at runtime */
21777 };
21778 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21779 index e98f68c..1992b15 100644
21780 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21781 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21782 @@ -737,7 +737,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21783 static int __init uncore_type_init(struct intel_uncore_type *type)
21784 {
21785 struct intel_uncore_pmu *pmus;
21786 - struct attribute_group *attr_group;
21787 + attribute_group_no_const *attr_group;
21788 struct attribute **attrs;
21789 int i, j;
21790
21791 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21792 index 863d9b0..6289b63 100644
21793 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21794 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21795 @@ -114,7 +114,7 @@ struct intel_uncore_box {
21796 struct uncore_event_desc {
21797 struct kobj_attribute attr;
21798 const char *config;
21799 -};
21800 +} __do_const;
21801
21802 ssize_t uncore_event_show(struct kobject *kobj,
21803 struct kobj_attribute *attr, char *buf);
21804 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21805 index 3225ae6c..ee3c6db 100644
21806 --- a/arch/x86/kernel/cpuid.c
21807 +++ b/arch/x86/kernel/cpuid.c
21808 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21809 return notifier_from_errno(err);
21810 }
21811
21812 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21813 +static struct notifier_block cpuid_class_cpu_notifier =
21814 {
21815 .notifier_call = cpuid_class_cpu_callback,
21816 };
21817 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21818 index f5ab56d..d3b201a 100644
21819 --- a/arch/x86/kernel/crash.c
21820 +++ b/arch/x86/kernel/crash.c
21821 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21822 #ifdef CONFIG_X86_32
21823 struct pt_regs fixed_regs;
21824
21825 - if (!user_mode_vm(regs)) {
21826 + if (!user_mode(regs)) {
21827 crash_fixup_ss_esp(&fixed_regs, regs);
21828 regs = &fixed_regs;
21829 }
21830 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21831 index afa64ad..dce67dd 100644
21832 --- a/arch/x86/kernel/crash_dump_64.c
21833 +++ b/arch/x86/kernel/crash_dump_64.c
21834 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21835 return -ENOMEM;
21836
21837 if (userbuf) {
21838 - if (copy_to_user(buf, vaddr + offset, csize)) {
21839 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21840 iounmap(vaddr);
21841 return -EFAULT;
21842 }
21843 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21844 index f6dfd93..892ade4 100644
21845 --- a/arch/x86/kernel/doublefault.c
21846 +++ b/arch/x86/kernel/doublefault.c
21847 @@ -12,7 +12,7 @@
21848
21849 #define DOUBLEFAULT_STACKSIZE (1024)
21850 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21851 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21852 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21853
21854 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21855
21856 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21857 unsigned long gdt, tss;
21858
21859 native_store_gdt(&gdt_desc);
21860 - gdt = gdt_desc.address;
21861 + gdt = (unsigned long)gdt_desc.address;
21862
21863 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21864
21865 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21866 /* 0x2 bit is always set */
21867 .flags = X86_EFLAGS_SF | 0x2,
21868 .sp = STACK_START,
21869 - .es = __USER_DS,
21870 + .es = __KERNEL_DS,
21871 .cs = __KERNEL_CS,
21872 .ss = __KERNEL_DS,
21873 - .ds = __USER_DS,
21874 + .ds = __KERNEL_DS,
21875 .fs = __KERNEL_PERCPU,
21876
21877 .__cr3 = __pa_nodebug(swapper_pg_dir),
21878 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21879 index b74ebc7..2c95874 100644
21880 --- a/arch/x86/kernel/dumpstack.c
21881 +++ b/arch/x86/kernel/dumpstack.c
21882 @@ -2,6 +2,9 @@
21883 * Copyright (C) 1991, 1992 Linus Torvalds
21884 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21885 */
21886 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21887 +#define __INCLUDED_BY_HIDESYM 1
21888 +#endif
21889 #include <linux/kallsyms.h>
21890 #include <linux/kprobes.h>
21891 #include <linux/uaccess.h>
21892 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21893
21894 void printk_address(unsigned long address)
21895 {
21896 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21897 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21898 }
21899
21900 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21901 static void
21902 print_ftrace_graph_addr(unsigned long addr, void *data,
21903 const struct stacktrace_ops *ops,
21904 - struct thread_info *tinfo, int *graph)
21905 + struct task_struct *task, int *graph)
21906 {
21907 - struct task_struct *task;
21908 unsigned long ret_addr;
21909 int index;
21910
21911 if (addr != (unsigned long)return_to_handler)
21912 return;
21913
21914 - task = tinfo->task;
21915 index = task->curr_ret_stack;
21916
21917 if (!task->ret_stack || index < *graph)
21918 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21919 static inline void
21920 print_ftrace_graph_addr(unsigned long addr, void *data,
21921 const struct stacktrace_ops *ops,
21922 - struct thread_info *tinfo, int *graph)
21923 + struct task_struct *task, int *graph)
21924 { }
21925 #endif
21926
21927 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21928 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21929 */
21930
21931 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21932 - void *p, unsigned int size, void *end)
21933 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21934 {
21935 - void *t = tinfo;
21936 if (end) {
21937 if (p < end && p >= (end-THREAD_SIZE))
21938 return 1;
21939 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21940 }
21941
21942 unsigned long
21943 -print_context_stack(struct thread_info *tinfo,
21944 +print_context_stack(struct task_struct *task, void *stack_start,
21945 unsigned long *stack, unsigned long bp,
21946 const struct stacktrace_ops *ops, void *data,
21947 unsigned long *end, int *graph)
21948 {
21949 struct stack_frame *frame = (struct stack_frame *)bp;
21950
21951 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21952 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21953 unsigned long addr;
21954
21955 addr = *stack;
21956 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21957 } else {
21958 ops->address(data, addr, 0);
21959 }
21960 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21961 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21962 }
21963 stack++;
21964 }
21965 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21966 EXPORT_SYMBOL_GPL(print_context_stack);
21967
21968 unsigned long
21969 -print_context_stack_bp(struct thread_info *tinfo,
21970 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21971 unsigned long *stack, unsigned long bp,
21972 const struct stacktrace_ops *ops, void *data,
21973 unsigned long *end, int *graph)
21974 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21975 struct stack_frame *frame = (struct stack_frame *)bp;
21976 unsigned long *ret_addr = &frame->return_address;
21977
21978 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21979 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21980 unsigned long addr = *ret_addr;
21981
21982 if (!__kernel_text_address(addr))
21983 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21984 ops->address(data, addr, 1);
21985 frame = frame->next_frame;
21986 ret_addr = &frame->return_address;
21987 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21988 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21989 }
21990
21991 return (unsigned long)frame;
21992 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21993 static void print_trace_address(void *data, unsigned long addr, int reliable)
21994 {
21995 touch_nmi_watchdog();
21996 - printk(data);
21997 + printk("%s", (char *)data);
21998 printk_stack_address(addr, reliable);
21999 }
22000
22001 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22002 EXPORT_SYMBOL_GPL(oops_begin);
22003 NOKPROBE_SYMBOL(oops_begin);
22004
22005 +extern void gr_handle_kernel_exploit(void);
22006 +
22007 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22008 {
22009 if (regs && kexec_should_crash(current))
22010 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22011 panic("Fatal exception in interrupt");
22012 if (panic_on_oops)
22013 panic("Fatal exception");
22014 - do_exit(signr);
22015 +
22016 + gr_handle_kernel_exploit();
22017 +
22018 + do_group_exit(signr);
22019 }
22020 NOKPROBE_SYMBOL(oops_end);
22021
22022 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22023 print_modules();
22024 show_regs(regs);
22025 #ifdef CONFIG_X86_32
22026 - if (user_mode_vm(regs)) {
22027 + if (user_mode(regs)) {
22028 sp = regs->sp;
22029 ss = regs->ss & 0xffff;
22030 } else {
22031 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22032 unsigned long flags = oops_begin();
22033 int sig = SIGSEGV;
22034
22035 - if (!user_mode_vm(regs))
22036 + if (!user_mode(regs))
22037 report_bug(regs->ip, regs);
22038
22039 if (__die(str, regs, err))
22040 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22041 index 5abd4cd..c65733b 100644
22042 --- a/arch/x86/kernel/dumpstack_32.c
22043 +++ b/arch/x86/kernel/dumpstack_32.c
22044 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22045 bp = stack_frame(task, regs);
22046
22047 for (;;) {
22048 - struct thread_info *context;
22049 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22050 void *end_stack;
22051
22052 end_stack = is_hardirq_stack(stack, cpu);
22053 if (!end_stack)
22054 end_stack = is_softirq_stack(stack, cpu);
22055
22056 - context = task_thread_info(task);
22057 - bp = ops->walk_stack(context, stack, bp, ops, data,
22058 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22059 end_stack, &graph);
22060
22061 /* Stop if not on irq stack */
22062 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22063 int i;
22064
22065 show_regs_print_info(KERN_EMERG);
22066 - __show_regs(regs, !user_mode_vm(regs));
22067 + __show_regs(regs, !user_mode(regs));
22068
22069 /*
22070 * When in-kernel, we also print out the stack and code at the
22071 * time of the fault..
22072 */
22073 - if (!user_mode_vm(regs)) {
22074 + if (!user_mode(regs)) {
22075 unsigned int code_prologue = code_bytes * 43 / 64;
22076 unsigned int code_len = code_bytes;
22077 unsigned char c;
22078 u8 *ip;
22079 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22080
22081 pr_emerg("Stack:\n");
22082 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22083
22084 pr_emerg("Code:");
22085
22086 - ip = (u8 *)regs->ip - code_prologue;
22087 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22088 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22089 /* try starting at IP */
22090 - ip = (u8 *)regs->ip;
22091 + ip = (u8 *)regs->ip + cs_base;
22092 code_len = code_len - code_prologue + 1;
22093 }
22094 for (i = 0; i < code_len; i++, ip++) {
22095 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22096 pr_cont(" Bad EIP value.");
22097 break;
22098 }
22099 - if (ip == (u8 *)regs->ip)
22100 + if (ip == (u8 *)regs->ip + cs_base)
22101 pr_cont(" <%02x>", c);
22102 else
22103 pr_cont(" %02x", c);
22104 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22105 {
22106 unsigned short ud2;
22107
22108 + ip = ktla_ktva(ip);
22109 if (ip < PAGE_OFFSET)
22110 return 0;
22111 if (probe_kernel_address((unsigned short *)ip, ud2))
22112 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22113
22114 return ud2 == 0x0b0f;
22115 }
22116 +
22117 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22118 +void pax_check_alloca(unsigned long size)
22119 +{
22120 + unsigned long sp = (unsigned long)&sp, stack_left;
22121 +
22122 + /* all kernel stacks are of the same size */
22123 + stack_left = sp & (THREAD_SIZE - 1);
22124 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22125 +}
22126 +EXPORT_SYMBOL(pax_check_alloca);
22127 +#endif
22128 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22129 index ff86f19..73eabf4 100644
22130 --- a/arch/x86/kernel/dumpstack_64.c
22131 +++ b/arch/x86/kernel/dumpstack_64.c
22132 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22133 const struct stacktrace_ops *ops, void *data)
22134 {
22135 const unsigned cpu = get_cpu();
22136 - struct thread_info *tinfo;
22137 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22138 unsigned long dummy;
22139 unsigned used = 0;
22140 int graph = 0;
22141 int done = 0;
22142 + void *stack_start;
22143
22144 if (!task)
22145 task = current;
22146 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22147 * current stack address. If the stacks consist of nested
22148 * exceptions
22149 */
22150 - tinfo = task_thread_info(task);
22151 while (!done) {
22152 unsigned long *stack_end;
22153 enum stack_type stype;
22154 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22155 if (ops->stack(data, id) < 0)
22156 break;
22157
22158 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22159 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22160 data, stack_end, &graph);
22161 ops->stack(data, "<EOE>");
22162 /*
22163 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22164 * second-to-last pointer (index -2 to end) in the
22165 * exception stack:
22166 */
22167 + if ((u16)stack_end[-1] != __KERNEL_DS)
22168 + goto out;
22169 stack = (unsigned long *) stack_end[-2];
22170 done = 0;
22171 break;
22172 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22173
22174 if (ops->stack(data, "IRQ") < 0)
22175 break;
22176 - bp = ops->walk_stack(tinfo, stack, bp,
22177 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22178 ops, data, stack_end, &graph);
22179 /*
22180 * We link to the next stack (which would be
22181 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22182 /*
22183 * This handles the process stack:
22184 */
22185 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22186 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22187 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22188 +out:
22189 put_cpu();
22190 }
22191 EXPORT_SYMBOL(dump_trace);
22192 @@ -344,8 +347,55 @@ int is_valid_bugaddr(unsigned long ip)
22193 {
22194 unsigned short ud2;
22195
22196 - if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
22197 + if (probe_kernel_address((unsigned short *)ip, ud2))
22198 return 0;
22199
22200 return ud2 == 0x0b0f;
22201 }
22202 +
22203 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22204 +void pax_check_alloca(unsigned long size)
22205 +{
22206 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22207 + unsigned cpu, used;
22208 + char *id;
22209 +
22210 + /* check the process stack first */
22211 + stack_start = (unsigned long)task_stack_page(current);
22212 + stack_end = stack_start + THREAD_SIZE;
22213 + if (likely(stack_start <= sp && sp < stack_end)) {
22214 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22215 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22216 + return;
22217 + }
22218 +
22219 + cpu = get_cpu();
22220 +
22221 + /* check the irq stacks */
22222 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22223 + stack_start = stack_end - IRQ_STACK_SIZE;
22224 + if (stack_start <= sp && sp < stack_end) {
22225 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22226 + put_cpu();
22227 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22228 + return;
22229 + }
22230 +
22231 + /* check the exception stacks */
22232 + used = 0;
22233 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22234 + stack_start = stack_end - EXCEPTION_STKSZ;
22235 + if (stack_end && stack_start <= sp && sp < stack_end) {
22236 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22237 + put_cpu();
22238 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22239 + return;
22240 + }
22241 +
22242 + put_cpu();
22243 +
22244 + /* unknown stack */
22245 + BUG();
22246 +}
22247 +EXPORT_SYMBOL(pax_check_alloca);
22248 +#endif
22249 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22250 index 49f8864..1cc6d07 100644
22251 --- a/arch/x86/kernel/e820.c
22252 +++ b/arch/x86/kernel/e820.c
22253 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22254
22255 static void early_panic(char *msg)
22256 {
22257 - early_printk(msg);
22258 - panic(msg);
22259 + early_printk("%s", msg);
22260 + panic("%s", msg);
22261 }
22262
22263 static int userdef __initdata;
22264 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22265 index 01d1c18..8073693 100644
22266 --- a/arch/x86/kernel/early_printk.c
22267 +++ b/arch/x86/kernel/early_printk.c
22268 @@ -7,6 +7,7 @@
22269 #include <linux/pci_regs.h>
22270 #include <linux/pci_ids.h>
22271 #include <linux/errno.h>
22272 +#include <linux/sched.h>
22273 #include <asm/io.h>
22274 #include <asm/processor.h>
22275 #include <asm/fcntl.h>
22276 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22277 index 344b63f..55adf14 100644
22278 --- a/arch/x86/kernel/entry_32.S
22279 +++ b/arch/x86/kernel/entry_32.S
22280 @@ -177,13 +177,154 @@
22281 /*CFI_REL_OFFSET gs, PT_GS*/
22282 .endm
22283 .macro SET_KERNEL_GS reg
22284 +
22285 +#ifdef CONFIG_CC_STACKPROTECTOR
22286 movl $(__KERNEL_STACK_CANARY), \reg
22287 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22288 + movl $(__USER_DS), \reg
22289 +#else
22290 + xorl \reg, \reg
22291 +#endif
22292 +
22293 movl \reg, %gs
22294 .endm
22295
22296 #endif /* CONFIG_X86_32_LAZY_GS */
22297
22298 -.macro SAVE_ALL
22299 +.macro pax_enter_kernel
22300 +#ifdef CONFIG_PAX_KERNEXEC
22301 + call pax_enter_kernel
22302 +#endif
22303 +.endm
22304 +
22305 +.macro pax_exit_kernel
22306 +#ifdef CONFIG_PAX_KERNEXEC
22307 + call pax_exit_kernel
22308 +#endif
22309 +.endm
22310 +
22311 +#ifdef CONFIG_PAX_KERNEXEC
22312 +ENTRY(pax_enter_kernel)
22313 +#ifdef CONFIG_PARAVIRT
22314 + pushl %eax
22315 + pushl %ecx
22316 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22317 + mov %eax, %esi
22318 +#else
22319 + mov %cr0, %esi
22320 +#endif
22321 + bts $16, %esi
22322 + jnc 1f
22323 + mov %cs, %esi
22324 + cmp $__KERNEL_CS, %esi
22325 + jz 3f
22326 + ljmp $__KERNEL_CS, $3f
22327 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22328 +2:
22329 +#ifdef CONFIG_PARAVIRT
22330 + mov %esi, %eax
22331 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22332 +#else
22333 + mov %esi, %cr0
22334 +#endif
22335 +3:
22336 +#ifdef CONFIG_PARAVIRT
22337 + popl %ecx
22338 + popl %eax
22339 +#endif
22340 + ret
22341 +ENDPROC(pax_enter_kernel)
22342 +
22343 +ENTRY(pax_exit_kernel)
22344 +#ifdef CONFIG_PARAVIRT
22345 + pushl %eax
22346 + pushl %ecx
22347 +#endif
22348 + mov %cs, %esi
22349 + cmp $__KERNEXEC_KERNEL_CS, %esi
22350 + jnz 2f
22351 +#ifdef CONFIG_PARAVIRT
22352 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22353 + mov %eax, %esi
22354 +#else
22355 + mov %cr0, %esi
22356 +#endif
22357 + btr $16, %esi
22358 + ljmp $__KERNEL_CS, $1f
22359 +1:
22360 +#ifdef CONFIG_PARAVIRT
22361 + mov %esi, %eax
22362 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22363 +#else
22364 + mov %esi, %cr0
22365 +#endif
22366 +2:
22367 +#ifdef CONFIG_PARAVIRT
22368 + popl %ecx
22369 + popl %eax
22370 +#endif
22371 + ret
22372 +ENDPROC(pax_exit_kernel)
22373 +#endif
22374 +
22375 + .macro pax_erase_kstack
22376 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22377 + call pax_erase_kstack
22378 +#endif
22379 + .endm
22380 +
22381 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22382 +/*
22383 + * ebp: thread_info
22384 + */
22385 +ENTRY(pax_erase_kstack)
22386 + pushl %edi
22387 + pushl %ecx
22388 + pushl %eax
22389 +
22390 + mov TI_lowest_stack(%ebp), %edi
22391 + mov $-0xBEEF, %eax
22392 + std
22393 +
22394 +1: mov %edi, %ecx
22395 + and $THREAD_SIZE_asm - 1, %ecx
22396 + shr $2, %ecx
22397 + repne scasl
22398 + jecxz 2f
22399 +
22400 + cmp $2*16, %ecx
22401 + jc 2f
22402 +
22403 + mov $2*16, %ecx
22404 + repe scasl
22405 + jecxz 2f
22406 + jne 1b
22407 +
22408 +2: cld
22409 + or $2*4, %edi
22410 + mov %esp, %ecx
22411 + sub %edi, %ecx
22412 +
22413 + cmp $THREAD_SIZE_asm, %ecx
22414 + jb 3f
22415 + ud2
22416 +3:
22417 +
22418 + shr $2, %ecx
22419 + rep stosl
22420 +
22421 + mov TI_task_thread_sp0(%ebp), %edi
22422 + sub $128, %edi
22423 + mov %edi, TI_lowest_stack(%ebp)
22424 +
22425 + popl %eax
22426 + popl %ecx
22427 + popl %edi
22428 + ret
22429 +ENDPROC(pax_erase_kstack)
22430 +#endif
22431 +
22432 +.macro __SAVE_ALL _DS
22433 cld
22434 PUSH_GS
22435 pushl_cfi %fs
22436 @@ -206,7 +347,7 @@
22437 CFI_REL_OFFSET ecx, 0
22438 pushl_cfi %ebx
22439 CFI_REL_OFFSET ebx, 0
22440 - movl $(__USER_DS), %edx
22441 + movl $\_DS, %edx
22442 movl %edx, %ds
22443 movl %edx, %es
22444 movl $(__KERNEL_PERCPU), %edx
22445 @@ -214,6 +355,15 @@
22446 SET_KERNEL_GS %edx
22447 .endm
22448
22449 +.macro SAVE_ALL
22450 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22451 + __SAVE_ALL __KERNEL_DS
22452 + pax_enter_kernel
22453 +#else
22454 + __SAVE_ALL __USER_DS
22455 +#endif
22456 +.endm
22457 +
22458 .macro RESTORE_INT_REGS
22459 popl_cfi %ebx
22460 CFI_RESTORE ebx
22461 @@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22462 popfl_cfi
22463 jmp syscall_exit
22464 CFI_ENDPROC
22465 -END(ret_from_fork)
22466 +ENDPROC(ret_from_fork)
22467
22468 ENTRY(ret_from_kernel_thread)
22469 CFI_STARTPROC
22470 @@ -340,7 +490,15 @@ ret_from_intr:
22471 andl $SEGMENT_RPL_MASK, %eax
22472 #endif
22473 cmpl $USER_RPL, %eax
22474 +
22475 +#ifdef CONFIG_PAX_KERNEXEC
22476 + jae resume_userspace
22477 +
22478 + pax_exit_kernel
22479 + jmp resume_kernel
22480 +#else
22481 jb resume_kernel # not returning to v8086 or userspace
22482 +#endif
22483
22484 ENTRY(resume_userspace)
22485 LOCKDEP_SYS_EXIT
22486 @@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22487 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22488 # int/exception return?
22489 jne work_pending
22490 - jmp restore_all
22491 -END(ret_from_exception)
22492 + jmp restore_all_pax
22493 +ENDPROC(ret_from_exception)
22494
22495 #ifdef CONFIG_PREEMPT
22496 ENTRY(resume_kernel)
22497 @@ -365,7 +523,7 @@ need_resched:
22498 jz restore_all
22499 call preempt_schedule_irq
22500 jmp need_resched
22501 -END(resume_kernel)
22502 +ENDPROC(resume_kernel)
22503 #endif
22504 CFI_ENDPROC
22505
22506 @@ -395,30 +553,45 @@ sysenter_past_esp:
22507 /*CFI_REL_OFFSET cs, 0*/
22508 /*
22509 * Push current_thread_info()->sysenter_return to the stack.
22510 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22511 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22512 */
22513 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22514 + pushl_cfi $0
22515 CFI_REL_OFFSET eip, 0
22516
22517 pushl_cfi %eax
22518 SAVE_ALL
22519 + GET_THREAD_INFO(%ebp)
22520 + movl TI_sysenter_return(%ebp),%ebp
22521 + movl %ebp,PT_EIP(%esp)
22522 ENABLE_INTERRUPTS(CLBR_NONE)
22523
22524 /*
22525 * Load the potential sixth argument from user stack.
22526 * Careful about security.
22527 */
22528 + movl PT_OLDESP(%esp),%ebp
22529 +
22530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22531 + mov PT_OLDSS(%esp),%ds
22532 +1: movl %ds:(%ebp),%ebp
22533 + push %ss
22534 + pop %ds
22535 +#else
22536 cmpl $__PAGE_OFFSET-3,%ebp
22537 jae syscall_fault
22538 ASM_STAC
22539 1: movl (%ebp),%ebp
22540 ASM_CLAC
22541 +#endif
22542 +
22543 movl %ebp,PT_EBP(%esp)
22544 _ASM_EXTABLE(1b,syscall_fault)
22545
22546 GET_THREAD_INFO(%ebp)
22547
22548 +#ifdef CONFIG_PAX_RANDKSTACK
22549 + pax_erase_kstack
22550 +#endif
22551 +
22552 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22553 jnz sysenter_audit
22554 sysenter_do_call:
22555 @@ -434,12 +607,24 @@ sysenter_after_call:
22556 testl $_TIF_ALLWORK_MASK, %ecx
22557 jne sysexit_audit
22558 sysenter_exit:
22559 +
22560 +#ifdef CONFIG_PAX_RANDKSTACK
22561 + pushl_cfi %eax
22562 + movl %esp, %eax
22563 + call pax_randomize_kstack
22564 + popl_cfi %eax
22565 +#endif
22566 +
22567 + pax_erase_kstack
22568 +
22569 /* if something modifies registers it must also disable sysexit */
22570 movl PT_EIP(%esp), %edx
22571 movl PT_OLDESP(%esp), %ecx
22572 xorl %ebp,%ebp
22573 TRACE_IRQS_ON
22574 1: mov PT_FS(%esp), %fs
22575 +2: mov PT_DS(%esp), %ds
22576 +3: mov PT_ES(%esp), %es
22577 PTGS_TO_GS
22578 ENABLE_INTERRUPTS_SYSEXIT
22579
22580 @@ -453,6 +638,9 @@ sysenter_audit:
22581 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22582 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22583 call __audit_syscall_entry
22584 +
22585 + pax_erase_kstack
22586 +
22587 popl_cfi %ecx /* get that remapped edx off the stack */
22588 popl_cfi %ecx /* get that remapped esi off the stack */
22589 movl PT_EAX(%esp),%eax /* reload syscall number */
22590 @@ -479,10 +667,16 @@ sysexit_audit:
22591
22592 CFI_ENDPROC
22593 .pushsection .fixup,"ax"
22594 -2: movl $0,PT_FS(%esp)
22595 +4: movl $0,PT_FS(%esp)
22596 + jmp 1b
22597 +5: movl $0,PT_DS(%esp)
22598 + jmp 1b
22599 +6: movl $0,PT_ES(%esp)
22600 jmp 1b
22601 .popsection
22602 - _ASM_EXTABLE(1b,2b)
22603 + _ASM_EXTABLE(1b,4b)
22604 + _ASM_EXTABLE(2b,5b)
22605 + _ASM_EXTABLE(3b,6b)
22606 PTGS_TO_GS_EX
22607 ENDPROC(ia32_sysenter_target)
22608
22609 @@ -493,6 +687,11 @@ ENTRY(system_call)
22610 pushl_cfi %eax # save orig_eax
22611 SAVE_ALL
22612 GET_THREAD_INFO(%ebp)
22613 +
22614 +#ifdef CONFIG_PAX_RANDKSTACK
22615 + pax_erase_kstack
22616 +#endif
22617 +
22618 # system call tracing in operation / emulation
22619 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22620 jnz syscall_trace_entry
22621 @@ -512,6 +711,15 @@ syscall_exit:
22622 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22623 jne syscall_exit_work
22624
22625 +restore_all_pax:
22626 +
22627 +#ifdef CONFIG_PAX_RANDKSTACK
22628 + movl %esp, %eax
22629 + call pax_randomize_kstack
22630 +#endif
22631 +
22632 + pax_erase_kstack
22633 +
22634 restore_all:
22635 TRACE_IRQS_IRET
22636 restore_all_notrace:
22637 @@ -566,14 +774,34 @@ ldt_ss:
22638 * compensating for the offset by changing to the ESPFIX segment with
22639 * a base address that matches for the difference.
22640 */
22641 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22642 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22643 mov %esp, %edx /* load kernel esp */
22644 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22645 mov %dx, %ax /* eax: new kernel esp */
22646 sub %eax, %edx /* offset (low word is 0) */
22647 +#ifdef CONFIG_SMP
22648 + movl PER_CPU_VAR(cpu_number), %ebx
22649 + shll $PAGE_SHIFT_asm, %ebx
22650 + addl $cpu_gdt_table, %ebx
22651 +#else
22652 + movl $cpu_gdt_table, %ebx
22653 +#endif
22654 shr $16, %edx
22655 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22656 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22657 +
22658 +#ifdef CONFIG_PAX_KERNEXEC
22659 + mov %cr0, %esi
22660 + btr $16, %esi
22661 + mov %esi, %cr0
22662 +#endif
22663 +
22664 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22665 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22666 +
22667 +#ifdef CONFIG_PAX_KERNEXEC
22668 + bts $16, %esi
22669 + mov %esi, %cr0
22670 +#endif
22671 +
22672 pushl_cfi $__ESPFIX_SS
22673 pushl_cfi %eax /* new kernel esp */
22674 /* Disable interrupts, but do not irqtrace this section: we
22675 @@ -603,20 +831,18 @@ work_resched:
22676 movl TI_flags(%ebp), %ecx
22677 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22678 # than syscall tracing?
22679 - jz restore_all
22680 + jz restore_all_pax
22681 testb $_TIF_NEED_RESCHED, %cl
22682 jnz work_resched
22683
22684 work_notifysig: # deal with pending signals and
22685 # notify-resume requests
22686 + movl %esp, %eax
22687 #ifdef CONFIG_VM86
22688 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22689 - movl %esp, %eax
22690 jne work_notifysig_v86 # returning to kernel-space or
22691 # vm86-space
22692 1:
22693 -#else
22694 - movl %esp, %eax
22695 #endif
22696 TRACE_IRQS_ON
22697 ENABLE_INTERRUPTS(CLBR_NONE)
22698 @@ -637,7 +863,7 @@ work_notifysig_v86:
22699 movl %eax, %esp
22700 jmp 1b
22701 #endif
22702 -END(work_pending)
22703 +ENDPROC(work_pending)
22704
22705 # perform syscall exit tracing
22706 ALIGN
22707 @@ -645,11 +871,14 @@ syscall_trace_entry:
22708 movl $-ENOSYS,PT_EAX(%esp)
22709 movl %esp, %eax
22710 call syscall_trace_enter
22711 +
22712 + pax_erase_kstack
22713 +
22714 /* What it returned is what we'll actually use. */
22715 cmpl $(NR_syscalls), %eax
22716 jnae syscall_call
22717 jmp syscall_exit
22718 -END(syscall_trace_entry)
22719 +ENDPROC(syscall_trace_entry)
22720
22721 # perform syscall exit tracing
22722 ALIGN
22723 @@ -662,26 +891,30 @@ syscall_exit_work:
22724 movl %esp, %eax
22725 call syscall_trace_leave
22726 jmp resume_userspace
22727 -END(syscall_exit_work)
22728 +ENDPROC(syscall_exit_work)
22729 CFI_ENDPROC
22730
22731 RING0_INT_FRAME # can't unwind into user space anyway
22732 syscall_fault:
22733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22734 + push %ss
22735 + pop %ds
22736 +#endif
22737 ASM_CLAC
22738 GET_THREAD_INFO(%ebp)
22739 movl $-EFAULT,PT_EAX(%esp)
22740 jmp resume_userspace
22741 -END(syscall_fault)
22742 +ENDPROC(syscall_fault)
22743
22744 syscall_badsys:
22745 movl $-ENOSYS,%eax
22746 jmp syscall_after_call
22747 -END(syscall_badsys)
22748 +ENDPROC(syscall_badsys)
22749
22750 sysenter_badsys:
22751 movl $-ENOSYS,%eax
22752 jmp sysenter_after_call
22753 -END(sysenter_badsys)
22754 +ENDPROC(sysenter_badsys)
22755 CFI_ENDPROC
22756
22757 .macro FIXUP_ESPFIX_STACK
22758 @@ -694,8 +927,15 @@ END(sysenter_badsys)
22759 */
22760 #ifdef CONFIG_X86_ESPFIX32
22761 /* fixup the stack */
22762 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22763 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22764 +#ifdef CONFIG_SMP
22765 + movl PER_CPU_VAR(cpu_number), %ebx
22766 + shll $PAGE_SHIFT_asm, %ebx
22767 + addl $cpu_gdt_table, %ebx
22768 +#else
22769 + movl $cpu_gdt_table, %ebx
22770 +#endif
22771 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22772 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22773 shl $16, %eax
22774 addl %esp, %eax /* the adjusted stack pointer */
22775 pushl_cfi $__KERNEL_DS
22776 @@ -751,7 +991,7 @@ vector=vector+1
22777 .endr
22778 2: jmp common_interrupt
22779 .endr
22780 -END(irq_entries_start)
22781 +ENDPROC(irq_entries_start)
22782
22783 .previous
22784 END(interrupt)
22785 @@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22786 pushl_cfi $do_coprocessor_error
22787 jmp error_code
22788 CFI_ENDPROC
22789 -END(coprocessor_error)
22790 +ENDPROC(coprocessor_error)
22791
22792 ENTRY(simd_coprocessor_error)
22793 RING0_INT_FRAME
22794 @@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22795 .section .altinstructions,"a"
22796 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22797 .previous
22798 -.section .altinstr_replacement,"ax"
22799 +.section .altinstr_replacement,"a"
22800 663: pushl $do_simd_coprocessor_error
22801 664:
22802 .previous
22803 @@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22804 #endif
22805 jmp error_code
22806 CFI_ENDPROC
22807 -END(simd_coprocessor_error)
22808 +ENDPROC(simd_coprocessor_error)
22809
22810 ENTRY(device_not_available)
22811 RING0_INT_FRAME
22812 @@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22813 pushl_cfi $do_device_not_available
22814 jmp error_code
22815 CFI_ENDPROC
22816 -END(device_not_available)
22817 +ENDPROC(device_not_available)
22818
22819 #ifdef CONFIG_PARAVIRT
22820 ENTRY(native_iret)
22821 iret
22822 _ASM_EXTABLE(native_iret, iret_exc)
22823 -END(native_iret)
22824 +ENDPROC(native_iret)
22825
22826 ENTRY(native_irq_enable_sysexit)
22827 sti
22828 sysexit
22829 -END(native_irq_enable_sysexit)
22830 +ENDPROC(native_irq_enable_sysexit)
22831 #endif
22832
22833 ENTRY(overflow)
22834 @@ -860,7 +1100,7 @@ ENTRY(overflow)
22835 pushl_cfi $do_overflow
22836 jmp error_code
22837 CFI_ENDPROC
22838 -END(overflow)
22839 +ENDPROC(overflow)
22840
22841 ENTRY(bounds)
22842 RING0_INT_FRAME
22843 @@ -869,7 +1109,7 @@ ENTRY(bounds)
22844 pushl_cfi $do_bounds
22845 jmp error_code
22846 CFI_ENDPROC
22847 -END(bounds)
22848 +ENDPROC(bounds)
22849
22850 ENTRY(invalid_op)
22851 RING0_INT_FRAME
22852 @@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22853 pushl_cfi $do_invalid_op
22854 jmp error_code
22855 CFI_ENDPROC
22856 -END(invalid_op)
22857 +ENDPROC(invalid_op)
22858
22859 ENTRY(coprocessor_segment_overrun)
22860 RING0_INT_FRAME
22861 @@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22862 pushl_cfi $do_coprocessor_segment_overrun
22863 jmp error_code
22864 CFI_ENDPROC
22865 -END(coprocessor_segment_overrun)
22866 +ENDPROC(coprocessor_segment_overrun)
22867
22868 ENTRY(invalid_TSS)
22869 RING0_EC_FRAME
22870 @@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22871 pushl_cfi $do_invalid_TSS
22872 jmp error_code
22873 CFI_ENDPROC
22874 -END(invalid_TSS)
22875 +ENDPROC(invalid_TSS)
22876
22877 ENTRY(segment_not_present)
22878 RING0_EC_FRAME
22879 @@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22880 pushl_cfi $do_segment_not_present
22881 jmp error_code
22882 CFI_ENDPROC
22883 -END(segment_not_present)
22884 +ENDPROC(segment_not_present)
22885
22886 ENTRY(stack_segment)
22887 RING0_EC_FRAME
22888 @@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22889 pushl_cfi $do_stack_segment
22890 jmp error_code
22891 CFI_ENDPROC
22892 -END(stack_segment)
22893 +ENDPROC(stack_segment)
22894
22895 ENTRY(alignment_check)
22896 RING0_EC_FRAME
22897 @@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22898 pushl_cfi $do_alignment_check
22899 jmp error_code
22900 CFI_ENDPROC
22901 -END(alignment_check)
22902 +ENDPROC(alignment_check)
22903
22904 ENTRY(divide_error)
22905 RING0_INT_FRAME
22906 @@ -928,7 +1168,7 @@ ENTRY(divide_error)
22907 pushl_cfi $do_divide_error
22908 jmp error_code
22909 CFI_ENDPROC
22910 -END(divide_error)
22911 +ENDPROC(divide_error)
22912
22913 #ifdef CONFIG_X86_MCE
22914 ENTRY(machine_check)
22915 @@ -938,7 +1178,7 @@ ENTRY(machine_check)
22916 pushl_cfi machine_check_vector
22917 jmp error_code
22918 CFI_ENDPROC
22919 -END(machine_check)
22920 +ENDPROC(machine_check)
22921 #endif
22922
22923 ENTRY(spurious_interrupt_bug)
22924 @@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22925 pushl_cfi $do_spurious_interrupt_bug
22926 jmp error_code
22927 CFI_ENDPROC
22928 -END(spurious_interrupt_bug)
22929 +ENDPROC(spurious_interrupt_bug)
22930
22931 #ifdef CONFIG_XEN
22932 /* Xen doesn't set %esp to be precisely what the normal sysenter
22933 @@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22934
22935 ENTRY(mcount)
22936 ret
22937 -END(mcount)
22938 +ENDPROC(mcount)
22939
22940 ENTRY(ftrace_caller)
22941 pushl %eax
22942 @@ -1084,7 +1324,7 @@ ftrace_graph_call:
22943 .globl ftrace_stub
22944 ftrace_stub:
22945 ret
22946 -END(ftrace_caller)
22947 +ENDPROC(ftrace_caller)
22948
22949 ENTRY(ftrace_regs_caller)
22950 pushf /* push flags before compare (in cs location) */
22951 @@ -1182,7 +1422,7 @@ trace:
22952 popl %ecx
22953 popl %eax
22954 jmp ftrace_stub
22955 -END(mcount)
22956 +ENDPROC(mcount)
22957 #endif /* CONFIG_DYNAMIC_FTRACE */
22958 #endif /* CONFIG_FUNCTION_TRACER */
22959
22960 @@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
22961 popl %ecx
22962 popl %eax
22963 ret
22964 -END(ftrace_graph_caller)
22965 +ENDPROC(ftrace_graph_caller)
22966
22967 .globl return_to_handler
22968 return_to_handler:
22969 @@ -1261,15 +1501,18 @@ error_code:
22970 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22971 REG_TO_PTGS %ecx
22972 SET_KERNEL_GS %ecx
22973 - movl $(__USER_DS), %ecx
22974 + movl $(__KERNEL_DS), %ecx
22975 movl %ecx, %ds
22976 movl %ecx, %es
22977 +
22978 + pax_enter_kernel
22979 +
22980 TRACE_IRQS_OFF
22981 movl %esp,%eax # pt_regs pointer
22982 call *%edi
22983 jmp ret_from_exception
22984 CFI_ENDPROC
22985 -END(page_fault)
22986 +ENDPROC(page_fault)
22987
22988 /*
22989 * Debug traps and NMI can happen at the one SYSENTER instruction
22990 @@ -1312,7 +1555,7 @@ debug_stack_correct:
22991 call do_debug
22992 jmp ret_from_exception
22993 CFI_ENDPROC
22994 -END(debug)
22995 +ENDPROC(debug)
22996
22997 /*
22998 * NMI is doubly nasty. It can happen _while_ we're handling
22999 @@ -1352,6 +1595,9 @@ nmi_stack_correct:
23000 xorl %edx,%edx # zero error code
23001 movl %esp,%eax # pt_regs pointer
23002 call do_nmi
23003 +
23004 + pax_exit_kernel
23005 +
23006 jmp restore_all_notrace
23007 CFI_ENDPROC
23008
23009 @@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23010 FIXUP_ESPFIX_STACK # %eax == %esp
23011 xorl %edx,%edx # zero error code
23012 call do_nmi
23013 +
23014 + pax_exit_kernel
23015 +
23016 RESTORE_REGS
23017 lss 12+4(%esp), %esp # back to espfix stack
23018 CFI_ADJUST_CFA_OFFSET -24
23019 jmp irq_return
23020 #endif
23021 CFI_ENDPROC
23022 -END(nmi)
23023 +ENDPROC(nmi)
23024
23025 ENTRY(int3)
23026 RING0_INT_FRAME
23027 @@ -1408,14 +1657,14 @@ ENTRY(int3)
23028 call do_int3
23029 jmp ret_from_exception
23030 CFI_ENDPROC
23031 -END(int3)
23032 +ENDPROC(int3)
23033
23034 ENTRY(general_protection)
23035 RING0_EC_FRAME
23036 pushl_cfi $do_general_protection
23037 jmp error_code
23038 CFI_ENDPROC
23039 -END(general_protection)
23040 +ENDPROC(general_protection)
23041
23042 #ifdef CONFIG_KVM_GUEST
23043 ENTRY(async_page_fault)
23044 @@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23045 pushl_cfi $do_async_page_fault
23046 jmp error_code
23047 CFI_ENDPROC
23048 -END(async_page_fault)
23049 +ENDPROC(async_page_fault)
23050 #endif
23051
23052 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23053 index c0226ab..0d1dc48 100644
23054 --- a/arch/x86/kernel/entry_64.S
23055 +++ b/arch/x86/kernel/entry_64.S
23056 @@ -59,6 +59,8 @@
23057 #include <asm/smap.h>
23058 #include <asm/pgtable_types.h>
23059 #include <linux/err.h>
23060 +#include <asm/pgtable.h>
23061 +#include <asm/alternative-asm.h>
23062
23063 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23064 #include <linux/elf-em.h>
23065 @@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23066 ENDPROC(native_usergs_sysret64)
23067 #endif /* CONFIG_PARAVIRT */
23068
23069 + .macro ljmpq sel, off
23070 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23071 + .byte 0x48; ljmp *1234f(%rip)
23072 + .pushsection .rodata
23073 + .align 16
23074 + 1234: .quad \off; .word \sel
23075 + .popsection
23076 +#else
23077 + pushq $\sel
23078 + pushq $\off
23079 + lretq
23080 +#endif
23081 + .endm
23082 +
23083 + .macro pax_enter_kernel
23084 + pax_set_fptr_mask
23085 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23086 + call pax_enter_kernel
23087 +#endif
23088 + .endm
23089 +
23090 + .macro pax_exit_kernel
23091 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23092 + call pax_exit_kernel
23093 +#endif
23094 +
23095 + .endm
23096 +
23097 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23098 +ENTRY(pax_enter_kernel)
23099 + pushq %rdi
23100 +
23101 +#ifdef CONFIG_PARAVIRT
23102 + PV_SAVE_REGS(CLBR_RDI)
23103 +#endif
23104 +
23105 +#ifdef CONFIG_PAX_KERNEXEC
23106 + GET_CR0_INTO_RDI
23107 + bts $16,%rdi
23108 + jnc 3f
23109 + mov %cs,%edi
23110 + cmp $__KERNEL_CS,%edi
23111 + jnz 2f
23112 +1:
23113 +#endif
23114 +
23115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23116 + 661: jmp 111f
23117 + .pushsection .altinstr_replacement, "a"
23118 + 662: ASM_NOP2
23119 + .popsection
23120 + .pushsection .altinstructions, "a"
23121 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23122 + .popsection
23123 + GET_CR3_INTO_RDI
23124 + cmp $0,%dil
23125 + jnz 112f
23126 + mov $__KERNEL_DS,%edi
23127 + mov %edi,%ss
23128 + jmp 111f
23129 +112: cmp $1,%dil
23130 + jz 113f
23131 + ud2
23132 +113: sub $4097,%rdi
23133 + bts $63,%rdi
23134 + SET_RDI_INTO_CR3
23135 + mov $__UDEREF_KERNEL_DS,%edi
23136 + mov %edi,%ss
23137 +111:
23138 +#endif
23139 +
23140 +#ifdef CONFIG_PARAVIRT
23141 + PV_RESTORE_REGS(CLBR_RDI)
23142 +#endif
23143 +
23144 + popq %rdi
23145 + pax_force_retaddr
23146 + retq
23147 +
23148 +#ifdef CONFIG_PAX_KERNEXEC
23149 +2: ljmpq __KERNEL_CS,1b
23150 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23151 +4: SET_RDI_INTO_CR0
23152 + jmp 1b
23153 +#endif
23154 +ENDPROC(pax_enter_kernel)
23155 +
23156 +ENTRY(pax_exit_kernel)
23157 + pushq %rdi
23158 +
23159 +#ifdef CONFIG_PARAVIRT
23160 + PV_SAVE_REGS(CLBR_RDI)
23161 +#endif
23162 +
23163 +#ifdef CONFIG_PAX_KERNEXEC
23164 + mov %cs,%rdi
23165 + cmp $__KERNEXEC_KERNEL_CS,%edi
23166 + jz 2f
23167 + GET_CR0_INTO_RDI
23168 + bts $16,%rdi
23169 + jnc 4f
23170 +1:
23171 +#endif
23172 +
23173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23174 + 661: jmp 111f
23175 + .pushsection .altinstr_replacement, "a"
23176 + 662: ASM_NOP2
23177 + .popsection
23178 + .pushsection .altinstructions, "a"
23179 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23180 + .popsection
23181 + mov %ss,%edi
23182 + cmp $__UDEREF_KERNEL_DS,%edi
23183 + jnz 111f
23184 + GET_CR3_INTO_RDI
23185 + cmp $0,%dil
23186 + jz 112f
23187 + ud2
23188 +112: add $4097,%rdi
23189 + bts $63,%rdi
23190 + SET_RDI_INTO_CR3
23191 + mov $__KERNEL_DS,%edi
23192 + mov %edi,%ss
23193 +111:
23194 +#endif
23195 +
23196 +#ifdef CONFIG_PARAVIRT
23197 + PV_RESTORE_REGS(CLBR_RDI);
23198 +#endif
23199 +
23200 + popq %rdi
23201 + pax_force_retaddr
23202 + retq
23203 +
23204 +#ifdef CONFIG_PAX_KERNEXEC
23205 +2: GET_CR0_INTO_RDI
23206 + btr $16,%rdi
23207 + jnc 4f
23208 + ljmpq __KERNEL_CS,3f
23209 +3: SET_RDI_INTO_CR0
23210 + jmp 1b
23211 +4: ud2
23212 + jmp 4b
23213 +#endif
23214 +ENDPROC(pax_exit_kernel)
23215 +#endif
23216 +
23217 + .macro pax_enter_kernel_user
23218 + pax_set_fptr_mask
23219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23220 + call pax_enter_kernel_user
23221 +#endif
23222 + .endm
23223 +
23224 + .macro pax_exit_kernel_user
23225 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23226 + call pax_exit_kernel_user
23227 +#endif
23228 +#ifdef CONFIG_PAX_RANDKSTACK
23229 + pushq %rax
23230 + pushq %r11
23231 + call pax_randomize_kstack
23232 + popq %r11
23233 + popq %rax
23234 +#endif
23235 + .endm
23236 +
23237 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23238 +ENTRY(pax_enter_kernel_user)
23239 + pushq %rdi
23240 + pushq %rbx
23241 +
23242 +#ifdef CONFIG_PARAVIRT
23243 + PV_SAVE_REGS(CLBR_RDI)
23244 +#endif
23245 +
23246 + 661: jmp 111f
23247 + .pushsection .altinstr_replacement, "a"
23248 + 662: ASM_NOP2
23249 + .popsection
23250 + .pushsection .altinstructions, "a"
23251 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23252 + .popsection
23253 + GET_CR3_INTO_RDI
23254 + cmp $1,%dil
23255 + jnz 4f
23256 + sub $4097,%rdi
23257 + bts $63,%rdi
23258 + SET_RDI_INTO_CR3
23259 + jmp 3f
23260 +111:
23261 +
23262 + GET_CR3_INTO_RDI
23263 + mov %rdi,%rbx
23264 + add $__START_KERNEL_map,%rbx
23265 + sub phys_base(%rip),%rbx
23266 +
23267 +#ifdef CONFIG_PARAVIRT
23268 + cmpl $0, pv_info+PARAVIRT_enabled
23269 + jz 1f
23270 + pushq %rdi
23271 + i = 0
23272 + .rept USER_PGD_PTRS
23273 + mov i*8(%rbx),%rsi
23274 + mov $0,%sil
23275 + lea i*8(%rbx),%rdi
23276 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23277 + i = i + 1
23278 + .endr
23279 + popq %rdi
23280 + jmp 2f
23281 +1:
23282 +#endif
23283 +
23284 + i = 0
23285 + .rept USER_PGD_PTRS
23286 + movb $0,i*8(%rbx)
23287 + i = i + 1
23288 + .endr
23289 +
23290 +2: SET_RDI_INTO_CR3
23291 +
23292 +#ifdef CONFIG_PAX_KERNEXEC
23293 + GET_CR0_INTO_RDI
23294 + bts $16,%rdi
23295 + SET_RDI_INTO_CR0
23296 +#endif
23297 +
23298 +3:
23299 +
23300 +#ifdef CONFIG_PARAVIRT
23301 + PV_RESTORE_REGS(CLBR_RDI)
23302 +#endif
23303 +
23304 + popq %rbx
23305 + popq %rdi
23306 + pax_force_retaddr
23307 + retq
23308 +4: ud2
23309 +ENDPROC(pax_enter_kernel_user)
23310 +
23311 +ENTRY(pax_exit_kernel_user)
23312 + pushq %rdi
23313 + pushq %rbx
23314 +
23315 +#ifdef CONFIG_PARAVIRT
23316 + PV_SAVE_REGS(CLBR_RDI)
23317 +#endif
23318 +
23319 + GET_CR3_INTO_RDI
23320 + 661: jmp 1f
23321 + .pushsection .altinstr_replacement, "a"
23322 + 662: ASM_NOP2
23323 + .popsection
23324 + .pushsection .altinstructions, "a"
23325 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23326 + .popsection
23327 + cmp $0,%dil
23328 + jnz 3f
23329 + add $4097,%rdi
23330 + bts $63,%rdi
23331 + SET_RDI_INTO_CR3
23332 + jmp 2f
23333 +1:
23334 +
23335 + mov %rdi,%rbx
23336 +
23337 +#ifdef CONFIG_PAX_KERNEXEC
23338 + GET_CR0_INTO_RDI
23339 + btr $16,%rdi
23340 + jnc 3f
23341 + SET_RDI_INTO_CR0
23342 +#endif
23343 +
23344 + add $__START_KERNEL_map,%rbx
23345 + sub phys_base(%rip),%rbx
23346 +
23347 +#ifdef CONFIG_PARAVIRT
23348 + cmpl $0, pv_info+PARAVIRT_enabled
23349 + jz 1f
23350 + i = 0
23351 + .rept USER_PGD_PTRS
23352 + mov i*8(%rbx),%rsi
23353 + mov $0x67,%sil
23354 + lea i*8(%rbx),%rdi
23355 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23356 + i = i + 1
23357 + .endr
23358 + jmp 2f
23359 +1:
23360 +#endif
23361 +
23362 + i = 0
23363 + .rept USER_PGD_PTRS
23364 + movb $0x67,i*8(%rbx)
23365 + i = i + 1
23366 + .endr
23367 +2:
23368 +
23369 +#ifdef CONFIG_PARAVIRT
23370 + PV_RESTORE_REGS(CLBR_RDI)
23371 +#endif
23372 +
23373 + popq %rbx
23374 + popq %rdi
23375 + pax_force_retaddr
23376 + retq
23377 +3: ud2
23378 +ENDPROC(pax_exit_kernel_user)
23379 +#endif
23380 +
23381 + .macro pax_enter_kernel_nmi
23382 + pax_set_fptr_mask
23383 +
23384 +#ifdef CONFIG_PAX_KERNEXEC
23385 + GET_CR0_INTO_RDI
23386 + bts $16,%rdi
23387 + jc 110f
23388 + SET_RDI_INTO_CR0
23389 + or $2,%ebx
23390 +110:
23391 +#endif
23392 +
23393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23394 + 661: jmp 111f
23395 + .pushsection .altinstr_replacement, "a"
23396 + 662: ASM_NOP2
23397 + .popsection
23398 + .pushsection .altinstructions, "a"
23399 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23400 + .popsection
23401 + GET_CR3_INTO_RDI
23402 + cmp $0,%dil
23403 + jz 111f
23404 + sub $4097,%rdi
23405 + or $4,%ebx
23406 + bts $63,%rdi
23407 + SET_RDI_INTO_CR3
23408 + mov $__UDEREF_KERNEL_DS,%edi
23409 + mov %edi,%ss
23410 +111:
23411 +#endif
23412 + .endm
23413 +
23414 + .macro pax_exit_kernel_nmi
23415 +#ifdef CONFIG_PAX_KERNEXEC
23416 + btr $1,%ebx
23417 + jnc 110f
23418 + GET_CR0_INTO_RDI
23419 + btr $16,%rdi
23420 + SET_RDI_INTO_CR0
23421 +110:
23422 +#endif
23423 +
23424 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23425 + btr $2,%ebx
23426 + jnc 111f
23427 + GET_CR3_INTO_RDI
23428 + add $4097,%rdi
23429 + bts $63,%rdi
23430 + SET_RDI_INTO_CR3
23431 + mov $__KERNEL_DS,%edi
23432 + mov %edi,%ss
23433 +111:
23434 +#endif
23435 + .endm
23436 +
23437 + .macro pax_erase_kstack
23438 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23439 + call pax_erase_kstack
23440 +#endif
23441 + .endm
23442 +
23443 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23444 +ENTRY(pax_erase_kstack)
23445 + pushq %rdi
23446 + pushq %rcx
23447 + pushq %rax
23448 + pushq %r11
23449 +
23450 + GET_THREAD_INFO(%r11)
23451 + mov TI_lowest_stack(%r11), %rdi
23452 + mov $-0xBEEF, %rax
23453 + std
23454 +
23455 +1: mov %edi, %ecx
23456 + and $THREAD_SIZE_asm - 1, %ecx
23457 + shr $3, %ecx
23458 + repne scasq
23459 + jecxz 2f
23460 +
23461 + cmp $2*8, %ecx
23462 + jc 2f
23463 +
23464 + mov $2*8, %ecx
23465 + repe scasq
23466 + jecxz 2f
23467 + jne 1b
23468 +
23469 +2: cld
23470 + or $2*8, %rdi
23471 + mov %esp, %ecx
23472 + sub %edi, %ecx
23473 +
23474 + cmp $THREAD_SIZE_asm, %rcx
23475 + jb 3f
23476 + ud2
23477 +3:
23478 +
23479 + shr $3, %ecx
23480 + rep stosq
23481 +
23482 + mov TI_task_thread_sp0(%r11), %rdi
23483 + sub $256, %rdi
23484 + mov %rdi, TI_lowest_stack(%r11)
23485 +
23486 + popq %r11
23487 + popq %rax
23488 + popq %rcx
23489 + popq %rdi
23490 + pax_force_retaddr
23491 + ret
23492 +ENDPROC(pax_erase_kstack)
23493 +#endif
23494
23495 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23496 #ifdef CONFIG_TRACE_IRQFLAGS
23497 @@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23498 .endm
23499
23500 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23501 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23502 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23503 jnc 1f
23504 TRACE_IRQS_ON_DEBUG
23505 1:
23506 @@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23507 movq \tmp,R11+\offset(%rsp)
23508 .endm
23509
23510 - .macro FAKE_STACK_FRAME child_rip
23511 - /* push in order ss, rsp, eflags, cs, rip */
23512 - xorl %eax, %eax
23513 - pushq_cfi $__KERNEL_DS /* ss */
23514 - /*CFI_REL_OFFSET ss,0*/
23515 - pushq_cfi %rax /* rsp */
23516 - CFI_REL_OFFSET rsp,0
23517 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23518 - /*CFI_REL_OFFSET rflags,0*/
23519 - pushq_cfi $__KERNEL_CS /* cs */
23520 - /*CFI_REL_OFFSET cs,0*/
23521 - pushq_cfi \child_rip /* rip */
23522 - CFI_REL_OFFSET rip,0
23523 - pushq_cfi %rax /* orig rax */
23524 - .endm
23525 -
23526 - .macro UNFAKE_STACK_FRAME
23527 - addq $8*6, %rsp
23528 - CFI_ADJUST_CFA_OFFSET -(6*8)
23529 - .endm
23530 -
23531 /*
23532 * initial frame state for interrupts (and exceptions without error code)
23533 */
23534 @@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23535 /* save partial stack frame */
23536 .macro SAVE_ARGS_IRQ
23537 cld
23538 - /* start from rbp in pt_regs and jump over */
23539 - movq_cfi rdi, (RDI-RBP)
23540 - movq_cfi rsi, (RSI-RBP)
23541 - movq_cfi rdx, (RDX-RBP)
23542 - movq_cfi rcx, (RCX-RBP)
23543 - movq_cfi rax, (RAX-RBP)
23544 - movq_cfi r8, (R8-RBP)
23545 - movq_cfi r9, (R9-RBP)
23546 - movq_cfi r10, (R10-RBP)
23547 - movq_cfi r11, (R11-RBP)
23548 + /* start from r15 in pt_regs and jump over */
23549 + movq_cfi rdi, RDI
23550 + movq_cfi rsi, RSI
23551 + movq_cfi rdx, RDX
23552 + movq_cfi rcx, RCX
23553 + movq_cfi rax, RAX
23554 + movq_cfi r8, R8
23555 + movq_cfi r9, R9
23556 + movq_cfi r10, R10
23557 + movq_cfi r11, R11
23558 + movq_cfi r12, R12
23559
23560 /* Save rbp so that we can unwind from get_irq_regs() */
23561 - movq_cfi rbp, 0
23562 + movq_cfi rbp, RBP
23563
23564 /* Save previous stack value */
23565 movq %rsp, %rsi
23566
23567 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23568 - testl $3, CS-RBP(%rsi)
23569 + movq %rsp,%rdi /* arg1 for handler */
23570 + testb $3, CS(%rsi)
23571 je 1f
23572 SWAPGS
23573 /*
23574 @@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23575 0x06 /* DW_OP_deref */, \
23576 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23577 0x22 /* DW_OP_plus */
23578 +
23579 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23580 + testb $3, CS(%rdi)
23581 + jnz 1f
23582 + pax_enter_kernel
23583 + jmp 2f
23584 +1: pax_enter_kernel_user
23585 +2:
23586 +#else
23587 + pax_enter_kernel
23588 +#endif
23589 +
23590 /* We entered an interrupt context - irqs are off: */
23591 TRACE_IRQS_OFF
23592 .endm
23593 @@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23594 js 1f /* negative -> in kernel */
23595 SWAPGS
23596 xorl %ebx,%ebx
23597 -1: ret
23598 +1:
23599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23600 + testb $3, CS+8(%rsp)
23601 + jnz 1f
23602 + pax_enter_kernel
23603 + jmp 2f
23604 +1: pax_enter_kernel_user
23605 +2:
23606 +#else
23607 + pax_enter_kernel
23608 +#endif
23609 + pax_force_retaddr
23610 + ret
23611 CFI_ENDPROC
23612 -END(save_paranoid)
23613 +ENDPROC(save_paranoid)
23614 +
23615 +ENTRY(save_paranoid_nmi)
23616 + XCPT_FRAME 1 RDI+8
23617 + cld
23618 + movq_cfi rdi, RDI+8
23619 + movq_cfi rsi, RSI+8
23620 + movq_cfi rdx, RDX+8
23621 + movq_cfi rcx, RCX+8
23622 + movq_cfi rax, RAX+8
23623 + movq_cfi r8, R8+8
23624 + movq_cfi r9, R9+8
23625 + movq_cfi r10, R10+8
23626 + movq_cfi r11, R11+8
23627 + movq_cfi rbx, RBX+8
23628 + movq_cfi rbp, RBP+8
23629 + movq_cfi r12, R12+8
23630 + movq_cfi r13, R13+8
23631 + movq_cfi r14, R14+8
23632 + movq_cfi r15, R15+8
23633 + movl $1,%ebx
23634 + movl $MSR_GS_BASE,%ecx
23635 + rdmsr
23636 + testl %edx,%edx
23637 + js 1f /* negative -> in kernel */
23638 + SWAPGS
23639 + xorl %ebx,%ebx
23640 +1: pax_enter_kernel_nmi
23641 + pax_force_retaddr
23642 + ret
23643 + CFI_ENDPROC
23644 +ENDPROC(save_paranoid_nmi)
23645
23646 /*
23647 * A newly forked process directly context switches into this address.
23648 @@ -331,7 +793,7 @@ ENTRY(ret_from_fork)
23649
23650 RESTORE_REST
23651
23652 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23653 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23654 jz 1f
23655
23656 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23657 @@ -341,15 +803,13 @@ ENTRY(ret_from_fork)
23658 jmp ret_from_sys_call # go to the SYSRET fastpath
23659
23660 1:
23661 - subq $REST_SKIP, %rsp # leave space for volatiles
23662 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23663 movq %rbp, %rdi
23664 call *%rbx
23665 movl $0, RAX(%rsp)
23666 RESTORE_REST
23667 jmp int_ret_from_sys_call
23668 CFI_ENDPROC
23669 -END(ret_from_fork)
23670 +ENDPROC(ret_from_fork)
23671
23672 /*
23673 * System call entry. Up to 6 arguments in registers are supported.
23674 @@ -386,7 +846,7 @@ END(ret_from_fork)
23675 ENTRY(system_call)
23676 CFI_STARTPROC simple
23677 CFI_SIGNAL_FRAME
23678 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23679 + CFI_DEF_CFA rsp,0
23680 CFI_REGISTER rip,rcx
23681 /*CFI_REGISTER rflags,r11*/
23682 SWAPGS_UNSAFE_STACK
23683 @@ -399,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23684
23685 movq %rsp,PER_CPU_VAR(old_rsp)
23686 movq PER_CPU_VAR(kernel_stack),%rsp
23687 + SAVE_ARGS 8*6, 0, rax_enosys=1
23688 + pax_enter_kernel_user
23689 +
23690 +#ifdef CONFIG_PAX_RANDKSTACK
23691 + pax_erase_kstack
23692 +#endif
23693 +
23694 /*
23695 * No need to follow this irqs off/on section - it's straight
23696 * and short:
23697 */
23698 ENABLE_INTERRUPTS(CLBR_NONE)
23699 - SAVE_ARGS 8, 0, rax_enosys=1
23700 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23701 movq %rcx,RIP-ARGOFFSET(%rsp)
23702 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23703 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23704 + GET_THREAD_INFO(%rcx)
23705 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23706 jnz tracesys
23707 system_call_fastpath:
23708 #if __SYSCALL_MASK == ~0
23709 @@ -432,10 +899,13 @@ sysret_check:
23710 LOCKDEP_SYS_EXIT
23711 DISABLE_INTERRUPTS(CLBR_NONE)
23712 TRACE_IRQS_OFF
23713 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23714 + GET_THREAD_INFO(%rcx)
23715 + movl TI_flags(%rcx),%edx
23716 andl %edi,%edx
23717 jnz sysret_careful
23718 CFI_REMEMBER_STATE
23719 + pax_exit_kernel_user
23720 + pax_erase_kstack
23721 /*
23722 * sysretq will re-enable interrupts:
23723 */
23724 @@ -494,12 +964,15 @@ sysret_audit:
23725
23726 /* Do syscall tracing */
23727 tracesys:
23728 - leaq -REST_SKIP(%rsp), %rdi
23729 + movq %rsp, %rdi
23730 movq $AUDIT_ARCH_X86_64, %rsi
23731 call syscall_trace_enter_phase1
23732 test %rax, %rax
23733 jnz tracesys_phase2 /* if needed, run the slow path */
23734 - LOAD_ARGS 0 /* else restore clobbered regs */
23735 +
23736 + pax_erase_kstack
23737 +
23738 + LOAD_ARGS /* else restore clobbered regs */
23739 jmp system_call_fastpath /* and return to the fast path */
23740
23741 tracesys_phase2:
23742 @@ -510,12 +983,14 @@ tracesys_phase2:
23743 movq %rax,%rdx
23744 call syscall_trace_enter_phase2
23745
23746 + pax_erase_kstack
23747 +
23748 /*
23749 * Reload arg registers from stack in case ptrace changed them.
23750 * We don't reload %rax because syscall_trace_entry_phase2() returned
23751 * the value it wants us to use in the table lookup.
23752 */
23753 - LOAD_ARGS ARGOFFSET, 1
23754 + LOAD_ARGS 1
23755 RESTORE_REST
23756 #if __SYSCALL_MASK == ~0
23757 cmpq $__NR_syscall_max,%rax
23758 @@ -545,7 +1020,9 @@ GLOBAL(int_with_check)
23759 andl %edi,%edx
23760 jnz int_careful
23761 andl $~TS_COMPAT,TI_status(%rcx)
23762 - jmp retint_swapgs
23763 + pax_exit_kernel_user
23764 + pax_erase_kstack
23765 + jmp retint_swapgs_pax
23766
23767 /* Either reschedule or signal or syscall exit tracking needed. */
23768 /* First do a reschedule test. */
23769 @@ -591,7 +1068,7 @@ int_restore_rest:
23770 TRACE_IRQS_OFF
23771 jmp int_with_check
23772 CFI_ENDPROC
23773 -END(system_call)
23774 +ENDPROC(system_call)
23775
23776 .macro FORK_LIKE func
23777 ENTRY(stub_\func)
23778 @@ -604,9 +1081,10 @@ ENTRY(stub_\func)
23779 DEFAULT_FRAME 0 8 /* offset 8: return address */
23780 call sys_\func
23781 RESTORE_TOP_OF_STACK %r11, 8
23782 - ret $REST_SKIP /* pop extended registers */
23783 + pax_force_retaddr
23784 + ret
23785 CFI_ENDPROC
23786 -END(stub_\func)
23787 +ENDPROC(stub_\func)
23788 .endm
23789
23790 .macro FIXED_FRAME label,func
23791 @@ -616,9 +1094,10 @@ ENTRY(\label)
23792 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23793 call \func
23794 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23795 + pax_force_retaddr
23796 ret
23797 CFI_ENDPROC
23798 -END(\label)
23799 +ENDPROC(\label)
23800 .endm
23801
23802 FORK_LIKE clone
23803 @@ -626,19 +1105,6 @@ END(\label)
23804 FORK_LIKE vfork
23805 FIXED_FRAME stub_iopl, sys_iopl
23806
23807 -ENTRY(ptregscall_common)
23808 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23809 - RESTORE_TOP_OF_STACK %r11, 8
23810 - movq_cfi_restore R15+8, r15
23811 - movq_cfi_restore R14+8, r14
23812 - movq_cfi_restore R13+8, r13
23813 - movq_cfi_restore R12+8, r12
23814 - movq_cfi_restore RBP+8, rbp
23815 - movq_cfi_restore RBX+8, rbx
23816 - ret $REST_SKIP /* pop extended registers */
23817 - CFI_ENDPROC
23818 -END(ptregscall_common)
23819 -
23820 ENTRY(stub_execve)
23821 CFI_STARTPROC
23822 addq $8, %rsp
23823 @@ -650,7 +1116,7 @@ ENTRY(stub_execve)
23824 RESTORE_REST
23825 jmp int_ret_from_sys_call
23826 CFI_ENDPROC
23827 -END(stub_execve)
23828 +ENDPROC(stub_execve)
23829
23830 /*
23831 * sigreturn is special because it needs to restore all registers on return.
23832 @@ -667,7 +1133,7 @@ ENTRY(stub_rt_sigreturn)
23833 RESTORE_REST
23834 jmp int_ret_from_sys_call
23835 CFI_ENDPROC
23836 -END(stub_rt_sigreturn)
23837 +ENDPROC(stub_rt_sigreturn)
23838
23839 #ifdef CONFIG_X86_X32_ABI
23840 ENTRY(stub_x32_rt_sigreturn)
23841 @@ -681,7 +1147,7 @@ ENTRY(stub_x32_rt_sigreturn)
23842 RESTORE_REST
23843 jmp int_ret_from_sys_call
23844 CFI_ENDPROC
23845 -END(stub_x32_rt_sigreturn)
23846 +ENDPROC(stub_x32_rt_sigreturn)
23847
23848 ENTRY(stub_x32_execve)
23849 CFI_STARTPROC
23850 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_execve)
23851 RESTORE_REST
23852 jmp int_ret_from_sys_call
23853 CFI_ENDPROC
23854 -END(stub_x32_execve)
23855 +ENDPROC(stub_x32_execve)
23856
23857 #endif
23858
23859 @@ -732,7 +1198,7 @@ vector=vector+1
23860 2: jmp common_interrupt
23861 .endr
23862 CFI_ENDPROC
23863 -END(irq_entries_start)
23864 +ENDPROC(irq_entries_start)
23865
23866 .previous
23867 END(interrupt)
23868 @@ -749,8 +1215,8 @@ END(interrupt)
23869 /* 0(%rsp): ~(interrupt number) */
23870 .macro interrupt func
23871 /* reserve pt_regs for scratch regs and rbp */
23872 - subq $ORIG_RAX-RBP, %rsp
23873 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23874 + subq $ORIG_RAX, %rsp
23875 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23876 SAVE_ARGS_IRQ
23877 call \func
23878 .endm
23879 @@ -773,14 +1239,14 @@ ret_from_intr:
23880
23881 /* Restore saved previous stack */
23882 popq %rsi
23883 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23884 - leaq ARGOFFSET-RBP(%rsi), %rsp
23885 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23886 + movq %rsi, %rsp
23887 CFI_DEF_CFA_REGISTER rsp
23888 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23889 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23890
23891 exit_intr:
23892 GET_THREAD_INFO(%rcx)
23893 - testl $3,CS-ARGOFFSET(%rsp)
23894 + testb $3,CS-ARGOFFSET(%rsp)
23895 je retint_kernel
23896
23897 /* Interrupt came from user space */
23898 @@ -802,12 +1268,35 @@ retint_swapgs: /* return to user-space */
23899 * The iretq could re-enable interrupts:
23900 */
23901 DISABLE_INTERRUPTS(CLBR_ANY)
23902 + pax_exit_kernel_user
23903 +retint_swapgs_pax:
23904 TRACE_IRQS_IRETQ
23905 SWAPGS
23906 jmp restore_args
23907
23908 retint_restore_args: /* return to kernel space */
23909 DISABLE_INTERRUPTS(CLBR_ANY)
23910 + pax_exit_kernel
23911 +
23912 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23913 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23914 + * namely calling EFI runtime services with a phys mapping. We're
23915 + * starting off with NOPs and patch in the real instrumentation
23916 + * (BTS/OR) before starting any userland process; even before starting
23917 + * up the APs.
23918 + */
23919 + .pushsection .altinstr_replacement, "a"
23920 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23921 + 602:
23922 + .popsection
23923 + 603: .fill 602b-601b, 1, 0x90
23924 + .pushsection .altinstructions, "a"
23925 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23926 + .popsection
23927 +#else
23928 + pax_force_retaddr (RIP-ARGOFFSET)
23929 +#endif
23930 +
23931 /*
23932 * The iretq could re-enable interrupts:
23933 */
23934 @@ -845,15 +1334,15 @@ native_irq_return_ldt:
23935 SWAPGS
23936 movq PER_CPU_VAR(espfix_waddr),%rdi
23937 movq %rax,(0*8)(%rdi) /* RAX */
23938 - movq (2*8)(%rsp),%rax /* RIP */
23939 + movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23940 movq %rax,(1*8)(%rdi)
23941 - movq (3*8)(%rsp),%rax /* CS */
23942 + movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23943 movq %rax,(2*8)(%rdi)
23944 - movq (4*8)(%rsp),%rax /* RFLAGS */
23945 + movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23946 movq %rax,(3*8)(%rdi)
23947 - movq (6*8)(%rsp),%rax /* SS */
23948 + movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23949 movq %rax,(5*8)(%rdi)
23950 - movq (5*8)(%rsp),%rax /* RSP */
23951 + movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23952 movq %rax,(4*8)(%rdi)
23953 andl $0xffff0000,%eax
23954 popq_cfi %rdi
23955 @@ -907,7 +1396,7 @@ ENTRY(retint_kernel)
23956 jmp exit_intr
23957 #endif
23958 CFI_ENDPROC
23959 -END(common_interrupt)
23960 +ENDPROC(common_interrupt)
23961
23962 /*
23963 * APIC interrupts.
23964 @@ -921,7 +1410,7 @@ ENTRY(\sym)
23965 interrupt \do_sym
23966 jmp ret_from_intr
23967 CFI_ENDPROC
23968 -END(\sym)
23969 +ENDPROC(\sym)
23970 .endm
23971
23972 #ifdef CONFIG_TRACING
23973 @@ -994,7 +1483,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23974 /*
23975 * Exception entry points.
23976 */
23977 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23978 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23979
23980 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
23981 ENTRY(\sym)
23982 @@ -1045,6 +1534,12 @@ ENTRY(\sym)
23983 .endif
23984
23985 .if \shift_ist != -1
23986 +#ifdef CONFIG_SMP
23987 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23988 + lea init_tss(%r13), %r13
23989 +#else
23990 + lea init_tss(%rip), %r13
23991 +#endif
23992 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
23993 .endif
23994
23995 @@ -1061,7 +1556,7 @@ ENTRY(\sym)
23996 .endif
23997
23998 CFI_ENDPROC
23999 -END(\sym)
24000 +ENDPROC(\sym)
24001 .endm
24002
24003 #ifdef CONFIG_TRACING
24004 @@ -1102,9 +1597,10 @@ gs_change:
24005 2: mfence /* workaround */
24006 SWAPGS
24007 popfq_cfi
24008 + pax_force_retaddr
24009 ret
24010 CFI_ENDPROC
24011 -END(native_load_gs_index)
24012 +ENDPROC(native_load_gs_index)
24013
24014 _ASM_EXTABLE(gs_change,bad_gs)
24015 .section .fixup,"ax"
24016 @@ -1132,9 +1628,10 @@ ENTRY(do_softirq_own_stack)
24017 CFI_DEF_CFA_REGISTER rsp
24018 CFI_ADJUST_CFA_OFFSET -8
24019 decl PER_CPU_VAR(irq_count)
24020 + pax_force_retaddr
24021 ret
24022 CFI_ENDPROC
24023 -END(do_softirq_own_stack)
24024 +ENDPROC(do_softirq_own_stack)
24025
24026 #ifdef CONFIG_XEN
24027 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24028 @@ -1172,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24029 decl PER_CPU_VAR(irq_count)
24030 jmp error_exit
24031 CFI_ENDPROC
24032 -END(xen_do_hypervisor_callback)
24033 +ENDPROC(xen_do_hypervisor_callback)
24034
24035 /*
24036 * Hypervisor uses this for application faults while it executes.
24037 @@ -1231,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
24038 SAVE_ALL
24039 jmp error_exit
24040 CFI_ENDPROC
24041 -END(xen_failsafe_callback)
24042 +ENDPROC(xen_failsafe_callback)
24043
24044 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24045 xen_hvm_callback_vector xen_evtchn_do_upcall
24046 @@ -1278,18 +1775,33 @@ ENTRY(paranoid_exit)
24047 DEFAULT_FRAME
24048 DISABLE_INTERRUPTS(CLBR_NONE)
24049 TRACE_IRQS_OFF_DEBUG
24050 - testl %ebx,%ebx /* swapgs needed? */
24051 + testl $1,%ebx /* swapgs needed? */
24052 jnz paranoid_restore
24053 - testl $3,CS(%rsp)
24054 + testb $3,CS(%rsp)
24055 jnz paranoid_userspace
24056 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24057 + pax_exit_kernel
24058 + TRACE_IRQS_IRETQ 0
24059 + SWAPGS_UNSAFE_STACK
24060 + RESTORE_ALL 8
24061 + pax_force_retaddr_bts
24062 + jmp irq_return
24063 +#endif
24064 paranoid_swapgs:
24065 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24066 + pax_exit_kernel_user
24067 +#else
24068 + pax_exit_kernel
24069 +#endif
24070 TRACE_IRQS_IRETQ 0
24071 SWAPGS_UNSAFE_STACK
24072 RESTORE_ALL 8
24073 jmp irq_return
24074 paranoid_restore:
24075 + pax_exit_kernel
24076 TRACE_IRQS_IRETQ_DEBUG 0
24077 RESTORE_ALL 8
24078 + pax_force_retaddr_bts
24079 jmp irq_return
24080 paranoid_userspace:
24081 GET_THREAD_INFO(%rcx)
24082 @@ -1318,7 +1830,7 @@ paranoid_schedule:
24083 TRACE_IRQS_OFF
24084 jmp paranoid_userspace
24085 CFI_ENDPROC
24086 -END(paranoid_exit)
24087 +ENDPROC(paranoid_exit)
24088
24089 /*
24090 * Exception entry point. This expects an error code/orig_rax on the stack.
24091 @@ -1345,12 +1857,23 @@ ENTRY(error_entry)
24092 movq %r14, R14+8(%rsp)
24093 movq %r15, R15+8(%rsp)
24094 xorl %ebx,%ebx
24095 - testl $3,CS+8(%rsp)
24096 + testb $3,CS+8(%rsp)
24097 je error_kernelspace
24098 error_swapgs:
24099 SWAPGS
24100 error_sti:
24101 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24102 + testb $3, CS+8(%rsp)
24103 + jnz 1f
24104 + pax_enter_kernel
24105 + jmp 2f
24106 +1: pax_enter_kernel_user
24107 +2:
24108 +#else
24109 + pax_enter_kernel
24110 +#endif
24111 TRACE_IRQS_OFF
24112 + pax_force_retaddr
24113 ret
24114
24115 /*
24116 @@ -1385,7 +1908,7 @@ error_bad_iret:
24117 decl %ebx /* Return to usergs */
24118 jmp error_sti
24119 CFI_ENDPROC
24120 -END(error_entry)
24121 +ENDPROC(error_entry)
24122
24123
24124 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24125 @@ -1396,7 +1919,7 @@ ENTRY(error_exit)
24126 DISABLE_INTERRUPTS(CLBR_NONE)
24127 TRACE_IRQS_OFF
24128 GET_THREAD_INFO(%rcx)
24129 - testl %eax,%eax
24130 + testl $1,%eax
24131 jne retint_kernel
24132 LOCKDEP_SYS_EXIT_IRQ
24133 movl TI_flags(%rcx),%edx
24134 @@ -1405,7 +1928,7 @@ ENTRY(error_exit)
24135 jnz retint_careful
24136 jmp retint_swapgs
24137 CFI_ENDPROC
24138 -END(error_exit)
24139 +ENDPROC(error_exit)
24140
24141 /*
24142 * Test if a given stack is an NMI stack or not.
24143 @@ -1463,9 +1986,11 @@ ENTRY(nmi)
24144 * If %cs was not the kernel segment, then the NMI triggered in user
24145 * space, which means it is definitely not nested.
24146 */
24147 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24148 + je 1f
24149 cmpl $__KERNEL_CS, 16(%rsp)
24150 jne first_nmi
24151 -
24152 +1:
24153 /*
24154 * Check the special variable on the stack to see if NMIs are
24155 * executing.
24156 @@ -1499,8 +2024,7 @@ nested_nmi:
24157
24158 1:
24159 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24160 - leaq -1*8(%rsp), %rdx
24161 - movq %rdx, %rsp
24162 + subq $8, %rsp
24163 CFI_ADJUST_CFA_OFFSET 1*8
24164 leaq -10*8(%rsp), %rdx
24165 pushq_cfi $__KERNEL_DS
24166 @@ -1518,6 +2042,7 @@ nested_nmi_out:
24167 CFI_RESTORE rdx
24168
24169 /* No need to check faults here */
24170 +# pax_force_retaddr_bts
24171 INTERRUPT_RETURN
24172
24173 CFI_RESTORE_STATE
24174 @@ -1614,13 +2139,13 @@ end_repeat_nmi:
24175 subq $ORIG_RAX-R15, %rsp
24176 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24177 /*
24178 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24179 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24180 * as we should not be calling schedule in NMI context.
24181 * Even with normal interrupts enabled. An NMI should not be
24182 * setting NEED_RESCHED or anything that normal interrupts and
24183 * exceptions might do.
24184 */
24185 - call save_paranoid
24186 + call save_paranoid_nmi
24187 DEFAULT_FRAME 0
24188
24189 /*
24190 @@ -1630,9 +2155,9 @@ end_repeat_nmi:
24191 * NMI itself takes a page fault, the page fault that was preempted
24192 * will read the information from the NMI page fault and not the
24193 * origin fault. Save it off and restore it if it changes.
24194 - * Use the r12 callee-saved register.
24195 + * Use the r13 callee-saved register.
24196 */
24197 - movq %cr2, %r12
24198 + movq %cr2, %r13
24199
24200 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24201 movq %rsp,%rdi
24202 @@ -1641,29 +2166,34 @@ end_repeat_nmi:
24203
24204 /* Did the NMI take a page fault? Restore cr2 if it did */
24205 movq %cr2, %rcx
24206 - cmpq %rcx, %r12
24207 + cmpq %rcx, %r13
24208 je 1f
24209 - movq %r12, %cr2
24210 + movq %r13, %cr2
24211 1:
24212
24213 - testl %ebx,%ebx /* swapgs needed? */
24214 + testl $1,%ebx /* swapgs needed? */
24215 jnz nmi_restore
24216 nmi_swapgs:
24217 SWAPGS_UNSAFE_STACK
24218 nmi_restore:
24219 + pax_exit_kernel_nmi
24220 /* Pop the extra iret frame at once */
24221 RESTORE_ALL 6*8
24222 + testb $3, 8(%rsp)
24223 + jnz 1f
24224 + pax_force_retaddr_bts
24225 +1:
24226
24227 /* Clear the NMI executing stack variable */
24228 movq $0, 5*8(%rsp)
24229 jmp irq_return
24230 CFI_ENDPROC
24231 -END(nmi)
24232 +ENDPROC(nmi)
24233
24234 ENTRY(ignore_sysret)
24235 CFI_STARTPROC
24236 mov $-ENOSYS,%eax
24237 sysret
24238 CFI_ENDPROC
24239 -END(ignore_sysret)
24240 +ENDPROC(ignore_sysret)
24241
24242 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24243 index 94d857f..5bce89c 100644
24244 --- a/arch/x86/kernel/espfix_64.c
24245 +++ b/arch/x86/kernel/espfix_64.c
24246 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24247 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24248 static void *espfix_pages[ESPFIX_MAX_PAGES];
24249
24250 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24251 - __aligned(PAGE_SIZE);
24252 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24253
24254 static unsigned int page_random, slot_random;
24255
24256 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24257 void __init init_espfix_bsp(void)
24258 {
24259 pgd_t *pgd_p;
24260 - pteval_t ptemask;
24261 -
24262 - ptemask = __supported_pte_mask;
24263 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24264
24265 /* Install the espfix pud into the kernel page directory */
24266 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24267 + pgd_p = &init_level4_pgt[index];
24268 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24269
24270 +#ifdef CONFIG_PAX_PER_CPU_PGD
24271 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24272 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24273 +#endif
24274 +
24275 /* Randomize the locations */
24276 init_espfix_random();
24277
24278 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24279 set_pte(&pte_p[n*PTE_STRIDE], pte);
24280
24281 /* Job is done for this CPU and any CPU which shares this page */
24282 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24283 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24284
24285 unlock_done:
24286 mutex_unlock(&espfix_init_mutex);
24287 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24288 index 3386dc9..28bdf81 100644
24289 --- a/arch/x86/kernel/ftrace.c
24290 +++ b/arch/x86/kernel/ftrace.c
24291 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24292 * kernel identity mapping to modify code.
24293 */
24294 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24295 - ip = (unsigned long)__va(__pa_symbol(ip));
24296 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24297
24298 return ip;
24299 }
24300 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24301 {
24302 unsigned char replaced[MCOUNT_INSN_SIZE];
24303
24304 + ip = ktla_ktva(ip);
24305 +
24306 /*
24307 * Note: Due to modules and __init, code can
24308 * disappear and change, we need to protect against faulting
24309 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24310 unsigned char old[MCOUNT_INSN_SIZE];
24311 int ret;
24312
24313 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24314 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24315
24316 ftrace_update_func = ip;
24317 /* Make sure the breakpoints see the ftrace_update_func update */
24318 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24319 unsigned char replaced[MCOUNT_INSN_SIZE];
24320 unsigned char brk = BREAKPOINT_INSTRUCTION;
24321
24322 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24323 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24324 return -EFAULT;
24325
24326 /* Make sure it is what we expect it to be */
24327 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24328 index eda1a86..8f6df48 100644
24329 --- a/arch/x86/kernel/head64.c
24330 +++ b/arch/x86/kernel/head64.c
24331 @@ -67,12 +67,12 @@ again:
24332 pgd = *pgd_p;
24333
24334 /*
24335 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24336 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24337 + * The use of __early_va rather than __va here is critical:
24338 + * __va would point us back into the dynamic
24339 * range and we might end up looping forever...
24340 */
24341 if (pgd)
24342 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24343 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24344 else {
24345 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24346 reset_early_page_tables();
24347 @@ -82,13 +82,13 @@ again:
24348 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24349 for (i = 0; i < PTRS_PER_PUD; i++)
24350 pud_p[i] = 0;
24351 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24352 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24353 }
24354 pud_p += pud_index(address);
24355 pud = *pud_p;
24356
24357 if (pud)
24358 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24359 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24360 else {
24361 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24362 reset_early_page_tables();
24363 @@ -98,7 +98,7 @@ again:
24364 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24365 for (i = 0; i < PTRS_PER_PMD; i++)
24366 pmd_p[i] = 0;
24367 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24368 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24369 }
24370 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24371 pmd_p[pmd_index(address)] = pmd;
24372 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24373 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24374 early_printk("Kernel alive\n");
24375
24376 - clear_page(init_level4_pgt);
24377 /* set init_level4_pgt kernel high mapping*/
24378 init_level4_pgt[511] = early_level4_pgt[511];
24379
24380 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24381 index f36bd42..0ab4474 100644
24382 --- a/arch/x86/kernel/head_32.S
24383 +++ b/arch/x86/kernel/head_32.S
24384 @@ -26,6 +26,12 @@
24385 /* Physical address */
24386 #define pa(X) ((X) - __PAGE_OFFSET)
24387
24388 +#ifdef CONFIG_PAX_KERNEXEC
24389 +#define ta(X) (X)
24390 +#else
24391 +#define ta(X) ((X) - __PAGE_OFFSET)
24392 +#endif
24393 +
24394 /*
24395 * References to members of the new_cpu_data structure.
24396 */
24397 @@ -55,11 +61,7 @@
24398 * and small than max_low_pfn, otherwise will waste some page table entries
24399 */
24400
24401 -#if PTRS_PER_PMD > 1
24402 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24403 -#else
24404 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24405 -#endif
24406 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24407
24408 /* Number of possible pages in the lowmem region */
24409 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24410 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24411 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24412
24413 /*
24414 + * Real beginning of normal "text" segment
24415 + */
24416 +ENTRY(stext)
24417 +ENTRY(_stext)
24418 +
24419 +/*
24420 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24421 * %esi points to the real-mode code as a 32-bit pointer.
24422 * CS and DS must be 4 GB flat segments, but we don't depend on
24423 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24424 * can.
24425 */
24426 __HEAD
24427 +
24428 +#ifdef CONFIG_PAX_KERNEXEC
24429 + jmp startup_32
24430 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24431 +.fill PAGE_SIZE-5,1,0xcc
24432 +#endif
24433 +
24434 ENTRY(startup_32)
24435 movl pa(stack_start),%ecx
24436
24437 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24438 2:
24439 leal -__PAGE_OFFSET(%ecx),%esp
24440
24441 +#ifdef CONFIG_SMP
24442 + movl $pa(cpu_gdt_table),%edi
24443 + movl $__per_cpu_load,%eax
24444 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24445 + rorl $16,%eax
24446 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24447 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24448 + movl $__per_cpu_end - 1,%eax
24449 + subl $__per_cpu_start,%eax
24450 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24451 +#endif
24452 +
24453 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24454 + movl $NR_CPUS,%ecx
24455 + movl $pa(cpu_gdt_table),%edi
24456 +1:
24457 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24458 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24459 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24460 + addl $PAGE_SIZE_asm,%edi
24461 + loop 1b
24462 +#endif
24463 +
24464 +#ifdef CONFIG_PAX_KERNEXEC
24465 + movl $pa(boot_gdt),%edi
24466 + movl $__LOAD_PHYSICAL_ADDR,%eax
24467 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24468 + rorl $16,%eax
24469 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24470 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24471 + rorl $16,%eax
24472 +
24473 + ljmp $(__BOOT_CS),$1f
24474 +1:
24475 +
24476 + movl $NR_CPUS,%ecx
24477 + movl $pa(cpu_gdt_table),%edi
24478 + addl $__PAGE_OFFSET,%eax
24479 +1:
24480 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24481 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24482 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24483 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24484 + rorl $16,%eax
24485 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24486 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24487 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24488 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24489 + rorl $16,%eax
24490 + addl $PAGE_SIZE_asm,%edi
24491 + loop 1b
24492 +#endif
24493 +
24494 /*
24495 * Clear BSS first so that there are no surprises...
24496 */
24497 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24498 movl %eax, pa(max_pfn_mapped)
24499
24500 /* Do early initialization of the fixmap area */
24501 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24502 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24503 +#ifdef CONFIG_COMPAT_VDSO
24504 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24505 +#else
24506 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24507 +#endif
24508 #else /* Not PAE */
24509
24510 page_pde_offset = (__PAGE_OFFSET >> 20);
24511 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24512 movl %eax, pa(max_pfn_mapped)
24513
24514 /* Do early initialization of the fixmap area */
24515 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24516 - movl %eax,pa(initial_page_table+0xffc)
24517 +#ifdef CONFIG_COMPAT_VDSO
24518 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24519 +#else
24520 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24521 +#endif
24522 #endif
24523
24524 #ifdef CONFIG_PARAVIRT
24525 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24526 cmpl $num_subarch_entries, %eax
24527 jae bad_subarch
24528
24529 - movl pa(subarch_entries)(,%eax,4), %eax
24530 - subl $__PAGE_OFFSET, %eax
24531 - jmp *%eax
24532 + jmp *pa(subarch_entries)(,%eax,4)
24533
24534 bad_subarch:
24535 WEAK(lguest_entry)
24536 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24537 __INITDATA
24538
24539 subarch_entries:
24540 - .long default_entry /* normal x86/PC */
24541 - .long lguest_entry /* lguest hypervisor */
24542 - .long xen_entry /* Xen hypervisor */
24543 - .long default_entry /* Moorestown MID */
24544 + .long ta(default_entry) /* normal x86/PC */
24545 + .long ta(lguest_entry) /* lguest hypervisor */
24546 + .long ta(xen_entry) /* Xen hypervisor */
24547 + .long ta(default_entry) /* Moorestown MID */
24548 num_subarch_entries = (. - subarch_entries) / 4
24549 .previous
24550 #else
24551 @@ -354,6 +426,7 @@ default_entry:
24552 movl pa(mmu_cr4_features),%eax
24553 movl %eax,%cr4
24554
24555 +#ifdef CONFIG_X86_PAE
24556 testb $X86_CR4_PAE, %al # check if PAE is enabled
24557 jz enable_paging
24558
24559 @@ -382,6 +455,9 @@ default_entry:
24560 /* Make changes effective */
24561 wrmsr
24562
24563 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24564 +#endif
24565 +
24566 enable_paging:
24567
24568 /*
24569 @@ -449,14 +525,20 @@ is486:
24570 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24571 movl %eax,%ss # after changing gdt.
24572
24573 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24574 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24575 movl %eax,%ds
24576 movl %eax,%es
24577
24578 movl $(__KERNEL_PERCPU), %eax
24579 movl %eax,%fs # set this cpu's percpu
24580
24581 +#ifdef CONFIG_CC_STACKPROTECTOR
24582 movl $(__KERNEL_STACK_CANARY),%eax
24583 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24584 + movl $(__USER_DS),%eax
24585 +#else
24586 + xorl %eax,%eax
24587 +#endif
24588 movl %eax,%gs
24589
24590 xorl %eax,%eax # Clear LDT
24591 @@ -512,8 +594,11 @@ setup_once:
24592 * relocation. Manually set base address in stack canary
24593 * segment descriptor.
24594 */
24595 - movl $gdt_page,%eax
24596 + movl $cpu_gdt_table,%eax
24597 movl $stack_canary,%ecx
24598 +#ifdef CONFIG_SMP
24599 + addl $__per_cpu_load,%ecx
24600 +#endif
24601 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24602 shrl $16, %ecx
24603 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24604 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24605 cmpl $2,(%esp) # X86_TRAP_NMI
24606 je is_nmi # Ignore NMI
24607
24608 - cmpl $2,%ss:early_recursion_flag
24609 + cmpl $1,%ss:early_recursion_flag
24610 je hlt_loop
24611 incl %ss:early_recursion_flag
24612
24613 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24614 pushl (20+6*4)(%esp) /* trapno */
24615 pushl $fault_msg
24616 call printk
24617 -#endif
24618 call dump_stack
24619 +#endif
24620 hlt_loop:
24621 hlt
24622 jmp hlt_loop
24623 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24624 /* This is the default interrupt "handler" :-) */
24625 ALIGN
24626 ignore_int:
24627 - cld
24628 #ifdef CONFIG_PRINTK
24629 + cmpl $2,%ss:early_recursion_flag
24630 + je hlt_loop
24631 + incl %ss:early_recursion_flag
24632 + cld
24633 pushl %eax
24634 pushl %ecx
24635 pushl %edx
24636 @@ -617,9 +705,6 @@ ignore_int:
24637 movl $(__KERNEL_DS),%eax
24638 movl %eax,%ds
24639 movl %eax,%es
24640 - cmpl $2,early_recursion_flag
24641 - je hlt_loop
24642 - incl early_recursion_flag
24643 pushl 16(%esp)
24644 pushl 24(%esp)
24645 pushl 32(%esp)
24646 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24647 /*
24648 * BSS section
24649 */
24650 -__PAGE_ALIGNED_BSS
24651 - .align PAGE_SIZE
24652 #ifdef CONFIG_X86_PAE
24653 +.section .initial_pg_pmd,"a",@progbits
24654 initial_pg_pmd:
24655 .fill 1024*KPMDS,4,0
24656 #else
24657 +.section .initial_page_table,"a",@progbits
24658 ENTRY(initial_page_table)
24659 .fill 1024,4,0
24660 #endif
24661 +.section .initial_pg_fixmap,"a",@progbits
24662 initial_pg_fixmap:
24663 .fill 1024,4,0
24664 +.section .empty_zero_page,"a",@progbits
24665 ENTRY(empty_zero_page)
24666 .fill 4096,1,0
24667 +.section .swapper_pg_dir,"a",@progbits
24668 ENTRY(swapper_pg_dir)
24669 +#ifdef CONFIG_X86_PAE
24670 + .fill 4,8,0
24671 +#else
24672 .fill 1024,4,0
24673 +#endif
24674
24675 /*
24676 * This starts the data section.
24677 */
24678 #ifdef CONFIG_X86_PAE
24679 -__PAGE_ALIGNED_DATA
24680 - /* Page-aligned for the benefit of paravirt? */
24681 - .align PAGE_SIZE
24682 +.section .initial_page_table,"a",@progbits
24683 ENTRY(initial_page_table)
24684 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24685 # if KPMDS == 3
24686 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24687 # error "Kernel PMDs should be 1, 2 or 3"
24688 # endif
24689 .align PAGE_SIZE /* needs to be page-sized too */
24690 +
24691 +#ifdef CONFIG_PAX_PER_CPU_PGD
24692 +ENTRY(cpu_pgd)
24693 + .rept 2*NR_CPUS
24694 + .fill 4,8,0
24695 + .endr
24696 +#endif
24697 +
24698 #endif
24699
24700 .data
24701 .balign 4
24702 ENTRY(stack_start)
24703 - .long init_thread_union+THREAD_SIZE
24704 + .long init_thread_union+THREAD_SIZE-8
24705
24706 __INITRODATA
24707 int_msg:
24708 @@ -727,7 +825,7 @@ fault_msg:
24709 * segment size, and 32-bit linear address value:
24710 */
24711
24712 - .data
24713 +.section .rodata,"a",@progbits
24714 .globl boot_gdt_descr
24715 .globl idt_descr
24716
24717 @@ -736,7 +834,7 @@ fault_msg:
24718 .word 0 # 32 bit align gdt_desc.address
24719 boot_gdt_descr:
24720 .word __BOOT_DS+7
24721 - .long boot_gdt - __PAGE_OFFSET
24722 + .long pa(boot_gdt)
24723
24724 .word 0 # 32-bit align idt_desc.address
24725 idt_descr:
24726 @@ -747,7 +845,7 @@ idt_descr:
24727 .word 0 # 32 bit align gdt_desc.address
24728 ENTRY(early_gdt_descr)
24729 .word GDT_ENTRIES*8-1
24730 - .long gdt_page /* Overwritten for secondary CPUs */
24731 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24732
24733 /*
24734 * The boot_gdt must mirror the equivalent in setup.S and is
24735 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24736 .align L1_CACHE_BYTES
24737 ENTRY(boot_gdt)
24738 .fill GDT_ENTRY_BOOT_CS,8,0
24739 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24740 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24741 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24742 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24743 +
24744 + .align PAGE_SIZE_asm
24745 +ENTRY(cpu_gdt_table)
24746 + .rept NR_CPUS
24747 + .quad 0x0000000000000000 /* NULL descriptor */
24748 + .quad 0x0000000000000000 /* 0x0b reserved */
24749 + .quad 0x0000000000000000 /* 0x13 reserved */
24750 + .quad 0x0000000000000000 /* 0x1b reserved */
24751 +
24752 +#ifdef CONFIG_PAX_KERNEXEC
24753 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24754 +#else
24755 + .quad 0x0000000000000000 /* 0x20 unused */
24756 +#endif
24757 +
24758 + .quad 0x0000000000000000 /* 0x28 unused */
24759 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24760 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24761 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24762 + .quad 0x0000000000000000 /* 0x4b reserved */
24763 + .quad 0x0000000000000000 /* 0x53 reserved */
24764 + .quad 0x0000000000000000 /* 0x5b reserved */
24765 +
24766 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24767 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24768 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24769 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24770 +
24771 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24772 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24773 +
24774 + /*
24775 + * Segments used for calling PnP BIOS have byte granularity.
24776 + * The code segments and data segments have fixed 64k limits,
24777 + * the transfer segment sizes are set at run time.
24778 + */
24779 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24780 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24781 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24782 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24783 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24784 +
24785 + /*
24786 + * The APM segments have byte granularity and their bases
24787 + * are set at run time. All have 64k limits.
24788 + */
24789 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24790 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24791 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24792 +
24793 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24794 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24795 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24796 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24797 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24798 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24799 +
24800 + /* Be sure this is zeroed to avoid false validations in Xen */
24801 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24802 + .endr
24803 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24804 index a468c0a..8b5a879 100644
24805 --- a/arch/x86/kernel/head_64.S
24806 +++ b/arch/x86/kernel/head_64.S
24807 @@ -20,6 +20,8 @@
24808 #include <asm/processor-flags.h>
24809 #include <asm/percpu.h>
24810 #include <asm/nops.h>
24811 +#include <asm/cpufeature.h>
24812 +#include <asm/alternative-asm.h>
24813
24814 #ifdef CONFIG_PARAVIRT
24815 #include <asm/asm-offsets.h>
24816 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24817 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24818 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24819 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24820 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24821 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24822 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24823 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24824 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24825 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24826
24827 .text
24828 __HEAD
24829 @@ -89,11 +97,24 @@ startup_64:
24830 * Fixup the physical addresses in the page table
24831 */
24832 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24833 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24834 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24835 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24836 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24837 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24838
24839 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24840 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24841 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24842 +#ifndef CONFIG_XEN
24843 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24844 +#endif
24845 +
24846 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24847 +
24848 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24849 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24850
24851 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24852 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24853
24854 /*
24855 * Set up the identity mapping for the switchover. These
24856 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24857 * after the boot processor executes this code.
24858 */
24859
24860 + orq $-1, %rbp
24861 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24862 1:
24863
24864 - /* Enable PAE mode and PGE */
24865 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24866 + /* Enable PAE mode and PSE/PGE */
24867 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24868 movq %rcx, %cr4
24869
24870 /* Setup early boot stage 4 level pagetables. */
24871 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24872 movl $MSR_EFER, %ecx
24873 rdmsr
24874 btsl $_EFER_SCE, %eax /* Enable System Call */
24875 - btl $20,%edi /* No Execute supported? */
24876 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24877 jnc 1f
24878 btsl $_EFER_NX, %eax
24879 + cmpq $-1, %rbp
24880 + je 1f
24881 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24882 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24883 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24884 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24885 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24886 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24887 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24888 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24889 1: wrmsr /* Make changes effective */
24890
24891 /* Setup cr0 */
24892 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24893 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24894 * address given in m16:64.
24895 */
24896 + pax_set_fptr_mask
24897 movq initial_code(%rip),%rax
24898 pushq $0 # fake return address to stop unwinder
24899 pushq $__KERNEL_CS # set correct cs
24900 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24901 .quad INIT_PER_CPU_VAR(irq_stack_union)
24902
24903 GLOBAL(stack_start)
24904 - .quad init_thread_union+THREAD_SIZE-8
24905 + .quad init_thread_union+THREAD_SIZE-16
24906 .word 0
24907 __FINITDATA
24908
24909 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24910 call dump_stack
24911 #ifdef CONFIG_KALLSYMS
24912 leaq early_idt_ripmsg(%rip),%rdi
24913 - movq 40(%rsp),%rsi # %rip again
24914 + movq 88(%rsp),%rsi # %rip again
24915 call __print_symbol
24916 #endif
24917 #endif /* EARLY_PRINTK */
24918 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24919 early_recursion_flag:
24920 .long 0
24921
24922 + .section .rodata,"a",@progbits
24923 #ifdef CONFIG_EARLY_PRINTK
24924 early_idt_msg:
24925 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24926 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24927 NEXT_PAGE(early_dynamic_pgts)
24928 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24929
24930 - .data
24931 + .section .rodata,"a",@progbits
24932
24933 -#ifndef CONFIG_XEN
24934 NEXT_PAGE(init_level4_pgt)
24935 - .fill 512,8,0
24936 -#else
24937 -NEXT_PAGE(init_level4_pgt)
24938 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24939 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24940 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24941 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24942 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24943 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24944 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24945 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24946 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24947 .org init_level4_pgt + L4_START_KERNEL*8, 0
24948 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24949 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24950
24951 +#ifdef CONFIG_PAX_PER_CPU_PGD
24952 +NEXT_PAGE(cpu_pgd)
24953 + .rept 2*NR_CPUS
24954 + .fill 512,8,0
24955 + .endr
24956 +#endif
24957 +
24958 NEXT_PAGE(level3_ident_pgt)
24959 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24960 +#ifdef CONFIG_XEN
24961 .fill 511, 8, 0
24962 +#else
24963 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24964 + .fill 510,8,0
24965 +#endif
24966 +
24967 +NEXT_PAGE(level3_vmalloc_start_pgt)
24968 + .fill 512,8,0
24969 +
24970 +NEXT_PAGE(level3_vmalloc_end_pgt)
24971 + .fill 512,8,0
24972 +
24973 +NEXT_PAGE(level3_vmemmap_pgt)
24974 + .fill L3_VMEMMAP_START,8,0
24975 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24976 +
24977 NEXT_PAGE(level2_ident_pgt)
24978 - /* Since I easily can, map the first 1G.
24979 + /* Since I easily can, map the first 2G.
24980 * Don't set NX because code runs from these pages.
24981 */
24982 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24983 -#endif
24984 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24985
24986 NEXT_PAGE(level3_kernel_pgt)
24987 .fill L3_START_KERNEL,8,0
24988 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
24989 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24990 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24991
24992 +NEXT_PAGE(level2_vmemmap_pgt)
24993 + .fill 512,8,0
24994 +
24995 NEXT_PAGE(level2_kernel_pgt)
24996 /*
24997 * 512 MB kernel mapping. We spend a full page on this pagetable
24998 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
24999 NEXT_PAGE(level2_fixmap_pgt)
25000 .fill 506,8,0
25001 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25002 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25003 - .fill 5,8,0
25004 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25005 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25006 + .fill 4,8,0
25007
25008 NEXT_PAGE(level1_fixmap_pgt)
25009 .fill 512,8,0
25010
25011 +NEXT_PAGE(level1_vsyscall_pgt)
25012 + .fill 512,8,0
25013 +
25014 #undef PMDS
25015
25016 - .data
25017 + .align PAGE_SIZE
25018 +ENTRY(cpu_gdt_table)
25019 + .rept NR_CPUS
25020 + .quad 0x0000000000000000 /* NULL descriptor */
25021 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25022 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25023 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25024 + .quad 0x00cffb000000ffff /* __USER32_CS */
25025 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25026 + .quad 0x00affb000000ffff /* __USER_CS */
25027 +
25028 +#ifdef CONFIG_PAX_KERNEXEC
25029 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25030 +#else
25031 + .quad 0x0 /* unused */
25032 +#endif
25033 +
25034 + .quad 0,0 /* TSS */
25035 + .quad 0,0 /* LDT */
25036 + .quad 0,0,0 /* three TLS descriptors */
25037 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25038 + /* asm/segment.h:GDT_ENTRIES must match this */
25039 +
25040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25041 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25042 +#else
25043 + .quad 0x0 /* unused */
25044 +#endif
25045 +
25046 + /* zero the remaining page */
25047 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25048 + .endr
25049 +
25050 .align 16
25051 .globl early_gdt_descr
25052 early_gdt_descr:
25053 .word GDT_ENTRIES*8-1
25054 early_gdt_descr_base:
25055 - .quad INIT_PER_CPU_VAR(gdt_page)
25056 + .quad cpu_gdt_table
25057
25058 ENTRY(phys_base)
25059 /* This must match the first entry in level2_kernel_pgt */
25060 .quad 0x0000000000000000
25061
25062 #include "../../x86/xen/xen-head.S"
25063 -
25064 - __PAGE_ALIGNED_BSS
25065 +
25066 + .section .rodata,"a",@progbits
25067 NEXT_PAGE(empty_zero_page)
25068 .skip PAGE_SIZE
25069 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25070 index 05fd74f..c3548b1 100644
25071 --- a/arch/x86/kernel/i386_ksyms_32.c
25072 +++ b/arch/x86/kernel/i386_ksyms_32.c
25073 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25074 EXPORT_SYMBOL(cmpxchg8b_emu);
25075 #endif
25076
25077 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25078 +
25079 /* Networking helper routines. */
25080 EXPORT_SYMBOL(csum_partial_copy_generic);
25081 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25082 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25083
25084 EXPORT_SYMBOL(__get_user_1);
25085 EXPORT_SYMBOL(__get_user_2);
25086 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25087 EXPORT_SYMBOL(___preempt_schedule_context);
25088 #endif
25089 #endif
25090 +
25091 +#ifdef CONFIG_PAX_KERNEXEC
25092 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25093 +#endif
25094 +
25095 +#ifdef CONFIG_PAX_PER_CPU_PGD
25096 +EXPORT_SYMBOL(cpu_pgd);
25097 +#endif
25098 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25099 index a9a4229..6f4d476 100644
25100 --- a/arch/x86/kernel/i387.c
25101 +++ b/arch/x86/kernel/i387.c
25102 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25103 static inline bool interrupted_user_mode(void)
25104 {
25105 struct pt_regs *regs = get_irq_regs();
25106 - return regs && user_mode_vm(regs);
25107 + return regs && user_mode(regs);
25108 }
25109
25110 /*
25111 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25112 index e7cc537..67d7372 100644
25113 --- a/arch/x86/kernel/i8259.c
25114 +++ b/arch/x86/kernel/i8259.c
25115 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25116 static void make_8259A_irq(unsigned int irq)
25117 {
25118 disable_irq_nosync(irq);
25119 - io_apic_irqs &= ~(1<<irq);
25120 + io_apic_irqs &= ~(1UL<<irq);
25121 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25122 enable_irq(irq);
25123 }
25124 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25125 "spurious 8259A interrupt: IRQ%d.\n", irq);
25126 spurious_irq_mask |= irqmask;
25127 }
25128 - atomic_inc(&irq_err_count);
25129 + atomic_inc_unchecked(&irq_err_count);
25130 /*
25131 * Theoretically we do not have to handle this IRQ,
25132 * but in Linux this does not cause problems and is
25133 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25134 /* (slave's support for AEOI in flat mode is to be investigated) */
25135 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25136
25137 + pax_open_kernel();
25138 if (auto_eoi)
25139 /*
25140 * In AEOI mode we just have to mask the interrupt
25141 * when acking.
25142 */
25143 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25144 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25145 else
25146 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25147 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25148 + pax_close_kernel();
25149
25150 udelay(100); /* wait for 8259A to initialize */
25151
25152 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25153 index a979b5b..1d6db75 100644
25154 --- a/arch/x86/kernel/io_delay.c
25155 +++ b/arch/x86/kernel/io_delay.c
25156 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25157 * Quirk table for systems that misbehave (lock up, etc.) if port
25158 * 0x80 is used:
25159 */
25160 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25161 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25162 {
25163 .callback = dmi_io_delay_0xed_port,
25164 .ident = "Compaq Presario V6000",
25165 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25166 index 4ddaf66..49d5c18 100644
25167 --- a/arch/x86/kernel/ioport.c
25168 +++ b/arch/x86/kernel/ioport.c
25169 @@ -6,6 +6,7 @@
25170 #include <linux/sched.h>
25171 #include <linux/kernel.h>
25172 #include <linux/capability.h>
25173 +#include <linux/security.h>
25174 #include <linux/errno.h>
25175 #include <linux/types.h>
25176 #include <linux/ioport.h>
25177 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25178 return -EINVAL;
25179 if (turn_on && !capable(CAP_SYS_RAWIO))
25180 return -EPERM;
25181 +#ifdef CONFIG_GRKERNSEC_IO
25182 + if (turn_on && grsec_disable_privio) {
25183 + gr_handle_ioperm();
25184 + return -ENODEV;
25185 + }
25186 +#endif
25187
25188 /*
25189 * If it's the first ioperm() call in this thread's lifetime, set the
25190 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25191 * because the ->io_bitmap_max value must match the bitmap
25192 * contents:
25193 */
25194 - tss = &per_cpu(init_tss, get_cpu());
25195 + tss = init_tss + get_cpu();
25196
25197 if (turn_on)
25198 bitmap_clear(t->io_bitmap_ptr, from, num);
25199 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25200 if (level > old) {
25201 if (!capable(CAP_SYS_RAWIO))
25202 return -EPERM;
25203 +#ifdef CONFIG_GRKERNSEC_IO
25204 + if (grsec_disable_privio) {
25205 + gr_handle_iopl();
25206 + return -ENODEV;
25207 + }
25208 +#endif
25209 }
25210 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25211 t->iopl = level << 12;
25212 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25213 index 3790775..53717dc 100644
25214 --- a/arch/x86/kernel/irq.c
25215 +++ b/arch/x86/kernel/irq.c
25216 @@ -22,7 +22,7 @@
25217 #define CREATE_TRACE_POINTS
25218 #include <asm/trace/irq_vectors.h>
25219
25220 -atomic_t irq_err_count;
25221 +atomic_unchecked_t irq_err_count;
25222
25223 /* Function pointer for generic interrupt vector handling */
25224 void (*x86_platform_ipi_callback)(void) = NULL;
25225 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25226 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25227 seq_printf(p, " Hypervisor callback interrupts\n");
25228 #endif
25229 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25230 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25231 #if defined(CONFIG_X86_IO_APIC)
25232 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25233 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25234 #endif
25235 return 0;
25236 }
25237 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25238
25239 u64 arch_irq_stat(void)
25240 {
25241 - u64 sum = atomic_read(&irq_err_count);
25242 + u64 sum = atomic_read_unchecked(&irq_err_count);
25243 return sum;
25244 }
25245
25246 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25247 index 63ce838..2ea3e06 100644
25248 --- a/arch/x86/kernel/irq_32.c
25249 +++ b/arch/x86/kernel/irq_32.c
25250 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25251
25252 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25253
25254 +extern void gr_handle_kernel_exploit(void);
25255 +
25256 int sysctl_panic_on_stackoverflow __read_mostly;
25257
25258 /* Debugging check for stack overflow: is there less than 1KB free? */
25259 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25260 __asm__ __volatile__("andl %%esp,%0" :
25261 "=r" (sp) : "0" (THREAD_SIZE - 1));
25262
25263 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25264 + return sp < STACK_WARN;
25265 }
25266
25267 static void print_stack_overflow(void)
25268 {
25269 printk(KERN_WARNING "low stack detected by irq handler\n");
25270 dump_stack();
25271 + gr_handle_kernel_exploit();
25272 if (sysctl_panic_on_stackoverflow)
25273 panic("low stack detected by irq handler - check messages\n");
25274 }
25275 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25276 static inline int
25277 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25278 {
25279 - struct irq_stack *curstk, *irqstk;
25280 + struct irq_stack *irqstk;
25281 u32 *isp, *prev_esp, arg1, arg2;
25282
25283 - curstk = (struct irq_stack *) current_stack();
25284 irqstk = __this_cpu_read(hardirq_stack);
25285
25286 /*
25287 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25288 * handler) we can't do that and just have to keep using the
25289 * current stack (which is the irq stack already after all)
25290 */
25291 - if (unlikely(curstk == irqstk))
25292 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25293 return 0;
25294
25295 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25296 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25297
25298 /* Save the next esp at the bottom of the stack */
25299 prev_esp = (u32 *)irqstk;
25300 *prev_esp = current_stack_pointer;
25301
25302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25303 + __set_fs(MAKE_MM_SEG(0));
25304 +#endif
25305 +
25306 if (unlikely(overflow))
25307 call_on_stack(print_stack_overflow, isp);
25308
25309 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25310 : "0" (irq), "1" (desc), "2" (isp),
25311 "D" (desc->handle_irq)
25312 : "memory", "cc", "ecx");
25313 +
25314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25315 + __set_fs(current_thread_info()->addr_limit);
25316 +#endif
25317 +
25318 return 1;
25319 }
25320
25321 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25322 */
25323 void irq_ctx_init(int cpu)
25324 {
25325 - struct irq_stack *irqstk;
25326 -
25327 if (per_cpu(hardirq_stack, cpu))
25328 return;
25329
25330 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25331 - THREADINFO_GFP,
25332 - THREAD_SIZE_ORDER));
25333 - per_cpu(hardirq_stack, cpu) = irqstk;
25334 -
25335 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25336 - THREADINFO_GFP,
25337 - THREAD_SIZE_ORDER));
25338 - per_cpu(softirq_stack, cpu) = irqstk;
25339 -
25340 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25341 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25342 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25343 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25344 }
25345
25346 void do_softirq_own_stack(void)
25347 {
25348 - struct thread_info *curstk;
25349 struct irq_stack *irqstk;
25350 u32 *isp, *prev_esp;
25351
25352 - curstk = current_stack();
25353 irqstk = __this_cpu_read(softirq_stack);
25354
25355 /* build the stack frame on the softirq stack */
25356 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25357 prev_esp = (u32 *)irqstk;
25358 *prev_esp = current_stack_pointer;
25359
25360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25361 + __set_fs(MAKE_MM_SEG(0));
25362 +#endif
25363 +
25364 call_on_stack(__do_softirq, isp);
25365 +
25366 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25367 + __set_fs(current_thread_info()->addr_limit);
25368 +#endif
25369 +
25370 }
25371
25372 bool handle_irq(unsigned irq, struct pt_regs *regs)
25373 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25374 if (unlikely(!desc))
25375 return false;
25376
25377 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25378 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25379 if (unlikely(overflow))
25380 print_stack_overflow();
25381 desc->handle_irq(irq, desc);
25382 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25383 index e4b503d..824fce8 100644
25384 --- a/arch/x86/kernel/irq_64.c
25385 +++ b/arch/x86/kernel/irq_64.c
25386 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25387 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25388 EXPORT_PER_CPU_SYMBOL(irq_regs);
25389
25390 +extern void gr_handle_kernel_exploit(void);
25391 +
25392 int sysctl_panic_on_stackoverflow;
25393
25394 /*
25395 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25396 u64 estack_top, estack_bottom;
25397 u64 curbase = (u64)task_stack_page(current);
25398
25399 - if (user_mode_vm(regs))
25400 + if (user_mode(regs))
25401 return;
25402
25403 if (regs->sp >= curbase + sizeof(struct thread_info) +
25404 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25405 irq_stack_top, irq_stack_bottom,
25406 estack_top, estack_bottom);
25407
25408 + gr_handle_kernel_exploit();
25409 +
25410 if (sysctl_panic_on_stackoverflow)
25411 panic("low stack detected by irq handler - check messages\n");
25412 #endif
25413 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25414 index 26d5a55..a01160a 100644
25415 --- a/arch/x86/kernel/jump_label.c
25416 +++ b/arch/x86/kernel/jump_label.c
25417 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25418 * Jump label is enabled for the first time.
25419 * So we expect a default_nop...
25420 */
25421 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25422 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25423 != 0))
25424 bug_at((void *)entry->code, __LINE__);
25425 } else {
25426 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25427 * ...otherwise expect an ideal_nop. Otherwise
25428 * something went horribly wrong.
25429 */
25430 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25431 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25432 != 0))
25433 bug_at((void *)entry->code, __LINE__);
25434 }
25435 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25436 * are converting the default nop to the ideal nop.
25437 */
25438 if (init) {
25439 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25440 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25441 bug_at((void *)entry->code, __LINE__);
25442 } else {
25443 code.jump = 0xe9;
25444 code.offset = entry->target -
25445 (entry->code + JUMP_LABEL_NOP_SIZE);
25446 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25447 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25448 bug_at((void *)entry->code, __LINE__);
25449 }
25450 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25451 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25452 index 7ec1d5f..5a7d130 100644
25453 --- a/arch/x86/kernel/kgdb.c
25454 +++ b/arch/x86/kernel/kgdb.c
25455 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25456 #ifdef CONFIG_X86_32
25457 switch (regno) {
25458 case GDB_SS:
25459 - if (!user_mode_vm(regs))
25460 + if (!user_mode(regs))
25461 *(unsigned long *)mem = __KERNEL_DS;
25462 break;
25463 case GDB_SP:
25464 - if (!user_mode_vm(regs))
25465 + if (!user_mode(regs))
25466 *(unsigned long *)mem = kernel_stack_pointer(regs);
25467 break;
25468 case GDB_GS:
25469 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25470 bp->attr.bp_addr = breakinfo[breakno].addr;
25471 bp->attr.bp_len = breakinfo[breakno].len;
25472 bp->attr.bp_type = breakinfo[breakno].type;
25473 - info->address = breakinfo[breakno].addr;
25474 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25475 + info->address = ktla_ktva(breakinfo[breakno].addr);
25476 + else
25477 + info->address = breakinfo[breakno].addr;
25478 info->len = breakinfo[breakno].len;
25479 info->type = breakinfo[breakno].type;
25480 val = arch_install_hw_breakpoint(bp);
25481 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25482 case 'k':
25483 /* clear the trace bit */
25484 linux_regs->flags &= ~X86_EFLAGS_TF;
25485 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25486 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25487
25488 /* set the trace bit if we're stepping */
25489 if (remcomInBuffer[0] == 's') {
25490 linux_regs->flags |= X86_EFLAGS_TF;
25491 - atomic_set(&kgdb_cpu_doing_single_step,
25492 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25493 raw_smp_processor_id());
25494 }
25495
25496 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25497
25498 switch (cmd) {
25499 case DIE_DEBUG:
25500 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25501 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25502 if (user_mode(regs))
25503 return single_step_cont(regs, args);
25504 break;
25505 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25506 #endif /* CONFIG_DEBUG_RODATA */
25507
25508 bpt->type = BP_BREAKPOINT;
25509 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25510 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25511 BREAK_INSTR_SIZE);
25512 if (err)
25513 return err;
25514 - err = probe_kernel_write((char *)bpt->bpt_addr,
25515 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25516 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25517 #ifdef CONFIG_DEBUG_RODATA
25518 if (!err)
25519 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25520 return -EBUSY;
25521 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25522 BREAK_INSTR_SIZE);
25523 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25524 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25525 if (err)
25526 return err;
25527 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25528 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25529 if (mutex_is_locked(&text_mutex))
25530 goto knl_write;
25531 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25532 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25533 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25534 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25535 goto knl_write;
25536 return err;
25537 knl_write:
25538 #endif /* CONFIG_DEBUG_RODATA */
25539 - return probe_kernel_write((char *)bpt->bpt_addr,
25540 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25541 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25542 }
25543
25544 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25545 index 93d2c04..36d0e94 100644
25546 --- a/arch/x86/kernel/kprobes/core.c
25547 +++ b/arch/x86/kernel/kprobes/core.c
25548 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25549 s32 raddr;
25550 } __packed *insn;
25551
25552 - insn = (struct __arch_relative_insn *)from;
25553 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25554 +
25555 + pax_open_kernel();
25556 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25557 insn->op = op;
25558 + pax_close_kernel();
25559 }
25560
25561 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25562 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25563 kprobe_opcode_t opcode;
25564 kprobe_opcode_t *orig_opcodes = opcodes;
25565
25566 - if (search_exception_tables((unsigned long)opcodes))
25567 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25568 return 0; /* Page fault may occur on this address. */
25569
25570 retry:
25571 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25572 * for the first byte, we can recover the original instruction
25573 * from it and kp->opcode.
25574 */
25575 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25576 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25577 buf[0] = kp->opcode;
25578 - return (unsigned long)buf;
25579 + return ktva_ktla((unsigned long)buf);
25580 }
25581
25582 /*
25583 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25584 /* Another subsystem puts a breakpoint, failed to recover */
25585 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25586 return 0;
25587 + pax_open_kernel();
25588 memcpy(dest, insn.kaddr, insn.length);
25589 + pax_close_kernel();
25590
25591 #ifdef CONFIG_X86_64
25592 if (insn_rip_relative(&insn)) {
25593 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25594 return 0;
25595 }
25596 disp = (u8 *) dest + insn_offset_displacement(&insn);
25597 + pax_open_kernel();
25598 *(s32 *) disp = (s32) newdisp;
25599 + pax_close_kernel();
25600 }
25601 #endif
25602 return insn.length;
25603 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25604 * nor set current_kprobe, because it doesn't use single
25605 * stepping.
25606 */
25607 - regs->ip = (unsigned long)p->ainsn.insn;
25608 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25609 preempt_enable_no_resched();
25610 return;
25611 }
25612 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25613 regs->flags &= ~X86_EFLAGS_IF;
25614 /* single step inline if the instruction is an int3 */
25615 if (p->opcode == BREAKPOINT_INSTRUCTION)
25616 - regs->ip = (unsigned long)p->addr;
25617 + regs->ip = ktla_ktva((unsigned long)p->addr);
25618 else
25619 - regs->ip = (unsigned long)p->ainsn.insn;
25620 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25621 }
25622 NOKPROBE_SYMBOL(setup_singlestep);
25623
25624 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25625 struct kprobe *p;
25626 struct kprobe_ctlblk *kcb;
25627
25628 - if (user_mode_vm(regs))
25629 + if (user_mode(regs))
25630 return 0;
25631
25632 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25633 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25634 setup_singlestep(p, regs, kcb, 0);
25635 return 1;
25636 }
25637 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25638 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25639 /*
25640 * The breakpoint instruction was removed right
25641 * after we hit it. Another cpu has removed
25642 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25643 " movq %rax, 152(%rsp)\n"
25644 RESTORE_REGS_STRING
25645 " popfq\n"
25646 +#ifdef KERNEXEC_PLUGIN
25647 + " btsq $63,(%rsp)\n"
25648 +#endif
25649 #else
25650 " pushf\n"
25651 SAVE_REGS_STRING
25652 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25653 struct kprobe_ctlblk *kcb)
25654 {
25655 unsigned long *tos = stack_addr(regs);
25656 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25657 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25658 unsigned long orig_ip = (unsigned long)p->addr;
25659 kprobe_opcode_t *insn = p->ainsn.insn;
25660
25661 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25662 struct die_args *args = data;
25663 int ret = NOTIFY_DONE;
25664
25665 - if (args->regs && user_mode_vm(args->regs))
25666 + if (args->regs && user_mode(args->regs))
25667 return ret;
25668
25669 if (val == DIE_GPF) {
25670 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25671 index f1314d0..15f3154 100644
25672 --- a/arch/x86/kernel/kprobes/opt.c
25673 +++ b/arch/x86/kernel/kprobes/opt.c
25674 @@ -79,6 +79,7 @@ found:
25675 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25676 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25677 {
25678 + pax_open_kernel();
25679 #ifdef CONFIG_X86_64
25680 *addr++ = 0x48;
25681 *addr++ = 0xbf;
25682 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25683 *addr++ = 0xb8;
25684 #endif
25685 *(unsigned long *)addr = val;
25686 + pax_close_kernel();
25687 }
25688
25689 asm (
25690 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25691 * Verify if the address gap is in 2GB range, because this uses
25692 * a relative jump.
25693 */
25694 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25695 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25696 if (abs(rel) > 0x7fffffff) {
25697 __arch_remove_optimized_kprobe(op, 0);
25698 return -ERANGE;
25699 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25700 op->optinsn.size = ret;
25701
25702 /* Copy arch-dep-instance from template */
25703 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25704 + pax_open_kernel();
25705 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25706 + pax_close_kernel();
25707
25708 /* Set probe information */
25709 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25710
25711 /* Set probe function call */
25712 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25713 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25714
25715 /* Set returning jmp instruction at the tail of out-of-line buffer */
25716 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25717 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25718 (u8 *)op->kp.addr + op->optinsn.size);
25719
25720 flush_icache_range((unsigned long) buf,
25721 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25722 WARN_ON(kprobe_disabled(&op->kp));
25723
25724 /* Backup instructions which will be replaced by jump address */
25725 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25726 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25727 RELATIVE_ADDR_SIZE);
25728
25729 insn_buf[0] = RELATIVEJUMP_OPCODE;
25730 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25731 /* This kprobe is really able to run optimized path. */
25732 op = container_of(p, struct optimized_kprobe, kp);
25733 /* Detour through copied instructions */
25734 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25735 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25736 if (!reenter)
25737 reset_current_kprobe();
25738 preempt_enable_no_resched();
25739 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25740 index c2bedae..25e7ab60 100644
25741 --- a/arch/x86/kernel/ksysfs.c
25742 +++ b/arch/x86/kernel/ksysfs.c
25743 @@ -184,7 +184,7 @@ out:
25744
25745 static struct kobj_attribute type_attr = __ATTR_RO(type);
25746
25747 -static struct bin_attribute data_attr = {
25748 +static bin_attribute_no_const data_attr __read_only = {
25749 .attr = {
25750 .name = "data",
25751 .mode = S_IRUGO,
25752 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25753 index c37886d..d851d32 100644
25754 --- a/arch/x86/kernel/ldt.c
25755 +++ b/arch/x86/kernel/ldt.c
25756 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25757 if (reload) {
25758 #ifdef CONFIG_SMP
25759 preempt_disable();
25760 - load_LDT(pc);
25761 + load_LDT_nolock(pc);
25762 if (!cpumask_equal(mm_cpumask(current->mm),
25763 cpumask_of(smp_processor_id())))
25764 smp_call_function(flush_ldt, current->mm, 1);
25765 preempt_enable();
25766 #else
25767 - load_LDT(pc);
25768 + load_LDT_nolock(pc);
25769 #endif
25770 }
25771 if (oldsize) {
25772 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25773 return err;
25774
25775 for (i = 0; i < old->size; i++)
25776 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25777 + write_ldt_entry(new->ldt, i, old->ldt + i);
25778 return 0;
25779 }
25780
25781 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25782 retval = copy_ldt(&mm->context, &old_mm->context);
25783 mutex_unlock(&old_mm->context.lock);
25784 }
25785 +
25786 + if (tsk == current) {
25787 + mm->context.vdso = 0;
25788 +
25789 +#ifdef CONFIG_X86_32
25790 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25791 + mm->context.user_cs_base = 0UL;
25792 + mm->context.user_cs_limit = ~0UL;
25793 +
25794 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25795 + cpus_clear(mm->context.cpu_user_cs_mask);
25796 +#endif
25797 +
25798 +#endif
25799 +#endif
25800 +
25801 + }
25802 +
25803 return retval;
25804 }
25805
25806 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25807 }
25808 }
25809
25810 +#ifdef CONFIG_PAX_SEGMEXEC
25811 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25812 + error = -EINVAL;
25813 + goto out_unlock;
25814 + }
25815 +#endif
25816 +
25817 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25818 error = -EINVAL;
25819 goto out_unlock;
25820 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25821 index 72e8e31..f2f1605 100644
25822 --- a/arch/x86/kernel/machine_kexec_32.c
25823 +++ b/arch/x86/kernel/machine_kexec_32.c
25824 @@ -25,7 +25,7 @@
25825 #include <asm/cacheflush.h>
25826 #include <asm/debugreg.h>
25827
25828 -static void set_idt(void *newidt, __u16 limit)
25829 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25830 {
25831 struct desc_ptr curidt;
25832
25833 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25834 }
25835
25836
25837 -static void set_gdt(void *newgdt, __u16 limit)
25838 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25839 {
25840 struct desc_ptr curgdt;
25841
25842 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25843 }
25844
25845 control_page = page_address(image->control_code_page);
25846 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25847 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25848
25849 relocate_kernel_ptr = control_page;
25850 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25851 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25852 index c73aecf..4c63630 100644
25853 --- a/arch/x86/kernel/mcount_64.S
25854 +++ b/arch/x86/kernel/mcount_64.S
25855 @@ -7,7 +7,7 @@
25856 #include <linux/linkage.h>
25857 #include <asm/ptrace.h>
25858 #include <asm/ftrace.h>
25859 -
25860 +#include <asm/alternative-asm.h>
25861
25862 .code64
25863 .section .entry.text, "ax"
25864 @@ -24,8 +24,9 @@
25865 #ifdef CONFIG_DYNAMIC_FTRACE
25866
25867 ENTRY(function_hook)
25868 + pax_force_retaddr
25869 retq
25870 -END(function_hook)
25871 +ENDPROC(function_hook)
25872
25873 /* skip is set if stack has been adjusted */
25874 .macro ftrace_caller_setup skip=0
25875 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25876 #endif
25877
25878 GLOBAL(ftrace_stub)
25879 + pax_force_retaddr
25880 retq
25881 -END(ftrace_caller)
25882 +ENDPROC(ftrace_caller)
25883
25884 ENTRY(ftrace_regs_caller)
25885 /* Save the current flags before compare (in SS location)*/
25886 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25887 popfq
25888 jmp ftrace_stub
25889
25890 -END(ftrace_regs_caller)
25891 +ENDPROC(ftrace_regs_caller)
25892
25893
25894 #else /* ! CONFIG_DYNAMIC_FTRACE */
25895 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25896 #endif
25897
25898 GLOBAL(ftrace_stub)
25899 + pax_force_retaddr
25900 retq
25901
25902 trace:
25903 @@ -158,12 +161,13 @@ trace:
25904 #endif
25905 subq $MCOUNT_INSN_SIZE, %rdi
25906
25907 + pax_force_fptr ftrace_trace_function
25908 call *ftrace_trace_function
25909
25910 MCOUNT_RESTORE_FRAME
25911
25912 jmp ftrace_stub
25913 -END(function_hook)
25914 +ENDPROC(function_hook)
25915 #endif /* CONFIG_DYNAMIC_FTRACE */
25916 #endif /* CONFIG_FUNCTION_TRACER */
25917
25918 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25919
25920 MCOUNT_RESTORE_FRAME
25921
25922 + pax_force_retaddr
25923 retq
25924 -END(ftrace_graph_caller)
25925 +ENDPROC(ftrace_graph_caller)
25926
25927 GLOBAL(return_to_handler)
25928 subq $24, %rsp
25929 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25930 movq 8(%rsp), %rdx
25931 movq (%rsp), %rax
25932 addq $24, %rsp
25933 + pax_force_fptr %rdi
25934 jmp *%rdi
25935 +ENDPROC(return_to_handler)
25936 #endif
25937 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25938 index e69f988..da078ea 100644
25939 --- a/arch/x86/kernel/module.c
25940 +++ b/arch/x86/kernel/module.c
25941 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25942 }
25943 #endif
25944
25945 -void *module_alloc(unsigned long size)
25946 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25947 {
25948 - if (PAGE_ALIGN(size) > MODULES_LEN)
25949 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25950 return NULL;
25951 return __vmalloc_node_range(size, 1,
25952 MODULES_VADDR + get_module_load_offset(),
25953 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25954 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25955 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25956 + prot, NUMA_NO_NODE,
25957 __builtin_return_address(0));
25958 }
25959
25960 +void *module_alloc(unsigned long size)
25961 +{
25962 +
25963 +#ifdef CONFIG_PAX_KERNEXEC
25964 + return __module_alloc(size, PAGE_KERNEL);
25965 +#else
25966 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25967 +#endif
25968 +
25969 +}
25970 +
25971 +#ifdef CONFIG_PAX_KERNEXEC
25972 +#ifdef CONFIG_X86_32
25973 +void *module_alloc_exec(unsigned long size)
25974 +{
25975 + struct vm_struct *area;
25976 +
25977 + if (size == 0)
25978 + return NULL;
25979 +
25980 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25981 +return area ? area->addr : NULL;
25982 +}
25983 +EXPORT_SYMBOL(module_alloc_exec);
25984 +
25985 +void module_free_exec(struct module *mod, void *module_region)
25986 +{
25987 + vunmap(module_region);
25988 +}
25989 +EXPORT_SYMBOL(module_free_exec);
25990 +#else
25991 +void module_free_exec(struct module *mod, void *module_region)
25992 +{
25993 + module_free(mod, module_region);
25994 +}
25995 +EXPORT_SYMBOL(module_free_exec);
25996 +
25997 +void *module_alloc_exec(unsigned long size)
25998 +{
25999 + return __module_alloc(size, PAGE_KERNEL_RX);
26000 +}
26001 +EXPORT_SYMBOL(module_alloc_exec);
26002 +#endif
26003 +#endif
26004 +
26005 #ifdef CONFIG_X86_32
26006 int apply_relocate(Elf32_Shdr *sechdrs,
26007 const char *strtab,
26008 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26009 unsigned int i;
26010 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26011 Elf32_Sym *sym;
26012 - uint32_t *location;
26013 + uint32_t *plocation, location;
26014
26015 DEBUGP("Applying relocate section %u to %u\n",
26016 relsec, sechdrs[relsec].sh_info);
26017 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26018 /* This is where to make the change */
26019 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26020 - + rel[i].r_offset;
26021 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26022 + location = (uint32_t)plocation;
26023 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26024 + plocation = ktla_ktva((void *)plocation);
26025 /* This is the symbol it is referring to. Note that all
26026 undefined symbols have been resolved. */
26027 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26028 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26029 switch (ELF32_R_TYPE(rel[i].r_info)) {
26030 case R_386_32:
26031 /* We add the value into the location given */
26032 - *location += sym->st_value;
26033 + pax_open_kernel();
26034 + *plocation += sym->st_value;
26035 + pax_close_kernel();
26036 break;
26037 case R_386_PC32:
26038 /* Add the value, subtract its position */
26039 - *location += sym->st_value - (uint32_t)location;
26040 + pax_open_kernel();
26041 + *plocation += sym->st_value - location;
26042 + pax_close_kernel();
26043 break;
26044 default:
26045 pr_err("%s: Unknown relocation: %u\n",
26046 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26047 case R_X86_64_NONE:
26048 break;
26049 case R_X86_64_64:
26050 + pax_open_kernel();
26051 *(u64 *)loc = val;
26052 + pax_close_kernel();
26053 break;
26054 case R_X86_64_32:
26055 + pax_open_kernel();
26056 *(u32 *)loc = val;
26057 + pax_close_kernel();
26058 if (val != *(u32 *)loc)
26059 goto overflow;
26060 break;
26061 case R_X86_64_32S:
26062 + pax_open_kernel();
26063 *(s32 *)loc = val;
26064 + pax_close_kernel();
26065 if ((s64)val != *(s32 *)loc)
26066 goto overflow;
26067 break;
26068 case R_X86_64_PC32:
26069 val -= (u64)loc;
26070 + pax_open_kernel();
26071 *(u32 *)loc = val;
26072 + pax_close_kernel();
26073 +
26074 #if 0
26075 if ((s64)val != *(s32 *)loc)
26076 goto overflow;
26077 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26078 index c9603ac..9f88728 100644
26079 --- a/arch/x86/kernel/msr.c
26080 +++ b/arch/x86/kernel/msr.c
26081 @@ -37,6 +37,7 @@
26082 #include <linux/notifier.h>
26083 #include <linux/uaccess.h>
26084 #include <linux/gfp.h>
26085 +#include <linux/grsecurity.h>
26086
26087 #include <asm/processor.h>
26088 #include <asm/msr.h>
26089 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26090 int err = 0;
26091 ssize_t bytes = 0;
26092
26093 +#ifdef CONFIG_GRKERNSEC_KMEM
26094 + gr_handle_msr_write();
26095 + return -EPERM;
26096 +#endif
26097 +
26098 if (count % 8)
26099 return -EINVAL; /* Invalid chunk size */
26100
26101 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26102 err = -EBADF;
26103 break;
26104 }
26105 +#ifdef CONFIG_GRKERNSEC_KMEM
26106 + gr_handle_msr_write();
26107 + return -EPERM;
26108 +#endif
26109 if (copy_from_user(&regs, uregs, sizeof regs)) {
26110 err = -EFAULT;
26111 break;
26112 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26113 return notifier_from_errno(err);
26114 }
26115
26116 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26117 +static struct notifier_block msr_class_cpu_notifier = {
26118 .notifier_call = msr_class_cpu_callback,
26119 };
26120
26121 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26122 index c3e985d..110a36a 100644
26123 --- a/arch/x86/kernel/nmi.c
26124 +++ b/arch/x86/kernel/nmi.c
26125 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26126
26127 static void nmi_max_handler(struct irq_work *w)
26128 {
26129 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26130 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26131 int remainder_ns, decimal_msecs;
26132 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26133 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26134
26135 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26136 decimal_msecs = remainder_ns / 1000;
26137
26138 printk_ratelimited(KERN_INFO
26139 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26140 - a->handler, whole_msecs, decimal_msecs);
26141 + n->action->handler, whole_msecs, decimal_msecs);
26142 }
26143
26144 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26145 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26146 delta = sched_clock() - delta;
26147 trace_nmi_handler(a->handler, (int)delta, thishandled);
26148
26149 - if (delta < nmi_longest_ns || delta < a->max_duration)
26150 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26151 continue;
26152
26153 - a->max_duration = delta;
26154 - irq_work_queue(&a->irq_work);
26155 + a->work->max_duration = delta;
26156 + irq_work_queue(&a->work->irq_work);
26157 }
26158
26159 rcu_read_unlock();
26160 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26161 }
26162 NOKPROBE_SYMBOL(nmi_handle);
26163
26164 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26165 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26166 {
26167 struct nmi_desc *desc = nmi_to_desc(type);
26168 unsigned long flags;
26169 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26170 if (!action->handler)
26171 return -EINVAL;
26172
26173 - init_irq_work(&action->irq_work, nmi_max_handler);
26174 + action->work->action = action;
26175 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26176
26177 spin_lock_irqsave(&desc->lock, flags);
26178
26179 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26180 * event confuses some handlers (kdump uses this flag)
26181 */
26182 if (action->flags & NMI_FLAG_FIRST)
26183 - list_add_rcu(&action->list, &desc->head);
26184 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26185 else
26186 - list_add_tail_rcu(&action->list, &desc->head);
26187 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26188
26189 spin_unlock_irqrestore(&desc->lock, flags);
26190 return 0;
26191 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26192 if (!strcmp(n->name, name)) {
26193 WARN(in_nmi(),
26194 "Trying to free NMI (%s) from NMI context!\n", n->name);
26195 - list_del_rcu(&n->list);
26196 + pax_list_del_rcu((struct list_head *)&n->list);
26197 break;
26198 }
26199 }
26200 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26201 dotraplinkage notrace void
26202 do_nmi(struct pt_regs *regs, long error_code)
26203 {
26204 +
26205 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26206 + if (!user_mode(regs)) {
26207 + unsigned long cs = regs->cs & 0xFFFF;
26208 + unsigned long ip = ktva_ktla(regs->ip);
26209 +
26210 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26211 + regs->ip = ip;
26212 + }
26213 +#endif
26214 +
26215 nmi_nesting_preprocess(regs);
26216
26217 nmi_enter();
26218 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26219 index 6d9582e..f746287 100644
26220 --- a/arch/x86/kernel/nmi_selftest.c
26221 +++ b/arch/x86/kernel/nmi_selftest.c
26222 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26223 {
26224 /* trap all the unknown NMIs we may generate */
26225 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26226 - __initdata);
26227 + __initconst);
26228 }
26229
26230 static void __init cleanup_nmi_testsuite(void)
26231 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26232 unsigned long timeout;
26233
26234 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26235 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26236 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26237 nmi_fail = FAILURE;
26238 return;
26239 }
26240 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26241 index bbb6c73..24a58ef 100644
26242 --- a/arch/x86/kernel/paravirt-spinlocks.c
26243 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26244 @@ -8,7 +8,7 @@
26245
26246 #include <asm/paravirt.h>
26247
26248 -struct pv_lock_ops pv_lock_ops = {
26249 +struct pv_lock_ops pv_lock_ops __read_only = {
26250 #ifdef CONFIG_SMP
26251 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26252 .unlock_kick = paravirt_nop,
26253 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26254 index 548d25f..f8fb99c 100644
26255 --- a/arch/x86/kernel/paravirt.c
26256 +++ b/arch/x86/kernel/paravirt.c
26257 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26258 {
26259 return x;
26260 }
26261 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26262 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26263 +#endif
26264
26265 void __init default_banner(void)
26266 {
26267 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26268
26269 if (opfunc == NULL)
26270 /* If there's no function, patch it with a ud2a (BUG) */
26271 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26272 - else if (opfunc == _paravirt_nop)
26273 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26274 + else if (opfunc == (void *)_paravirt_nop)
26275 /* If the operation is a nop, then nop the callsite */
26276 ret = paravirt_patch_nop();
26277
26278 /* identity functions just return their single argument */
26279 - else if (opfunc == _paravirt_ident_32)
26280 + else if (opfunc == (void *)_paravirt_ident_32)
26281 ret = paravirt_patch_ident_32(insnbuf, len);
26282 - else if (opfunc == _paravirt_ident_64)
26283 + else if (opfunc == (void *)_paravirt_ident_64)
26284 ret = paravirt_patch_ident_64(insnbuf, len);
26285 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26286 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26287 + ret = paravirt_patch_ident_64(insnbuf, len);
26288 +#endif
26289
26290 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26291 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26292 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26293 if (insn_len > len || start == NULL)
26294 insn_len = len;
26295 else
26296 - memcpy(insnbuf, start, insn_len);
26297 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26298
26299 return insn_len;
26300 }
26301 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26302 return this_cpu_read(paravirt_lazy_mode);
26303 }
26304
26305 -struct pv_info pv_info = {
26306 +struct pv_info pv_info __read_only = {
26307 .name = "bare hardware",
26308 .paravirt_enabled = 0,
26309 .kernel_rpl = 0,
26310 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26311 #endif
26312 };
26313
26314 -struct pv_init_ops pv_init_ops = {
26315 +struct pv_init_ops pv_init_ops __read_only = {
26316 .patch = native_patch,
26317 };
26318
26319 -struct pv_time_ops pv_time_ops = {
26320 +struct pv_time_ops pv_time_ops __read_only = {
26321 .sched_clock = native_sched_clock,
26322 .steal_clock = native_steal_clock,
26323 };
26324
26325 -__visible struct pv_irq_ops pv_irq_ops = {
26326 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26327 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26328 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26329 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26330 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26331 #endif
26332 };
26333
26334 -__visible struct pv_cpu_ops pv_cpu_ops = {
26335 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26336 .cpuid = native_cpuid,
26337 .get_debugreg = native_get_debugreg,
26338 .set_debugreg = native_set_debugreg,
26339 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26340 NOKPROBE_SYMBOL(native_set_debugreg);
26341 NOKPROBE_SYMBOL(native_load_idt);
26342
26343 -struct pv_apic_ops pv_apic_ops = {
26344 +struct pv_apic_ops pv_apic_ops __read_only= {
26345 #ifdef CONFIG_X86_LOCAL_APIC
26346 .startup_ipi_hook = paravirt_nop,
26347 #endif
26348 };
26349
26350 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26351 +#ifdef CONFIG_X86_32
26352 +#ifdef CONFIG_X86_PAE
26353 +/* 64-bit pagetable entries */
26354 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26355 +#else
26356 /* 32-bit pagetable entries */
26357 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26358 +#endif
26359 #else
26360 /* 64-bit pagetable entries */
26361 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26362 #endif
26363
26364 -struct pv_mmu_ops pv_mmu_ops = {
26365 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26366
26367 .read_cr2 = native_read_cr2,
26368 .write_cr2 = native_write_cr2,
26369 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26370 .make_pud = PTE_IDENT,
26371
26372 .set_pgd = native_set_pgd,
26373 + .set_pgd_batched = native_set_pgd_batched,
26374 #endif
26375 #endif /* PAGETABLE_LEVELS >= 3 */
26376
26377 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26378 },
26379
26380 .set_fixmap = native_set_fixmap,
26381 +
26382 +#ifdef CONFIG_PAX_KERNEXEC
26383 + .pax_open_kernel = native_pax_open_kernel,
26384 + .pax_close_kernel = native_pax_close_kernel,
26385 +#endif
26386 +
26387 };
26388
26389 EXPORT_SYMBOL_GPL(pv_time_ops);
26390 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26391 index a1da673..b6f5831 100644
26392 --- a/arch/x86/kernel/paravirt_patch_64.c
26393 +++ b/arch/x86/kernel/paravirt_patch_64.c
26394 @@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26395 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26396 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26397 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26398 +
26399 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26400 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26401 +#endif
26402 +
26403 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26404 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26405
26406 @@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26407 PATCH_SITE(pv_mmu_ops, read_cr3);
26408 PATCH_SITE(pv_mmu_ops, write_cr3);
26409 PATCH_SITE(pv_cpu_ops, clts);
26410 +
26411 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26412 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26413 +#endif
26414 +
26415 PATCH_SITE(pv_cpu_ops, wbinvd);
26416
26417 patch_site:
26418 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26419 index 0497f71..7186c0d 100644
26420 --- a/arch/x86/kernel/pci-calgary_64.c
26421 +++ b/arch/x86/kernel/pci-calgary_64.c
26422 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26423 tce_space = be64_to_cpu(readq(target));
26424 tce_space = tce_space & TAR_SW_BITS;
26425
26426 - tce_space = tce_space & (~specified_table_size);
26427 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26428 info->tce_space = (u64 *)__va(tce_space);
26429 }
26430 }
26431 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26432 index 35ccf75..7a15747 100644
26433 --- a/arch/x86/kernel/pci-iommu_table.c
26434 +++ b/arch/x86/kernel/pci-iommu_table.c
26435 @@ -2,7 +2,7 @@
26436 #include <asm/iommu_table.h>
26437 #include <linux/string.h>
26438 #include <linux/kallsyms.h>
26439 -
26440 +#include <linux/sched.h>
26441
26442 #define DEBUG 1
26443
26444 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26445 index 77dd0ad..9ec4723 100644
26446 --- a/arch/x86/kernel/pci-swiotlb.c
26447 +++ b/arch/x86/kernel/pci-swiotlb.c
26448 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26449 struct dma_attrs *attrs)
26450 {
26451 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26452 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26453 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26454 else
26455 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26456 }
26457 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26458 index e127dda..94e384d 100644
26459 --- a/arch/x86/kernel/process.c
26460 +++ b/arch/x86/kernel/process.c
26461 @@ -36,7 +36,8 @@
26462 * section. Since TSS's are completely CPU-local, we want them
26463 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26464 */
26465 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26466 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26467 +EXPORT_SYMBOL(init_tss);
26468
26469 #ifdef CONFIG_X86_64
26470 static DEFINE_PER_CPU(unsigned char, is_idle);
26471 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26472 task_xstate_cachep =
26473 kmem_cache_create("task_xstate", xstate_size,
26474 __alignof__(union thread_xstate),
26475 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26476 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26477 setup_xstate_comp();
26478 }
26479
26480 @@ -108,7 +109,7 @@ void exit_thread(void)
26481 unsigned long *bp = t->io_bitmap_ptr;
26482
26483 if (bp) {
26484 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26485 + struct tss_struct *tss = init_tss + get_cpu();
26486
26487 t->io_bitmap_ptr = NULL;
26488 clear_thread_flag(TIF_IO_BITMAP);
26489 @@ -128,6 +129,9 @@ void flush_thread(void)
26490 {
26491 struct task_struct *tsk = current;
26492
26493 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26494 + loadsegment(gs, 0);
26495 +#endif
26496 flush_ptrace_hw_breakpoint(tsk);
26497 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26498 drop_init_fpu(tsk);
26499 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26500 void exit_idle(void)
26501 {
26502 /* idle loop has pid 0 */
26503 - if (current->pid)
26504 + if (task_pid_nr(current))
26505 return;
26506 __exit_idle();
26507 }
26508 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26509 return ret;
26510 }
26511 #endif
26512 -void stop_this_cpu(void *dummy)
26513 +__noreturn void stop_this_cpu(void *dummy)
26514 {
26515 local_irq_disable();
26516 /*
26517 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26518 }
26519 early_param("idle", idle_setup);
26520
26521 -unsigned long arch_align_stack(unsigned long sp)
26522 +#ifdef CONFIG_PAX_RANDKSTACK
26523 +void pax_randomize_kstack(struct pt_regs *regs)
26524 {
26525 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26526 - sp -= get_random_int() % 8192;
26527 - return sp & ~0xf;
26528 -}
26529 + struct thread_struct *thread = &current->thread;
26530 + unsigned long time;
26531
26532 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26533 -{
26534 - unsigned long range_end = mm->brk + 0x02000000;
26535 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26536 -}
26537 + if (!randomize_va_space)
26538 + return;
26539 +
26540 + if (v8086_mode(regs))
26541 + return;
26542
26543 + rdtscl(time);
26544 +
26545 + /* P4 seems to return a 0 LSB, ignore it */
26546 +#ifdef CONFIG_MPENTIUM4
26547 + time &= 0x3EUL;
26548 + time <<= 2;
26549 +#elif defined(CONFIG_X86_64)
26550 + time &= 0xFUL;
26551 + time <<= 4;
26552 +#else
26553 + time &= 0x1FUL;
26554 + time <<= 3;
26555 +#endif
26556 +
26557 + thread->sp0 ^= time;
26558 + load_sp0(init_tss + smp_processor_id(), thread);
26559 +
26560 +#ifdef CONFIG_X86_64
26561 + this_cpu_write(kernel_stack, thread->sp0);
26562 +#endif
26563 +}
26564 +#endif
26565 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26566 index 8f3ebfe..cbc731b 100644
26567 --- a/arch/x86/kernel/process_32.c
26568 +++ b/arch/x86/kernel/process_32.c
26569 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26570 unsigned long thread_saved_pc(struct task_struct *tsk)
26571 {
26572 return ((unsigned long *)tsk->thread.sp)[3];
26573 +//XXX return tsk->thread.eip;
26574 }
26575
26576 void __show_regs(struct pt_regs *regs, int all)
26577 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26578 unsigned long sp;
26579 unsigned short ss, gs;
26580
26581 - if (user_mode_vm(regs)) {
26582 + if (user_mode(regs)) {
26583 sp = regs->sp;
26584 ss = regs->ss & 0xffff;
26585 - gs = get_user_gs(regs);
26586 } else {
26587 sp = kernel_stack_pointer(regs);
26588 savesegment(ss, ss);
26589 - savesegment(gs, gs);
26590 }
26591 + gs = get_user_gs(regs);
26592
26593 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26594 (u16)regs->cs, regs->ip, regs->flags,
26595 - smp_processor_id());
26596 + raw_smp_processor_id());
26597 print_symbol("EIP is at %s\n", regs->ip);
26598
26599 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26600 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26601 int copy_thread(unsigned long clone_flags, unsigned long sp,
26602 unsigned long arg, struct task_struct *p)
26603 {
26604 - struct pt_regs *childregs = task_pt_regs(p);
26605 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26606 struct task_struct *tsk;
26607 int err;
26608
26609 p->thread.sp = (unsigned long) childregs;
26610 p->thread.sp0 = (unsigned long) (childregs+1);
26611 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26612 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26613
26614 if (unlikely(p->flags & PF_KTHREAD)) {
26615 /* kernel thread */
26616 memset(childregs, 0, sizeof(struct pt_regs));
26617 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26618 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26619 - childregs->ds = __USER_DS;
26620 - childregs->es = __USER_DS;
26621 + savesegment(gs, childregs->gs);
26622 + childregs->ds = __KERNEL_DS;
26623 + childregs->es = __KERNEL_DS;
26624 childregs->fs = __KERNEL_PERCPU;
26625 childregs->bx = sp; /* function */
26626 childregs->bp = arg;
26627 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26628 struct thread_struct *prev = &prev_p->thread,
26629 *next = &next_p->thread;
26630 int cpu = smp_processor_id();
26631 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26632 + struct tss_struct *tss = init_tss + cpu;
26633 fpu_switch_t fpu;
26634
26635 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26636 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26637 */
26638 lazy_save_gs(prev->gs);
26639
26640 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26641 + __set_fs(task_thread_info(next_p)->addr_limit);
26642 +#endif
26643 +
26644 /*
26645 * Load the per-thread Thread-Local Storage descriptor.
26646 */
26647 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26648 */
26649 arch_end_context_switch(next_p);
26650
26651 - this_cpu_write(kernel_stack,
26652 - (unsigned long)task_stack_page(next_p) +
26653 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26654 + this_cpu_write(current_task, next_p);
26655 + this_cpu_write(current_tinfo, &next_p->tinfo);
26656 + this_cpu_write(kernel_stack, next->sp0);
26657
26658 /*
26659 * Restore %gs if needed (which is common)
26660 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26661
26662 switch_fpu_finish(next_p, fpu);
26663
26664 - this_cpu_write(current_task, next_p);
26665 -
26666 return prev_p;
26667 }
26668
26669 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26670 } while (count++ < 16);
26671 return 0;
26672 }
26673 -
26674 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26675 index 5a2c029..ec8611d 100644
26676 --- a/arch/x86/kernel/process_64.c
26677 +++ b/arch/x86/kernel/process_64.c
26678 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26679 struct pt_regs *childregs;
26680 struct task_struct *me = current;
26681
26682 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26683 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26684 childregs = task_pt_regs(p);
26685 p->thread.sp = (unsigned long) childregs;
26686 p->thread.usersp = me->thread.usersp;
26687 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26688 set_tsk_thread_flag(p, TIF_FORK);
26689 p->thread.io_bitmap_ptr = NULL;
26690
26691 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26692 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26693 savesegment(es, p->thread.es);
26694 savesegment(ds, p->thread.ds);
26695 + savesegment(ss, p->thread.ss);
26696 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26697 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26698
26699 if (unlikely(p->flags & PF_KTHREAD)) {
26700 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26701 struct thread_struct *prev = &prev_p->thread;
26702 struct thread_struct *next = &next_p->thread;
26703 int cpu = smp_processor_id();
26704 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26705 + struct tss_struct *tss = init_tss + cpu;
26706 unsigned fsindex, gsindex;
26707 fpu_switch_t fpu;
26708
26709 @@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26710 if (unlikely(next->ds | prev->ds))
26711 loadsegment(ds, next->ds);
26712
26713 + savesegment(ss, prev->ss);
26714 + if (unlikely(next->ss != prev->ss))
26715 + loadsegment(ss, next->ss);
26716 +
26717 /*
26718 * Switch FS and GS.
26719 *
26720 @@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26721 prev->usersp = this_cpu_read(old_rsp);
26722 this_cpu_write(old_rsp, next->usersp);
26723 this_cpu_write(current_task, next_p);
26724 + this_cpu_write(current_tinfo, &next_p->tinfo);
26725
26726 /*
26727 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26728 @@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26729 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26730 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26731
26732 - this_cpu_write(kernel_stack,
26733 - (unsigned long)task_stack_page(next_p) +
26734 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26735 + this_cpu_write(kernel_stack, next->sp0);
26736
26737 /*
26738 * Now maybe reload the debug registers and handle I/O bitmaps
26739 @@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26740 if (!p || p == current || p->state == TASK_RUNNING)
26741 return 0;
26742 stack = (unsigned long)task_stack_page(p);
26743 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26744 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26745 return 0;
26746 fp = *(u64 *)(p->thread.sp);
26747 do {
26748 - if (fp < (unsigned long)stack ||
26749 - fp >= (unsigned long)stack+THREAD_SIZE)
26750 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26751 return 0;
26752 ip = *(u64 *)(fp+8);
26753 if (!in_sched_functions(ip))
26754 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26755 index e510618..5165ac0 100644
26756 --- a/arch/x86/kernel/ptrace.c
26757 +++ b/arch/x86/kernel/ptrace.c
26758 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26759 unsigned long sp = (unsigned long)&regs->sp;
26760 u32 *prev_esp;
26761
26762 - if (context == (sp & ~(THREAD_SIZE - 1)))
26763 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26764 return sp;
26765
26766 - prev_esp = (u32 *)(context);
26767 + prev_esp = *(u32 **)(context);
26768 if (prev_esp)
26769 return (unsigned long)prev_esp;
26770
26771 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26772 if (child->thread.gs != value)
26773 return do_arch_prctl(child, ARCH_SET_GS, value);
26774 return 0;
26775 +
26776 + case offsetof(struct user_regs_struct,ip):
26777 + /*
26778 + * Protect against any attempt to set ip to an
26779 + * impossible address. There are dragons lurking if the
26780 + * address is noncanonical. (This explicitly allows
26781 + * setting ip to TASK_SIZE_MAX, because user code can do
26782 + * that all by itself by running off the end of its
26783 + * address space.
26784 + */
26785 + if (value > TASK_SIZE_MAX)
26786 + return -EIO;
26787 + break;
26788 +
26789 #endif
26790 }
26791
26792 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26793 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26794 {
26795 int i;
26796 - int dr7 = 0;
26797 + unsigned long dr7 = 0;
26798 struct arch_hw_breakpoint *info;
26799
26800 for (i = 0; i < HBP_NUM; i++) {
26801 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26802 unsigned long addr, unsigned long data)
26803 {
26804 int ret;
26805 - unsigned long __user *datap = (unsigned long __user *)data;
26806 + unsigned long __user *datap = (__force unsigned long __user *)data;
26807
26808 switch (request) {
26809 /* read the word at location addr in the USER area. */
26810 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26811 if ((int) addr < 0)
26812 return -EIO;
26813 ret = do_get_thread_area(child, addr,
26814 - (struct user_desc __user *)data);
26815 + (__force struct user_desc __user *) data);
26816 break;
26817
26818 case PTRACE_SET_THREAD_AREA:
26819 if ((int) addr < 0)
26820 return -EIO;
26821 ret = do_set_thread_area(child, addr,
26822 - (struct user_desc __user *)data, 0);
26823 + (__force struct user_desc __user *) data, 0);
26824 break;
26825 #endif
26826
26827 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26828
26829 #ifdef CONFIG_X86_64
26830
26831 -static struct user_regset x86_64_regsets[] __read_mostly = {
26832 +static user_regset_no_const x86_64_regsets[] __read_only = {
26833 [REGSET_GENERAL] = {
26834 .core_note_type = NT_PRSTATUS,
26835 .n = sizeof(struct user_regs_struct) / sizeof(long),
26836 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26837 #endif /* CONFIG_X86_64 */
26838
26839 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26840 -static struct user_regset x86_32_regsets[] __read_mostly = {
26841 +static user_regset_no_const x86_32_regsets[] __read_only = {
26842 [REGSET_GENERAL] = {
26843 .core_note_type = NT_PRSTATUS,
26844 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26845 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26846 */
26847 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26848
26849 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26850 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26851 {
26852 #ifdef CONFIG_X86_64
26853 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26854 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26855 memset(info, 0, sizeof(*info));
26856 info->si_signo = SIGTRAP;
26857 info->si_code = si_code;
26858 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26859 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26860 }
26861
26862 void user_single_step_siginfo(struct task_struct *tsk,
26863 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26864 }
26865 }
26866
26867 +#ifdef CONFIG_GRKERNSEC_SETXID
26868 +extern void gr_delayed_cred_worker(void);
26869 +#endif
26870 +
26871 /*
26872 * We can return 0 to resume the syscall or anything else to go to phase
26873 * 2. If we resume the syscall, we need to put something appropriate in
26874 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26875
26876 BUG_ON(regs != task_pt_regs(current));
26877
26878 +#ifdef CONFIG_GRKERNSEC_SETXID
26879 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26880 + gr_delayed_cred_worker();
26881 +#endif
26882 +
26883 /*
26884 * If we stepped into a sysenter/syscall insn, it trapped in
26885 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26886 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26887 */
26888 user_exit();
26889
26890 +#ifdef CONFIG_GRKERNSEC_SETXID
26891 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26892 + gr_delayed_cred_worker();
26893 +#endif
26894 +
26895 audit_syscall_exit(regs);
26896
26897 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26898 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26899 index 2f355d2..e75ed0a 100644
26900 --- a/arch/x86/kernel/pvclock.c
26901 +++ b/arch/x86/kernel/pvclock.c
26902 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26903 reset_hung_task_detector();
26904 }
26905
26906 -static atomic64_t last_value = ATOMIC64_INIT(0);
26907 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26908
26909 void pvclock_resume(void)
26910 {
26911 - atomic64_set(&last_value, 0);
26912 + atomic64_set_unchecked(&last_value, 0);
26913 }
26914
26915 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26916 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26917 * updating at the same time, and one of them could be slightly behind,
26918 * making the assumption that last_value always go forward fail to hold.
26919 */
26920 - last = atomic64_read(&last_value);
26921 + last = atomic64_read_unchecked(&last_value);
26922 do {
26923 if (ret < last)
26924 return last;
26925 - last = atomic64_cmpxchg(&last_value, last, ret);
26926 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26927 } while (unlikely(last != ret));
26928
26929 return ret;
26930 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26931 index 17962e6..47f55db 100644
26932 --- a/arch/x86/kernel/reboot.c
26933 +++ b/arch/x86/kernel/reboot.c
26934 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26935
26936 void __noreturn machine_real_restart(unsigned int type)
26937 {
26938 +
26939 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26940 + struct desc_struct *gdt;
26941 +#endif
26942 +
26943 local_irq_disable();
26944
26945 /*
26946 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26947
26948 /* Jump to the identity-mapped low memory code */
26949 #ifdef CONFIG_X86_32
26950 - asm volatile("jmpl *%0" : :
26951 +
26952 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26953 + gdt = get_cpu_gdt_table(smp_processor_id());
26954 + pax_open_kernel();
26955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26956 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26957 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26958 + loadsegment(ds, __KERNEL_DS);
26959 + loadsegment(es, __KERNEL_DS);
26960 + loadsegment(ss, __KERNEL_DS);
26961 +#endif
26962 +#ifdef CONFIG_PAX_KERNEXEC
26963 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26964 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26965 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26966 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26967 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26968 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26969 +#endif
26970 + pax_close_kernel();
26971 +#endif
26972 +
26973 + asm volatile("ljmpl *%0" : :
26974 "rm" (real_mode_header->machine_real_restart_asm),
26975 "a" (type));
26976 #else
26977 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26978 * This means that this function can never return, it can misbehave
26979 * by not rebooting properly and hanging.
26980 */
26981 -static void native_machine_emergency_restart(void)
26982 +static void __noreturn native_machine_emergency_restart(void)
26983 {
26984 int i;
26985 int attempt = 0;
26986 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
26987 #endif
26988 }
26989
26990 -static void __machine_emergency_restart(int emergency)
26991 +static void __noreturn __machine_emergency_restart(int emergency)
26992 {
26993 reboot_emergency = emergency;
26994 machine_ops.emergency_restart();
26995 }
26996
26997 -static void native_machine_restart(char *__unused)
26998 +static void __noreturn native_machine_restart(char *__unused)
26999 {
27000 pr_notice("machine restart\n");
27001
27002 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27003 __machine_emergency_restart(0);
27004 }
27005
27006 -static void native_machine_halt(void)
27007 +static void __noreturn native_machine_halt(void)
27008 {
27009 /* Stop other cpus and apics */
27010 machine_shutdown();
27011 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27012 stop_this_cpu(NULL);
27013 }
27014
27015 -static void native_machine_power_off(void)
27016 +static void __noreturn native_machine_power_off(void)
27017 {
27018 if (pm_power_off) {
27019 if (!reboot_force)
27020 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27021 }
27022 /* A fallback in case there is no PM info available */
27023 tboot_shutdown(TB_SHUTDOWN_HALT);
27024 + unreachable();
27025 }
27026
27027 -struct machine_ops machine_ops = {
27028 +struct machine_ops machine_ops __read_only = {
27029 .power_off = native_machine_power_off,
27030 .shutdown = native_machine_shutdown,
27031 .emergency_restart = native_machine_emergency_restart,
27032 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27033 index c8e41e9..64049ef 100644
27034 --- a/arch/x86/kernel/reboot_fixups_32.c
27035 +++ b/arch/x86/kernel/reboot_fixups_32.c
27036 @@ -57,7 +57,7 @@ struct device_fixup {
27037 unsigned int vendor;
27038 unsigned int device;
27039 void (*reboot_fixup)(struct pci_dev *);
27040 -};
27041 +} __do_const;
27042
27043 /*
27044 * PCI ids solely used for fixups_table go here
27045 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27046 index 3fd2c69..a444264 100644
27047 --- a/arch/x86/kernel/relocate_kernel_64.S
27048 +++ b/arch/x86/kernel/relocate_kernel_64.S
27049 @@ -96,8 +96,7 @@ relocate_kernel:
27050
27051 /* jump to identity mapped page */
27052 addq $(identity_mapped - relocate_kernel), %r8
27053 - pushq %r8
27054 - ret
27055 + jmp *%r8
27056
27057 identity_mapped:
27058 /* set return address to 0 if not preserving context */
27059 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27060 index ab08aa2..6d74a3a 100644
27061 --- a/arch/x86/kernel/setup.c
27062 +++ b/arch/x86/kernel/setup.c
27063 @@ -110,6 +110,7 @@
27064 #include <asm/mce.h>
27065 #include <asm/alternative.h>
27066 #include <asm/prom.h>
27067 +#include <asm/boot.h>
27068
27069 /*
27070 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27071 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27072 #endif
27073
27074
27075 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27076 -__visible unsigned long mmu_cr4_features;
27077 +#ifdef CONFIG_X86_64
27078 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27079 +#elif defined(CONFIG_X86_PAE)
27080 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27081 #else
27082 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27083 +__visible unsigned long mmu_cr4_features __read_only;
27084 #endif
27085
27086 +void set_in_cr4(unsigned long mask)
27087 +{
27088 + unsigned long cr4 = read_cr4();
27089 +
27090 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27091 + return;
27092 +
27093 + pax_open_kernel();
27094 + mmu_cr4_features |= mask;
27095 + pax_close_kernel();
27096 +
27097 + if (trampoline_cr4_features)
27098 + *trampoline_cr4_features = mmu_cr4_features;
27099 + cr4 |= mask;
27100 + write_cr4(cr4);
27101 +}
27102 +EXPORT_SYMBOL(set_in_cr4);
27103 +
27104 +void clear_in_cr4(unsigned long mask)
27105 +{
27106 + unsigned long cr4 = read_cr4();
27107 +
27108 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27109 + return;
27110 +
27111 + pax_open_kernel();
27112 + mmu_cr4_features &= ~mask;
27113 + pax_close_kernel();
27114 +
27115 + if (trampoline_cr4_features)
27116 + *trampoline_cr4_features = mmu_cr4_features;
27117 + cr4 &= ~mask;
27118 + write_cr4(cr4);
27119 +}
27120 +EXPORT_SYMBOL(clear_in_cr4);
27121 +
27122 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27123 int bootloader_type, bootloader_version;
27124
27125 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27126 * area (640->1Mb) as ram even though it is not.
27127 * take them out.
27128 */
27129 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27130 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27131
27132 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27133 }
27134 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27135 /* called before trim_bios_range() to spare extra sanitize */
27136 static void __init e820_add_kernel_range(void)
27137 {
27138 - u64 start = __pa_symbol(_text);
27139 + u64 start = __pa_symbol(ktla_ktva(_text));
27140 u64 size = __pa_symbol(_end) - start;
27141
27142 /*
27143 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27144
27145 void __init setup_arch(char **cmdline_p)
27146 {
27147 +#ifdef CONFIG_X86_32
27148 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27149 +#else
27150 memblock_reserve(__pa_symbol(_text),
27151 (unsigned long)__bss_stop - (unsigned long)_text);
27152 +#endif
27153
27154 early_reserve_initrd();
27155
27156 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27157
27158 if (!boot_params.hdr.root_flags)
27159 root_mountflags &= ~MS_RDONLY;
27160 - init_mm.start_code = (unsigned long) _text;
27161 - init_mm.end_code = (unsigned long) _etext;
27162 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27163 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27164 init_mm.end_data = (unsigned long) _edata;
27165 init_mm.brk = _brk_end;
27166
27167 - code_resource.start = __pa_symbol(_text);
27168 - code_resource.end = __pa_symbol(_etext)-1;
27169 - data_resource.start = __pa_symbol(_etext);
27170 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27171 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27172 + data_resource.start = __pa_symbol(_sdata);
27173 data_resource.end = __pa_symbol(_edata)-1;
27174 bss_resource.start = __pa_symbol(__bss_start);
27175 bss_resource.end = __pa_symbol(__bss_stop)-1;
27176 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27177 index 5cdff03..80fa283 100644
27178 --- a/arch/x86/kernel/setup_percpu.c
27179 +++ b/arch/x86/kernel/setup_percpu.c
27180 @@ -21,19 +21,17 @@
27181 #include <asm/cpu.h>
27182 #include <asm/stackprotector.h>
27183
27184 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27185 +#ifdef CONFIG_SMP
27186 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27187 EXPORT_PER_CPU_SYMBOL(cpu_number);
27188 +#endif
27189
27190 -#ifdef CONFIG_X86_64
27191 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27192 -#else
27193 -#define BOOT_PERCPU_OFFSET 0
27194 -#endif
27195
27196 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27197 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27198
27199 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27200 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27201 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27202 };
27203 EXPORT_SYMBOL(__per_cpu_offset);
27204 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27205 {
27206 #ifdef CONFIG_NEED_MULTIPLE_NODES
27207 pg_data_t *last = NULL;
27208 - unsigned int cpu;
27209 + int cpu;
27210
27211 for_each_possible_cpu(cpu) {
27212 int node = early_cpu_to_node(cpu);
27213 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27214 {
27215 #ifdef CONFIG_X86_32
27216 struct desc_struct gdt;
27217 + unsigned long base = per_cpu_offset(cpu);
27218
27219 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27220 - 0x2 | DESCTYPE_S, 0x8);
27221 - gdt.s = 1;
27222 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27223 + 0x83 | DESCTYPE_S, 0xC);
27224 write_gdt_entry(get_cpu_gdt_table(cpu),
27225 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27226 #endif
27227 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27228 /* alrighty, percpu areas up and running */
27229 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27230 for_each_possible_cpu(cpu) {
27231 +#ifdef CONFIG_CC_STACKPROTECTOR
27232 +#ifdef CONFIG_X86_32
27233 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27234 +#endif
27235 +#endif
27236 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27237 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27238 per_cpu(cpu_number, cpu) = cpu;
27239 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27240 */
27241 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27242 #endif
27243 +#ifdef CONFIG_CC_STACKPROTECTOR
27244 +#ifdef CONFIG_X86_32
27245 + if (!cpu)
27246 + per_cpu(stack_canary.canary, cpu) = canary;
27247 +#endif
27248 +#endif
27249 /*
27250 * Up to this point, the boot CPU has been using .init.data
27251 * area. Reload any changed state for the boot CPU.
27252 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27253 index ed37a76..39f936e 100644
27254 --- a/arch/x86/kernel/signal.c
27255 +++ b/arch/x86/kernel/signal.c
27256 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27257 * Align the stack pointer according to the i386 ABI,
27258 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27259 */
27260 - sp = ((sp + 4) & -16ul) - 4;
27261 + sp = ((sp - 12) & -16ul) - 4;
27262 #else /* !CONFIG_X86_32 */
27263 sp = round_down(sp, 16) - 8;
27264 #endif
27265 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27266 }
27267
27268 if (current->mm->context.vdso)
27269 - restorer = current->mm->context.vdso +
27270 - selected_vdso32->sym___kernel_sigreturn;
27271 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27272 else
27273 - restorer = &frame->retcode;
27274 + restorer = (void __user *)&frame->retcode;
27275 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27276 restorer = ksig->ka.sa.sa_restorer;
27277
27278 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27279 * reasons and because gdb uses it as a signature to notice
27280 * signal handler stack frames.
27281 */
27282 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27283 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27284
27285 if (err)
27286 return -EFAULT;
27287 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27288 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27289
27290 /* Set up to return from userspace. */
27291 - restorer = current->mm->context.vdso +
27292 - selected_vdso32->sym___kernel_rt_sigreturn;
27293 + if (current->mm->context.vdso)
27294 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27295 + else
27296 + restorer = (void __user *)&frame->retcode;
27297 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27298 restorer = ksig->ka.sa.sa_restorer;
27299 put_user_ex(restorer, &frame->pretcode);
27300 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27301 * reasons and because gdb uses it as a signature to notice
27302 * signal handler stack frames.
27303 */
27304 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27305 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27306 } put_user_catch(err);
27307
27308 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27309 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27310 {
27311 int usig = signr_convert(ksig->sig);
27312 sigset_t *set = sigmask_to_save();
27313 - compat_sigset_t *cset = (compat_sigset_t *) set;
27314 + sigset_t sigcopy;
27315 + compat_sigset_t *cset;
27316 +
27317 + sigcopy = *set;
27318 +
27319 + cset = (compat_sigset_t *) &sigcopy;
27320
27321 /* Set up the stack frame */
27322 if (is_ia32_frame()) {
27323 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27324 } else if (is_x32_frame()) {
27325 return x32_setup_rt_frame(ksig, cset, regs);
27326 } else {
27327 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27328 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27329 }
27330 }
27331
27332 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27333 index be8e1bd..a3d93fa 100644
27334 --- a/arch/x86/kernel/smp.c
27335 +++ b/arch/x86/kernel/smp.c
27336 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27337
27338 __setup("nonmi_ipi", nonmi_ipi_setup);
27339
27340 -struct smp_ops smp_ops = {
27341 +struct smp_ops smp_ops __read_only = {
27342 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27343 .smp_prepare_cpus = native_smp_prepare_cpus,
27344 .smp_cpus_done = native_smp_cpus_done,
27345 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27346 index 668d8f2..84a9d54 100644
27347 --- a/arch/x86/kernel/smpboot.c
27348 +++ b/arch/x86/kernel/smpboot.c
27349 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27350
27351 enable_start_cpu0 = 0;
27352
27353 -#ifdef CONFIG_X86_32
27354 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27355 + barrier();
27356 +
27357 /* switch away from the initial page table */
27358 +#ifdef CONFIG_PAX_PER_CPU_PGD
27359 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27360 +#else
27361 load_cr3(swapper_pg_dir);
27362 +#endif
27363 __flush_tlb_all();
27364 -#endif
27365
27366 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27367 - barrier();
27368 /*
27369 * Check TSC synchronization with the BP:
27370 */
27371 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27372 alternatives_enable_smp();
27373
27374 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27375 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27376 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27377 per_cpu(current_task, cpu) = idle;
27378 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27379
27380 #ifdef CONFIG_X86_32
27381 /* Stack for startup_32 can be just as for start_secondary onwards */
27382 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27383 clear_tsk_thread_flag(idle, TIF_FORK);
27384 initial_gs = per_cpu_offset(cpu);
27385 #endif
27386 - per_cpu(kernel_stack, cpu) =
27387 - (unsigned long)task_stack_page(idle) -
27388 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27389 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27390 + pax_open_kernel();
27391 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27392 + pax_close_kernel();
27393 initial_code = (unsigned long)start_secondary;
27394 stack_start = idle->thread.sp;
27395
27396 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27397 /* the FPU context is blank, nobody can own it */
27398 __cpu_disable_lazy_restore(cpu);
27399
27400 +#ifdef CONFIG_PAX_PER_CPU_PGD
27401 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27402 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27403 + KERNEL_PGD_PTRS);
27404 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27405 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27406 + KERNEL_PGD_PTRS);
27407 +#endif
27408 +
27409 err = do_boot_cpu(apicid, cpu, tidle);
27410 if (err) {
27411 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27412 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27413 index 9b4d51d..5d28b58 100644
27414 --- a/arch/x86/kernel/step.c
27415 +++ b/arch/x86/kernel/step.c
27416 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27417 struct desc_struct *desc;
27418 unsigned long base;
27419
27420 - seg &= ~7UL;
27421 + seg >>= 3;
27422
27423 mutex_lock(&child->mm->context.lock);
27424 - if (unlikely((seg >> 3) >= child->mm->context.size))
27425 + if (unlikely(seg >= child->mm->context.size))
27426 addr = -1L; /* bogus selector, access would fault */
27427 else {
27428 desc = child->mm->context.ldt + seg;
27429 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27430 addr += base;
27431 }
27432 mutex_unlock(&child->mm->context.lock);
27433 - }
27434 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27435 + addr = ktla_ktva(addr);
27436
27437 return addr;
27438 }
27439 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27440 unsigned char opcode[15];
27441 unsigned long addr = convert_ip_to_linear(child, regs);
27442
27443 + if (addr == -EINVAL)
27444 + return 0;
27445 +
27446 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27447 for (i = 0; i < copied; i++) {
27448 switch (opcode[i]) {
27449 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27450 new file mode 100644
27451 index 0000000..5877189
27452 --- /dev/null
27453 +++ b/arch/x86/kernel/sys_i386_32.c
27454 @@ -0,0 +1,189 @@
27455 +/*
27456 + * This file contains various random system calls that
27457 + * have a non-standard calling sequence on the Linux/i386
27458 + * platform.
27459 + */
27460 +
27461 +#include <linux/errno.h>
27462 +#include <linux/sched.h>
27463 +#include <linux/mm.h>
27464 +#include <linux/fs.h>
27465 +#include <linux/smp.h>
27466 +#include <linux/sem.h>
27467 +#include <linux/msg.h>
27468 +#include <linux/shm.h>
27469 +#include <linux/stat.h>
27470 +#include <linux/syscalls.h>
27471 +#include <linux/mman.h>
27472 +#include <linux/file.h>
27473 +#include <linux/utsname.h>
27474 +#include <linux/ipc.h>
27475 +#include <linux/elf.h>
27476 +
27477 +#include <linux/uaccess.h>
27478 +#include <linux/unistd.h>
27479 +
27480 +#include <asm/syscalls.h>
27481 +
27482 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27483 +{
27484 + unsigned long pax_task_size = TASK_SIZE;
27485 +
27486 +#ifdef CONFIG_PAX_SEGMEXEC
27487 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27488 + pax_task_size = SEGMEXEC_TASK_SIZE;
27489 +#endif
27490 +
27491 + if (flags & MAP_FIXED)
27492 + if (len > pax_task_size || addr > pax_task_size - len)
27493 + return -EINVAL;
27494 +
27495 + return 0;
27496 +}
27497 +
27498 +/*
27499 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27500 + */
27501 +static unsigned long get_align_mask(void)
27502 +{
27503 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27504 + return 0;
27505 +
27506 + if (!(current->flags & PF_RANDOMIZE))
27507 + return 0;
27508 +
27509 + return va_align.mask;
27510 +}
27511 +
27512 +unsigned long
27513 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27514 + unsigned long len, unsigned long pgoff, unsigned long flags)
27515 +{
27516 + struct mm_struct *mm = current->mm;
27517 + struct vm_area_struct *vma;
27518 + unsigned long pax_task_size = TASK_SIZE;
27519 + struct vm_unmapped_area_info info;
27520 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27521 +
27522 +#ifdef CONFIG_PAX_SEGMEXEC
27523 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27524 + pax_task_size = SEGMEXEC_TASK_SIZE;
27525 +#endif
27526 +
27527 + pax_task_size -= PAGE_SIZE;
27528 +
27529 + if (len > pax_task_size)
27530 + return -ENOMEM;
27531 +
27532 + if (flags & MAP_FIXED)
27533 + return addr;
27534 +
27535 +#ifdef CONFIG_PAX_RANDMMAP
27536 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27537 +#endif
27538 +
27539 + if (addr) {
27540 + addr = PAGE_ALIGN(addr);
27541 + if (pax_task_size - len >= addr) {
27542 + vma = find_vma(mm, addr);
27543 + if (check_heap_stack_gap(vma, addr, len, offset))
27544 + return addr;
27545 + }
27546 + }
27547 +
27548 + info.flags = 0;
27549 + info.length = len;
27550 + info.align_mask = filp ? get_align_mask() : 0;
27551 + info.align_offset = pgoff << PAGE_SHIFT;
27552 + info.threadstack_offset = offset;
27553 +
27554 +#ifdef CONFIG_PAX_PAGEEXEC
27555 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27556 + info.low_limit = 0x00110000UL;
27557 + info.high_limit = mm->start_code;
27558 +
27559 +#ifdef CONFIG_PAX_RANDMMAP
27560 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27561 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27562 +#endif
27563 +
27564 + if (info.low_limit < info.high_limit) {
27565 + addr = vm_unmapped_area(&info);
27566 + if (!IS_ERR_VALUE(addr))
27567 + return addr;
27568 + }
27569 + } else
27570 +#endif
27571 +
27572 + info.low_limit = mm->mmap_base;
27573 + info.high_limit = pax_task_size;
27574 +
27575 + return vm_unmapped_area(&info);
27576 +}
27577 +
27578 +unsigned long
27579 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27580 + const unsigned long len, const unsigned long pgoff,
27581 + const unsigned long flags)
27582 +{
27583 + struct vm_area_struct *vma;
27584 + struct mm_struct *mm = current->mm;
27585 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27586 + struct vm_unmapped_area_info info;
27587 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27588 +
27589 +#ifdef CONFIG_PAX_SEGMEXEC
27590 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27591 + pax_task_size = SEGMEXEC_TASK_SIZE;
27592 +#endif
27593 +
27594 + pax_task_size -= PAGE_SIZE;
27595 +
27596 + /* requested length too big for entire address space */
27597 + if (len > pax_task_size)
27598 + return -ENOMEM;
27599 +
27600 + if (flags & MAP_FIXED)
27601 + return addr;
27602 +
27603 +#ifdef CONFIG_PAX_PAGEEXEC
27604 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27605 + goto bottomup;
27606 +#endif
27607 +
27608 +#ifdef CONFIG_PAX_RANDMMAP
27609 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27610 +#endif
27611 +
27612 + /* requesting a specific address */
27613 + if (addr) {
27614 + addr = PAGE_ALIGN(addr);
27615 + if (pax_task_size - len >= addr) {
27616 + vma = find_vma(mm, addr);
27617 + if (check_heap_stack_gap(vma, addr, len, offset))
27618 + return addr;
27619 + }
27620 + }
27621 +
27622 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27623 + info.length = len;
27624 + info.low_limit = PAGE_SIZE;
27625 + info.high_limit = mm->mmap_base;
27626 + info.align_mask = filp ? get_align_mask() : 0;
27627 + info.align_offset = pgoff << PAGE_SHIFT;
27628 + info.threadstack_offset = offset;
27629 +
27630 + addr = vm_unmapped_area(&info);
27631 + if (!(addr & ~PAGE_MASK))
27632 + return addr;
27633 + VM_BUG_ON(addr != -ENOMEM);
27634 +
27635 +bottomup:
27636 + /*
27637 + * A failed mmap() very likely causes application failure,
27638 + * so fall back to the bottom-up function here. This scenario
27639 + * can happen with large stack limits and large mmap()
27640 + * allocations.
27641 + */
27642 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27643 +}
27644 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27645 index 30277e2..5664a29 100644
27646 --- a/arch/x86/kernel/sys_x86_64.c
27647 +++ b/arch/x86/kernel/sys_x86_64.c
27648 @@ -81,8 +81,8 @@ out:
27649 return error;
27650 }
27651
27652 -static void find_start_end(unsigned long flags, unsigned long *begin,
27653 - unsigned long *end)
27654 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27655 + unsigned long *begin, unsigned long *end)
27656 {
27657 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27658 unsigned long new_begin;
27659 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27660 *begin = new_begin;
27661 }
27662 } else {
27663 - *begin = current->mm->mmap_legacy_base;
27664 + *begin = mm->mmap_legacy_base;
27665 *end = TASK_SIZE;
27666 }
27667 }
27668 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27669 struct vm_area_struct *vma;
27670 struct vm_unmapped_area_info info;
27671 unsigned long begin, end;
27672 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27673
27674 if (flags & MAP_FIXED)
27675 return addr;
27676
27677 - find_start_end(flags, &begin, &end);
27678 + find_start_end(mm, flags, &begin, &end);
27679
27680 if (len > end)
27681 return -ENOMEM;
27682
27683 +#ifdef CONFIG_PAX_RANDMMAP
27684 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27685 +#endif
27686 +
27687 if (addr) {
27688 addr = PAGE_ALIGN(addr);
27689 vma = find_vma(mm, addr);
27690 - if (end - len >= addr &&
27691 - (!vma || addr + len <= vma->vm_start))
27692 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27693 return addr;
27694 }
27695
27696 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27697 info.high_limit = end;
27698 info.align_mask = filp ? get_align_mask() : 0;
27699 info.align_offset = pgoff << PAGE_SHIFT;
27700 + info.threadstack_offset = offset;
27701 return vm_unmapped_area(&info);
27702 }
27703
27704 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27705 struct mm_struct *mm = current->mm;
27706 unsigned long addr = addr0;
27707 struct vm_unmapped_area_info info;
27708 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27709
27710 /* requested length too big for entire address space */
27711 if (len > TASK_SIZE)
27712 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27713 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27714 goto bottomup;
27715
27716 +#ifdef CONFIG_PAX_RANDMMAP
27717 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27718 +#endif
27719 +
27720 /* requesting a specific address */
27721 if (addr) {
27722 addr = PAGE_ALIGN(addr);
27723 vma = find_vma(mm, addr);
27724 - if (TASK_SIZE - len >= addr &&
27725 - (!vma || addr + len <= vma->vm_start))
27726 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27727 return addr;
27728 }
27729
27730 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27731 info.high_limit = mm->mmap_base;
27732 info.align_mask = filp ? get_align_mask() : 0;
27733 info.align_offset = pgoff << PAGE_SHIFT;
27734 + info.threadstack_offset = offset;
27735 addr = vm_unmapped_area(&info);
27736 if (!(addr & ~PAGE_MASK))
27737 return addr;
27738 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27739 index 91a4496..bb87552 100644
27740 --- a/arch/x86/kernel/tboot.c
27741 +++ b/arch/x86/kernel/tboot.c
27742 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27743
27744 void tboot_shutdown(u32 shutdown_type)
27745 {
27746 - void (*shutdown)(void);
27747 + void (* __noreturn shutdown)(void);
27748
27749 if (!tboot_enabled())
27750 return;
27751 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27752
27753 switch_to_tboot_pt();
27754
27755 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27756 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27757 shutdown();
27758
27759 /* should not reach here */
27760 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27761 return -ENODEV;
27762 }
27763
27764 -static atomic_t ap_wfs_count;
27765 +static atomic_unchecked_t ap_wfs_count;
27766
27767 static int tboot_wait_for_aps(int num_aps)
27768 {
27769 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27770 {
27771 switch (action) {
27772 case CPU_DYING:
27773 - atomic_inc(&ap_wfs_count);
27774 + atomic_inc_unchecked(&ap_wfs_count);
27775 if (num_online_cpus() == 1)
27776 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27777 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27778 return NOTIFY_BAD;
27779 break;
27780 }
27781 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27782
27783 tboot_create_trampoline();
27784
27785 - atomic_set(&ap_wfs_count, 0);
27786 + atomic_set_unchecked(&ap_wfs_count, 0);
27787 register_hotcpu_notifier(&tboot_cpu_notifier);
27788
27789 #ifdef CONFIG_DEBUG_FS
27790 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27791 index 0fa2960..91eabbe 100644
27792 --- a/arch/x86/kernel/time.c
27793 +++ b/arch/x86/kernel/time.c
27794 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27795 {
27796 unsigned long pc = instruction_pointer(regs);
27797
27798 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27799 + if (!user_mode(regs) && in_lock_functions(pc)) {
27800 #ifdef CONFIG_FRAME_POINTER
27801 - return *(unsigned long *)(regs->bp + sizeof(long));
27802 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27803 #else
27804 unsigned long *sp =
27805 (unsigned long *)kernel_stack_pointer(regs);
27806 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27807 * or above a saved flags. Eflags has bits 22-31 zero,
27808 * kernel addresses don't.
27809 */
27810 +
27811 +#ifdef CONFIG_PAX_KERNEXEC
27812 + return ktla_ktva(sp[0]);
27813 +#else
27814 if (sp[0] >> 22)
27815 return sp[0];
27816 if (sp[1] >> 22)
27817 return sp[1];
27818 #endif
27819 +
27820 +#endif
27821 }
27822 return pc;
27823 }
27824 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27825 index 7fc5e84..c6e445a 100644
27826 --- a/arch/x86/kernel/tls.c
27827 +++ b/arch/x86/kernel/tls.c
27828 @@ -139,6 +139,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27829 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27830 return -EINVAL;
27831
27832 +#ifdef CONFIG_PAX_SEGMEXEC
27833 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27834 + return -EINVAL;
27835 +#endif
27836 +
27837 set_tls_desc(p, idx, &info, 1);
27838
27839 return 0;
27840 @@ -256,7 +261,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27841
27842 if (kbuf)
27843 info = kbuf;
27844 - else if (__copy_from_user(infobuf, ubuf, count))
27845 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27846 return -EFAULT;
27847 else
27848 info = infobuf;
27849 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27850 index 1c113db..287b42e 100644
27851 --- a/arch/x86/kernel/tracepoint.c
27852 +++ b/arch/x86/kernel/tracepoint.c
27853 @@ -9,11 +9,11 @@
27854 #include <linux/atomic.h>
27855
27856 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27857 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27858 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27859 (unsigned long) trace_idt_table };
27860
27861 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27862 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27863 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27864
27865 static int trace_irq_vector_refcount;
27866 static DEFINE_MUTEX(irq_vector_mutex);
27867 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27868 index 07ab8e9..99c8456 100644
27869 --- a/arch/x86/kernel/traps.c
27870 +++ b/arch/x86/kernel/traps.c
27871 @@ -67,7 +67,7 @@
27872 #include <asm/proto.h>
27873
27874 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27875 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27876 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27877 #else
27878 #include <asm/processor-flags.h>
27879 #include <asm/setup.h>
27880 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27881 #endif
27882
27883 /* Must be page-aligned because the real IDT is used in a fixmap. */
27884 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27885 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27886
27887 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27888 EXPORT_SYMBOL_GPL(used_vectors);
27889 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27890 }
27891
27892 static nokprobe_inline int
27893 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27894 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27895 struct pt_regs *regs, long error_code)
27896 {
27897 #ifdef CONFIG_X86_32
27898 - if (regs->flags & X86_VM_MASK) {
27899 + if (v8086_mode(regs)) {
27900 /*
27901 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27902 * On nmi (interrupt 2), do_trap should not be called.
27903 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27904 return -1;
27905 }
27906 #endif
27907 - if (!user_mode(regs)) {
27908 + if (!user_mode_novm(regs)) {
27909 if (!fixup_exception(regs)) {
27910 tsk->thread.error_code = error_code;
27911 tsk->thread.trap_nr = trapnr;
27912 +
27913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27914 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27915 + str = "PAX: suspicious stack segment fault";
27916 +#endif
27917 +
27918 die(str, regs, error_code);
27919 }
27920 +
27921 +#ifdef CONFIG_PAX_REFCOUNT
27922 + if (trapnr == X86_TRAP_OF)
27923 + pax_report_refcount_overflow(regs);
27924 +#endif
27925 +
27926 return 0;
27927 }
27928
27929 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27930 }
27931
27932 static void
27933 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27934 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27935 long error_code, siginfo_t *info)
27936 {
27937 struct task_struct *tsk = current;
27938 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27939 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27940 printk_ratelimit()) {
27941 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27942 - tsk->comm, tsk->pid, str,
27943 + tsk->comm, task_pid_nr(tsk), str,
27944 regs->ip, regs->sp, error_code);
27945 print_vma_addr(" in ", regs->ip);
27946 pr_cont("\n");
27947 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27948 tsk->thread.error_code = error_code;
27949 tsk->thread.trap_nr = X86_TRAP_DF;
27950
27951 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27952 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27953 + die("grsec: kernel stack overflow detected", regs, error_code);
27954 +#endif
27955 +
27956 #ifdef CONFIG_DOUBLEFAULT
27957 df_debug(regs, error_code);
27958 #endif
27959 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27960 conditional_sti(regs);
27961
27962 #ifdef CONFIG_X86_32
27963 - if (regs->flags & X86_VM_MASK) {
27964 + if (v8086_mode(regs)) {
27965 local_irq_enable();
27966 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27967 goto exit;
27968 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27969 #endif
27970
27971 tsk = current;
27972 - if (!user_mode(regs)) {
27973 + if (!user_mode_novm(regs)) {
27974 if (fixup_exception(regs))
27975 goto exit;
27976
27977 tsk->thread.error_code = error_code;
27978 tsk->thread.trap_nr = X86_TRAP_GP;
27979 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27980 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27981 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27982 +
27983 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27984 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27985 + die("PAX: suspicious general protection fault", regs, error_code);
27986 + else
27987 +#endif
27988 +
27989 die("general protection fault", regs, error_code);
27990 + }
27991 goto exit;
27992 }
27993
27994 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27995 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27996 + struct mm_struct *mm = tsk->mm;
27997 + unsigned long limit;
27998 +
27999 + down_write(&mm->mmap_sem);
28000 + limit = mm->context.user_cs_limit;
28001 + if (limit < TASK_SIZE) {
28002 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28003 + up_write(&mm->mmap_sem);
28004 + return;
28005 + }
28006 + up_write(&mm->mmap_sem);
28007 + }
28008 +#endif
28009 +
28010 tsk->thread.error_code = error_code;
28011 tsk->thread.trap_nr = X86_TRAP_GP;
28012
28013 @@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28014 container_of(task_pt_regs(current),
28015 struct bad_iret_stack, regs);
28016
28017 + if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28018 + new_stack = s;
28019 +
28020 /* Copy the IRET target to the new stack. */
28021 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28022
28023 /* Copy the remainder of the stack from the current stack. */
28024 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28025
28026 - BUG_ON(!user_mode_vm(&new_stack->regs));
28027 + BUG_ON(!user_mode(&new_stack->regs));
28028 return new_stack;
28029 }
28030 NOKPROBE_SYMBOL(fixup_bad_iret);
28031 @@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28032 /* It's safe to allow irq's after DR6 has been saved */
28033 preempt_conditional_sti(regs);
28034
28035 - if (regs->flags & X86_VM_MASK) {
28036 + if (v8086_mode(regs)) {
28037 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28038 X86_TRAP_DB);
28039 preempt_conditional_cli(regs);
28040 @@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28041 * We already checked v86 mode above, so we can check for kernel mode
28042 * by just checking the CPL of CS.
28043 */
28044 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28045 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28046 tsk->thread.debugreg6 &= ~DR_STEP;
28047 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28048 regs->flags &= ~X86_EFLAGS_TF;
28049 @@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28050 return;
28051 conditional_sti(regs);
28052
28053 - if (!user_mode_vm(regs))
28054 + if (!user_mode(regs))
28055 {
28056 if (!fixup_exception(regs)) {
28057 task->thread.error_code = error_code;
28058 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28059 index 5054497..139f8f8 100644
28060 --- a/arch/x86/kernel/tsc.c
28061 +++ b/arch/x86/kernel/tsc.c
28062 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28063 */
28064 smp_wmb();
28065
28066 - ACCESS_ONCE(c2n->head) = data;
28067 + ACCESS_ONCE_RW(c2n->head) = data;
28068 }
28069
28070 /*
28071 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28072 index 5d1cbfe..2a21feb 100644
28073 --- a/arch/x86/kernel/uprobes.c
28074 +++ b/arch/x86/kernel/uprobes.c
28075 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28076 int ret = NOTIFY_DONE;
28077
28078 /* We are only interested in userspace traps */
28079 - if (regs && !user_mode_vm(regs))
28080 + if (regs && !user_mode(regs))
28081 return NOTIFY_DONE;
28082
28083 switch (val) {
28084 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28085
28086 if (nleft != rasize) {
28087 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28088 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28089 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28090
28091 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28092 }
28093 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28094 index b9242ba..50c5edd 100644
28095 --- a/arch/x86/kernel/verify_cpu.S
28096 +++ b/arch/x86/kernel/verify_cpu.S
28097 @@ -20,6 +20,7 @@
28098 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28099 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28100 * arch/x86/kernel/head_32.S: processor startup
28101 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28102 *
28103 * verify_cpu, returns the status of longmode and SSE in register %eax.
28104 * 0: Success 1: Failure
28105 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28106 index e8edcf5..27f9344 100644
28107 --- a/arch/x86/kernel/vm86_32.c
28108 +++ b/arch/x86/kernel/vm86_32.c
28109 @@ -44,6 +44,7 @@
28110 #include <linux/ptrace.h>
28111 #include <linux/audit.h>
28112 #include <linux/stddef.h>
28113 +#include <linux/grsecurity.h>
28114
28115 #include <asm/uaccess.h>
28116 #include <asm/io.h>
28117 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28118 do_exit(SIGSEGV);
28119 }
28120
28121 - tss = &per_cpu(init_tss, get_cpu());
28122 + tss = init_tss + get_cpu();
28123 current->thread.sp0 = current->thread.saved_sp0;
28124 current->thread.sysenter_cs = __KERNEL_CS;
28125 load_sp0(tss, &current->thread);
28126 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28127
28128 if (tsk->thread.saved_sp0)
28129 return -EPERM;
28130 +
28131 +#ifdef CONFIG_GRKERNSEC_VM86
28132 + if (!capable(CAP_SYS_RAWIO)) {
28133 + gr_handle_vm86();
28134 + return -EPERM;
28135 + }
28136 +#endif
28137 +
28138 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28139 offsetof(struct kernel_vm86_struct, vm86plus) -
28140 sizeof(info.regs));
28141 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28142 int tmp;
28143 struct vm86plus_struct __user *v86;
28144
28145 +#ifdef CONFIG_GRKERNSEC_VM86
28146 + if (!capable(CAP_SYS_RAWIO)) {
28147 + gr_handle_vm86();
28148 + return -EPERM;
28149 + }
28150 +#endif
28151 +
28152 tsk = current;
28153 switch (cmd) {
28154 case VM86_REQUEST_IRQ:
28155 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28156 tsk->thread.saved_fs = info->regs32->fs;
28157 tsk->thread.saved_gs = get_user_gs(info->regs32);
28158
28159 - tss = &per_cpu(init_tss, get_cpu());
28160 + tss = init_tss + get_cpu();
28161 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28162 if (cpu_has_sep)
28163 tsk->thread.sysenter_cs = 0;
28164 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28165 goto cannot_handle;
28166 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28167 goto cannot_handle;
28168 - intr_ptr = (unsigned long __user *) (i << 2);
28169 + intr_ptr = (__force unsigned long __user *) (i << 2);
28170 if (get_user(segoffs, intr_ptr))
28171 goto cannot_handle;
28172 if ((segoffs >> 16) == BIOSSEG)
28173 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28174 index 49edf2d..df596b1 100644
28175 --- a/arch/x86/kernel/vmlinux.lds.S
28176 +++ b/arch/x86/kernel/vmlinux.lds.S
28177 @@ -26,6 +26,13 @@
28178 #include <asm/page_types.h>
28179 #include <asm/cache.h>
28180 #include <asm/boot.h>
28181 +#include <asm/segment.h>
28182 +
28183 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28184 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28185 +#else
28186 +#define __KERNEL_TEXT_OFFSET 0
28187 +#endif
28188
28189 #undef i386 /* in case the preprocessor is a 32bit one */
28190
28191 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28192
28193 PHDRS {
28194 text PT_LOAD FLAGS(5); /* R_E */
28195 +#ifdef CONFIG_X86_32
28196 + module PT_LOAD FLAGS(5); /* R_E */
28197 +#endif
28198 +#ifdef CONFIG_XEN
28199 + rodata PT_LOAD FLAGS(5); /* R_E */
28200 +#else
28201 + rodata PT_LOAD FLAGS(4); /* R__ */
28202 +#endif
28203 data PT_LOAD FLAGS(6); /* RW_ */
28204 -#ifdef CONFIG_X86_64
28205 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28206 #ifdef CONFIG_SMP
28207 percpu PT_LOAD FLAGS(6); /* RW_ */
28208 #endif
28209 + text.init PT_LOAD FLAGS(5); /* R_E */
28210 + text.exit PT_LOAD FLAGS(5); /* R_E */
28211 init PT_LOAD FLAGS(7); /* RWE */
28212 -#endif
28213 note PT_NOTE FLAGS(0); /* ___ */
28214 }
28215
28216 SECTIONS
28217 {
28218 #ifdef CONFIG_X86_32
28219 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28220 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28221 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28222 #else
28223 - . = __START_KERNEL;
28224 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28225 + . = __START_KERNEL;
28226 #endif
28227
28228 /* Text and read-only data */
28229 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28230 - _text = .;
28231 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28232 /* bootstrapping code */
28233 +#ifdef CONFIG_X86_32
28234 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28235 +#else
28236 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28237 +#endif
28238 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28239 + _text = .;
28240 HEAD_TEXT
28241 . = ALIGN(8);
28242 _stext = .;
28243 @@ -104,13 +124,47 @@ SECTIONS
28244 IRQENTRY_TEXT
28245 *(.fixup)
28246 *(.gnu.warning)
28247 - /* End of text section */
28248 - _etext = .;
28249 } :text = 0x9090
28250
28251 - NOTES :text :note
28252 + . += __KERNEL_TEXT_OFFSET;
28253
28254 - EXCEPTION_TABLE(16) :text = 0x9090
28255 +#ifdef CONFIG_X86_32
28256 + . = ALIGN(PAGE_SIZE);
28257 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28258 +
28259 +#ifdef CONFIG_PAX_KERNEXEC
28260 + MODULES_EXEC_VADDR = .;
28261 + BYTE(0)
28262 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28263 + . = ALIGN(HPAGE_SIZE) - 1;
28264 + MODULES_EXEC_END = .;
28265 +#endif
28266 +
28267 + } :module
28268 +#endif
28269 +
28270 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28271 + /* End of text section */
28272 + BYTE(0)
28273 + _etext = . - __KERNEL_TEXT_OFFSET;
28274 + }
28275 +
28276 +#ifdef CONFIG_X86_32
28277 + . = ALIGN(PAGE_SIZE);
28278 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28279 + . = ALIGN(PAGE_SIZE);
28280 + *(.empty_zero_page)
28281 + *(.initial_pg_fixmap)
28282 + *(.initial_pg_pmd)
28283 + *(.initial_page_table)
28284 + *(.swapper_pg_dir)
28285 + } :rodata
28286 +#endif
28287 +
28288 + . = ALIGN(PAGE_SIZE);
28289 + NOTES :rodata :note
28290 +
28291 + EXCEPTION_TABLE(16) :rodata
28292
28293 #if defined(CONFIG_DEBUG_RODATA)
28294 /* .text should occupy whole number of pages */
28295 @@ -122,16 +176,20 @@ SECTIONS
28296
28297 /* Data */
28298 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28299 +
28300 +#ifdef CONFIG_PAX_KERNEXEC
28301 + . = ALIGN(HPAGE_SIZE);
28302 +#else
28303 + . = ALIGN(PAGE_SIZE);
28304 +#endif
28305 +
28306 /* Start of data section */
28307 _sdata = .;
28308
28309 /* init_task */
28310 INIT_TASK_DATA(THREAD_SIZE)
28311
28312 -#ifdef CONFIG_X86_32
28313 - /* 32 bit has nosave before _edata */
28314 NOSAVE_DATA
28315 -#endif
28316
28317 PAGE_ALIGNED_DATA(PAGE_SIZE)
28318
28319 @@ -174,12 +232,19 @@ SECTIONS
28320 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28321
28322 /* Init code and data - will be freed after init */
28323 - . = ALIGN(PAGE_SIZE);
28324 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28325 + BYTE(0)
28326 +
28327 +#ifdef CONFIG_PAX_KERNEXEC
28328 + . = ALIGN(HPAGE_SIZE);
28329 +#else
28330 + . = ALIGN(PAGE_SIZE);
28331 +#endif
28332 +
28333 __init_begin = .; /* paired with __init_end */
28334 - }
28335 + } :init.begin
28336
28337 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28338 +#ifdef CONFIG_SMP
28339 /*
28340 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28341 * output PHDR, so the next output section - .init.text - should
28342 @@ -188,12 +253,27 @@ SECTIONS
28343 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28344 #endif
28345
28346 - INIT_TEXT_SECTION(PAGE_SIZE)
28347 -#ifdef CONFIG_X86_64
28348 - :init
28349 -#endif
28350 + . = ALIGN(PAGE_SIZE);
28351 + init_begin = .;
28352 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28353 + VMLINUX_SYMBOL(_sinittext) = .;
28354 + INIT_TEXT
28355 + . = ALIGN(PAGE_SIZE);
28356 + } :text.init
28357
28358 - INIT_DATA_SECTION(16)
28359 + /*
28360 + * .exit.text is discard at runtime, not link time, to deal with
28361 + * references from .altinstructions and .eh_frame
28362 + */
28363 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28364 + EXIT_TEXT
28365 + VMLINUX_SYMBOL(_einittext) = .;
28366 + . = ALIGN(16);
28367 + } :text.exit
28368 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28369 +
28370 + . = ALIGN(PAGE_SIZE);
28371 + INIT_DATA_SECTION(16) :init
28372
28373 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28374 __x86_cpu_dev_start = .;
28375 @@ -264,19 +344,12 @@ SECTIONS
28376 }
28377
28378 . = ALIGN(8);
28379 - /*
28380 - * .exit.text is discard at runtime, not link time, to deal with
28381 - * references from .altinstructions and .eh_frame
28382 - */
28383 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28384 - EXIT_TEXT
28385 - }
28386
28387 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28388 EXIT_DATA
28389 }
28390
28391 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28392 +#ifndef CONFIG_SMP
28393 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28394 #endif
28395
28396 @@ -295,16 +368,10 @@ SECTIONS
28397 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28398 __smp_locks = .;
28399 *(.smp_locks)
28400 - . = ALIGN(PAGE_SIZE);
28401 __smp_locks_end = .;
28402 + . = ALIGN(PAGE_SIZE);
28403 }
28404
28405 -#ifdef CONFIG_X86_64
28406 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28407 - NOSAVE_DATA
28408 - }
28409 -#endif
28410 -
28411 /* BSS */
28412 . = ALIGN(PAGE_SIZE);
28413 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28414 @@ -320,6 +387,7 @@ SECTIONS
28415 __brk_base = .;
28416 . += 64 * 1024; /* 64k alignment slop space */
28417 *(.brk_reservation) /* areas brk users have reserved */
28418 + . = ALIGN(HPAGE_SIZE);
28419 __brk_limit = .;
28420 }
28421
28422 @@ -346,13 +414,12 @@ SECTIONS
28423 * for the boot processor.
28424 */
28425 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28426 -INIT_PER_CPU(gdt_page);
28427 INIT_PER_CPU(irq_stack_union);
28428
28429 /*
28430 * Build-time check on the image size:
28431 */
28432 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28433 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28434 "kernel image bigger than KERNEL_IMAGE_SIZE");
28435
28436 #ifdef CONFIG_SMP
28437 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28438 index 957779f..74e405c 100644
28439 --- a/arch/x86/kernel/vsyscall_64.c
28440 +++ b/arch/x86/kernel/vsyscall_64.c
28441 @@ -54,15 +54,13 @@
28442
28443 DEFINE_VVAR(int, vgetcpu_mode);
28444
28445 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28446 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28447
28448 static int __init vsyscall_setup(char *str)
28449 {
28450 if (str) {
28451 if (!strcmp("emulate", str))
28452 vsyscall_mode = EMULATE;
28453 - else if (!strcmp("native", str))
28454 - vsyscall_mode = NATIVE;
28455 else if (!strcmp("none", str))
28456 vsyscall_mode = NONE;
28457 else
28458 @@ -279,8 +277,7 @@ do_ret:
28459 return true;
28460
28461 sigsegv:
28462 - force_sig(SIGSEGV, current);
28463 - return true;
28464 + do_group_exit(SIGKILL);
28465 }
28466
28467 /*
28468 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28469 extern char __vsyscall_page;
28470 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28471
28472 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28473 - vsyscall_mode == NATIVE
28474 - ? PAGE_KERNEL_VSYSCALL
28475 - : PAGE_KERNEL_VVAR);
28476 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28477 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28478 (unsigned long)VSYSCALL_ADDR);
28479 }
28480 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28481 index 04068192..4d75aa6 100644
28482 --- a/arch/x86/kernel/x8664_ksyms_64.c
28483 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28484 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28485 EXPORT_SYMBOL(copy_user_generic_unrolled);
28486 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28487 EXPORT_SYMBOL(__copy_user_nocache);
28488 -EXPORT_SYMBOL(_copy_from_user);
28489 -EXPORT_SYMBOL(_copy_to_user);
28490
28491 EXPORT_SYMBOL(copy_page);
28492 EXPORT_SYMBOL(clear_page);
28493 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28494 EXPORT_SYMBOL(___preempt_schedule_context);
28495 #endif
28496 #endif
28497 +
28498 +#ifdef CONFIG_PAX_PER_CPU_PGD
28499 +EXPORT_SYMBOL(cpu_pgd);
28500 +#endif
28501 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28502 index e48b674..a451dd9 100644
28503 --- a/arch/x86/kernel/x86_init.c
28504 +++ b/arch/x86/kernel/x86_init.c
28505 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28506 static void default_nmi_init(void) { };
28507 static int default_i8042_detect(void) { return 1; };
28508
28509 -struct x86_platform_ops x86_platform = {
28510 +struct x86_platform_ops x86_platform __read_only = {
28511 .calibrate_tsc = native_calibrate_tsc,
28512 .get_wallclock = mach_get_cmos_time,
28513 .set_wallclock = mach_set_rtc_mmss,
28514 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28515 EXPORT_SYMBOL_GPL(x86_platform);
28516
28517 #if defined(CONFIG_PCI_MSI)
28518 -struct x86_msi_ops x86_msi = {
28519 +struct x86_msi_ops x86_msi __read_only = {
28520 .setup_msi_irqs = native_setup_msi_irqs,
28521 .compose_msi_msg = native_compose_msi_msg,
28522 .teardown_msi_irq = native_teardown_msi_irq,
28523 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28524 }
28525 #endif
28526
28527 -struct x86_io_apic_ops x86_io_apic_ops = {
28528 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28529 .init = native_io_apic_init_mappings,
28530 .read = native_io_apic_read,
28531 .write = native_io_apic_write,
28532 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28533 index 0de1fae..298d037 100644
28534 --- a/arch/x86/kernel/xsave.c
28535 +++ b/arch/x86/kernel/xsave.c
28536 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28537
28538 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28539 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28540 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28541 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28542
28543 if (!use_xsave())
28544 return err;
28545
28546 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28547 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28548
28549 /*
28550 * Read the xstate_bv which we copied (directly from the cpu or
28551 * from the state in task struct) to the user buffers.
28552 */
28553 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28554 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28555
28556 /*
28557 * For legacy compatible, we always set FP/SSE bits in the bit
28558 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28559 */
28560 xstate_bv |= XSTATE_FPSSE;
28561
28562 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28563 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28564
28565 return err;
28566 }
28567 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28568 {
28569 int err;
28570
28571 + buf = (struct xsave_struct __user *)____m(buf);
28572 if (use_xsave())
28573 err = xsave_user(buf);
28574 else if (use_fxsr())
28575 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28576 */
28577 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28578 {
28579 + buf = (void __user *)____m(buf);
28580 if (use_xsave()) {
28581 if ((unsigned long)buf % 64 || fx_only) {
28582 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28583 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28584 index 88f9201..0e7f1a3 100644
28585 --- a/arch/x86/kvm/cpuid.c
28586 +++ b/arch/x86/kvm/cpuid.c
28587 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28588 struct kvm_cpuid2 *cpuid,
28589 struct kvm_cpuid_entry2 __user *entries)
28590 {
28591 - int r;
28592 + int r, i;
28593
28594 r = -E2BIG;
28595 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28596 goto out;
28597 r = -EFAULT;
28598 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28599 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28600 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28601 goto out;
28602 + for (i = 0; i < cpuid->nent; ++i) {
28603 + struct kvm_cpuid_entry2 cpuid_entry;
28604 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28605 + goto out;
28606 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28607 + }
28608 vcpu->arch.cpuid_nent = cpuid->nent;
28609 kvm_apic_set_version(vcpu);
28610 kvm_x86_ops->cpuid_update(vcpu);
28611 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28612 struct kvm_cpuid2 *cpuid,
28613 struct kvm_cpuid_entry2 __user *entries)
28614 {
28615 - int r;
28616 + int r, i;
28617
28618 r = -E2BIG;
28619 if (cpuid->nent < vcpu->arch.cpuid_nent)
28620 goto out;
28621 r = -EFAULT;
28622 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28623 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28624 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28625 goto out;
28626 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28627 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28628 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28629 + goto out;
28630 + }
28631 return 0;
28632
28633 out:
28634 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28635 index c7327a7..c3e2419 100644
28636 --- a/arch/x86/kvm/emulate.c
28637 +++ b/arch/x86/kvm/emulate.c
28638 @@ -3508,7 +3508,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28639 int cr = ctxt->modrm_reg;
28640 u64 efer = 0;
28641
28642 - static u64 cr_reserved_bits[] = {
28643 + static const u64 cr_reserved_bits[] = {
28644 0xffffffff00000000ULL,
28645 0, 0, 0, /* CR3 checked later */
28646 CR4_RESERVED_BITS,
28647 @@ -3543,7 +3543,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28648
28649 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28650 if (efer & EFER_LMA)
28651 - rsvd = CR3_L_MODE_RESERVED_BITS;
28652 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28653
28654 if (new_val & rsvd)
28655 return emulate_gp(ctxt, 0);
28656 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28657 index b8345dd..f225d71 100644
28658 --- a/arch/x86/kvm/lapic.c
28659 +++ b/arch/x86/kvm/lapic.c
28660 @@ -55,7 +55,7 @@
28661 #define APIC_BUS_CYCLE_NS 1
28662
28663 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28664 -#define apic_debug(fmt, arg...)
28665 +#define apic_debug(fmt, arg...) do {} while (0)
28666
28667 #define APIC_LVT_NUM 6
28668 /* 14 is the version for Xeon and Pentium 8.4.8*/
28669 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28670 index fd49c86..77e1aa0 100644
28671 --- a/arch/x86/kvm/paging_tmpl.h
28672 +++ b/arch/x86/kvm/paging_tmpl.h
28673 @@ -343,7 +343,7 @@ retry_walk:
28674 if (unlikely(kvm_is_error_hva(host_addr)))
28675 goto error;
28676
28677 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28678 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28679 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28680 goto error;
28681 walker->ptep_user[walker->level - 1] = ptep_user;
28682 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28683 index 7527cef..c63a838e 100644
28684 --- a/arch/x86/kvm/svm.c
28685 +++ b/arch/x86/kvm/svm.c
28686 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28687 int cpu = raw_smp_processor_id();
28688
28689 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28690 +
28691 + pax_open_kernel();
28692 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28693 + pax_close_kernel();
28694 +
28695 load_TR_desc();
28696 }
28697
28698 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28699 #endif
28700 #endif
28701
28702 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28703 + __set_fs(current_thread_info()->addr_limit);
28704 +#endif
28705 +
28706 reload_tss(vcpu);
28707
28708 local_irq_disable();
28709 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28710 index ed70394..c629a68 100644
28711 --- a/arch/x86/kvm/vmx.c
28712 +++ b/arch/x86/kvm/vmx.c
28713 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28714 #endif
28715 }
28716
28717 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28718 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28719 {
28720 vmcs_writel(field, vmcs_readl(field) & ~mask);
28721 }
28722
28723 -static void vmcs_set_bits(unsigned long field, u32 mask)
28724 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28725 {
28726 vmcs_writel(field, vmcs_readl(field) | mask);
28727 }
28728 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28729 struct desc_struct *descs;
28730
28731 descs = (void *)gdt->address;
28732 +
28733 + pax_open_kernel();
28734 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28735 + pax_close_kernel();
28736 +
28737 load_TR_desc();
28738 }
28739
28740 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28741 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28742 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28743
28744 +#ifdef CONFIG_PAX_PER_CPU_PGD
28745 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28746 +#endif
28747 +
28748 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28749 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28750 vmx->loaded_vmcs->cpu = cpu;
28751 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28752 * reads and returns guest's timestamp counter "register"
28753 * guest_tsc = host_tsc + tsc_offset -- 21.3
28754 */
28755 -static u64 guest_read_tsc(void)
28756 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28757 {
28758 u64 host_tsc, tsc_offset;
28759
28760 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28761 * page upon invalidation. No need to do anything if the
28762 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28763 */
28764 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28765 + pax_open_kernel();
28766 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28767 + pax_close_kernel();
28768 }
28769
28770 - if (!cpu_has_vmx_tpr_shadow())
28771 - kvm_x86_ops->update_cr8_intercept = NULL;
28772 + if (!cpu_has_vmx_tpr_shadow()) {
28773 + pax_open_kernel();
28774 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28775 + pax_close_kernel();
28776 + }
28777
28778 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28779 kvm_disable_largepages();
28780 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28781 if (!cpu_has_vmx_apicv())
28782 enable_apicv = 0;
28783
28784 + pax_open_kernel();
28785 if (enable_apicv)
28786 - kvm_x86_ops->update_cr8_intercept = NULL;
28787 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28788 else {
28789 - kvm_x86_ops->hwapic_irr_update = NULL;
28790 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28791 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28792 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28793 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28794 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28795 }
28796 + pax_close_kernel();
28797
28798 if (nested)
28799 nested_vmx_setup_ctls_msrs();
28800 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28801 unsigned long cr4;
28802
28803 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28804 +
28805 +#ifndef CONFIG_PAX_PER_CPU_PGD
28806 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28807 +#endif
28808
28809 /* Save the most likely value for this task's CR4 in the VMCS. */
28810 cr4 = read_cr4();
28811 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28812 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28813 vmx->host_idt_base = dt.address;
28814
28815 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28816 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28817
28818 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28819 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28820 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28821 "jmp 2f \n\t"
28822 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28823 "2: "
28824 +
28825 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28826 + "ljmp %[cs],$3f\n\t"
28827 + "3: "
28828 +#endif
28829 +
28830 /* Save guest registers, load host registers, keep flags */
28831 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28832 "pop %0 \n\t"
28833 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28834 #endif
28835 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28836 [wordsize]"i"(sizeof(ulong))
28837 +
28838 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28839 + ,[cs]"i"(__KERNEL_CS)
28840 +#endif
28841 +
28842 : "cc", "memory"
28843 #ifdef CONFIG_X86_64
28844 , "rax", "rbx", "rdi", "rsi"
28845 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28846 if (debugctlmsr)
28847 update_debugctlmsr(debugctlmsr);
28848
28849 -#ifndef CONFIG_X86_64
28850 +#ifdef CONFIG_X86_32
28851 /*
28852 * The sysexit path does not restore ds/es, so we must set them to
28853 * a reasonable value ourselves.
28854 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28855 * may be executed in interrupt context, which saves and restore segments
28856 * around it, nullifying its effect.
28857 */
28858 - loadsegment(ds, __USER_DS);
28859 - loadsegment(es, __USER_DS);
28860 + loadsegment(ds, __KERNEL_DS);
28861 + loadsegment(es, __KERNEL_DS);
28862 + loadsegment(ss, __KERNEL_DS);
28863 +
28864 +#ifdef CONFIG_PAX_KERNEXEC
28865 + loadsegment(fs, __KERNEL_PERCPU);
28866 +#endif
28867 +
28868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28869 + __set_fs(current_thread_info()->addr_limit);
28870 +#endif
28871 +
28872 #endif
28873
28874 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28875 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28876 index 506488c..f8df17e 100644
28877 --- a/arch/x86/kvm/x86.c
28878 +++ b/arch/x86/kvm/x86.c
28879 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28880
28881 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28882 {
28883 + cr3 &= ~CR3_PCID_INVD;
28884 +
28885 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28886 kvm_mmu_sync_roots(vcpu);
28887 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28888 @@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28889 {
28890 struct kvm *kvm = vcpu->kvm;
28891 int lm = is_long_mode(vcpu);
28892 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28893 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28894 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28895 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28896 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28897 : kvm->arch.xen_hvm_config.blob_size_32;
28898 u32 page_num = data & ~PAGE_MASK;
28899 @@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28900 if (n < msr_list.nmsrs)
28901 goto out;
28902 r = -EFAULT;
28903 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28904 + goto out;
28905 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28906 num_msrs_to_save * sizeof(u32)))
28907 goto out;
28908 @@ -5743,7 +5747,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28909 };
28910 #endif
28911
28912 -int kvm_arch_init(void *opaque)
28913 +int kvm_arch_init(const void *opaque)
28914 {
28915 int r;
28916 struct kvm_x86_ops *ops = opaque;
28917 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28918 index aae9413..d11e829 100644
28919 --- a/arch/x86/lguest/boot.c
28920 +++ b/arch/x86/lguest/boot.c
28921 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28922 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28923 * Launcher to reboot us.
28924 */
28925 -static void lguest_restart(char *reason)
28926 +static __noreturn void lguest_restart(char *reason)
28927 {
28928 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28929 + BUG();
28930 }
28931
28932 /*G:050
28933 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28934 index 00933d5..3a64af9 100644
28935 --- a/arch/x86/lib/atomic64_386_32.S
28936 +++ b/arch/x86/lib/atomic64_386_32.S
28937 @@ -48,6 +48,10 @@ BEGIN(read)
28938 movl (v), %eax
28939 movl 4(v), %edx
28940 RET_ENDP
28941 +BEGIN(read_unchecked)
28942 + movl (v), %eax
28943 + movl 4(v), %edx
28944 +RET_ENDP
28945 #undef v
28946
28947 #define v %esi
28948 @@ -55,6 +59,10 @@ BEGIN(set)
28949 movl %ebx, (v)
28950 movl %ecx, 4(v)
28951 RET_ENDP
28952 +BEGIN(set_unchecked)
28953 + movl %ebx, (v)
28954 + movl %ecx, 4(v)
28955 +RET_ENDP
28956 #undef v
28957
28958 #define v %esi
28959 @@ -70,6 +78,20 @@ RET_ENDP
28960 BEGIN(add)
28961 addl %eax, (v)
28962 adcl %edx, 4(v)
28963 +
28964 +#ifdef CONFIG_PAX_REFCOUNT
28965 + jno 0f
28966 + subl %eax, (v)
28967 + sbbl %edx, 4(v)
28968 + int $4
28969 +0:
28970 + _ASM_EXTABLE(0b, 0b)
28971 +#endif
28972 +
28973 +RET_ENDP
28974 +BEGIN(add_unchecked)
28975 + addl %eax, (v)
28976 + adcl %edx, 4(v)
28977 RET_ENDP
28978 #undef v
28979
28980 @@ -77,6 +99,24 @@ RET_ENDP
28981 BEGIN(add_return)
28982 addl (v), %eax
28983 adcl 4(v), %edx
28984 +
28985 +#ifdef CONFIG_PAX_REFCOUNT
28986 + into
28987 +1234:
28988 + _ASM_EXTABLE(1234b, 2f)
28989 +#endif
28990 +
28991 + movl %eax, (v)
28992 + movl %edx, 4(v)
28993 +
28994 +#ifdef CONFIG_PAX_REFCOUNT
28995 +2:
28996 +#endif
28997 +
28998 +RET_ENDP
28999 +BEGIN(add_return_unchecked)
29000 + addl (v), %eax
29001 + adcl 4(v), %edx
29002 movl %eax, (v)
29003 movl %edx, 4(v)
29004 RET_ENDP
29005 @@ -86,6 +126,20 @@ RET_ENDP
29006 BEGIN(sub)
29007 subl %eax, (v)
29008 sbbl %edx, 4(v)
29009 +
29010 +#ifdef CONFIG_PAX_REFCOUNT
29011 + jno 0f
29012 + addl %eax, (v)
29013 + adcl %edx, 4(v)
29014 + int $4
29015 +0:
29016 + _ASM_EXTABLE(0b, 0b)
29017 +#endif
29018 +
29019 +RET_ENDP
29020 +BEGIN(sub_unchecked)
29021 + subl %eax, (v)
29022 + sbbl %edx, 4(v)
29023 RET_ENDP
29024 #undef v
29025
29026 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29027 sbbl $0, %edx
29028 addl (v), %eax
29029 adcl 4(v), %edx
29030 +
29031 +#ifdef CONFIG_PAX_REFCOUNT
29032 + into
29033 +1234:
29034 + _ASM_EXTABLE(1234b, 2f)
29035 +#endif
29036 +
29037 + movl %eax, (v)
29038 + movl %edx, 4(v)
29039 +
29040 +#ifdef CONFIG_PAX_REFCOUNT
29041 +2:
29042 +#endif
29043 +
29044 +RET_ENDP
29045 +BEGIN(sub_return_unchecked)
29046 + negl %edx
29047 + negl %eax
29048 + sbbl $0, %edx
29049 + addl (v), %eax
29050 + adcl 4(v), %edx
29051 movl %eax, (v)
29052 movl %edx, 4(v)
29053 RET_ENDP
29054 @@ -105,6 +180,20 @@ RET_ENDP
29055 BEGIN(inc)
29056 addl $1, (v)
29057 adcl $0, 4(v)
29058 +
29059 +#ifdef CONFIG_PAX_REFCOUNT
29060 + jno 0f
29061 + subl $1, (v)
29062 + sbbl $0, 4(v)
29063 + int $4
29064 +0:
29065 + _ASM_EXTABLE(0b, 0b)
29066 +#endif
29067 +
29068 +RET_ENDP
29069 +BEGIN(inc_unchecked)
29070 + addl $1, (v)
29071 + adcl $0, 4(v)
29072 RET_ENDP
29073 #undef v
29074
29075 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29076 movl 4(v), %edx
29077 addl $1, %eax
29078 adcl $0, %edx
29079 +
29080 +#ifdef CONFIG_PAX_REFCOUNT
29081 + into
29082 +1234:
29083 + _ASM_EXTABLE(1234b, 2f)
29084 +#endif
29085 +
29086 + movl %eax, (v)
29087 + movl %edx, 4(v)
29088 +
29089 +#ifdef CONFIG_PAX_REFCOUNT
29090 +2:
29091 +#endif
29092 +
29093 +RET_ENDP
29094 +BEGIN(inc_return_unchecked)
29095 + movl (v), %eax
29096 + movl 4(v), %edx
29097 + addl $1, %eax
29098 + adcl $0, %edx
29099 movl %eax, (v)
29100 movl %edx, 4(v)
29101 RET_ENDP
29102 @@ -123,6 +232,20 @@ RET_ENDP
29103 BEGIN(dec)
29104 subl $1, (v)
29105 sbbl $0, 4(v)
29106 +
29107 +#ifdef CONFIG_PAX_REFCOUNT
29108 + jno 0f
29109 + addl $1, (v)
29110 + adcl $0, 4(v)
29111 + int $4
29112 +0:
29113 + _ASM_EXTABLE(0b, 0b)
29114 +#endif
29115 +
29116 +RET_ENDP
29117 +BEGIN(dec_unchecked)
29118 + subl $1, (v)
29119 + sbbl $0, 4(v)
29120 RET_ENDP
29121 #undef v
29122
29123 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29124 movl 4(v), %edx
29125 subl $1, %eax
29126 sbbl $0, %edx
29127 +
29128 +#ifdef CONFIG_PAX_REFCOUNT
29129 + into
29130 +1234:
29131 + _ASM_EXTABLE(1234b, 2f)
29132 +#endif
29133 +
29134 + movl %eax, (v)
29135 + movl %edx, 4(v)
29136 +
29137 +#ifdef CONFIG_PAX_REFCOUNT
29138 +2:
29139 +#endif
29140 +
29141 +RET_ENDP
29142 +BEGIN(dec_return_unchecked)
29143 + movl (v), %eax
29144 + movl 4(v), %edx
29145 + subl $1, %eax
29146 + sbbl $0, %edx
29147 movl %eax, (v)
29148 movl %edx, 4(v)
29149 RET_ENDP
29150 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29151 adcl %edx, %edi
29152 addl (v), %eax
29153 adcl 4(v), %edx
29154 +
29155 +#ifdef CONFIG_PAX_REFCOUNT
29156 + into
29157 +1234:
29158 + _ASM_EXTABLE(1234b, 2f)
29159 +#endif
29160 +
29161 cmpl %eax, %ecx
29162 je 3f
29163 1:
29164 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29165 1:
29166 addl $1, %eax
29167 adcl $0, %edx
29168 +
29169 +#ifdef CONFIG_PAX_REFCOUNT
29170 + into
29171 +1234:
29172 + _ASM_EXTABLE(1234b, 2f)
29173 +#endif
29174 +
29175 movl %eax, (v)
29176 movl %edx, 4(v)
29177 movl $1, %eax
29178 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29179 movl 4(v), %edx
29180 subl $1, %eax
29181 sbbl $0, %edx
29182 +
29183 +#ifdef CONFIG_PAX_REFCOUNT
29184 + into
29185 +1234:
29186 + _ASM_EXTABLE(1234b, 1f)
29187 +#endif
29188 +
29189 js 1f
29190 movl %eax, (v)
29191 movl %edx, 4(v)
29192 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29193 index f5cc9eb..51fa319 100644
29194 --- a/arch/x86/lib/atomic64_cx8_32.S
29195 +++ b/arch/x86/lib/atomic64_cx8_32.S
29196 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29197 CFI_STARTPROC
29198
29199 read64 %ecx
29200 + pax_force_retaddr
29201 ret
29202 CFI_ENDPROC
29203 ENDPROC(atomic64_read_cx8)
29204
29205 +ENTRY(atomic64_read_unchecked_cx8)
29206 + CFI_STARTPROC
29207 +
29208 + read64 %ecx
29209 + pax_force_retaddr
29210 + ret
29211 + CFI_ENDPROC
29212 +ENDPROC(atomic64_read_unchecked_cx8)
29213 +
29214 ENTRY(atomic64_set_cx8)
29215 CFI_STARTPROC
29216
29217 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29218 cmpxchg8b (%esi)
29219 jne 1b
29220
29221 + pax_force_retaddr
29222 ret
29223 CFI_ENDPROC
29224 ENDPROC(atomic64_set_cx8)
29225
29226 +ENTRY(atomic64_set_unchecked_cx8)
29227 + CFI_STARTPROC
29228 +
29229 +1:
29230 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29231 + * are atomic on 586 and newer */
29232 + cmpxchg8b (%esi)
29233 + jne 1b
29234 +
29235 + pax_force_retaddr
29236 + ret
29237 + CFI_ENDPROC
29238 +ENDPROC(atomic64_set_unchecked_cx8)
29239 +
29240 ENTRY(atomic64_xchg_cx8)
29241 CFI_STARTPROC
29242
29243 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29244 cmpxchg8b (%esi)
29245 jne 1b
29246
29247 + pax_force_retaddr
29248 ret
29249 CFI_ENDPROC
29250 ENDPROC(atomic64_xchg_cx8)
29251
29252 -.macro addsub_return func ins insc
29253 -ENTRY(atomic64_\func\()_return_cx8)
29254 +.macro addsub_return func ins insc unchecked=""
29255 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29256 CFI_STARTPROC
29257 SAVE ebp
29258 SAVE ebx
29259 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29260 movl %edx, %ecx
29261 \ins\()l %esi, %ebx
29262 \insc\()l %edi, %ecx
29263 +
29264 +.ifb \unchecked
29265 +#ifdef CONFIG_PAX_REFCOUNT
29266 + into
29267 +2:
29268 + _ASM_EXTABLE(2b, 3f)
29269 +#endif
29270 +.endif
29271 +
29272 LOCK_PREFIX
29273 cmpxchg8b (%ebp)
29274 jne 1b
29275 -
29276 -10:
29277 movl %ebx, %eax
29278 movl %ecx, %edx
29279 +
29280 +.ifb \unchecked
29281 +#ifdef CONFIG_PAX_REFCOUNT
29282 +3:
29283 +#endif
29284 +.endif
29285 +
29286 RESTORE edi
29287 RESTORE esi
29288 RESTORE ebx
29289 RESTORE ebp
29290 + pax_force_retaddr
29291 ret
29292 CFI_ENDPROC
29293 -ENDPROC(atomic64_\func\()_return_cx8)
29294 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29295 .endm
29296
29297 addsub_return add add adc
29298 addsub_return sub sub sbb
29299 +addsub_return add add adc _unchecked
29300 +addsub_return sub sub sbb _unchecked
29301
29302 -.macro incdec_return func ins insc
29303 -ENTRY(atomic64_\func\()_return_cx8)
29304 +.macro incdec_return func ins insc unchecked=""
29305 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29306 CFI_STARTPROC
29307 SAVE ebx
29308
29309 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29310 movl %edx, %ecx
29311 \ins\()l $1, %ebx
29312 \insc\()l $0, %ecx
29313 +
29314 +.ifb \unchecked
29315 +#ifdef CONFIG_PAX_REFCOUNT
29316 + into
29317 +2:
29318 + _ASM_EXTABLE(2b, 3f)
29319 +#endif
29320 +.endif
29321 +
29322 LOCK_PREFIX
29323 cmpxchg8b (%esi)
29324 jne 1b
29325
29326 -10:
29327 movl %ebx, %eax
29328 movl %ecx, %edx
29329 +
29330 +.ifb \unchecked
29331 +#ifdef CONFIG_PAX_REFCOUNT
29332 +3:
29333 +#endif
29334 +.endif
29335 +
29336 RESTORE ebx
29337 + pax_force_retaddr
29338 ret
29339 CFI_ENDPROC
29340 -ENDPROC(atomic64_\func\()_return_cx8)
29341 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29342 .endm
29343
29344 incdec_return inc add adc
29345 incdec_return dec sub sbb
29346 +incdec_return inc add adc _unchecked
29347 +incdec_return dec sub sbb _unchecked
29348
29349 ENTRY(atomic64_dec_if_positive_cx8)
29350 CFI_STARTPROC
29351 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29352 movl %edx, %ecx
29353 subl $1, %ebx
29354 sbb $0, %ecx
29355 +
29356 +#ifdef CONFIG_PAX_REFCOUNT
29357 + into
29358 +1234:
29359 + _ASM_EXTABLE(1234b, 2f)
29360 +#endif
29361 +
29362 js 2f
29363 LOCK_PREFIX
29364 cmpxchg8b (%esi)
29365 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29366 movl %ebx, %eax
29367 movl %ecx, %edx
29368 RESTORE ebx
29369 + pax_force_retaddr
29370 ret
29371 CFI_ENDPROC
29372 ENDPROC(atomic64_dec_if_positive_cx8)
29373 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29374 movl %edx, %ecx
29375 addl %ebp, %ebx
29376 adcl %edi, %ecx
29377 +
29378 +#ifdef CONFIG_PAX_REFCOUNT
29379 + into
29380 +1234:
29381 + _ASM_EXTABLE(1234b, 3f)
29382 +#endif
29383 +
29384 LOCK_PREFIX
29385 cmpxchg8b (%esi)
29386 jne 1b
29387 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29388 CFI_ADJUST_CFA_OFFSET -8
29389 RESTORE ebx
29390 RESTORE ebp
29391 + pax_force_retaddr
29392 ret
29393 4:
29394 cmpl %edx, 4(%esp)
29395 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29396 xorl %ecx, %ecx
29397 addl $1, %ebx
29398 adcl %edx, %ecx
29399 +
29400 +#ifdef CONFIG_PAX_REFCOUNT
29401 + into
29402 +1234:
29403 + _ASM_EXTABLE(1234b, 3f)
29404 +#endif
29405 +
29406 LOCK_PREFIX
29407 cmpxchg8b (%esi)
29408 jne 1b
29409 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29410 movl $1, %eax
29411 3:
29412 RESTORE ebx
29413 + pax_force_retaddr
29414 ret
29415 CFI_ENDPROC
29416 ENDPROC(atomic64_inc_not_zero_cx8)
29417 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29418 index e78b8eee..7e173a8 100644
29419 --- a/arch/x86/lib/checksum_32.S
29420 +++ b/arch/x86/lib/checksum_32.S
29421 @@ -29,7 +29,8 @@
29422 #include <asm/dwarf2.h>
29423 #include <asm/errno.h>
29424 #include <asm/asm.h>
29425 -
29426 +#include <asm/segment.h>
29427 +
29428 /*
29429 * computes a partial checksum, e.g. for TCP/UDP fragments
29430 */
29431 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29432
29433 #define ARGBASE 16
29434 #define FP 12
29435 -
29436 -ENTRY(csum_partial_copy_generic)
29437 +
29438 +ENTRY(csum_partial_copy_generic_to_user)
29439 CFI_STARTPROC
29440 +
29441 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29442 + pushl_cfi %gs
29443 + popl_cfi %es
29444 + jmp csum_partial_copy_generic
29445 +#endif
29446 +
29447 +ENTRY(csum_partial_copy_generic_from_user)
29448 +
29449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29450 + pushl_cfi %gs
29451 + popl_cfi %ds
29452 +#endif
29453 +
29454 +ENTRY(csum_partial_copy_generic)
29455 subl $4,%esp
29456 CFI_ADJUST_CFA_OFFSET 4
29457 pushl_cfi %edi
29458 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29459 jmp 4f
29460 SRC(1: movw (%esi), %bx )
29461 addl $2, %esi
29462 -DST( movw %bx, (%edi) )
29463 +DST( movw %bx, %es:(%edi) )
29464 addl $2, %edi
29465 addw %bx, %ax
29466 adcl $0, %eax
29467 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29468 SRC(1: movl (%esi), %ebx )
29469 SRC( movl 4(%esi), %edx )
29470 adcl %ebx, %eax
29471 -DST( movl %ebx, (%edi) )
29472 +DST( movl %ebx, %es:(%edi) )
29473 adcl %edx, %eax
29474 -DST( movl %edx, 4(%edi) )
29475 +DST( movl %edx, %es:4(%edi) )
29476
29477 SRC( movl 8(%esi), %ebx )
29478 SRC( movl 12(%esi), %edx )
29479 adcl %ebx, %eax
29480 -DST( movl %ebx, 8(%edi) )
29481 +DST( movl %ebx, %es:8(%edi) )
29482 adcl %edx, %eax
29483 -DST( movl %edx, 12(%edi) )
29484 +DST( movl %edx, %es:12(%edi) )
29485
29486 SRC( movl 16(%esi), %ebx )
29487 SRC( movl 20(%esi), %edx )
29488 adcl %ebx, %eax
29489 -DST( movl %ebx, 16(%edi) )
29490 +DST( movl %ebx, %es:16(%edi) )
29491 adcl %edx, %eax
29492 -DST( movl %edx, 20(%edi) )
29493 +DST( movl %edx, %es:20(%edi) )
29494
29495 SRC( movl 24(%esi), %ebx )
29496 SRC( movl 28(%esi), %edx )
29497 adcl %ebx, %eax
29498 -DST( movl %ebx, 24(%edi) )
29499 +DST( movl %ebx, %es:24(%edi) )
29500 adcl %edx, %eax
29501 -DST( movl %edx, 28(%edi) )
29502 +DST( movl %edx, %es:28(%edi) )
29503
29504 lea 32(%esi), %esi
29505 lea 32(%edi), %edi
29506 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29507 shrl $2, %edx # This clears CF
29508 SRC(3: movl (%esi), %ebx )
29509 adcl %ebx, %eax
29510 -DST( movl %ebx, (%edi) )
29511 +DST( movl %ebx, %es:(%edi) )
29512 lea 4(%esi), %esi
29513 lea 4(%edi), %edi
29514 dec %edx
29515 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29516 jb 5f
29517 SRC( movw (%esi), %cx )
29518 leal 2(%esi), %esi
29519 -DST( movw %cx, (%edi) )
29520 +DST( movw %cx, %es:(%edi) )
29521 leal 2(%edi), %edi
29522 je 6f
29523 shll $16,%ecx
29524 SRC(5: movb (%esi), %cl )
29525 -DST( movb %cl, (%edi) )
29526 +DST( movb %cl, %es:(%edi) )
29527 6: addl %ecx, %eax
29528 adcl $0, %eax
29529 7:
29530 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29531
29532 6001:
29533 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29534 - movl $-EFAULT, (%ebx)
29535 + movl $-EFAULT, %ss:(%ebx)
29536
29537 # zero the complete destination - computing the rest
29538 # is too much work
29539 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29540
29541 6002:
29542 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29543 - movl $-EFAULT,(%ebx)
29544 + movl $-EFAULT,%ss:(%ebx)
29545 jmp 5000b
29546
29547 .previous
29548
29549 + pushl_cfi %ss
29550 + popl_cfi %ds
29551 + pushl_cfi %ss
29552 + popl_cfi %es
29553 popl_cfi %ebx
29554 CFI_RESTORE ebx
29555 popl_cfi %esi
29556 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29557 popl_cfi %ecx # equivalent to addl $4,%esp
29558 ret
29559 CFI_ENDPROC
29560 -ENDPROC(csum_partial_copy_generic)
29561 +ENDPROC(csum_partial_copy_generic_to_user)
29562
29563 #else
29564
29565 /* Version for PentiumII/PPro */
29566
29567 #define ROUND1(x) \
29568 + nop; nop; nop; \
29569 SRC(movl x(%esi), %ebx ) ; \
29570 addl %ebx, %eax ; \
29571 - DST(movl %ebx, x(%edi) ) ;
29572 + DST(movl %ebx, %es:x(%edi)) ;
29573
29574 #define ROUND(x) \
29575 + nop; nop; nop; \
29576 SRC(movl x(%esi), %ebx ) ; \
29577 adcl %ebx, %eax ; \
29578 - DST(movl %ebx, x(%edi) ) ;
29579 + DST(movl %ebx, %es:x(%edi)) ;
29580
29581 #define ARGBASE 12
29582 -
29583 -ENTRY(csum_partial_copy_generic)
29584 +
29585 +ENTRY(csum_partial_copy_generic_to_user)
29586 CFI_STARTPROC
29587 +
29588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29589 + pushl_cfi %gs
29590 + popl_cfi %es
29591 + jmp csum_partial_copy_generic
29592 +#endif
29593 +
29594 +ENTRY(csum_partial_copy_generic_from_user)
29595 +
29596 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29597 + pushl_cfi %gs
29598 + popl_cfi %ds
29599 +#endif
29600 +
29601 +ENTRY(csum_partial_copy_generic)
29602 pushl_cfi %ebx
29603 CFI_REL_OFFSET ebx, 0
29604 pushl_cfi %edi
29605 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29606 subl %ebx, %edi
29607 lea -1(%esi),%edx
29608 andl $-32,%edx
29609 - lea 3f(%ebx,%ebx), %ebx
29610 + lea 3f(%ebx,%ebx,2), %ebx
29611 testl %esi, %esi
29612 jmp *%ebx
29613 1: addl $64,%esi
29614 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29615 jb 5f
29616 SRC( movw (%esi), %dx )
29617 leal 2(%esi), %esi
29618 -DST( movw %dx, (%edi) )
29619 +DST( movw %dx, %es:(%edi) )
29620 leal 2(%edi), %edi
29621 je 6f
29622 shll $16,%edx
29623 5:
29624 SRC( movb (%esi), %dl )
29625 -DST( movb %dl, (%edi) )
29626 +DST( movb %dl, %es:(%edi) )
29627 6: addl %edx, %eax
29628 adcl $0, %eax
29629 7:
29630 .section .fixup, "ax"
29631 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29632 - movl $-EFAULT, (%ebx)
29633 + movl $-EFAULT, %ss:(%ebx)
29634 # zero the complete destination (computing the rest is too much work)
29635 movl ARGBASE+8(%esp),%edi # dst
29636 movl ARGBASE+12(%esp),%ecx # len
29637 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29638 rep; stosb
29639 jmp 7b
29640 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29641 - movl $-EFAULT, (%ebx)
29642 + movl $-EFAULT, %ss:(%ebx)
29643 jmp 7b
29644 .previous
29645
29646 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29647 + pushl_cfi %ss
29648 + popl_cfi %ds
29649 + pushl_cfi %ss
29650 + popl_cfi %es
29651 +#endif
29652 +
29653 popl_cfi %esi
29654 CFI_RESTORE esi
29655 popl_cfi %edi
29656 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29657 CFI_RESTORE ebx
29658 ret
29659 CFI_ENDPROC
29660 -ENDPROC(csum_partial_copy_generic)
29661 +ENDPROC(csum_partial_copy_generic_to_user)
29662
29663 #undef ROUND
29664 #undef ROUND1
29665 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29666 index f2145cf..cea889d 100644
29667 --- a/arch/x86/lib/clear_page_64.S
29668 +++ b/arch/x86/lib/clear_page_64.S
29669 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29670 movl $4096/8,%ecx
29671 xorl %eax,%eax
29672 rep stosq
29673 + pax_force_retaddr
29674 ret
29675 CFI_ENDPROC
29676 ENDPROC(clear_page_c)
29677 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29678 movl $4096,%ecx
29679 xorl %eax,%eax
29680 rep stosb
29681 + pax_force_retaddr
29682 ret
29683 CFI_ENDPROC
29684 ENDPROC(clear_page_c_e)
29685 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29686 leaq 64(%rdi),%rdi
29687 jnz .Lloop
29688 nop
29689 + pax_force_retaddr
29690 ret
29691 CFI_ENDPROC
29692 .Lclear_page_end:
29693 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29694
29695 #include <asm/cpufeature.h>
29696
29697 - .section .altinstr_replacement,"ax"
29698 + .section .altinstr_replacement,"a"
29699 1: .byte 0xeb /* jmp <disp8> */
29700 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29701 2: .byte 0xeb /* jmp <disp8> */
29702 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29703 index 40a1725..5d12ac4 100644
29704 --- a/arch/x86/lib/cmpxchg16b_emu.S
29705 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29706 @@ -8,6 +8,7 @@
29707 #include <linux/linkage.h>
29708 #include <asm/dwarf2.h>
29709 #include <asm/percpu.h>
29710 +#include <asm/alternative-asm.h>
29711
29712 .text
29713
29714 @@ -46,12 +47,14 @@ CFI_STARTPROC
29715 CFI_REMEMBER_STATE
29716 popfq_cfi
29717 mov $1, %al
29718 + pax_force_retaddr
29719 ret
29720
29721 CFI_RESTORE_STATE
29722 .Lnot_same:
29723 popfq_cfi
29724 xor %al,%al
29725 + pax_force_retaddr
29726 ret
29727
29728 CFI_ENDPROC
29729 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29730 index 176cca6..e0d658e 100644
29731 --- a/arch/x86/lib/copy_page_64.S
29732 +++ b/arch/x86/lib/copy_page_64.S
29733 @@ -9,6 +9,7 @@ copy_page_rep:
29734 CFI_STARTPROC
29735 movl $4096/8, %ecx
29736 rep movsq
29737 + pax_force_retaddr
29738 ret
29739 CFI_ENDPROC
29740 ENDPROC(copy_page_rep)
29741 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29742 CFI_ADJUST_CFA_OFFSET 2*8
29743 movq %rbx, (%rsp)
29744 CFI_REL_OFFSET rbx, 0
29745 - movq %r12, 1*8(%rsp)
29746 - CFI_REL_OFFSET r12, 1*8
29747 + movq %r13, 1*8(%rsp)
29748 + CFI_REL_OFFSET r13, 1*8
29749
29750 movl $(4096/64)-5, %ecx
29751 .p2align 4
29752 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29753 movq 0x8*4(%rsi), %r9
29754 movq 0x8*5(%rsi), %r10
29755 movq 0x8*6(%rsi), %r11
29756 - movq 0x8*7(%rsi), %r12
29757 + movq 0x8*7(%rsi), %r13
29758
29759 prefetcht0 5*64(%rsi)
29760
29761 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29762 movq %r9, 0x8*4(%rdi)
29763 movq %r10, 0x8*5(%rdi)
29764 movq %r11, 0x8*6(%rdi)
29765 - movq %r12, 0x8*7(%rdi)
29766 + movq %r13, 0x8*7(%rdi)
29767
29768 leaq 64 (%rsi), %rsi
29769 leaq 64 (%rdi), %rdi
29770 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29771 movq 0x8*4(%rsi), %r9
29772 movq 0x8*5(%rsi), %r10
29773 movq 0x8*6(%rsi), %r11
29774 - movq 0x8*7(%rsi), %r12
29775 + movq 0x8*7(%rsi), %r13
29776
29777 movq %rax, 0x8*0(%rdi)
29778 movq %rbx, 0x8*1(%rdi)
29779 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29780 movq %r9, 0x8*4(%rdi)
29781 movq %r10, 0x8*5(%rdi)
29782 movq %r11, 0x8*6(%rdi)
29783 - movq %r12, 0x8*7(%rdi)
29784 + movq %r13, 0x8*7(%rdi)
29785
29786 leaq 64(%rdi), %rdi
29787 leaq 64(%rsi), %rsi
29788 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29789
29790 movq (%rsp), %rbx
29791 CFI_RESTORE rbx
29792 - movq 1*8(%rsp), %r12
29793 - CFI_RESTORE r12
29794 + movq 1*8(%rsp), %r13
29795 + CFI_RESTORE r13
29796 addq $2*8, %rsp
29797 CFI_ADJUST_CFA_OFFSET -2*8
29798 + pax_force_retaddr
29799 ret
29800 .Lcopy_page_end:
29801 CFI_ENDPROC
29802 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29803
29804 #include <asm/cpufeature.h>
29805
29806 - .section .altinstr_replacement,"ax"
29807 + .section .altinstr_replacement,"a"
29808 1: .byte 0xeb /* jmp <disp8> */
29809 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29810 2:
29811 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29812 index dee945d..a84067b 100644
29813 --- a/arch/x86/lib/copy_user_64.S
29814 +++ b/arch/x86/lib/copy_user_64.S
29815 @@ -18,31 +18,7 @@
29816 #include <asm/alternative-asm.h>
29817 #include <asm/asm.h>
29818 #include <asm/smap.h>
29819 -
29820 -/*
29821 - * By placing feature2 after feature1 in altinstructions section, we logically
29822 - * implement:
29823 - * If CPU has feature2, jmp to alt2 is used
29824 - * else if CPU has feature1, jmp to alt1 is used
29825 - * else jmp to orig is used.
29826 - */
29827 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29828 -0:
29829 - .byte 0xe9 /* 32bit jump */
29830 - .long \orig-1f /* by default jump to orig */
29831 -1:
29832 - .section .altinstr_replacement,"ax"
29833 -2: .byte 0xe9 /* near jump with 32bit immediate */
29834 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29835 -3: .byte 0xe9 /* near jump with 32bit immediate */
29836 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29837 - .previous
29838 -
29839 - .section .altinstructions,"a"
29840 - altinstruction_entry 0b,2b,\feature1,5,5
29841 - altinstruction_entry 0b,3b,\feature2,5,5
29842 - .previous
29843 - .endm
29844 +#include <asm/pgtable.h>
29845
29846 .macro ALIGN_DESTINATION
29847 #ifdef FIX_ALIGNMENT
29848 @@ -70,52 +46,6 @@
29849 #endif
29850 .endm
29851
29852 -/* Standard copy_to_user with segment limit checking */
29853 -ENTRY(_copy_to_user)
29854 - CFI_STARTPROC
29855 - GET_THREAD_INFO(%rax)
29856 - movq %rdi,%rcx
29857 - addq %rdx,%rcx
29858 - jc bad_to_user
29859 - cmpq TI_addr_limit(%rax),%rcx
29860 - ja bad_to_user
29861 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29862 - copy_user_generic_unrolled,copy_user_generic_string, \
29863 - copy_user_enhanced_fast_string
29864 - CFI_ENDPROC
29865 -ENDPROC(_copy_to_user)
29866 -
29867 -/* Standard copy_from_user with segment limit checking */
29868 -ENTRY(_copy_from_user)
29869 - CFI_STARTPROC
29870 - GET_THREAD_INFO(%rax)
29871 - movq %rsi,%rcx
29872 - addq %rdx,%rcx
29873 - jc bad_from_user
29874 - cmpq TI_addr_limit(%rax),%rcx
29875 - ja bad_from_user
29876 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29877 - copy_user_generic_unrolled,copy_user_generic_string, \
29878 - copy_user_enhanced_fast_string
29879 - CFI_ENDPROC
29880 -ENDPROC(_copy_from_user)
29881 -
29882 - .section .fixup,"ax"
29883 - /* must zero dest */
29884 -ENTRY(bad_from_user)
29885 -bad_from_user:
29886 - CFI_STARTPROC
29887 - movl %edx,%ecx
29888 - xorl %eax,%eax
29889 - rep
29890 - stosb
29891 -bad_to_user:
29892 - movl %edx,%eax
29893 - ret
29894 - CFI_ENDPROC
29895 -ENDPROC(bad_from_user)
29896 - .previous
29897 -
29898 /*
29899 * copy_user_generic_unrolled - memory copy with exception handling.
29900 * This version is for CPUs like P4 that don't have efficient micro
29901 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29902 */
29903 ENTRY(copy_user_generic_unrolled)
29904 CFI_STARTPROC
29905 + ASM_PAX_OPEN_USERLAND
29906 ASM_STAC
29907 cmpl $8,%edx
29908 jb 20f /* less then 8 bytes, go to byte copy loop */
29909 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29910 jnz 21b
29911 23: xor %eax,%eax
29912 ASM_CLAC
29913 + ASM_PAX_CLOSE_USERLAND
29914 + pax_force_retaddr
29915 ret
29916
29917 .section .fixup,"ax"
29918 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29919 */
29920 ENTRY(copy_user_generic_string)
29921 CFI_STARTPROC
29922 + ASM_PAX_OPEN_USERLAND
29923 ASM_STAC
29924 cmpl $8,%edx
29925 jb 2f /* less than 8 bytes, go to byte copy loop */
29926 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29927 movsb
29928 xorl %eax,%eax
29929 ASM_CLAC
29930 + ASM_PAX_CLOSE_USERLAND
29931 + pax_force_retaddr
29932 ret
29933
29934 .section .fixup,"ax"
29935 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29936 */
29937 ENTRY(copy_user_enhanced_fast_string)
29938 CFI_STARTPROC
29939 + ASM_PAX_OPEN_USERLAND
29940 ASM_STAC
29941 movl %edx,%ecx
29942 1: rep
29943 movsb
29944 xorl %eax,%eax
29945 ASM_CLAC
29946 + ASM_PAX_CLOSE_USERLAND
29947 + pax_force_retaddr
29948 ret
29949
29950 .section .fixup,"ax"
29951 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29952 index 6a4f43c..c70fb52 100644
29953 --- a/arch/x86/lib/copy_user_nocache_64.S
29954 +++ b/arch/x86/lib/copy_user_nocache_64.S
29955 @@ -8,6 +8,7 @@
29956
29957 #include <linux/linkage.h>
29958 #include <asm/dwarf2.h>
29959 +#include <asm/alternative-asm.h>
29960
29961 #define FIX_ALIGNMENT 1
29962
29963 @@ -16,6 +17,7 @@
29964 #include <asm/thread_info.h>
29965 #include <asm/asm.h>
29966 #include <asm/smap.h>
29967 +#include <asm/pgtable.h>
29968
29969 .macro ALIGN_DESTINATION
29970 #ifdef FIX_ALIGNMENT
29971 @@ -49,6 +51,16 @@
29972 */
29973 ENTRY(__copy_user_nocache)
29974 CFI_STARTPROC
29975 +
29976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29977 + mov pax_user_shadow_base,%rcx
29978 + cmp %rcx,%rsi
29979 + jae 1f
29980 + add %rcx,%rsi
29981 +1:
29982 +#endif
29983 +
29984 + ASM_PAX_OPEN_USERLAND
29985 ASM_STAC
29986 cmpl $8,%edx
29987 jb 20f /* less then 8 bytes, go to byte copy loop */
29988 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29989 jnz 21b
29990 23: xorl %eax,%eax
29991 ASM_CLAC
29992 + ASM_PAX_CLOSE_USERLAND
29993 sfence
29994 + pax_force_retaddr
29995 ret
29996
29997 .section .fixup,"ax"
29998 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29999 index 2419d5f..fe52d0e 100644
30000 --- a/arch/x86/lib/csum-copy_64.S
30001 +++ b/arch/x86/lib/csum-copy_64.S
30002 @@ -9,6 +9,7 @@
30003 #include <asm/dwarf2.h>
30004 #include <asm/errno.h>
30005 #include <asm/asm.h>
30006 +#include <asm/alternative-asm.h>
30007
30008 /*
30009 * Checksum copy with exception handling.
30010 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30011 CFI_ADJUST_CFA_OFFSET 7*8
30012 movq %rbx, 2*8(%rsp)
30013 CFI_REL_OFFSET rbx, 2*8
30014 - movq %r12, 3*8(%rsp)
30015 - CFI_REL_OFFSET r12, 3*8
30016 + movq %r15, 3*8(%rsp)
30017 + CFI_REL_OFFSET r15, 3*8
30018 movq %r14, 4*8(%rsp)
30019 CFI_REL_OFFSET r14, 4*8
30020 movq %r13, 5*8(%rsp)
30021 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30022 movl %edx, %ecx
30023
30024 xorl %r9d, %r9d
30025 - movq %rcx, %r12
30026 + movq %rcx, %r15
30027
30028 - shrq $6, %r12
30029 + shrq $6, %r15
30030 jz .Lhandle_tail /* < 64 */
30031
30032 clc
30033
30034 /* main loop. clear in 64 byte blocks */
30035 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30036 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30037 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30038 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30039 .p2align 4
30040 .Lloop:
30041 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30042 adcq %r14, %rax
30043 adcq %r13, %rax
30044
30045 - decl %r12d
30046 + decl %r15d
30047
30048 dest
30049 movq %rbx, (%rsi)
30050 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30051 .Lende:
30052 movq 2*8(%rsp), %rbx
30053 CFI_RESTORE rbx
30054 - movq 3*8(%rsp), %r12
30055 - CFI_RESTORE r12
30056 + movq 3*8(%rsp), %r15
30057 + CFI_RESTORE r15
30058 movq 4*8(%rsp), %r14
30059 CFI_RESTORE r14
30060 movq 5*8(%rsp), %r13
30061 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30062 CFI_RESTORE rbp
30063 addq $7*8, %rsp
30064 CFI_ADJUST_CFA_OFFSET -7*8
30065 + pax_force_retaddr
30066 ret
30067 CFI_RESTORE_STATE
30068
30069 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30070 index 1318f75..44c30fd 100644
30071 --- a/arch/x86/lib/csum-wrappers_64.c
30072 +++ b/arch/x86/lib/csum-wrappers_64.c
30073 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30074 len -= 2;
30075 }
30076 }
30077 + pax_open_userland();
30078 stac();
30079 - isum = csum_partial_copy_generic((__force const void *)src,
30080 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30081 dst, len, isum, errp, NULL);
30082 clac();
30083 + pax_close_userland();
30084 if (unlikely(*errp))
30085 goto out_err;
30086
30087 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30088 }
30089
30090 *errp = 0;
30091 + pax_open_userland();
30092 stac();
30093 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30094 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30095 len, isum, NULL, errp);
30096 clac();
30097 + pax_close_userland();
30098 return ret;
30099 }
30100 EXPORT_SYMBOL(csum_partial_copy_to_user);
30101 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30102 index a451235..1daa956 100644
30103 --- a/arch/x86/lib/getuser.S
30104 +++ b/arch/x86/lib/getuser.S
30105 @@ -33,17 +33,40 @@
30106 #include <asm/thread_info.h>
30107 #include <asm/asm.h>
30108 #include <asm/smap.h>
30109 +#include <asm/segment.h>
30110 +#include <asm/pgtable.h>
30111 +#include <asm/alternative-asm.h>
30112 +
30113 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30114 +#define __copyuser_seg gs;
30115 +#else
30116 +#define __copyuser_seg
30117 +#endif
30118
30119 .text
30120 ENTRY(__get_user_1)
30121 CFI_STARTPROC
30122 +
30123 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30124 GET_THREAD_INFO(%_ASM_DX)
30125 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30126 jae bad_get_user
30127 ASM_STAC
30128 -1: movzbl (%_ASM_AX),%edx
30129 +
30130 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30131 + mov pax_user_shadow_base,%_ASM_DX
30132 + cmp %_ASM_DX,%_ASM_AX
30133 + jae 1234f
30134 + add %_ASM_DX,%_ASM_AX
30135 +1234:
30136 +#endif
30137 +
30138 +#endif
30139 +
30140 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30141 xor %eax,%eax
30142 ASM_CLAC
30143 + pax_force_retaddr
30144 ret
30145 CFI_ENDPROC
30146 ENDPROC(__get_user_1)
30147 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30148 ENTRY(__get_user_2)
30149 CFI_STARTPROC
30150 add $1,%_ASM_AX
30151 +
30152 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30153 jc bad_get_user
30154 GET_THREAD_INFO(%_ASM_DX)
30155 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30156 jae bad_get_user
30157 ASM_STAC
30158 -2: movzwl -1(%_ASM_AX),%edx
30159 +
30160 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30161 + mov pax_user_shadow_base,%_ASM_DX
30162 + cmp %_ASM_DX,%_ASM_AX
30163 + jae 1234f
30164 + add %_ASM_DX,%_ASM_AX
30165 +1234:
30166 +#endif
30167 +
30168 +#endif
30169 +
30170 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30171 xor %eax,%eax
30172 ASM_CLAC
30173 + pax_force_retaddr
30174 ret
30175 CFI_ENDPROC
30176 ENDPROC(__get_user_2)
30177 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30178 ENTRY(__get_user_4)
30179 CFI_STARTPROC
30180 add $3,%_ASM_AX
30181 +
30182 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30183 jc bad_get_user
30184 GET_THREAD_INFO(%_ASM_DX)
30185 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30186 jae bad_get_user
30187 ASM_STAC
30188 -3: movl -3(%_ASM_AX),%edx
30189 +
30190 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30191 + mov pax_user_shadow_base,%_ASM_DX
30192 + cmp %_ASM_DX,%_ASM_AX
30193 + jae 1234f
30194 + add %_ASM_DX,%_ASM_AX
30195 +1234:
30196 +#endif
30197 +
30198 +#endif
30199 +
30200 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30201 xor %eax,%eax
30202 ASM_CLAC
30203 + pax_force_retaddr
30204 ret
30205 CFI_ENDPROC
30206 ENDPROC(__get_user_4)
30207 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30208 GET_THREAD_INFO(%_ASM_DX)
30209 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30210 jae bad_get_user
30211 +
30212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30213 + mov pax_user_shadow_base,%_ASM_DX
30214 + cmp %_ASM_DX,%_ASM_AX
30215 + jae 1234f
30216 + add %_ASM_DX,%_ASM_AX
30217 +1234:
30218 +#endif
30219 +
30220 ASM_STAC
30221 4: movq -7(%_ASM_AX),%rdx
30222 xor %eax,%eax
30223 ASM_CLAC
30224 + pax_force_retaddr
30225 ret
30226 #else
30227 add $7,%_ASM_AX
30228 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30229 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30230 jae bad_get_user_8
30231 ASM_STAC
30232 -4: movl -7(%_ASM_AX),%edx
30233 -5: movl -3(%_ASM_AX),%ecx
30234 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30235 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30236 xor %eax,%eax
30237 ASM_CLAC
30238 + pax_force_retaddr
30239 ret
30240 #endif
30241 CFI_ENDPROC
30242 @@ -113,6 +175,7 @@ bad_get_user:
30243 xor %edx,%edx
30244 mov $(-EFAULT),%_ASM_AX
30245 ASM_CLAC
30246 + pax_force_retaddr
30247 ret
30248 CFI_ENDPROC
30249 END(bad_get_user)
30250 @@ -124,6 +187,7 @@ bad_get_user_8:
30251 xor %ecx,%ecx
30252 mov $(-EFAULT),%_ASM_AX
30253 ASM_CLAC
30254 + pax_force_retaddr
30255 ret
30256 CFI_ENDPROC
30257 END(bad_get_user_8)
30258 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30259 index 54fcffe..7be149e 100644
30260 --- a/arch/x86/lib/insn.c
30261 +++ b/arch/x86/lib/insn.c
30262 @@ -20,8 +20,10 @@
30263
30264 #ifdef __KERNEL__
30265 #include <linux/string.h>
30266 +#include <asm/pgtable_types.h>
30267 #else
30268 #include <string.h>
30269 +#define ktla_ktva(addr) addr
30270 #endif
30271 #include <asm/inat.h>
30272 #include <asm/insn.h>
30273 @@ -53,8 +55,8 @@
30274 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30275 {
30276 memset(insn, 0, sizeof(*insn));
30277 - insn->kaddr = kaddr;
30278 - insn->next_byte = kaddr;
30279 + insn->kaddr = ktla_ktva(kaddr);
30280 + insn->next_byte = ktla_ktva(kaddr);
30281 insn->x86_64 = x86_64 ? 1 : 0;
30282 insn->opnd_bytes = 4;
30283 if (x86_64)
30284 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30285 index 05a95e7..326f2fa 100644
30286 --- a/arch/x86/lib/iomap_copy_64.S
30287 +++ b/arch/x86/lib/iomap_copy_64.S
30288 @@ -17,6 +17,7 @@
30289
30290 #include <linux/linkage.h>
30291 #include <asm/dwarf2.h>
30292 +#include <asm/alternative-asm.h>
30293
30294 /*
30295 * override generic version in lib/iomap_copy.c
30296 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30297 CFI_STARTPROC
30298 movl %edx,%ecx
30299 rep movsd
30300 + pax_force_retaddr
30301 ret
30302 CFI_ENDPROC
30303 ENDPROC(__iowrite32_copy)
30304 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30305 index 56313a3..0db417e 100644
30306 --- a/arch/x86/lib/memcpy_64.S
30307 +++ b/arch/x86/lib/memcpy_64.S
30308 @@ -24,7 +24,7 @@
30309 * This gets patched over the unrolled variant (below) via the
30310 * alternative instructions framework:
30311 */
30312 - .section .altinstr_replacement, "ax", @progbits
30313 + .section .altinstr_replacement, "a", @progbits
30314 .Lmemcpy_c:
30315 movq %rdi, %rax
30316 movq %rdx, %rcx
30317 @@ -33,6 +33,7 @@
30318 rep movsq
30319 movl %edx, %ecx
30320 rep movsb
30321 + pax_force_retaddr
30322 ret
30323 .Lmemcpy_e:
30324 .previous
30325 @@ -44,11 +45,12 @@
30326 * This gets patched over the unrolled variant (below) via the
30327 * alternative instructions framework:
30328 */
30329 - .section .altinstr_replacement, "ax", @progbits
30330 + .section .altinstr_replacement, "a", @progbits
30331 .Lmemcpy_c_e:
30332 movq %rdi, %rax
30333 movq %rdx, %rcx
30334 rep movsb
30335 + pax_force_retaddr
30336 ret
30337 .Lmemcpy_e_e:
30338 .previous
30339 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30340 movq %r9, 1*8(%rdi)
30341 movq %r10, -2*8(%rdi, %rdx)
30342 movq %r11, -1*8(%rdi, %rdx)
30343 + pax_force_retaddr
30344 retq
30345 .p2align 4
30346 .Lless_16bytes:
30347 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30348 movq -1*8(%rsi, %rdx), %r9
30349 movq %r8, 0*8(%rdi)
30350 movq %r9, -1*8(%rdi, %rdx)
30351 + pax_force_retaddr
30352 retq
30353 .p2align 4
30354 .Lless_8bytes:
30355 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30356 movl -4(%rsi, %rdx), %r8d
30357 movl %ecx, (%rdi)
30358 movl %r8d, -4(%rdi, %rdx)
30359 + pax_force_retaddr
30360 retq
30361 .p2align 4
30362 .Lless_3bytes:
30363 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30364 movb %cl, (%rdi)
30365
30366 .Lend:
30367 + pax_force_retaddr
30368 retq
30369 CFI_ENDPROC
30370 ENDPROC(memcpy)
30371 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30372 index 65268a6..dd1de11 100644
30373 --- a/arch/x86/lib/memmove_64.S
30374 +++ b/arch/x86/lib/memmove_64.S
30375 @@ -202,14 +202,16 @@ ENTRY(memmove)
30376 movb (%rsi), %r11b
30377 movb %r11b, (%rdi)
30378 13:
30379 + pax_force_retaddr
30380 retq
30381 CFI_ENDPROC
30382
30383 - .section .altinstr_replacement,"ax"
30384 + .section .altinstr_replacement,"a"
30385 .Lmemmove_begin_forward_efs:
30386 /* Forward moving data. */
30387 movq %rdx, %rcx
30388 rep movsb
30389 + pax_force_retaddr
30390 retq
30391 .Lmemmove_end_forward_efs:
30392 .previous
30393 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30394 index 2dcb380..2eb79fe 100644
30395 --- a/arch/x86/lib/memset_64.S
30396 +++ b/arch/x86/lib/memset_64.S
30397 @@ -16,7 +16,7 @@
30398 *
30399 * rax original destination
30400 */
30401 - .section .altinstr_replacement, "ax", @progbits
30402 + .section .altinstr_replacement, "a", @progbits
30403 .Lmemset_c:
30404 movq %rdi,%r9
30405 movq %rdx,%rcx
30406 @@ -30,6 +30,7 @@
30407 movl %edx,%ecx
30408 rep stosb
30409 movq %r9,%rax
30410 + pax_force_retaddr
30411 ret
30412 .Lmemset_e:
30413 .previous
30414 @@ -45,13 +46,14 @@
30415 *
30416 * rax original destination
30417 */
30418 - .section .altinstr_replacement, "ax", @progbits
30419 + .section .altinstr_replacement, "a", @progbits
30420 .Lmemset_c_e:
30421 movq %rdi,%r9
30422 movb %sil,%al
30423 movq %rdx,%rcx
30424 rep stosb
30425 movq %r9,%rax
30426 + pax_force_retaddr
30427 ret
30428 .Lmemset_e_e:
30429 .previous
30430 @@ -118,6 +120,7 @@ ENTRY(__memset)
30431
30432 .Lende:
30433 movq %r10,%rax
30434 + pax_force_retaddr
30435 ret
30436
30437 CFI_RESTORE_STATE
30438 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30439 index c9f2d9b..e7fd2c0 100644
30440 --- a/arch/x86/lib/mmx_32.c
30441 +++ b/arch/x86/lib/mmx_32.c
30442 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30443 {
30444 void *p;
30445 int i;
30446 + unsigned long cr0;
30447
30448 if (unlikely(in_interrupt()))
30449 return __memcpy(to, from, len);
30450 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30451 kernel_fpu_begin();
30452
30453 __asm__ __volatile__ (
30454 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30455 - " prefetch 64(%0)\n"
30456 - " prefetch 128(%0)\n"
30457 - " prefetch 192(%0)\n"
30458 - " prefetch 256(%0)\n"
30459 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30460 + " prefetch 64(%1)\n"
30461 + " prefetch 128(%1)\n"
30462 + " prefetch 192(%1)\n"
30463 + " prefetch 256(%1)\n"
30464 "2: \n"
30465 ".section .fixup, \"ax\"\n"
30466 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30467 + "3: \n"
30468 +
30469 +#ifdef CONFIG_PAX_KERNEXEC
30470 + " movl %%cr0, %0\n"
30471 + " movl %0, %%eax\n"
30472 + " andl $0xFFFEFFFF, %%eax\n"
30473 + " movl %%eax, %%cr0\n"
30474 +#endif
30475 +
30476 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30477 +
30478 +#ifdef CONFIG_PAX_KERNEXEC
30479 + " movl %0, %%cr0\n"
30480 +#endif
30481 +
30482 " jmp 2b\n"
30483 ".previous\n"
30484 _ASM_EXTABLE(1b, 3b)
30485 - : : "r" (from));
30486 + : "=&r" (cr0) : "r" (from) : "ax");
30487
30488 for ( ; i > 5; i--) {
30489 __asm__ __volatile__ (
30490 - "1: prefetch 320(%0)\n"
30491 - "2: movq (%0), %%mm0\n"
30492 - " movq 8(%0), %%mm1\n"
30493 - " movq 16(%0), %%mm2\n"
30494 - " movq 24(%0), %%mm3\n"
30495 - " movq %%mm0, (%1)\n"
30496 - " movq %%mm1, 8(%1)\n"
30497 - " movq %%mm2, 16(%1)\n"
30498 - " movq %%mm3, 24(%1)\n"
30499 - " movq 32(%0), %%mm0\n"
30500 - " movq 40(%0), %%mm1\n"
30501 - " movq 48(%0), %%mm2\n"
30502 - " movq 56(%0), %%mm3\n"
30503 - " movq %%mm0, 32(%1)\n"
30504 - " movq %%mm1, 40(%1)\n"
30505 - " movq %%mm2, 48(%1)\n"
30506 - " movq %%mm3, 56(%1)\n"
30507 + "1: prefetch 320(%1)\n"
30508 + "2: movq (%1), %%mm0\n"
30509 + " movq 8(%1), %%mm1\n"
30510 + " movq 16(%1), %%mm2\n"
30511 + " movq 24(%1), %%mm3\n"
30512 + " movq %%mm0, (%2)\n"
30513 + " movq %%mm1, 8(%2)\n"
30514 + " movq %%mm2, 16(%2)\n"
30515 + " movq %%mm3, 24(%2)\n"
30516 + " movq 32(%1), %%mm0\n"
30517 + " movq 40(%1), %%mm1\n"
30518 + " movq 48(%1), %%mm2\n"
30519 + " movq 56(%1), %%mm3\n"
30520 + " movq %%mm0, 32(%2)\n"
30521 + " movq %%mm1, 40(%2)\n"
30522 + " movq %%mm2, 48(%2)\n"
30523 + " movq %%mm3, 56(%2)\n"
30524 ".section .fixup, \"ax\"\n"
30525 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30526 + "3:\n"
30527 +
30528 +#ifdef CONFIG_PAX_KERNEXEC
30529 + " movl %%cr0, %0\n"
30530 + " movl %0, %%eax\n"
30531 + " andl $0xFFFEFFFF, %%eax\n"
30532 + " movl %%eax, %%cr0\n"
30533 +#endif
30534 +
30535 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30536 +
30537 +#ifdef CONFIG_PAX_KERNEXEC
30538 + " movl %0, %%cr0\n"
30539 +#endif
30540 +
30541 " jmp 2b\n"
30542 ".previous\n"
30543 _ASM_EXTABLE(1b, 3b)
30544 - : : "r" (from), "r" (to) : "memory");
30545 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30546
30547 from += 64;
30548 to += 64;
30549 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30550 static void fast_copy_page(void *to, void *from)
30551 {
30552 int i;
30553 + unsigned long cr0;
30554
30555 kernel_fpu_begin();
30556
30557 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30558 * but that is for later. -AV
30559 */
30560 __asm__ __volatile__(
30561 - "1: prefetch (%0)\n"
30562 - " prefetch 64(%0)\n"
30563 - " prefetch 128(%0)\n"
30564 - " prefetch 192(%0)\n"
30565 - " prefetch 256(%0)\n"
30566 + "1: prefetch (%1)\n"
30567 + " prefetch 64(%1)\n"
30568 + " prefetch 128(%1)\n"
30569 + " prefetch 192(%1)\n"
30570 + " prefetch 256(%1)\n"
30571 "2: \n"
30572 ".section .fixup, \"ax\"\n"
30573 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30574 + "3: \n"
30575 +
30576 +#ifdef CONFIG_PAX_KERNEXEC
30577 + " movl %%cr0, %0\n"
30578 + " movl %0, %%eax\n"
30579 + " andl $0xFFFEFFFF, %%eax\n"
30580 + " movl %%eax, %%cr0\n"
30581 +#endif
30582 +
30583 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30584 +
30585 +#ifdef CONFIG_PAX_KERNEXEC
30586 + " movl %0, %%cr0\n"
30587 +#endif
30588 +
30589 " jmp 2b\n"
30590 ".previous\n"
30591 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30592 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30593
30594 for (i = 0; i < (4096-320)/64; i++) {
30595 __asm__ __volatile__ (
30596 - "1: prefetch 320(%0)\n"
30597 - "2: movq (%0), %%mm0\n"
30598 - " movntq %%mm0, (%1)\n"
30599 - " movq 8(%0), %%mm1\n"
30600 - " movntq %%mm1, 8(%1)\n"
30601 - " movq 16(%0), %%mm2\n"
30602 - " movntq %%mm2, 16(%1)\n"
30603 - " movq 24(%0), %%mm3\n"
30604 - " movntq %%mm3, 24(%1)\n"
30605 - " movq 32(%0), %%mm4\n"
30606 - " movntq %%mm4, 32(%1)\n"
30607 - " movq 40(%0), %%mm5\n"
30608 - " movntq %%mm5, 40(%1)\n"
30609 - " movq 48(%0), %%mm6\n"
30610 - " movntq %%mm6, 48(%1)\n"
30611 - " movq 56(%0), %%mm7\n"
30612 - " movntq %%mm7, 56(%1)\n"
30613 + "1: prefetch 320(%1)\n"
30614 + "2: movq (%1), %%mm0\n"
30615 + " movntq %%mm0, (%2)\n"
30616 + " movq 8(%1), %%mm1\n"
30617 + " movntq %%mm1, 8(%2)\n"
30618 + " movq 16(%1), %%mm2\n"
30619 + " movntq %%mm2, 16(%2)\n"
30620 + " movq 24(%1), %%mm3\n"
30621 + " movntq %%mm3, 24(%2)\n"
30622 + " movq 32(%1), %%mm4\n"
30623 + " movntq %%mm4, 32(%2)\n"
30624 + " movq 40(%1), %%mm5\n"
30625 + " movntq %%mm5, 40(%2)\n"
30626 + " movq 48(%1), %%mm6\n"
30627 + " movntq %%mm6, 48(%2)\n"
30628 + " movq 56(%1), %%mm7\n"
30629 + " movntq %%mm7, 56(%2)\n"
30630 ".section .fixup, \"ax\"\n"
30631 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30632 + "3:\n"
30633 +
30634 +#ifdef CONFIG_PAX_KERNEXEC
30635 + " movl %%cr0, %0\n"
30636 + " movl %0, %%eax\n"
30637 + " andl $0xFFFEFFFF, %%eax\n"
30638 + " movl %%eax, %%cr0\n"
30639 +#endif
30640 +
30641 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30642 +
30643 +#ifdef CONFIG_PAX_KERNEXEC
30644 + " movl %0, %%cr0\n"
30645 +#endif
30646 +
30647 " jmp 2b\n"
30648 ".previous\n"
30649 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30650 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30651
30652 from += 64;
30653 to += 64;
30654 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30655 static void fast_copy_page(void *to, void *from)
30656 {
30657 int i;
30658 + unsigned long cr0;
30659
30660 kernel_fpu_begin();
30661
30662 __asm__ __volatile__ (
30663 - "1: prefetch (%0)\n"
30664 - " prefetch 64(%0)\n"
30665 - " prefetch 128(%0)\n"
30666 - " prefetch 192(%0)\n"
30667 - " prefetch 256(%0)\n"
30668 + "1: prefetch (%1)\n"
30669 + " prefetch 64(%1)\n"
30670 + " prefetch 128(%1)\n"
30671 + " prefetch 192(%1)\n"
30672 + " prefetch 256(%1)\n"
30673 "2: \n"
30674 ".section .fixup, \"ax\"\n"
30675 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30676 + "3: \n"
30677 +
30678 +#ifdef CONFIG_PAX_KERNEXEC
30679 + " movl %%cr0, %0\n"
30680 + " movl %0, %%eax\n"
30681 + " andl $0xFFFEFFFF, %%eax\n"
30682 + " movl %%eax, %%cr0\n"
30683 +#endif
30684 +
30685 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30686 +
30687 +#ifdef CONFIG_PAX_KERNEXEC
30688 + " movl %0, %%cr0\n"
30689 +#endif
30690 +
30691 " jmp 2b\n"
30692 ".previous\n"
30693 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30694 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30695
30696 for (i = 0; i < 4096/64; i++) {
30697 __asm__ __volatile__ (
30698 - "1: prefetch 320(%0)\n"
30699 - "2: movq (%0), %%mm0\n"
30700 - " movq 8(%0), %%mm1\n"
30701 - " movq 16(%0), %%mm2\n"
30702 - " movq 24(%0), %%mm3\n"
30703 - " movq %%mm0, (%1)\n"
30704 - " movq %%mm1, 8(%1)\n"
30705 - " movq %%mm2, 16(%1)\n"
30706 - " movq %%mm3, 24(%1)\n"
30707 - " movq 32(%0), %%mm0\n"
30708 - " movq 40(%0), %%mm1\n"
30709 - " movq 48(%0), %%mm2\n"
30710 - " movq 56(%0), %%mm3\n"
30711 - " movq %%mm0, 32(%1)\n"
30712 - " movq %%mm1, 40(%1)\n"
30713 - " movq %%mm2, 48(%1)\n"
30714 - " movq %%mm3, 56(%1)\n"
30715 + "1: prefetch 320(%1)\n"
30716 + "2: movq (%1), %%mm0\n"
30717 + " movq 8(%1), %%mm1\n"
30718 + " movq 16(%1), %%mm2\n"
30719 + " movq 24(%1), %%mm3\n"
30720 + " movq %%mm0, (%2)\n"
30721 + " movq %%mm1, 8(%2)\n"
30722 + " movq %%mm2, 16(%2)\n"
30723 + " movq %%mm3, 24(%2)\n"
30724 + " movq 32(%1), %%mm0\n"
30725 + " movq 40(%1), %%mm1\n"
30726 + " movq 48(%1), %%mm2\n"
30727 + " movq 56(%1), %%mm3\n"
30728 + " movq %%mm0, 32(%2)\n"
30729 + " movq %%mm1, 40(%2)\n"
30730 + " movq %%mm2, 48(%2)\n"
30731 + " movq %%mm3, 56(%2)\n"
30732 ".section .fixup, \"ax\"\n"
30733 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30734 + "3:\n"
30735 +
30736 +#ifdef CONFIG_PAX_KERNEXEC
30737 + " movl %%cr0, %0\n"
30738 + " movl %0, %%eax\n"
30739 + " andl $0xFFFEFFFF, %%eax\n"
30740 + " movl %%eax, %%cr0\n"
30741 +#endif
30742 +
30743 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30744 +
30745 +#ifdef CONFIG_PAX_KERNEXEC
30746 + " movl %0, %%cr0\n"
30747 +#endif
30748 +
30749 " jmp 2b\n"
30750 ".previous\n"
30751 _ASM_EXTABLE(1b, 3b)
30752 - : : "r" (from), "r" (to) : "memory");
30753 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30754
30755 from += 64;
30756 to += 64;
30757 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30758 index f6d13ee..d789440 100644
30759 --- a/arch/x86/lib/msr-reg.S
30760 +++ b/arch/x86/lib/msr-reg.S
30761 @@ -3,6 +3,7 @@
30762 #include <asm/dwarf2.h>
30763 #include <asm/asm.h>
30764 #include <asm/msr.h>
30765 +#include <asm/alternative-asm.h>
30766
30767 #ifdef CONFIG_X86_64
30768 /*
30769 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30770 movl %edi, 28(%r10)
30771 popq_cfi %rbp
30772 popq_cfi %rbx
30773 + pax_force_retaddr
30774 ret
30775 3:
30776 CFI_RESTORE_STATE
30777 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30778 index fc6ba17..d4d989d 100644
30779 --- a/arch/x86/lib/putuser.S
30780 +++ b/arch/x86/lib/putuser.S
30781 @@ -16,7 +16,9 @@
30782 #include <asm/errno.h>
30783 #include <asm/asm.h>
30784 #include <asm/smap.h>
30785 -
30786 +#include <asm/segment.h>
30787 +#include <asm/pgtable.h>
30788 +#include <asm/alternative-asm.h>
30789
30790 /*
30791 * __put_user_X
30792 @@ -30,57 +32,125 @@
30793 * as they get called from within inline assembly.
30794 */
30795
30796 -#define ENTER CFI_STARTPROC ; \
30797 - GET_THREAD_INFO(%_ASM_BX)
30798 -#define EXIT ASM_CLAC ; \
30799 - ret ; \
30800 +#define ENTER CFI_STARTPROC
30801 +#define EXIT ASM_CLAC ; \
30802 + pax_force_retaddr ; \
30803 + ret ; \
30804 CFI_ENDPROC
30805
30806 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30807 +#define _DEST %_ASM_CX,%_ASM_BX
30808 +#else
30809 +#define _DEST %_ASM_CX
30810 +#endif
30811 +
30812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30813 +#define __copyuser_seg gs;
30814 +#else
30815 +#define __copyuser_seg
30816 +#endif
30817 +
30818 .text
30819 ENTRY(__put_user_1)
30820 ENTER
30821 +
30822 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30823 + GET_THREAD_INFO(%_ASM_BX)
30824 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30825 jae bad_put_user
30826 ASM_STAC
30827 -1: movb %al,(%_ASM_CX)
30828 +
30829 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30830 + mov pax_user_shadow_base,%_ASM_BX
30831 + cmp %_ASM_BX,%_ASM_CX
30832 + jb 1234f
30833 + xor %ebx,%ebx
30834 +1234:
30835 +#endif
30836 +
30837 +#endif
30838 +
30839 +1: __copyuser_seg movb %al,(_DEST)
30840 xor %eax,%eax
30841 EXIT
30842 ENDPROC(__put_user_1)
30843
30844 ENTRY(__put_user_2)
30845 ENTER
30846 +
30847 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30848 + GET_THREAD_INFO(%_ASM_BX)
30849 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30850 sub $1,%_ASM_BX
30851 cmp %_ASM_BX,%_ASM_CX
30852 jae bad_put_user
30853 ASM_STAC
30854 -2: movw %ax,(%_ASM_CX)
30855 +
30856 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30857 + mov pax_user_shadow_base,%_ASM_BX
30858 + cmp %_ASM_BX,%_ASM_CX
30859 + jb 1234f
30860 + xor %ebx,%ebx
30861 +1234:
30862 +#endif
30863 +
30864 +#endif
30865 +
30866 +2: __copyuser_seg movw %ax,(_DEST)
30867 xor %eax,%eax
30868 EXIT
30869 ENDPROC(__put_user_2)
30870
30871 ENTRY(__put_user_4)
30872 ENTER
30873 +
30874 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30875 + GET_THREAD_INFO(%_ASM_BX)
30876 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30877 sub $3,%_ASM_BX
30878 cmp %_ASM_BX,%_ASM_CX
30879 jae bad_put_user
30880 ASM_STAC
30881 -3: movl %eax,(%_ASM_CX)
30882 +
30883 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30884 + mov pax_user_shadow_base,%_ASM_BX
30885 + cmp %_ASM_BX,%_ASM_CX
30886 + jb 1234f
30887 + xor %ebx,%ebx
30888 +1234:
30889 +#endif
30890 +
30891 +#endif
30892 +
30893 +3: __copyuser_seg movl %eax,(_DEST)
30894 xor %eax,%eax
30895 EXIT
30896 ENDPROC(__put_user_4)
30897
30898 ENTRY(__put_user_8)
30899 ENTER
30900 +
30901 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30902 + GET_THREAD_INFO(%_ASM_BX)
30903 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30904 sub $7,%_ASM_BX
30905 cmp %_ASM_BX,%_ASM_CX
30906 jae bad_put_user
30907 ASM_STAC
30908 -4: mov %_ASM_AX,(%_ASM_CX)
30909 +
30910 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30911 + mov pax_user_shadow_base,%_ASM_BX
30912 + cmp %_ASM_BX,%_ASM_CX
30913 + jb 1234f
30914 + xor %ebx,%ebx
30915 +1234:
30916 +#endif
30917 +
30918 +#endif
30919 +
30920 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30921 #ifdef CONFIG_X86_32
30922 -5: movl %edx,4(%_ASM_CX)
30923 +5: __copyuser_seg movl %edx,4(_DEST)
30924 #endif
30925 xor %eax,%eax
30926 EXIT
30927 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30928 index 5dff5f0..cadebf4 100644
30929 --- a/arch/x86/lib/rwsem.S
30930 +++ b/arch/x86/lib/rwsem.S
30931 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30932 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30933 CFI_RESTORE __ASM_REG(dx)
30934 restore_common_regs
30935 + pax_force_retaddr
30936 ret
30937 CFI_ENDPROC
30938 ENDPROC(call_rwsem_down_read_failed)
30939 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30940 movq %rax,%rdi
30941 call rwsem_down_write_failed
30942 restore_common_regs
30943 + pax_force_retaddr
30944 ret
30945 CFI_ENDPROC
30946 ENDPROC(call_rwsem_down_write_failed)
30947 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30948 movq %rax,%rdi
30949 call rwsem_wake
30950 restore_common_regs
30951 -1: ret
30952 +1: pax_force_retaddr
30953 + ret
30954 CFI_ENDPROC
30955 ENDPROC(call_rwsem_wake)
30956
30957 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30958 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30959 CFI_RESTORE __ASM_REG(dx)
30960 restore_common_regs
30961 + pax_force_retaddr
30962 ret
30963 CFI_ENDPROC
30964 ENDPROC(call_rwsem_downgrade_wake)
30965 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30966 index b30b5eb..2b57052 100644
30967 --- a/arch/x86/lib/thunk_64.S
30968 +++ b/arch/x86/lib/thunk_64.S
30969 @@ -9,6 +9,7 @@
30970 #include <asm/dwarf2.h>
30971 #include <asm/calling.h>
30972 #include <asm/asm.h>
30973 +#include <asm/alternative-asm.h>
30974
30975 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30976 .macro THUNK name, func, put_ret_addr_in_rdi=0
30977 @@ -16,11 +17,11 @@
30978 \name:
30979 CFI_STARTPROC
30980
30981 - /* this one pushes 9 elems, the next one would be %rIP */
30982 - SAVE_ARGS
30983 + /* this one pushes 15+1 elems, the next one would be %rIP */
30984 + SAVE_ARGS 8
30985
30986 .if \put_ret_addr_in_rdi
30987 - movq_cfi_restore 9*8, rdi
30988 + movq_cfi_restore RIP, rdi
30989 .endif
30990
30991 call \func
30992 @@ -47,9 +48,10 @@
30993
30994 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30995 CFI_STARTPROC
30996 - SAVE_ARGS
30997 + SAVE_ARGS 8
30998 restore:
30999 - RESTORE_ARGS
31000 + RESTORE_ARGS 1,8
31001 + pax_force_retaddr
31002 ret
31003 CFI_ENDPROC
31004 _ASM_NOKPROBE(restore)
31005 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31006 index e2f5e21..4b22130 100644
31007 --- a/arch/x86/lib/usercopy_32.c
31008 +++ b/arch/x86/lib/usercopy_32.c
31009 @@ -42,11 +42,13 @@ do { \
31010 int __d0; \
31011 might_fault(); \
31012 __asm__ __volatile__( \
31013 + __COPYUSER_SET_ES \
31014 ASM_STAC "\n" \
31015 "0: rep; stosl\n" \
31016 " movl %2,%0\n" \
31017 "1: rep; stosb\n" \
31018 "2: " ASM_CLAC "\n" \
31019 + __COPYUSER_RESTORE_ES \
31020 ".section .fixup,\"ax\"\n" \
31021 "3: lea 0(%2,%0,4),%0\n" \
31022 " jmp 2b\n" \
31023 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31024
31025 #ifdef CONFIG_X86_INTEL_USERCOPY
31026 static unsigned long
31027 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31028 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31029 {
31030 int d0, d1;
31031 __asm__ __volatile__(
31032 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31033 " .align 2,0x90\n"
31034 "3: movl 0(%4), %%eax\n"
31035 "4: movl 4(%4), %%edx\n"
31036 - "5: movl %%eax, 0(%3)\n"
31037 - "6: movl %%edx, 4(%3)\n"
31038 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31039 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31040 "7: movl 8(%4), %%eax\n"
31041 "8: movl 12(%4),%%edx\n"
31042 - "9: movl %%eax, 8(%3)\n"
31043 - "10: movl %%edx, 12(%3)\n"
31044 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31045 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31046 "11: movl 16(%4), %%eax\n"
31047 "12: movl 20(%4), %%edx\n"
31048 - "13: movl %%eax, 16(%3)\n"
31049 - "14: movl %%edx, 20(%3)\n"
31050 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31051 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31052 "15: movl 24(%4), %%eax\n"
31053 "16: movl 28(%4), %%edx\n"
31054 - "17: movl %%eax, 24(%3)\n"
31055 - "18: movl %%edx, 28(%3)\n"
31056 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31057 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31058 "19: movl 32(%4), %%eax\n"
31059 "20: movl 36(%4), %%edx\n"
31060 - "21: movl %%eax, 32(%3)\n"
31061 - "22: movl %%edx, 36(%3)\n"
31062 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31063 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31064 "23: movl 40(%4), %%eax\n"
31065 "24: movl 44(%4), %%edx\n"
31066 - "25: movl %%eax, 40(%3)\n"
31067 - "26: movl %%edx, 44(%3)\n"
31068 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31069 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31070 "27: movl 48(%4), %%eax\n"
31071 "28: movl 52(%4), %%edx\n"
31072 - "29: movl %%eax, 48(%3)\n"
31073 - "30: movl %%edx, 52(%3)\n"
31074 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31075 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31076 "31: movl 56(%4), %%eax\n"
31077 "32: movl 60(%4), %%edx\n"
31078 - "33: movl %%eax, 56(%3)\n"
31079 - "34: movl %%edx, 60(%3)\n"
31080 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31081 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31082 " addl $-64, %0\n"
31083 " addl $64, %4\n"
31084 " addl $64, %3\n"
31085 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31086 " shrl $2, %0\n"
31087 " andl $3, %%eax\n"
31088 " cld\n"
31089 + __COPYUSER_SET_ES
31090 "99: rep; movsl\n"
31091 "36: movl %%eax, %0\n"
31092 "37: rep; movsb\n"
31093 "100:\n"
31094 + __COPYUSER_RESTORE_ES
31095 + ".section .fixup,\"ax\"\n"
31096 + "101: lea 0(%%eax,%0,4),%0\n"
31097 + " jmp 100b\n"
31098 + ".previous\n"
31099 + _ASM_EXTABLE(1b,100b)
31100 + _ASM_EXTABLE(2b,100b)
31101 + _ASM_EXTABLE(3b,100b)
31102 + _ASM_EXTABLE(4b,100b)
31103 + _ASM_EXTABLE(5b,100b)
31104 + _ASM_EXTABLE(6b,100b)
31105 + _ASM_EXTABLE(7b,100b)
31106 + _ASM_EXTABLE(8b,100b)
31107 + _ASM_EXTABLE(9b,100b)
31108 + _ASM_EXTABLE(10b,100b)
31109 + _ASM_EXTABLE(11b,100b)
31110 + _ASM_EXTABLE(12b,100b)
31111 + _ASM_EXTABLE(13b,100b)
31112 + _ASM_EXTABLE(14b,100b)
31113 + _ASM_EXTABLE(15b,100b)
31114 + _ASM_EXTABLE(16b,100b)
31115 + _ASM_EXTABLE(17b,100b)
31116 + _ASM_EXTABLE(18b,100b)
31117 + _ASM_EXTABLE(19b,100b)
31118 + _ASM_EXTABLE(20b,100b)
31119 + _ASM_EXTABLE(21b,100b)
31120 + _ASM_EXTABLE(22b,100b)
31121 + _ASM_EXTABLE(23b,100b)
31122 + _ASM_EXTABLE(24b,100b)
31123 + _ASM_EXTABLE(25b,100b)
31124 + _ASM_EXTABLE(26b,100b)
31125 + _ASM_EXTABLE(27b,100b)
31126 + _ASM_EXTABLE(28b,100b)
31127 + _ASM_EXTABLE(29b,100b)
31128 + _ASM_EXTABLE(30b,100b)
31129 + _ASM_EXTABLE(31b,100b)
31130 + _ASM_EXTABLE(32b,100b)
31131 + _ASM_EXTABLE(33b,100b)
31132 + _ASM_EXTABLE(34b,100b)
31133 + _ASM_EXTABLE(35b,100b)
31134 + _ASM_EXTABLE(36b,100b)
31135 + _ASM_EXTABLE(37b,100b)
31136 + _ASM_EXTABLE(99b,101b)
31137 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31138 + : "1"(to), "2"(from), "0"(size)
31139 + : "eax", "edx", "memory");
31140 + return size;
31141 +}
31142 +
31143 +static unsigned long
31144 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31145 +{
31146 + int d0, d1;
31147 + __asm__ __volatile__(
31148 + " .align 2,0x90\n"
31149 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31150 + " cmpl $67, %0\n"
31151 + " jbe 3f\n"
31152 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31153 + " .align 2,0x90\n"
31154 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31155 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31156 + "5: movl %%eax, 0(%3)\n"
31157 + "6: movl %%edx, 4(%3)\n"
31158 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31159 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31160 + "9: movl %%eax, 8(%3)\n"
31161 + "10: movl %%edx, 12(%3)\n"
31162 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31163 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31164 + "13: movl %%eax, 16(%3)\n"
31165 + "14: movl %%edx, 20(%3)\n"
31166 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31167 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31168 + "17: movl %%eax, 24(%3)\n"
31169 + "18: movl %%edx, 28(%3)\n"
31170 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31171 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31172 + "21: movl %%eax, 32(%3)\n"
31173 + "22: movl %%edx, 36(%3)\n"
31174 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31175 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31176 + "25: movl %%eax, 40(%3)\n"
31177 + "26: movl %%edx, 44(%3)\n"
31178 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31179 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31180 + "29: movl %%eax, 48(%3)\n"
31181 + "30: movl %%edx, 52(%3)\n"
31182 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31183 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31184 + "33: movl %%eax, 56(%3)\n"
31185 + "34: movl %%edx, 60(%3)\n"
31186 + " addl $-64, %0\n"
31187 + " addl $64, %4\n"
31188 + " addl $64, %3\n"
31189 + " cmpl $63, %0\n"
31190 + " ja 1b\n"
31191 + "35: movl %0, %%eax\n"
31192 + " shrl $2, %0\n"
31193 + " andl $3, %%eax\n"
31194 + " cld\n"
31195 + "99: rep; "__copyuser_seg" movsl\n"
31196 + "36: movl %%eax, %0\n"
31197 + "37: rep; "__copyuser_seg" movsb\n"
31198 + "100:\n"
31199 ".section .fixup,\"ax\"\n"
31200 "101: lea 0(%%eax,%0,4),%0\n"
31201 " jmp 100b\n"
31202 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31203 int d0, d1;
31204 __asm__ __volatile__(
31205 " .align 2,0x90\n"
31206 - "0: movl 32(%4), %%eax\n"
31207 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31208 " cmpl $67, %0\n"
31209 " jbe 2f\n"
31210 - "1: movl 64(%4), %%eax\n"
31211 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31212 " .align 2,0x90\n"
31213 - "2: movl 0(%4), %%eax\n"
31214 - "21: movl 4(%4), %%edx\n"
31215 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31216 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31217 " movl %%eax, 0(%3)\n"
31218 " movl %%edx, 4(%3)\n"
31219 - "3: movl 8(%4), %%eax\n"
31220 - "31: movl 12(%4),%%edx\n"
31221 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31222 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31223 " movl %%eax, 8(%3)\n"
31224 " movl %%edx, 12(%3)\n"
31225 - "4: movl 16(%4), %%eax\n"
31226 - "41: movl 20(%4), %%edx\n"
31227 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31228 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31229 " movl %%eax, 16(%3)\n"
31230 " movl %%edx, 20(%3)\n"
31231 - "10: movl 24(%4), %%eax\n"
31232 - "51: movl 28(%4), %%edx\n"
31233 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31234 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31235 " movl %%eax, 24(%3)\n"
31236 " movl %%edx, 28(%3)\n"
31237 - "11: movl 32(%4), %%eax\n"
31238 - "61: movl 36(%4), %%edx\n"
31239 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31240 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31241 " movl %%eax, 32(%3)\n"
31242 " movl %%edx, 36(%3)\n"
31243 - "12: movl 40(%4), %%eax\n"
31244 - "71: movl 44(%4), %%edx\n"
31245 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31246 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31247 " movl %%eax, 40(%3)\n"
31248 " movl %%edx, 44(%3)\n"
31249 - "13: movl 48(%4), %%eax\n"
31250 - "81: movl 52(%4), %%edx\n"
31251 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31252 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31253 " movl %%eax, 48(%3)\n"
31254 " movl %%edx, 52(%3)\n"
31255 - "14: movl 56(%4), %%eax\n"
31256 - "91: movl 60(%4), %%edx\n"
31257 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31258 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31259 " movl %%eax, 56(%3)\n"
31260 " movl %%edx, 60(%3)\n"
31261 " addl $-64, %0\n"
31262 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31263 " shrl $2, %0\n"
31264 " andl $3, %%eax\n"
31265 " cld\n"
31266 - "6: rep; movsl\n"
31267 + "6: rep; "__copyuser_seg" movsl\n"
31268 " movl %%eax,%0\n"
31269 - "7: rep; movsb\n"
31270 + "7: rep; "__copyuser_seg" movsb\n"
31271 "8:\n"
31272 ".section .fixup,\"ax\"\n"
31273 "9: lea 0(%%eax,%0,4),%0\n"
31274 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31275
31276 __asm__ __volatile__(
31277 " .align 2,0x90\n"
31278 - "0: movl 32(%4), %%eax\n"
31279 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31280 " cmpl $67, %0\n"
31281 " jbe 2f\n"
31282 - "1: movl 64(%4), %%eax\n"
31283 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31284 " .align 2,0x90\n"
31285 - "2: movl 0(%4), %%eax\n"
31286 - "21: movl 4(%4), %%edx\n"
31287 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31288 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31289 " movnti %%eax, 0(%3)\n"
31290 " movnti %%edx, 4(%3)\n"
31291 - "3: movl 8(%4), %%eax\n"
31292 - "31: movl 12(%4),%%edx\n"
31293 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31294 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31295 " movnti %%eax, 8(%3)\n"
31296 " movnti %%edx, 12(%3)\n"
31297 - "4: movl 16(%4), %%eax\n"
31298 - "41: movl 20(%4), %%edx\n"
31299 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31300 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31301 " movnti %%eax, 16(%3)\n"
31302 " movnti %%edx, 20(%3)\n"
31303 - "10: movl 24(%4), %%eax\n"
31304 - "51: movl 28(%4), %%edx\n"
31305 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31306 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31307 " movnti %%eax, 24(%3)\n"
31308 " movnti %%edx, 28(%3)\n"
31309 - "11: movl 32(%4), %%eax\n"
31310 - "61: movl 36(%4), %%edx\n"
31311 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31312 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31313 " movnti %%eax, 32(%3)\n"
31314 " movnti %%edx, 36(%3)\n"
31315 - "12: movl 40(%4), %%eax\n"
31316 - "71: movl 44(%4), %%edx\n"
31317 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31318 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31319 " movnti %%eax, 40(%3)\n"
31320 " movnti %%edx, 44(%3)\n"
31321 - "13: movl 48(%4), %%eax\n"
31322 - "81: movl 52(%4), %%edx\n"
31323 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31324 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31325 " movnti %%eax, 48(%3)\n"
31326 " movnti %%edx, 52(%3)\n"
31327 - "14: movl 56(%4), %%eax\n"
31328 - "91: movl 60(%4), %%edx\n"
31329 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31330 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31331 " movnti %%eax, 56(%3)\n"
31332 " movnti %%edx, 60(%3)\n"
31333 " addl $-64, %0\n"
31334 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31335 " shrl $2, %0\n"
31336 " andl $3, %%eax\n"
31337 " cld\n"
31338 - "6: rep; movsl\n"
31339 + "6: rep; "__copyuser_seg" movsl\n"
31340 " movl %%eax,%0\n"
31341 - "7: rep; movsb\n"
31342 + "7: rep; "__copyuser_seg" movsb\n"
31343 "8:\n"
31344 ".section .fixup,\"ax\"\n"
31345 "9: lea 0(%%eax,%0,4),%0\n"
31346 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31347
31348 __asm__ __volatile__(
31349 " .align 2,0x90\n"
31350 - "0: movl 32(%4), %%eax\n"
31351 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31352 " cmpl $67, %0\n"
31353 " jbe 2f\n"
31354 - "1: movl 64(%4), %%eax\n"
31355 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31356 " .align 2,0x90\n"
31357 - "2: movl 0(%4), %%eax\n"
31358 - "21: movl 4(%4), %%edx\n"
31359 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31360 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31361 " movnti %%eax, 0(%3)\n"
31362 " movnti %%edx, 4(%3)\n"
31363 - "3: movl 8(%4), %%eax\n"
31364 - "31: movl 12(%4),%%edx\n"
31365 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31366 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31367 " movnti %%eax, 8(%3)\n"
31368 " movnti %%edx, 12(%3)\n"
31369 - "4: movl 16(%4), %%eax\n"
31370 - "41: movl 20(%4), %%edx\n"
31371 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31372 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31373 " movnti %%eax, 16(%3)\n"
31374 " movnti %%edx, 20(%3)\n"
31375 - "10: movl 24(%4), %%eax\n"
31376 - "51: movl 28(%4), %%edx\n"
31377 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31378 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31379 " movnti %%eax, 24(%3)\n"
31380 " movnti %%edx, 28(%3)\n"
31381 - "11: movl 32(%4), %%eax\n"
31382 - "61: movl 36(%4), %%edx\n"
31383 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31384 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31385 " movnti %%eax, 32(%3)\n"
31386 " movnti %%edx, 36(%3)\n"
31387 - "12: movl 40(%4), %%eax\n"
31388 - "71: movl 44(%4), %%edx\n"
31389 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31390 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31391 " movnti %%eax, 40(%3)\n"
31392 " movnti %%edx, 44(%3)\n"
31393 - "13: movl 48(%4), %%eax\n"
31394 - "81: movl 52(%4), %%edx\n"
31395 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31396 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31397 " movnti %%eax, 48(%3)\n"
31398 " movnti %%edx, 52(%3)\n"
31399 - "14: movl 56(%4), %%eax\n"
31400 - "91: movl 60(%4), %%edx\n"
31401 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31402 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31403 " movnti %%eax, 56(%3)\n"
31404 " movnti %%edx, 60(%3)\n"
31405 " addl $-64, %0\n"
31406 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31407 " shrl $2, %0\n"
31408 " andl $3, %%eax\n"
31409 " cld\n"
31410 - "6: rep; movsl\n"
31411 + "6: rep; "__copyuser_seg" movsl\n"
31412 " movl %%eax,%0\n"
31413 - "7: rep; movsb\n"
31414 + "7: rep; "__copyuser_seg" movsb\n"
31415 "8:\n"
31416 ".section .fixup,\"ax\"\n"
31417 "9: lea 0(%%eax,%0,4),%0\n"
31418 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31419 */
31420 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31421 unsigned long size);
31422 -unsigned long __copy_user_intel(void __user *to, const void *from,
31423 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31424 + unsigned long size);
31425 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31426 unsigned long size);
31427 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31428 const void __user *from, unsigned long size);
31429 #endif /* CONFIG_X86_INTEL_USERCOPY */
31430
31431 /* Generic arbitrary sized copy. */
31432 -#define __copy_user(to, from, size) \
31433 +#define __copy_user(to, from, size, prefix, set, restore) \
31434 do { \
31435 int __d0, __d1, __d2; \
31436 __asm__ __volatile__( \
31437 + set \
31438 " cmp $7,%0\n" \
31439 " jbe 1f\n" \
31440 " movl %1,%0\n" \
31441 " negl %0\n" \
31442 " andl $7,%0\n" \
31443 " subl %0,%3\n" \
31444 - "4: rep; movsb\n" \
31445 + "4: rep; "prefix"movsb\n" \
31446 " movl %3,%0\n" \
31447 " shrl $2,%0\n" \
31448 " andl $3,%3\n" \
31449 " .align 2,0x90\n" \
31450 - "0: rep; movsl\n" \
31451 + "0: rep; "prefix"movsl\n" \
31452 " movl %3,%0\n" \
31453 - "1: rep; movsb\n" \
31454 + "1: rep; "prefix"movsb\n" \
31455 "2:\n" \
31456 + restore \
31457 ".section .fixup,\"ax\"\n" \
31458 "5: addl %3,%0\n" \
31459 " jmp 2b\n" \
31460 @@ -538,14 +650,14 @@ do { \
31461 " negl %0\n" \
31462 " andl $7,%0\n" \
31463 " subl %0,%3\n" \
31464 - "4: rep; movsb\n" \
31465 + "4: rep; "__copyuser_seg"movsb\n" \
31466 " movl %3,%0\n" \
31467 " shrl $2,%0\n" \
31468 " andl $3,%3\n" \
31469 " .align 2,0x90\n" \
31470 - "0: rep; movsl\n" \
31471 + "0: rep; "__copyuser_seg"movsl\n" \
31472 " movl %3,%0\n" \
31473 - "1: rep; movsb\n" \
31474 + "1: rep; "__copyuser_seg"movsb\n" \
31475 "2:\n" \
31476 ".section .fixup,\"ax\"\n" \
31477 "5: addl %3,%0\n" \
31478 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31479 {
31480 stac();
31481 if (movsl_is_ok(to, from, n))
31482 - __copy_user(to, from, n);
31483 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31484 else
31485 - n = __copy_user_intel(to, from, n);
31486 + n = __generic_copy_to_user_intel(to, from, n);
31487 clac();
31488 return n;
31489 }
31490 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31491 {
31492 stac();
31493 if (movsl_is_ok(to, from, n))
31494 - __copy_user(to, from, n);
31495 + __copy_user(to, from, n, __copyuser_seg, "", "");
31496 else
31497 - n = __copy_user_intel((void __user *)to,
31498 - (const void *)from, n);
31499 + n = __generic_copy_from_user_intel(to, from, n);
31500 clac();
31501 return n;
31502 }
31503 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31504 if (n > 64 && cpu_has_xmm2)
31505 n = __copy_user_intel_nocache(to, from, n);
31506 else
31507 - __copy_user(to, from, n);
31508 + __copy_user(to, from, n, __copyuser_seg, "", "");
31509 #else
31510 - __copy_user(to, from, n);
31511 + __copy_user(to, from, n, __copyuser_seg, "", "");
31512 #endif
31513 clac();
31514 return n;
31515 }
31516 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31517
31518 -/**
31519 - * copy_to_user: - Copy a block of data into user space.
31520 - * @to: Destination address, in user space.
31521 - * @from: Source address, in kernel space.
31522 - * @n: Number of bytes to copy.
31523 - *
31524 - * Context: User context only. This function may sleep.
31525 - *
31526 - * Copy data from kernel space to user space.
31527 - *
31528 - * Returns number of bytes that could not be copied.
31529 - * On success, this will be zero.
31530 - */
31531 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31532 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31533 +void __set_fs(mm_segment_t x)
31534 {
31535 - if (access_ok(VERIFY_WRITE, to, n))
31536 - n = __copy_to_user(to, from, n);
31537 - return n;
31538 + switch (x.seg) {
31539 + case 0:
31540 + loadsegment(gs, 0);
31541 + break;
31542 + case TASK_SIZE_MAX:
31543 + loadsegment(gs, __USER_DS);
31544 + break;
31545 + case -1UL:
31546 + loadsegment(gs, __KERNEL_DS);
31547 + break;
31548 + default:
31549 + BUG();
31550 + }
31551 }
31552 -EXPORT_SYMBOL(_copy_to_user);
31553 +EXPORT_SYMBOL(__set_fs);
31554
31555 -/**
31556 - * copy_from_user: - Copy a block of data from user space.
31557 - * @to: Destination address, in kernel space.
31558 - * @from: Source address, in user space.
31559 - * @n: Number of bytes to copy.
31560 - *
31561 - * Context: User context only. This function may sleep.
31562 - *
31563 - * Copy data from user space to kernel space.
31564 - *
31565 - * Returns number of bytes that could not be copied.
31566 - * On success, this will be zero.
31567 - *
31568 - * If some data could not be copied, this function will pad the copied
31569 - * data to the requested size using zero bytes.
31570 - */
31571 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31572 +void set_fs(mm_segment_t x)
31573 {
31574 - if (access_ok(VERIFY_READ, from, n))
31575 - n = __copy_from_user(to, from, n);
31576 - else
31577 - memset(to, 0, n);
31578 - return n;
31579 + current_thread_info()->addr_limit = x;
31580 + __set_fs(x);
31581 }
31582 -EXPORT_SYMBOL(_copy_from_user);
31583 +EXPORT_SYMBOL(set_fs);
31584 +#endif
31585 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31586 index c905e89..01ab928 100644
31587 --- a/arch/x86/lib/usercopy_64.c
31588 +++ b/arch/x86/lib/usercopy_64.c
31589 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31590 might_fault();
31591 /* no memory constraint because it doesn't change any memory gcc knows
31592 about */
31593 + pax_open_userland();
31594 stac();
31595 asm volatile(
31596 " testq %[size8],%[size8]\n"
31597 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31598 _ASM_EXTABLE(0b,3b)
31599 _ASM_EXTABLE(1b,2b)
31600 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31601 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31602 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31603 [zero] "r" (0UL), [eight] "r" (8UL));
31604 clac();
31605 + pax_close_userland();
31606 return size;
31607 }
31608 EXPORT_SYMBOL(__clear_user);
31609 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31610 }
31611 EXPORT_SYMBOL(clear_user);
31612
31613 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31614 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31615 {
31616 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31617 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31618 - }
31619 - return len;
31620 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31621 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31622 + return len;
31623 }
31624 EXPORT_SYMBOL(copy_in_user);
31625
31626 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31627 * it is not necessary to optimize tail handling.
31628 */
31629 __visible unsigned long
31630 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31631 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31632 {
31633 char c;
31634 unsigned zero_len;
31635
31636 + clac();
31637 + pax_close_userland();
31638 for (; len; --len, to++) {
31639 if (__get_user_nocheck(c, from++, sizeof(char)))
31640 break;
31641 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31642 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31643 if (__put_user_nocheck(c, to++, sizeof(char)))
31644 break;
31645 - clac();
31646 return len;
31647 }
31648 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31649 index 6a19ad9..1c48f9a 100644
31650 --- a/arch/x86/mm/Makefile
31651 +++ b/arch/x86/mm/Makefile
31652 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31653 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31654
31655 obj-$(CONFIG_MEMTEST) += memtest.o
31656 +
31657 +quote:="
31658 +obj-$(CONFIG_X86_64) += uderef_64.o
31659 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31660 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31661 index 903ec1e..c4166b2 100644
31662 --- a/arch/x86/mm/extable.c
31663 +++ b/arch/x86/mm/extable.c
31664 @@ -6,12 +6,24 @@
31665 static inline unsigned long
31666 ex_insn_addr(const struct exception_table_entry *x)
31667 {
31668 - return (unsigned long)&x->insn + x->insn;
31669 + unsigned long reloc = 0;
31670 +
31671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31672 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31673 +#endif
31674 +
31675 + return (unsigned long)&x->insn + x->insn + reloc;
31676 }
31677 static inline unsigned long
31678 ex_fixup_addr(const struct exception_table_entry *x)
31679 {
31680 - return (unsigned long)&x->fixup + x->fixup;
31681 + unsigned long reloc = 0;
31682 +
31683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31684 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31685 +#endif
31686 +
31687 + return (unsigned long)&x->fixup + x->fixup + reloc;
31688 }
31689
31690 int fixup_exception(struct pt_regs *regs)
31691 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31692 unsigned long new_ip;
31693
31694 #ifdef CONFIG_PNPBIOS
31695 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31696 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31697 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31698 extern u32 pnp_bios_is_utter_crap;
31699 pnp_bios_is_utter_crap = 1;
31700 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31701 i += 4;
31702 p->fixup -= i;
31703 i += 4;
31704 +
31705 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31706 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31707 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31708 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31709 +#endif
31710 +
31711 }
31712 }
31713
31714 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31715 index 4d8ee82..ffc1011 100644
31716 --- a/arch/x86/mm/fault.c
31717 +++ b/arch/x86/mm/fault.c
31718 @@ -13,12 +13,19 @@
31719 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31720 #include <linux/prefetch.h> /* prefetchw */
31721 #include <linux/context_tracking.h> /* exception_enter(), ... */
31722 +#include <linux/unistd.h>
31723 +#include <linux/compiler.h>
31724
31725 #include <asm/traps.h> /* dotraplinkage, ... */
31726 #include <asm/pgalloc.h> /* pgd_*(), ... */
31727 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31728 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31729 #include <asm/vsyscall.h> /* emulate_vsyscall */
31730 +#include <asm/tlbflush.h>
31731 +
31732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31733 +#include <asm/stacktrace.h>
31734 +#endif
31735
31736 #define CREATE_TRACE_POINTS
31737 #include <asm/trace/exceptions.h>
31738 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31739 int ret = 0;
31740
31741 /* kprobe_running() needs smp_processor_id() */
31742 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31743 + if (kprobes_built_in() && !user_mode(regs)) {
31744 preempt_disable();
31745 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31746 ret = 1;
31747 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31748 return !instr_lo || (instr_lo>>1) == 1;
31749 case 0x00:
31750 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31751 - if (probe_kernel_address(instr, opcode))
31752 + if (user_mode(regs)) {
31753 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31754 + return 0;
31755 + } else if (probe_kernel_address(instr, opcode))
31756 return 0;
31757
31758 *prefetch = (instr_lo == 0xF) &&
31759 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31760 while (instr < max_instr) {
31761 unsigned char opcode;
31762
31763 - if (probe_kernel_address(instr, opcode))
31764 + if (user_mode(regs)) {
31765 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31766 + break;
31767 + } else if (probe_kernel_address(instr, opcode))
31768 break;
31769
31770 instr++;
31771 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31772 force_sig_info(si_signo, &info, tsk);
31773 }
31774
31775 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31776 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31777 +#endif
31778 +
31779 +#ifdef CONFIG_PAX_EMUTRAMP
31780 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31781 +#endif
31782 +
31783 +#ifdef CONFIG_PAX_PAGEEXEC
31784 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31785 +{
31786 + pgd_t *pgd;
31787 + pud_t *pud;
31788 + pmd_t *pmd;
31789 +
31790 + pgd = pgd_offset(mm, address);
31791 + if (!pgd_present(*pgd))
31792 + return NULL;
31793 + pud = pud_offset(pgd, address);
31794 + if (!pud_present(*pud))
31795 + return NULL;
31796 + pmd = pmd_offset(pud, address);
31797 + if (!pmd_present(*pmd))
31798 + return NULL;
31799 + return pmd;
31800 +}
31801 +#endif
31802 +
31803 DEFINE_SPINLOCK(pgd_lock);
31804 LIST_HEAD(pgd_list);
31805
31806 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31807 for (address = VMALLOC_START & PMD_MASK;
31808 address >= TASK_SIZE && address < FIXADDR_TOP;
31809 address += PMD_SIZE) {
31810 +
31811 +#ifdef CONFIG_PAX_PER_CPU_PGD
31812 + unsigned long cpu;
31813 +#else
31814 struct page *page;
31815 +#endif
31816
31817 spin_lock(&pgd_lock);
31818 +
31819 +#ifdef CONFIG_PAX_PER_CPU_PGD
31820 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31821 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31822 + pmd_t *ret;
31823 +
31824 + ret = vmalloc_sync_one(pgd, address);
31825 + if (!ret)
31826 + break;
31827 + pgd = get_cpu_pgd(cpu, kernel);
31828 +#else
31829 list_for_each_entry(page, &pgd_list, lru) {
31830 + pgd_t *pgd;
31831 spinlock_t *pgt_lock;
31832 pmd_t *ret;
31833
31834 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31835 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31836
31837 spin_lock(pgt_lock);
31838 - ret = vmalloc_sync_one(page_address(page), address);
31839 + pgd = page_address(page);
31840 +#endif
31841 +
31842 + ret = vmalloc_sync_one(pgd, address);
31843 +
31844 +#ifndef CONFIG_PAX_PER_CPU_PGD
31845 spin_unlock(pgt_lock);
31846 +#endif
31847
31848 if (!ret)
31849 break;
31850 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31851 * an interrupt in the middle of a task switch..
31852 */
31853 pgd_paddr = read_cr3();
31854 +
31855 +#ifdef CONFIG_PAX_PER_CPU_PGD
31856 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31857 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31858 +#endif
31859 +
31860 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31861 if (!pmd_k)
31862 return -1;
31863 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31864 * happen within a race in page table update. In the later
31865 * case just flush:
31866 */
31867 - pgd = pgd_offset(current->active_mm, address);
31868 +
31869 pgd_ref = pgd_offset_k(address);
31870 if (pgd_none(*pgd_ref))
31871 return -1;
31872
31873 +#ifdef CONFIG_PAX_PER_CPU_PGD
31874 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31875 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31876 + if (pgd_none(*pgd)) {
31877 + set_pgd(pgd, *pgd_ref);
31878 + arch_flush_lazy_mmu_mode();
31879 + } else {
31880 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31881 + }
31882 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31883 +#else
31884 + pgd = pgd_offset(current->active_mm, address);
31885 +#endif
31886 +
31887 if (pgd_none(*pgd)) {
31888 set_pgd(pgd, *pgd_ref);
31889 arch_flush_lazy_mmu_mode();
31890 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31891 static int is_errata100(struct pt_regs *regs, unsigned long address)
31892 {
31893 #ifdef CONFIG_X86_64
31894 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31895 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31896 return 1;
31897 #endif
31898 return 0;
31899 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31900 }
31901
31902 static const char nx_warning[] = KERN_CRIT
31903 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31904 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31905 static const char smep_warning[] = KERN_CRIT
31906 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
31907 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31908
31909 static void
31910 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31911 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31912 if (!oops_may_print())
31913 return;
31914
31915 - if (error_code & PF_INSTR) {
31916 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31917 unsigned int level;
31918 pgd_t *pgd;
31919 pte_t *pte;
31920 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31921 pte = lookup_address_in_pgd(pgd, address, &level);
31922
31923 if (pte && pte_present(*pte) && !pte_exec(*pte))
31924 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31925 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31926 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31927 (pgd_flags(*pgd) & _PAGE_USER) &&
31928 (read_cr4() & X86_CR4_SMEP))
31929 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31930 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31931 }
31932
31933 +#ifdef CONFIG_PAX_KERNEXEC
31934 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31935 + if (current->signal->curr_ip)
31936 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31937 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31938 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31939 + else
31940 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31941 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31942 + }
31943 +#endif
31944 +
31945 printk(KERN_ALERT "BUG: unable to handle kernel ");
31946 if (address < PAGE_SIZE)
31947 printk(KERN_CONT "NULL pointer dereference");
31948 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31949 return;
31950 }
31951 #endif
31952 +
31953 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31954 + if (pax_is_fetch_fault(regs, error_code, address)) {
31955 +
31956 +#ifdef CONFIG_PAX_EMUTRAMP
31957 + switch (pax_handle_fetch_fault(regs)) {
31958 + case 2:
31959 + return;
31960 + }
31961 +#endif
31962 +
31963 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31964 + do_group_exit(SIGKILL);
31965 + }
31966 +#endif
31967 +
31968 /* Kernel addresses are always protection faults: */
31969 if (address >= TASK_SIZE)
31970 error_code |= PF_PROT;
31971 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31972 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31973 printk(KERN_ERR
31974 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31975 - tsk->comm, tsk->pid, address);
31976 + tsk->comm, task_pid_nr(tsk), address);
31977 code = BUS_MCEERR_AR;
31978 }
31979 #endif
31980 @@ -916,6 +1028,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31981 return 1;
31982 }
31983
31984 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31985 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31986 +{
31987 + pte_t *pte;
31988 + pmd_t *pmd;
31989 + spinlock_t *ptl;
31990 + unsigned char pte_mask;
31991 +
31992 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31993 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31994 + return 0;
31995 +
31996 + /* PaX: it's our fault, let's handle it if we can */
31997 +
31998 + /* PaX: take a look at read faults before acquiring any locks */
31999 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32000 + /* instruction fetch attempt from a protected page in user mode */
32001 + up_read(&mm->mmap_sem);
32002 +
32003 +#ifdef CONFIG_PAX_EMUTRAMP
32004 + switch (pax_handle_fetch_fault(regs)) {
32005 + case 2:
32006 + return 1;
32007 + }
32008 +#endif
32009 +
32010 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32011 + do_group_exit(SIGKILL);
32012 + }
32013 +
32014 + pmd = pax_get_pmd(mm, address);
32015 + if (unlikely(!pmd))
32016 + return 0;
32017 +
32018 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32019 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32020 + pte_unmap_unlock(pte, ptl);
32021 + return 0;
32022 + }
32023 +
32024 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32025 + /* write attempt to a protected page in user mode */
32026 + pte_unmap_unlock(pte, ptl);
32027 + return 0;
32028 + }
32029 +
32030 +#ifdef CONFIG_SMP
32031 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32032 +#else
32033 + if (likely(address > get_limit(regs->cs)))
32034 +#endif
32035 + {
32036 + set_pte(pte, pte_mkread(*pte));
32037 + __flush_tlb_one(address);
32038 + pte_unmap_unlock(pte, ptl);
32039 + up_read(&mm->mmap_sem);
32040 + return 1;
32041 + }
32042 +
32043 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32044 +
32045 + /*
32046 + * PaX: fill DTLB with user rights and retry
32047 + */
32048 + __asm__ __volatile__ (
32049 + "orb %2,(%1)\n"
32050 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32051 +/*
32052 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32053 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32054 + * page fault when examined during a TLB load attempt. this is true not only
32055 + * for PTEs holding a non-present entry but also present entries that will
32056 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32057 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32058 + * for our target pages since their PTEs are simply not in the TLBs at all.
32059 +
32060 + * the best thing in omitting it is that we gain around 15-20% speed in the
32061 + * fast path of the page fault handler and can get rid of tracing since we
32062 + * can no longer flush unintended entries.
32063 + */
32064 + "invlpg (%0)\n"
32065 +#endif
32066 + __copyuser_seg"testb $0,(%0)\n"
32067 + "xorb %3,(%1)\n"
32068 + :
32069 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32070 + : "memory", "cc");
32071 + pte_unmap_unlock(pte, ptl);
32072 + up_read(&mm->mmap_sem);
32073 + return 1;
32074 +}
32075 +#endif
32076 +
32077 /*
32078 * Handle a spurious fault caused by a stale TLB entry.
32079 *
32080 @@ -1001,6 +1206,9 @@ int show_unhandled_signals = 1;
32081 static inline int
32082 access_error(unsigned long error_code, struct vm_area_struct *vma)
32083 {
32084 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32085 + return 1;
32086 +
32087 if (error_code & PF_WRITE) {
32088 /* write, present and write, not present: */
32089 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32090 @@ -1035,7 +1243,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32091 if (error_code & PF_USER)
32092 return false;
32093
32094 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32095 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32096 return false;
32097
32098 return true;
32099 @@ -1063,6 +1271,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32100 tsk = current;
32101 mm = tsk->mm;
32102
32103 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32104 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32105 + if (!search_exception_tables(regs->ip)) {
32106 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32107 + bad_area_nosemaphore(regs, error_code, address);
32108 + return;
32109 + }
32110 + if (address < pax_user_shadow_base) {
32111 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32112 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32113 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32114 + } else
32115 + address -= pax_user_shadow_base;
32116 + }
32117 +#endif
32118 +
32119 /*
32120 * Detect and handle instructions that would cause a page fault for
32121 * both a tracked kernel page and a userspace page.
32122 @@ -1140,7 +1364,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32123 * User-mode registers count as a user access even for any
32124 * potential system fault or CPU buglet:
32125 */
32126 - if (user_mode_vm(regs)) {
32127 + if (user_mode(regs)) {
32128 local_irq_enable();
32129 error_code |= PF_USER;
32130 flags |= FAULT_FLAG_USER;
32131 @@ -1187,6 +1411,11 @@ retry:
32132 might_sleep();
32133 }
32134
32135 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32136 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32137 + return;
32138 +#endif
32139 +
32140 vma = find_vma(mm, address);
32141 if (unlikely(!vma)) {
32142 bad_area(regs, error_code, address);
32143 @@ -1198,18 +1427,24 @@ retry:
32144 bad_area(regs, error_code, address);
32145 return;
32146 }
32147 - if (error_code & PF_USER) {
32148 - /*
32149 - * Accessing the stack below %sp is always a bug.
32150 - * The large cushion allows instructions like enter
32151 - * and pusha to work. ("enter $65535, $31" pushes
32152 - * 32 pointers and then decrements %sp by 65535.)
32153 - */
32154 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32155 - bad_area(regs, error_code, address);
32156 - return;
32157 - }
32158 + /*
32159 + * Accessing the stack below %sp is always a bug.
32160 + * The large cushion allows instructions like enter
32161 + * and pusha to work. ("enter $65535, $31" pushes
32162 + * 32 pointers and then decrements %sp by 65535.)
32163 + */
32164 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32165 + bad_area(regs, error_code, address);
32166 + return;
32167 }
32168 +
32169 +#ifdef CONFIG_PAX_SEGMEXEC
32170 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32171 + bad_area(regs, error_code, address);
32172 + return;
32173 + }
32174 +#endif
32175 +
32176 if (unlikely(expand_stack(vma, address))) {
32177 bad_area(regs, error_code, address);
32178 return;
32179 @@ -1327,3 +1562,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32180 }
32181 NOKPROBE_SYMBOL(trace_do_page_fault);
32182 #endif /* CONFIG_TRACING */
32183 +
32184 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32185 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32186 +{
32187 + struct mm_struct *mm = current->mm;
32188 + unsigned long ip = regs->ip;
32189 +
32190 + if (v8086_mode(regs))
32191 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32192 +
32193 +#ifdef CONFIG_PAX_PAGEEXEC
32194 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32195 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32196 + return true;
32197 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32198 + return true;
32199 + return false;
32200 + }
32201 +#endif
32202 +
32203 +#ifdef CONFIG_PAX_SEGMEXEC
32204 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32205 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32206 + return true;
32207 + return false;
32208 + }
32209 +#endif
32210 +
32211 + return false;
32212 +}
32213 +#endif
32214 +
32215 +#ifdef CONFIG_PAX_EMUTRAMP
32216 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32217 +{
32218 + int err;
32219 +
32220 + do { /* PaX: libffi trampoline emulation */
32221 + unsigned char mov, jmp;
32222 + unsigned int addr1, addr2;
32223 +
32224 +#ifdef CONFIG_X86_64
32225 + if ((regs->ip + 9) >> 32)
32226 + break;
32227 +#endif
32228 +
32229 + err = get_user(mov, (unsigned char __user *)regs->ip);
32230 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32231 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32232 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32233 +
32234 + if (err)
32235 + break;
32236 +
32237 + if (mov == 0xB8 && jmp == 0xE9) {
32238 + regs->ax = addr1;
32239 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32240 + return 2;
32241 + }
32242 + } while (0);
32243 +
32244 + do { /* PaX: gcc trampoline emulation #1 */
32245 + unsigned char mov1, mov2;
32246 + unsigned short jmp;
32247 + unsigned int addr1, addr2;
32248 +
32249 +#ifdef CONFIG_X86_64
32250 + if ((regs->ip + 11) >> 32)
32251 + break;
32252 +#endif
32253 +
32254 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32255 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32256 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32257 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32258 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32259 +
32260 + if (err)
32261 + break;
32262 +
32263 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32264 + regs->cx = addr1;
32265 + regs->ax = addr2;
32266 + regs->ip = addr2;
32267 + return 2;
32268 + }
32269 + } while (0);
32270 +
32271 + do { /* PaX: gcc trampoline emulation #2 */
32272 + unsigned char mov, jmp;
32273 + unsigned int addr1, addr2;
32274 +
32275 +#ifdef CONFIG_X86_64
32276 + if ((regs->ip + 9) >> 32)
32277 + break;
32278 +#endif
32279 +
32280 + err = get_user(mov, (unsigned char __user *)regs->ip);
32281 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32282 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32283 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32284 +
32285 + if (err)
32286 + break;
32287 +
32288 + if (mov == 0xB9 && jmp == 0xE9) {
32289 + regs->cx = addr1;
32290 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32291 + return 2;
32292 + }
32293 + } while (0);
32294 +
32295 + return 1; /* PaX in action */
32296 +}
32297 +
32298 +#ifdef CONFIG_X86_64
32299 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32300 +{
32301 + int err;
32302 +
32303 + do { /* PaX: libffi trampoline emulation */
32304 + unsigned short mov1, mov2, jmp1;
32305 + unsigned char stcclc, jmp2;
32306 + unsigned long addr1, addr2;
32307 +
32308 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32309 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32310 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32311 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32312 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32313 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32314 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32315 +
32316 + if (err)
32317 + break;
32318 +
32319 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32320 + regs->r11 = addr1;
32321 + regs->r10 = addr2;
32322 + if (stcclc == 0xF8)
32323 + regs->flags &= ~X86_EFLAGS_CF;
32324 + else
32325 + regs->flags |= X86_EFLAGS_CF;
32326 + regs->ip = addr1;
32327 + return 2;
32328 + }
32329 + } while (0);
32330 +
32331 + do { /* PaX: gcc trampoline emulation #1 */
32332 + unsigned short mov1, mov2, jmp1;
32333 + unsigned char jmp2;
32334 + unsigned int addr1;
32335 + unsigned long addr2;
32336 +
32337 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32338 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32339 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32340 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32341 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32342 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32343 +
32344 + if (err)
32345 + break;
32346 +
32347 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32348 + regs->r11 = addr1;
32349 + regs->r10 = addr2;
32350 + regs->ip = addr1;
32351 + return 2;
32352 + }
32353 + } while (0);
32354 +
32355 + do { /* PaX: gcc trampoline emulation #2 */
32356 + unsigned short mov1, mov2, jmp1;
32357 + unsigned char jmp2;
32358 + unsigned long addr1, addr2;
32359 +
32360 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32361 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32362 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32363 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32364 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32365 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32366 +
32367 + if (err)
32368 + break;
32369 +
32370 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32371 + regs->r11 = addr1;
32372 + regs->r10 = addr2;
32373 + regs->ip = addr1;
32374 + return 2;
32375 + }
32376 + } while (0);
32377 +
32378 + return 1; /* PaX in action */
32379 +}
32380 +#endif
32381 +
32382 +/*
32383 + * PaX: decide what to do with offenders (regs->ip = fault address)
32384 + *
32385 + * returns 1 when task should be killed
32386 + * 2 when gcc trampoline was detected
32387 + */
32388 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32389 +{
32390 + if (v8086_mode(regs))
32391 + return 1;
32392 +
32393 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32394 + return 1;
32395 +
32396 +#ifdef CONFIG_X86_32
32397 + return pax_handle_fetch_fault_32(regs);
32398 +#else
32399 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32400 + return pax_handle_fetch_fault_32(regs);
32401 + else
32402 + return pax_handle_fetch_fault_64(regs);
32403 +#endif
32404 +}
32405 +#endif
32406 +
32407 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32408 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32409 +{
32410 + long i;
32411 +
32412 + printk(KERN_ERR "PAX: bytes at PC: ");
32413 + for (i = 0; i < 20; i++) {
32414 + unsigned char c;
32415 + if (get_user(c, (unsigned char __force_user *)pc+i))
32416 + printk(KERN_CONT "?? ");
32417 + else
32418 + printk(KERN_CONT "%02x ", c);
32419 + }
32420 + printk("\n");
32421 +
32422 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32423 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32424 + unsigned long c;
32425 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32426 +#ifdef CONFIG_X86_32
32427 + printk(KERN_CONT "???????? ");
32428 +#else
32429 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32430 + printk(KERN_CONT "???????? ???????? ");
32431 + else
32432 + printk(KERN_CONT "???????????????? ");
32433 +#endif
32434 + } else {
32435 +#ifdef CONFIG_X86_64
32436 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32437 + printk(KERN_CONT "%08x ", (unsigned int)c);
32438 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32439 + } else
32440 +#endif
32441 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32442 + }
32443 + }
32444 + printk("\n");
32445 +}
32446 +#endif
32447 +
32448 +/**
32449 + * probe_kernel_write(): safely attempt to write to a location
32450 + * @dst: address to write to
32451 + * @src: pointer to the data that shall be written
32452 + * @size: size of the data chunk
32453 + *
32454 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32455 + * happens, handle that and return -EFAULT.
32456 + */
32457 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32458 +{
32459 + long ret;
32460 + mm_segment_t old_fs = get_fs();
32461 +
32462 + set_fs(KERNEL_DS);
32463 + pagefault_disable();
32464 + pax_open_kernel();
32465 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32466 + pax_close_kernel();
32467 + pagefault_enable();
32468 + set_fs(old_fs);
32469 +
32470 + return ret ? -EFAULT : 0;
32471 +}
32472 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32473 index 207d9aef..69030980 100644
32474 --- a/arch/x86/mm/gup.c
32475 +++ b/arch/x86/mm/gup.c
32476 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32477 addr = start;
32478 len = (unsigned long) nr_pages << PAGE_SHIFT;
32479 end = start + len;
32480 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32481 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32482 (void __user *)start, len)))
32483 return 0;
32484
32485 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32486 goto slow_irqon;
32487 #endif
32488
32489 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32490 + (void __user *)start, len)))
32491 + return 0;
32492 +
32493 /*
32494 * XXX: batch / limit 'nr', to avoid large irq off latency
32495 * needs some instrumenting to determine the common sizes used by
32496 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32497 index 4500142..53a363c 100644
32498 --- a/arch/x86/mm/highmem_32.c
32499 +++ b/arch/x86/mm/highmem_32.c
32500 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32501 idx = type + KM_TYPE_NR*smp_processor_id();
32502 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32503 BUG_ON(!pte_none(*(kmap_pte-idx)));
32504 +
32505 + pax_open_kernel();
32506 set_pte(kmap_pte-idx, mk_pte(page, prot));
32507 + pax_close_kernel();
32508 +
32509 arch_flush_lazy_mmu_mode();
32510
32511 return (void *)vaddr;
32512 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32513 index 8b977eb..4732c33 100644
32514 --- a/arch/x86/mm/hugetlbpage.c
32515 +++ b/arch/x86/mm/hugetlbpage.c
32516 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32517 #ifdef CONFIG_HUGETLB_PAGE
32518 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32519 unsigned long addr, unsigned long len,
32520 - unsigned long pgoff, unsigned long flags)
32521 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32522 {
32523 struct hstate *h = hstate_file(file);
32524 struct vm_unmapped_area_info info;
32525 -
32526 +
32527 info.flags = 0;
32528 info.length = len;
32529 info.low_limit = current->mm->mmap_legacy_base;
32530 info.high_limit = TASK_SIZE;
32531 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32532 info.align_offset = 0;
32533 + info.threadstack_offset = offset;
32534 return vm_unmapped_area(&info);
32535 }
32536
32537 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32538 unsigned long addr0, unsigned long len,
32539 - unsigned long pgoff, unsigned long flags)
32540 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32541 {
32542 struct hstate *h = hstate_file(file);
32543 struct vm_unmapped_area_info info;
32544 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32545 info.high_limit = current->mm->mmap_base;
32546 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32547 info.align_offset = 0;
32548 + info.threadstack_offset = offset;
32549 addr = vm_unmapped_area(&info);
32550
32551 /*
32552 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32553 VM_BUG_ON(addr != -ENOMEM);
32554 info.flags = 0;
32555 info.low_limit = TASK_UNMAPPED_BASE;
32556 +
32557 +#ifdef CONFIG_PAX_RANDMMAP
32558 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32559 + info.low_limit += current->mm->delta_mmap;
32560 +#endif
32561 +
32562 info.high_limit = TASK_SIZE;
32563 addr = vm_unmapped_area(&info);
32564 }
32565 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32566 struct hstate *h = hstate_file(file);
32567 struct mm_struct *mm = current->mm;
32568 struct vm_area_struct *vma;
32569 + unsigned long pax_task_size = TASK_SIZE;
32570 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32571
32572 if (len & ~huge_page_mask(h))
32573 return -EINVAL;
32574 - if (len > TASK_SIZE)
32575 +
32576 +#ifdef CONFIG_PAX_SEGMEXEC
32577 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32578 + pax_task_size = SEGMEXEC_TASK_SIZE;
32579 +#endif
32580 +
32581 + pax_task_size -= PAGE_SIZE;
32582 +
32583 + if (len > pax_task_size)
32584 return -ENOMEM;
32585
32586 if (flags & MAP_FIXED) {
32587 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32588 return addr;
32589 }
32590
32591 +#ifdef CONFIG_PAX_RANDMMAP
32592 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32593 +#endif
32594 +
32595 if (addr) {
32596 addr = ALIGN(addr, huge_page_size(h));
32597 vma = find_vma(mm, addr);
32598 - if (TASK_SIZE - len >= addr &&
32599 - (!vma || addr + len <= vma->vm_start))
32600 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32601 return addr;
32602 }
32603 if (mm->get_unmapped_area == arch_get_unmapped_area)
32604 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32605 - pgoff, flags);
32606 + pgoff, flags, offset);
32607 else
32608 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32609 - pgoff, flags);
32610 + pgoff, flags, offset);
32611 }
32612 #endif /* CONFIG_HUGETLB_PAGE */
32613
32614 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32615 index 66dba36..f8082ec 100644
32616 --- a/arch/x86/mm/init.c
32617 +++ b/arch/x86/mm/init.c
32618 @@ -4,6 +4,7 @@
32619 #include <linux/swap.h>
32620 #include <linux/memblock.h>
32621 #include <linux/bootmem.h> /* for max_low_pfn */
32622 +#include <linux/tboot.h>
32623
32624 #include <asm/cacheflush.h>
32625 #include <asm/e820.h>
32626 @@ -17,6 +18,8 @@
32627 #include <asm/proto.h>
32628 #include <asm/dma.h> /* for MAX_DMA_PFN */
32629 #include <asm/microcode.h>
32630 +#include <asm/desc.h>
32631 +#include <asm/bios_ebda.h>
32632
32633 /*
32634 * We need to define the tracepoints somewhere, and tlb.c
32635 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32636 early_ioremap_page_table_range_init();
32637 #endif
32638
32639 +#ifdef CONFIG_PAX_PER_CPU_PGD
32640 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32641 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32642 + KERNEL_PGD_PTRS);
32643 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32644 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32645 + KERNEL_PGD_PTRS);
32646 + load_cr3(get_cpu_pgd(0, kernel));
32647 +#else
32648 load_cr3(swapper_pg_dir);
32649 +#endif
32650 +
32651 __flush_tlb_all();
32652
32653 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32654 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32655 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32656 * mmio resources as well as potential bios/acpi data regions.
32657 */
32658 +
32659 +#ifdef CONFIG_GRKERNSEC_KMEM
32660 +static unsigned int ebda_start __read_only;
32661 +static unsigned int ebda_end __read_only;
32662 +#endif
32663 +
32664 int devmem_is_allowed(unsigned long pagenr)
32665 {
32666 - if (pagenr < 256)
32667 +#ifdef CONFIG_GRKERNSEC_KMEM
32668 + /* allow BDA */
32669 + if (!pagenr)
32670 return 1;
32671 + /* allow EBDA */
32672 + if (pagenr >= ebda_start && pagenr < ebda_end)
32673 + return 1;
32674 + /* if tboot is in use, allow access to its hardcoded serial log range */
32675 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32676 + return 1;
32677 +#else
32678 + if (!pagenr)
32679 + return 1;
32680 +#ifdef CONFIG_VM86
32681 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32682 + return 1;
32683 +#endif
32684 +#endif
32685 +
32686 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32687 + return 1;
32688 +#ifdef CONFIG_GRKERNSEC_KMEM
32689 + /* throw out everything else below 1MB */
32690 + if (pagenr <= 256)
32691 + return 0;
32692 +#endif
32693 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32694 return 0;
32695 if (!page_is_ram(pagenr))
32696 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32697 #endif
32698 }
32699
32700 +#ifdef CONFIG_GRKERNSEC_KMEM
32701 +static inline void gr_init_ebda(void)
32702 +{
32703 + unsigned int ebda_addr;
32704 + unsigned int ebda_size = 0;
32705 +
32706 + ebda_addr = get_bios_ebda();
32707 + if (ebda_addr) {
32708 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32709 + ebda_size <<= 10;
32710 + }
32711 + if (ebda_addr && ebda_size) {
32712 + ebda_start = ebda_addr >> PAGE_SHIFT;
32713 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32714 + } else {
32715 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32716 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32717 + }
32718 +}
32719 +#else
32720 +static inline void gr_init_ebda(void) { }
32721 +#endif
32722 +
32723 void free_initmem(void)
32724 {
32725 +#ifdef CONFIG_PAX_KERNEXEC
32726 +#ifdef CONFIG_X86_32
32727 + /* PaX: limit KERNEL_CS to actual size */
32728 + unsigned long addr, limit;
32729 + struct desc_struct d;
32730 + int cpu;
32731 +#else
32732 + pgd_t *pgd;
32733 + pud_t *pud;
32734 + pmd_t *pmd;
32735 + unsigned long addr, end;
32736 +#endif
32737 +#endif
32738 +
32739 + gr_init_ebda();
32740 +
32741 +#ifdef CONFIG_PAX_KERNEXEC
32742 +#ifdef CONFIG_X86_32
32743 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32744 + limit = (limit - 1UL) >> PAGE_SHIFT;
32745 +
32746 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32747 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32748 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32749 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32750 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32751 + }
32752 +
32753 + /* PaX: make KERNEL_CS read-only */
32754 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32755 + if (!paravirt_enabled())
32756 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32757 +/*
32758 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32759 + pgd = pgd_offset_k(addr);
32760 + pud = pud_offset(pgd, addr);
32761 + pmd = pmd_offset(pud, addr);
32762 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32763 + }
32764 +*/
32765 +#ifdef CONFIG_X86_PAE
32766 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32767 +/*
32768 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32769 + pgd = pgd_offset_k(addr);
32770 + pud = pud_offset(pgd, addr);
32771 + pmd = pmd_offset(pud, addr);
32772 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32773 + }
32774 +*/
32775 +#endif
32776 +
32777 +#ifdef CONFIG_MODULES
32778 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32779 +#endif
32780 +
32781 +#else
32782 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32783 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32784 + pgd = pgd_offset_k(addr);
32785 + pud = pud_offset(pgd, addr);
32786 + pmd = pmd_offset(pud, addr);
32787 + if (!pmd_present(*pmd))
32788 + continue;
32789 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32790 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32791 + else
32792 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32793 + }
32794 +
32795 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32796 + end = addr + KERNEL_IMAGE_SIZE;
32797 + for (; addr < end; addr += PMD_SIZE) {
32798 + pgd = pgd_offset_k(addr);
32799 + pud = pud_offset(pgd, addr);
32800 + pmd = pmd_offset(pud, addr);
32801 + if (!pmd_present(*pmd))
32802 + continue;
32803 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32804 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32805 + }
32806 +#endif
32807 +
32808 + flush_tlb_all();
32809 +#endif
32810 +
32811 free_init_pages("unused kernel",
32812 (unsigned long)(&__init_begin),
32813 (unsigned long)(&__init_end));
32814 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32815 index c8140e1..59257fc 100644
32816 --- a/arch/x86/mm/init_32.c
32817 +++ b/arch/x86/mm/init_32.c
32818 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32819 bool __read_mostly __vmalloc_start_set = false;
32820
32821 /*
32822 - * Creates a middle page table and puts a pointer to it in the
32823 - * given global directory entry. This only returns the gd entry
32824 - * in non-PAE compilation mode, since the middle layer is folded.
32825 - */
32826 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32827 -{
32828 - pud_t *pud;
32829 - pmd_t *pmd_table;
32830 -
32831 -#ifdef CONFIG_X86_PAE
32832 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32833 - pmd_table = (pmd_t *)alloc_low_page();
32834 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32835 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32836 - pud = pud_offset(pgd, 0);
32837 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32838 -
32839 - return pmd_table;
32840 - }
32841 -#endif
32842 - pud = pud_offset(pgd, 0);
32843 - pmd_table = pmd_offset(pud, 0);
32844 -
32845 - return pmd_table;
32846 -}
32847 -
32848 -/*
32849 * Create a page table and place a pointer to it in a middle page
32850 * directory entry:
32851 */
32852 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32853 pte_t *page_table = (pte_t *)alloc_low_page();
32854
32855 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32856 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32857 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32858 +#else
32859 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32860 +#endif
32861 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32862 }
32863
32864 return pte_offset_kernel(pmd, 0);
32865 }
32866
32867 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32868 +{
32869 + pud_t *pud;
32870 + pmd_t *pmd_table;
32871 +
32872 + pud = pud_offset(pgd, 0);
32873 + pmd_table = pmd_offset(pud, 0);
32874 +
32875 + return pmd_table;
32876 +}
32877 +
32878 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32879 {
32880 int pgd_idx = pgd_index(vaddr);
32881 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32882 int pgd_idx, pmd_idx;
32883 unsigned long vaddr;
32884 pgd_t *pgd;
32885 + pud_t *pud;
32886 pmd_t *pmd;
32887 pte_t *pte = NULL;
32888 unsigned long count = page_table_range_init_count(start, end);
32889 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32890 pgd = pgd_base + pgd_idx;
32891
32892 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32893 - pmd = one_md_table_init(pgd);
32894 - pmd = pmd + pmd_index(vaddr);
32895 + pud = pud_offset(pgd, vaddr);
32896 + pmd = pmd_offset(pud, vaddr);
32897 +
32898 +#ifdef CONFIG_X86_PAE
32899 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32900 +#endif
32901 +
32902 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32903 pmd++, pmd_idx++) {
32904 pte = page_table_kmap_check(one_page_table_init(pmd),
32905 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32906 }
32907 }
32908
32909 -static inline int is_kernel_text(unsigned long addr)
32910 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32911 {
32912 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32913 - return 1;
32914 - return 0;
32915 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32916 + end <= ktla_ktva((unsigned long)_stext)) &&
32917 + (start >= ktla_ktva((unsigned long)_einittext) ||
32918 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32919 +
32920 +#ifdef CONFIG_ACPI_SLEEP
32921 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32922 +#endif
32923 +
32924 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32925 + return 0;
32926 + return 1;
32927 }
32928
32929 /*
32930 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32931 unsigned long last_map_addr = end;
32932 unsigned long start_pfn, end_pfn;
32933 pgd_t *pgd_base = swapper_pg_dir;
32934 - int pgd_idx, pmd_idx, pte_ofs;
32935 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32936 unsigned long pfn;
32937 pgd_t *pgd;
32938 + pud_t *pud;
32939 pmd_t *pmd;
32940 pte_t *pte;
32941 unsigned pages_2m, pages_4k;
32942 @@ -291,8 +295,13 @@ repeat:
32943 pfn = start_pfn;
32944 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32945 pgd = pgd_base + pgd_idx;
32946 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32947 - pmd = one_md_table_init(pgd);
32948 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32949 + pud = pud_offset(pgd, 0);
32950 + pmd = pmd_offset(pud, 0);
32951 +
32952 +#ifdef CONFIG_X86_PAE
32953 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32954 +#endif
32955
32956 if (pfn >= end_pfn)
32957 continue;
32958 @@ -304,14 +313,13 @@ repeat:
32959 #endif
32960 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32961 pmd++, pmd_idx++) {
32962 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32963 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32964
32965 /*
32966 * Map with big pages if possible, otherwise
32967 * create normal page tables:
32968 */
32969 if (use_pse) {
32970 - unsigned int addr2;
32971 pgprot_t prot = PAGE_KERNEL_LARGE;
32972 /*
32973 * first pass will use the same initial
32974 @@ -322,11 +330,7 @@ repeat:
32975 _PAGE_PSE);
32976
32977 pfn &= PMD_MASK >> PAGE_SHIFT;
32978 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32979 - PAGE_OFFSET + PAGE_SIZE-1;
32980 -
32981 - if (is_kernel_text(addr) ||
32982 - is_kernel_text(addr2))
32983 + if (is_kernel_text(address, address + PMD_SIZE))
32984 prot = PAGE_KERNEL_LARGE_EXEC;
32985
32986 pages_2m++;
32987 @@ -343,7 +347,7 @@ repeat:
32988 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32989 pte += pte_ofs;
32990 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32991 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32992 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32993 pgprot_t prot = PAGE_KERNEL;
32994 /*
32995 * first pass will use the same initial
32996 @@ -351,7 +355,7 @@ repeat:
32997 */
32998 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32999
33000 - if (is_kernel_text(addr))
33001 + if (is_kernel_text(address, address + PAGE_SIZE))
33002 prot = PAGE_KERNEL_EXEC;
33003
33004 pages_4k++;
33005 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33006
33007 pud = pud_offset(pgd, va);
33008 pmd = pmd_offset(pud, va);
33009 - if (!pmd_present(*pmd))
33010 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33011 break;
33012
33013 /* should not be large page here */
33014 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33015
33016 static void __init pagetable_init(void)
33017 {
33018 - pgd_t *pgd_base = swapper_pg_dir;
33019 -
33020 - permanent_kmaps_init(pgd_base);
33021 + permanent_kmaps_init(swapper_pg_dir);
33022 }
33023
33024 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33025 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33026 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33027
33028 /* user-defined highmem size */
33029 @@ -787,10 +789,10 @@ void __init mem_init(void)
33030 ((unsigned long)&__init_end -
33031 (unsigned long)&__init_begin) >> 10,
33032
33033 - (unsigned long)&_etext, (unsigned long)&_edata,
33034 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33035 + (unsigned long)&_sdata, (unsigned long)&_edata,
33036 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33037
33038 - (unsigned long)&_text, (unsigned long)&_etext,
33039 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33040 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33041
33042 /*
33043 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33044 if (!kernel_set_to_readonly)
33045 return;
33046
33047 + start = ktla_ktva(start);
33048 pr_debug("Set kernel text: %lx - %lx for read write\n",
33049 start, start+size);
33050
33051 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33052 if (!kernel_set_to_readonly)
33053 return;
33054
33055 + start = ktla_ktva(start);
33056 pr_debug("Set kernel text: %lx - %lx for read only\n",
33057 start, start+size);
33058
33059 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33060 unsigned long start = PFN_ALIGN(_text);
33061 unsigned long size = PFN_ALIGN(_etext) - start;
33062
33063 + start = ktla_ktva(start);
33064 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33065 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33066 size >> 10);
33067 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33068 index 4e5dfec..6fd6dc5 100644
33069 --- a/arch/x86/mm/init_64.c
33070 +++ b/arch/x86/mm/init_64.c
33071 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33072 * around without checking the pgd every time.
33073 */
33074
33075 -pteval_t __supported_pte_mask __read_mostly = ~0;
33076 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33077 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33078
33079 int force_personality32;
33080 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33081
33082 for (address = start; address <= end; address += PGDIR_SIZE) {
33083 const pgd_t *pgd_ref = pgd_offset_k(address);
33084 +
33085 +#ifdef CONFIG_PAX_PER_CPU_PGD
33086 + unsigned long cpu;
33087 +#else
33088 struct page *page;
33089 +#endif
33090
33091 /*
33092 * When it is called after memory hot remove, pgd_none()
33093 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33094 continue;
33095
33096 spin_lock(&pgd_lock);
33097 +
33098 +#ifdef CONFIG_PAX_PER_CPU_PGD
33099 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33100 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33101 +
33102 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33103 + BUG_ON(pgd_page_vaddr(*pgd)
33104 + != pgd_page_vaddr(*pgd_ref));
33105 +
33106 + if (removed) {
33107 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33108 + pgd_clear(pgd);
33109 + } else {
33110 + if (pgd_none(*pgd))
33111 + set_pgd(pgd, *pgd_ref);
33112 + }
33113 +
33114 + pgd = pgd_offset_cpu(cpu, kernel, address);
33115 +#else
33116 list_for_each_entry(page, &pgd_list, lru) {
33117 pgd_t *pgd;
33118 spinlock_t *pgt_lock;
33119 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33120 /* the pgt_lock only for Xen */
33121 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33122 spin_lock(pgt_lock);
33123 +#endif
33124
33125 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33126 BUG_ON(pgd_page_vaddr(*pgd)
33127 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33128 set_pgd(pgd, *pgd_ref);
33129 }
33130
33131 +#ifndef CONFIG_PAX_PER_CPU_PGD
33132 spin_unlock(pgt_lock);
33133 +#endif
33134 +
33135 }
33136 spin_unlock(&pgd_lock);
33137 }
33138 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33139 {
33140 if (pgd_none(*pgd)) {
33141 pud_t *pud = (pud_t *)spp_getpage();
33142 - pgd_populate(&init_mm, pgd, pud);
33143 + pgd_populate_kernel(&init_mm, pgd, pud);
33144 if (pud != pud_offset(pgd, 0))
33145 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33146 pud, pud_offset(pgd, 0));
33147 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33148 {
33149 if (pud_none(*pud)) {
33150 pmd_t *pmd = (pmd_t *) spp_getpage();
33151 - pud_populate(&init_mm, pud, pmd);
33152 + pud_populate_kernel(&init_mm, pud, pmd);
33153 if (pmd != pmd_offset(pud, 0))
33154 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33155 pmd, pmd_offset(pud, 0));
33156 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33157 pmd = fill_pmd(pud, vaddr);
33158 pte = fill_pte(pmd, vaddr);
33159
33160 + pax_open_kernel();
33161 set_pte(pte, new_pte);
33162 + pax_close_kernel();
33163
33164 /*
33165 * It's enough to flush this one mapping.
33166 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33167 pgd = pgd_offset_k((unsigned long)__va(phys));
33168 if (pgd_none(*pgd)) {
33169 pud = (pud_t *) spp_getpage();
33170 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33171 - _PAGE_USER));
33172 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33173 }
33174 pud = pud_offset(pgd, (unsigned long)__va(phys));
33175 if (pud_none(*pud)) {
33176 pmd = (pmd_t *) spp_getpage();
33177 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33178 - _PAGE_USER));
33179 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33180 }
33181 pmd = pmd_offset(pud, phys);
33182 BUG_ON(!pmd_none(*pmd));
33183 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33184 prot);
33185
33186 spin_lock(&init_mm.page_table_lock);
33187 - pud_populate(&init_mm, pud, pmd);
33188 + pud_populate_kernel(&init_mm, pud, pmd);
33189 spin_unlock(&init_mm.page_table_lock);
33190 }
33191 __flush_tlb_all();
33192 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33193 page_size_mask);
33194
33195 spin_lock(&init_mm.page_table_lock);
33196 - pgd_populate(&init_mm, pgd, pud);
33197 + pgd_populate_kernel(&init_mm, pgd, pud);
33198 spin_unlock(&init_mm.page_table_lock);
33199 pgd_changed = true;
33200 }
33201 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33202 static struct vm_area_struct gate_vma = {
33203 .vm_start = VSYSCALL_ADDR,
33204 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33205 - .vm_page_prot = PAGE_READONLY_EXEC,
33206 - .vm_flags = VM_READ | VM_EXEC,
33207 + .vm_page_prot = PAGE_READONLY,
33208 + .vm_flags = VM_READ,
33209 .vm_ops = &gate_vma_ops,
33210 };
33211
33212 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33213 index 7b179b49..6bd17777 100644
33214 --- a/arch/x86/mm/iomap_32.c
33215 +++ b/arch/x86/mm/iomap_32.c
33216 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33217 type = kmap_atomic_idx_push();
33218 idx = type + KM_TYPE_NR * smp_processor_id();
33219 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33220 +
33221 + pax_open_kernel();
33222 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33223 + pax_close_kernel();
33224 +
33225 arch_flush_lazy_mmu_mode();
33226
33227 return (void *)vaddr;
33228 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33229 index af78e50..4f1fe56 100644
33230 --- a/arch/x86/mm/ioremap.c
33231 +++ b/arch/x86/mm/ioremap.c
33232 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33233 unsigned long i;
33234
33235 for (i = 0; i < nr_pages; ++i)
33236 - if (pfn_valid(start_pfn + i) &&
33237 - !PageReserved(pfn_to_page(start_pfn + i)))
33238 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33239 + !PageReserved(pfn_to_page(start_pfn + i))))
33240 return 1;
33241
33242 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33243 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33244 *
33245 * Caller must ensure there is only one unmapping for the same pointer.
33246 */
33247 -void iounmap(volatile void __iomem *addr)
33248 +void iounmap(const volatile void __iomem *addr)
33249 {
33250 struct vm_struct *p, *o;
33251
33252 @@ -329,30 +329,29 @@ EXPORT_SYMBOL(iounmap);
33253 */
33254 void *xlate_dev_mem_ptr(unsigned long phys)
33255 {
33256 - void *addr;
33257 - unsigned long start = phys & PAGE_MASK;
33258 -
33259 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33260 - if (page_is_ram(start >> PAGE_SHIFT))
33261 + if (page_is_ram(phys >> PAGE_SHIFT))
33262 +#ifdef CONFIG_HIGHMEM
33263 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33264 +#endif
33265 return __va(phys);
33266
33267 - addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33268 - if (addr)
33269 - addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
33270 -
33271 - return addr;
33272 + return (void __force *)ioremap_cache(phys, PAGE_SIZE);
33273 }
33274
33275 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33276 {
33277 if (page_is_ram(phys >> PAGE_SHIFT))
33278 +#ifdef CONFIG_HIGHMEM
33279 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33280 +#endif
33281 return;
33282
33283 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33284 return;
33285 }
33286
33287 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33288 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33289
33290 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33291 {
33292 @@ -388,8 +387,7 @@ void __init early_ioremap_init(void)
33293 early_ioremap_setup();
33294
33295 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33296 - memset(bm_pte, 0, sizeof(bm_pte));
33297 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33298 + pmd_populate_user(&init_mm, pmd, bm_pte);
33299
33300 /*
33301 * The boot-ioremap range spans multiple pmds, for which
33302 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33303 index b4f2e7e..96c9c3e 100644
33304 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33305 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33306 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33307 * memory (e.g. tracked pages)? For now, we need this to avoid
33308 * invoking kmemcheck for PnP BIOS calls.
33309 */
33310 - if (regs->flags & X86_VM_MASK)
33311 + if (v8086_mode(regs))
33312 return false;
33313 - if (regs->cs != __KERNEL_CS)
33314 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33315 return false;
33316
33317 pte = kmemcheck_pte_lookup(address);
33318 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33319 index 919b912..9267313 100644
33320 --- a/arch/x86/mm/mmap.c
33321 +++ b/arch/x86/mm/mmap.c
33322 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33323 * Leave an at least ~128 MB hole with possible stack randomization.
33324 */
33325 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33326 -#define MAX_GAP (TASK_SIZE/6*5)
33327 +#define MAX_GAP (pax_task_size/6*5)
33328
33329 static int mmap_is_legacy(void)
33330 {
33331 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33332 return rnd << PAGE_SHIFT;
33333 }
33334
33335 -static unsigned long mmap_base(void)
33336 +static unsigned long mmap_base(struct mm_struct *mm)
33337 {
33338 unsigned long gap = rlimit(RLIMIT_STACK);
33339 + unsigned long pax_task_size = TASK_SIZE;
33340 +
33341 +#ifdef CONFIG_PAX_SEGMEXEC
33342 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33343 + pax_task_size = SEGMEXEC_TASK_SIZE;
33344 +#endif
33345
33346 if (gap < MIN_GAP)
33347 gap = MIN_GAP;
33348 else if (gap > MAX_GAP)
33349 gap = MAX_GAP;
33350
33351 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33352 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33353 }
33354
33355 /*
33356 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33357 * does, but not when emulating X86_32
33358 */
33359 -static unsigned long mmap_legacy_base(void)
33360 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33361 {
33362 - if (mmap_is_ia32())
33363 + if (mmap_is_ia32()) {
33364 +
33365 +#ifdef CONFIG_PAX_SEGMEXEC
33366 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33367 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33368 + else
33369 +#endif
33370 +
33371 return TASK_UNMAPPED_BASE;
33372 - else
33373 + } else
33374 return TASK_UNMAPPED_BASE + mmap_rnd();
33375 }
33376
33377 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33378 */
33379 void arch_pick_mmap_layout(struct mm_struct *mm)
33380 {
33381 - mm->mmap_legacy_base = mmap_legacy_base();
33382 - mm->mmap_base = mmap_base();
33383 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33384 + mm->mmap_base = mmap_base(mm);
33385 +
33386 +#ifdef CONFIG_PAX_RANDMMAP
33387 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33388 + mm->mmap_legacy_base += mm->delta_mmap;
33389 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33390 + }
33391 +#endif
33392
33393 if (mmap_is_legacy()) {
33394 mm->mmap_base = mm->mmap_legacy_base;
33395 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33396 index 0057a7a..95c7edd 100644
33397 --- a/arch/x86/mm/mmio-mod.c
33398 +++ b/arch/x86/mm/mmio-mod.c
33399 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33400 break;
33401 default:
33402 {
33403 - unsigned char *ip = (unsigned char *)instptr;
33404 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33405 my_trace->opcode = MMIO_UNKNOWN_OP;
33406 my_trace->width = 0;
33407 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33408 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33409 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33410 void __iomem *addr)
33411 {
33412 - static atomic_t next_id;
33413 + static atomic_unchecked_t next_id;
33414 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33415 /* These are page-unaligned. */
33416 struct mmiotrace_map map = {
33417 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33418 .private = trace
33419 },
33420 .phys = offset,
33421 - .id = atomic_inc_return(&next_id)
33422 + .id = atomic_inc_return_unchecked(&next_id)
33423 };
33424 map.map_id = trace->id;
33425
33426 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33427 ioremap_trace_core(offset, size, addr);
33428 }
33429
33430 -static void iounmap_trace_core(volatile void __iomem *addr)
33431 +static void iounmap_trace_core(const volatile void __iomem *addr)
33432 {
33433 struct mmiotrace_map map = {
33434 .phys = 0,
33435 @@ -328,7 +328,7 @@ not_enabled:
33436 }
33437 }
33438
33439 -void mmiotrace_iounmap(volatile void __iomem *addr)
33440 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33441 {
33442 might_sleep();
33443 if (is_enabled()) /* recheck and proper locking in *_core() */
33444 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33445 index 1a88370..3f598b5 100644
33446 --- a/arch/x86/mm/numa.c
33447 +++ b/arch/x86/mm/numa.c
33448 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33449 }
33450 }
33451
33452 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33453 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33454 {
33455 unsigned long uninitialized_var(pfn_align);
33456 int i, nid;
33457 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33458 index 36de293..b820ddc 100644
33459 --- a/arch/x86/mm/pageattr.c
33460 +++ b/arch/x86/mm/pageattr.c
33461 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33462 */
33463 #ifdef CONFIG_PCI_BIOS
33464 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33465 - pgprot_val(forbidden) |= _PAGE_NX;
33466 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33467 #endif
33468
33469 /*
33470 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33471 * Does not cover __inittext since that is gone later on. On
33472 * 64bit we do not enforce !NX on the low mapping
33473 */
33474 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33475 - pgprot_val(forbidden) |= _PAGE_NX;
33476 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33477 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33478
33479 +#ifdef CONFIG_DEBUG_RODATA
33480 /*
33481 * The .rodata section needs to be read-only. Using the pfn
33482 * catches all aliases.
33483 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33484 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33485 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33486 pgprot_val(forbidden) |= _PAGE_RW;
33487 +#endif
33488
33489 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33490 /*
33491 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33492 }
33493 #endif
33494
33495 +#ifdef CONFIG_PAX_KERNEXEC
33496 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33497 + pgprot_val(forbidden) |= _PAGE_RW;
33498 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33499 + }
33500 +#endif
33501 +
33502 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33503
33504 return prot;
33505 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33506 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33507 {
33508 /* change init_mm */
33509 + pax_open_kernel();
33510 set_pte_atomic(kpte, pte);
33511 +
33512 #ifdef CONFIG_X86_32
33513 if (!SHARED_KERNEL_PMD) {
33514 +
33515 +#ifdef CONFIG_PAX_PER_CPU_PGD
33516 + unsigned long cpu;
33517 +#else
33518 struct page *page;
33519 +#endif
33520
33521 +#ifdef CONFIG_PAX_PER_CPU_PGD
33522 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33523 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33524 +#else
33525 list_for_each_entry(page, &pgd_list, lru) {
33526 - pgd_t *pgd;
33527 + pgd_t *pgd = (pgd_t *)page_address(page);
33528 +#endif
33529 +
33530 pud_t *pud;
33531 pmd_t *pmd;
33532
33533 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33534 + pgd += pgd_index(address);
33535 pud = pud_offset(pgd, address);
33536 pmd = pmd_offset(pud, address);
33537 set_pte_atomic((pte_t *)pmd, pte);
33538 }
33539 }
33540 #endif
33541 + pax_close_kernel();
33542 }
33543
33544 static int
33545 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33546 index 6574388..87e9bef 100644
33547 --- a/arch/x86/mm/pat.c
33548 +++ b/arch/x86/mm/pat.c
33549 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33550
33551 if (!entry) {
33552 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33553 - current->comm, current->pid, start, end - 1);
33554 + current->comm, task_pid_nr(current), start, end - 1);
33555 return -EINVAL;
33556 }
33557
33558 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33559
33560 while (cursor < to) {
33561 if (!devmem_is_allowed(pfn)) {
33562 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33563 - current->comm, from, to - 1);
33564 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33565 + current->comm, from, to - 1, cursor);
33566 return 0;
33567 }
33568 cursor += PAGE_SIZE;
33569 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33570 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33571 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33572 "for [mem %#010Lx-%#010Lx]\n",
33573 - current->comm, current->pid,
33574 + current->comm, task_pid_nr(current),
33575 cattr_name(flags),
33576 base, (unsigned long long)(base + size-1));
33577 return -EINVAL;
33578 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33579 flags = lookup_memtype(paddr);
33580 if (want_flags != flags) {
33581 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33582 - current->comm, current->pid,
33583 + current->comm, task_pid_nr(current),
33584 cattr_name(want_flags),
33585 (unsigned long long)paddr,
33586 (unsigned long long)(paddr + size - 1),
33587 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33588 free_memtype(paddr, paddr + size);
33589 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33590 " for [mem %#010Lx-%#010Lx], got %s\n",
33591 - current->comm, current->pid,
33592 + current->comm, task_pid_nr(current),
33593 cattr_name(want_flags),
33594 (unsigned long long)paddr,
33595 (unsigned long long)(paddr + size - 1),
33596 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33597 index 415f6c4..d319983 100644
33598 --- a/arch/x86/mm/pat_rbtree.c
33599 +++ b/arch/x86/mm/pat_rbtree.c
33600 @@ -160,7 +160,7 @@ success:
33601
33602 failure:
33603 printk(KERN_INFO "%s:%d conflicting memory types "
33604 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33605 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33606 end, cattr_name(found_type), cattr_name(match->type));
33607 return -EBUSY;
33608 }
33609 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33610 index 9f0614d..92ae64a 100644
33611 --- a/arch/x86/mm/pf_in.c
33612 +++ b/arch/x86/mm/pf_in.c
33613 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33614 int i;
33615 enum reason_type rv = OTHERS;
33616
33617 - p = (unsigned char *)ins_addr;
33618 + p = (unsigned char *)ktla_ktva(ins_addr);
33619 p += skip_prefix(p, &prf);
33620 p += get_opcode(p, &opcode);
33621
33622 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33623 struct prefix_bits prf;
33624 int i;
33625
33626 - p = (unsigned char *)ins_addr;
33627 + p = (unsigned char *)ktla_ktva(ins_addr);
33628 p += skip_prefix(p, &prf);
33629 p += get_opcode(p, &opcode);
33630
33631 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33632 struct prefix_bits prf;
33633 int i;
33634
33635 - p = (unsigned char *)ins_addr;
33636 + p = (unsigned char *)ktla_ktva(ins_addr);
33637 p += skip_prefix(p, &prf);
33638 p += get_opcode(p, &opcode);
33639
33640 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33641 struct prefix_bits prf;
33642 int i;
33643
33644 - p = (unsigned char *)ins_addr;
33645 + p = (unsigned char *)ktla_ktva(ins_addr);
33646 p += skip_prefix(p, &prf);
33647 p += get_opcode(p, &opcode);
33648 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33649 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33650 struct prefix_bits prf;
33651 int i;
33652
33653 - p = (unsigned char *)ins_addr;
33654 + p = (unsigned char *)ktla_ktva(ins_addr);
33655 p += skip_prefix(p, &prf);
33656 p += get_opcode(p, &opcode);
33657 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33658 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33659 index 6fb6927..4fc13c0 100644
33660 --- a/arch/x86/mm/pgtable.c
33661 +++ b/arch/x86/mm/pgtable.c
33662 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33663 list_del(&page->lru);
33664 }
33665
33666 -#define UNSHARED_PTRS_PER_PGD \
33667 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33668 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33669 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33670
33671 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33672 +{
33673 + unsigned int count = USER_PGD_PTRS;
33674
33675 + if (!pax_user_shadow_base)
33676 + return;
33677 +
33678 + while (count--)
33679 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33680 +}
33681 +#endif
33682 +
33683 +#ifdef CONFIG_PAX_PER_CPU_PGD
33684 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33685 +{
33686 + unsigned int count = USER_PGD_PTRS;
33687 +
33688 + while (count--) {
33689 + pgd_t pgd;
33690 +
33691 +#ifdef CONFIG_X86_64
33692 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33693 +#else
33694 + pgd = *src++;
33695 +#endif
33696 +
33697 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33698 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33699 +#endif
33700 +
33701 + *dst++ = pgd;
33702 + }
33703 +
33704 +}
33705 +#endif
33706 +
33707 +#ifdef CONFIG_X86_64
33708 +#define pxd_t pud_t
33709 +#define pyd_t pgd_t
33710 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33711 +#define pgtable_pxd_page_ctor(page) true
33712 +#define pgtable_pxd_page_dtor(page)
33713 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33714 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33715 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33716 +#define PYD_SIZE PGDIR_SIZE
33717 +#else
33718 +#define pxd_t pmd_t
33719 +#define pyd_t pud_t
33720 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33721 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33722 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33723 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33724 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33725 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33726 +#define PYD_SIZE PUD_SIZE
33727 +#endif
33728 +
33729 +#ifdef CONFIG_PAX_PER_CPU_PGD
33730 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33731 +static inline void pgd_dtor(pgd_t *pgd) {}
33732 +#else
33733 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33734 {
33735 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33736 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33737 pgd_list_del(pgd);
33738 spin_unlock(&pgd_lock);
33739 }
33740 +#endif
33741
33742 /*
33743 * List of all pgd's needed for non-PAE so it can invalidate entries
33744 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33745 * -- nyc
33746 */
33747
33748 -#ifdef CONFIG_X86_PAE
33749 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33750 /*
33751 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33752 * updating the top-level pagetable entries to guarantee the
33753 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33754 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33755 * and initialize the kernel pmds here.
33756 */
33757 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33758 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33759
33760 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33761 {
33762 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33763 */
33764 flush_tlb_mm(mm);
33765 }
33766 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33767 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33768 #else /* !CONFIG_X86_PAE */
33769
33770 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33771 -#define PREALLOCATED_PMDS 0
33772 +#define PREALLOCATED_PXDS 0
33773
33774 #endif /* CONFIG_X86_PAE */
33775
33776 -static void free_pmds(pmd_t *pmds[])
33777 +static void free_pxds(pxd_t *pxds[])
33778 {
33779 int i;
33780
33781 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33782 - if (pmds[i]) {
33783 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33784 - free_page((unsigned long)pmds[i]);
33785 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33786 + if (pxds[i]) {
33787 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33788 + free_page((unsigned long)pxds[i]);
33789 }
33790 }
33791
33792 -static int preallocate_pmds(pmd_t *pmds[])
33793 +static int preallocate_pxds(pxd_t *pxds[])
33794 {
33795 int i;
33796 bool failed = false;
33797
33798 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33799 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33800 - if (!pmd)
33801 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33802 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33803 + if (!pxd)
33804 failed = true;
33805 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33806 - free_page((unsigned long)pmd);
33807 - pmd = NULL;
33808 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33809 + free_page((unsigned long)pxd);
33810 + pxd = NULL;
33811 failed = true;
33812 }
33813 - pmds[i] = pmd;
33814 + pxds[i] = pxd;
33815 }
33816
33817 if (failed) {
33818 - free_pmds(pmds);
33819 + free_pxds(pxds);
33820 return -ENOMEM;
33821 }
33822
33823 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33824 * preallocate which never got a corresponding vma will need to be
33825 * freed manually.
33826 */
33827 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33828 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33829 {
33830 int i;
33831
33832 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33833 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33834 pgd_t pgd = pgdp[i];
33835
33836 if (pgd_val(pgd) != 0) {
33837 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33838 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33839
33840 - pgdp[i] = native_make_pgd(0);
33841 + set_pgd(pgdp + i, native_make_pgd(0));
33842
33843 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33844 - pmd_free(mm, pmd);
33845 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33846 + pxd_free(mm, pxd);
33847 }
33848 }
33849 }
33850
33851 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33852 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33853 {
33854 - pud_t *pud;
33855 + pyd_t *pyd;
33856 int i;
33857
33858 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33859 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33860 return;
33861
33862 - pud = pud_offset(pgd, 0);
33863 -
33864 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33865 - pmd_t *pmd = pmds[i];
33866 +#ifdef CONFIG_X86_64
33867 + pyd = pyd_offset(mm, 0L);
33868 +#else
33869 + pyd = pyd_offset(pgd, 0L);
33870 +#endif
33871
33872 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33873 + pxd_t *pxd = pxds[i];
33874 if (i >= KERNEL_PGD_BOUNDARY)
33875 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33876 - sizeof(pmd_t) * PTRS_PER_PMD);
33877 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33878 + sizeof(pxd_t) * PTRS_PER_PMD);
33879
33880 - pud_populate(mm, pud, pmd);
33881 + pyd_populate(mm, pyd, pxd);
33882 }
33883 }
33884
33885 pgd_t *pgd_alloc(struct mm_struct *mm)
33886 {
33887 pgd_t *pgd;
33888 - pmd_t *pmds[PREALLOCATED_PMDS];
33889 + pxd_t *pxds[PREALLOCATED_PXDS];
33890
33891 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33892
33893 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33894
33895 mm->pgd = pgd;
33896
33897 - if (preallocate_pmds(pmds) != 0)
33898 + if (preallocate_pxds(pxds) != 0)
33899 goto out_free_pgd;
33900
33901 if (paravirt_pgd_alloc(mm) != 0)
33902 - goto out_free_pmds;
33903 + goto out_free_pxds;
33904
33905 /*
33906 * Make sure that pre-populating the pmds is atomic with
33907 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33908 spin_lock(&pgd_lock);
33909
33910 pgd_ctor(mm, pgd);
33911 - pgd_prepopulate_pmd(mm, pgd, pmds);
33912 + pgd_prepopulate_pxd(mm, pgd, pxds);
33913
33914 spin_unlock(&pgd_lock);
33915
33916 return pgd;
33917
33918 -out_free_pmds:
33919 - free_pmds(pmds);
33920 +out_free_pxds:
33921 + free_pxds(pxds);
33922 out_free_pgd:
33923 free_page((unsigned long)pgd);
33924 out:
33925 @@ -313,7 +380,7 @@ out:
33926
33927 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33928 {
33929 - pgd_mop_up_pmds(mm, pgd);
33930 + pgd_mop_up_pxds(mm, pgd);
33931 pgd_dtor(pgd);
33932 paravirt_pgd_free(mm, pgd);
33933 free_page((unsigned long)pgd);
33934 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33935 index 75cc097..79a097f 100644
33936 --- a/arch/x86/mm/pgtable_32.c
33937 +++ b/arch/x86/mm/pgtable_32.c
33938 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33939 return;
33940 }
33941 pte = pte_offset_kernel(pmd, vaddr);
33942 +
33943 + pax_open_kernel();
33944 if (pte_val(pteval))
33945 set_pte_at(&init_mm, vaddr, pte, pteval);
33946 else
33947 pte_clear(&init_mm, vaddr, pte);
33948 + pax_close_kernel();
33949
33950 /*
33951 * It's enough to flush this one mapping.
33952 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33953 index e666cbb..61788c45 100644
33954 --- a/arch/x86/mm/physaddr.c
33955 +++ b/arch/x86/mm/physaddr.c
33956 @@ -10,7 +10,7 @@
33957 #ifdef CONFIG_X86_64
33958
33959 #ifdef CONFIG_DEBUG_VIRTUAL
33960 -unsigned long __phys_addr(unsigned long x)
33961 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33962 {
33963 unsigned long y = x - __START_KERNEL_map;
33964
33965 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33966 #else
33967
33968 #ifdef CONFIG_DEBUG_VIRTUAL
33969 -unsigned long __phys_addr(unsigned long x)
33970 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33971 {
33972 unsigned long phys_addr = x - PAGE_OFFSET;
33973 /* VMALLOC_* aren't constants */
33974 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33975 index 90555bf..f5f1828 100644
33976 --- a/arch/x86/mm/setup_nx.c
33977 +++ b/arch/x86/mm/setup_nx.c
33978 @@ -5,8 +5,10 @@
33979 #include <asm/pgtable.h>
33980 #include <asm/proto.h>
33981
33982 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33983 static int disable_nx;
33984
33985 +#ifndef CONFIG_PAX_PAGEEXEC
33986 /*
33987 * noexec = on|off
33988 *
33989 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33990 return 0;
33991 }
33992 early_param("noexec", noexec_setup);
33993 +#endif
33994 +
33995 +#endif
33996
33997 void x86_configure_nx(void)
33998 {
33999 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34000 if (cpu_has_nx && !disable_nx)
34001 __supported_pte_mask |= _PAGE_NX;
34002 else
34003 +#endif
34004 __supported_pte_mask &= ~_PAGE_NX;
34005 }
34006
34007 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34008 index ee61c36..e6fedeb 100644
34009 --- a/arch/x86/mm/tlb.c
34010 +++ b/arch/x86/mm/tlb.c
34011 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34012 BUG();
34013 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34014 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34015 +
34016 +#ifndef CONFIG_PAX_PER_CPU_PGD
34017 load_cr3(swapper_pg_dir);
34018 +#endif
34019 +
34020 /*
34021 * This gets called in the idle path where RCU
34022 * functions differently. Tracing normally
34023 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34024 new file mode 100644
34025 index 0000000..dace51c
34026 --- /dev/null
34027 +++ b/arch/x86/mm/uderef_64.c
34028 @@ -0,0 +1,37 @@
34029 +#include <linux/mm.h>
34030 +#include <asm/pgtable.h>
34031 +#include <asm/uaccess.h>
34032 +
34033 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34034 +/* PaX: due to the special call convention these functions must
34035 + * - remain leaf functions under all configurations,
34036 + * - never be called directly, only dereferenced from the wrappers.
34037 + */
34038 +void __pax_open_userland(void)
34039 +{
34040 + unsigned int cpu;
34041 +
34042 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34043 + return;
34044 +
34045 + cpu = raw_get_cpu();
34046 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34047 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34048 + raw_put_cpu_no_resched();
34049 +}
34050 +EXPORT_SYMBOL(__pax_open_userland);
34051 +
34052 +void __pax_close_userland(void)
34053 +{
34054 + unsigned int cpu;
34055 +
34056 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34057 + return;
34058 +
34059 + cpu = raw_get_cpu();
34060 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34061 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34062 + raw_put_cpu_no_resched();
34063 +}
34064 +EXPORT_SYMBOL(__pax_close_userland);
34065 +#endif
34066 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34067 index 6440221..f84b5c7 100644
34068 --- a/arch/x86/net/bpf_jit.S
34069 +++ b/arch/x86/net/bpf_jit.S
34070 @@ -9,6 +9,7 @@
34071 */
34072 #include <linux/linkage.h>
34073 #include <asm/dwarf2.h>
34074 +#include <asm/alternative-asm.h>
34075
34076 /*
34077 * Calling convention :
34078 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34079 jle bpf_slow_path_word
34080 mov (SKBDATA,%rsi),%eax
34081 bswap %eax /* ntohl() */
34082 + pax_force_retaddr
34083 ret
34084
34085 sk_load_half:
34086 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34087 jle bpf_slow_path_half
34088 movzwl (SKBDATA,%rsi),%eax
34089 rol $8,%ax # ntohs()
34090 + pax_force_retaddr
34091 ret
34092
34093 sk_load_byte:
34094 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34095 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34096 jle bpf_slow_path_byte
34097 movzbl (SKBDATA,%rsi),%eax
34098 + pax_force_retaddr
34099 ret
34100
34101 /* rsi contains offset and can be scratched */
34102 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34103 js bpf_error
34104 mov - MAX_BPF_STACK + 32(%rbp),%eax
34105 bswap %eax
34106 + pax_force_retaddr
34107 ret
34108
34109 bpf_slow_path_half:
34110 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34111 mov - MAX_BPF_STACK + 32(%rbp),%ax
34112 rol $8,%ax
34113 movzwl %ax,%eax
34114 + pax_force_retaddr
34115 ret
34116
34117 bpf_slow_path_byte:
34118 bpf_slow_path_common(1)
34119 js bpf_error
34120 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34121 + pax_force_retaddr
34122 ret
34123
34124 #define sk_negative_common(SIZE) \
34125 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34126 sk_negative_common(4)
34127 mov (%rax), %eax
34128 bswap %eax
34129 + pax_force_retaddr
34130 ret
34131
34132 bpf_slow_path_half_neg:
34133 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34134 mov (%rax),%ax
34135 rol $8,%ax
34136 movzwl %ax,%eax
34137 + pax_force_retaddr
34138 ret
34139
34140 bpf_slow_path_byte_neg:
34141 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34142 .globl sk_load_byte_negative_offset
34143 sk_negative_common(1)
34144 movzbl (%rax), %eax
34145 + pax_force_retaddr
34146 ret
34147
34148 bpf_error:
34149 @@ -156,4 +166,5 @@ bpf_error:
34150 mov - MAX_BPF_STACK + 16(%rbp),%r14
34151 mov - MAX_BPF_STACK + 24(%rbp),%r15
34152 leaveq
34153 + pax_force_retaddr
34154 ret
34155 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34156 index 3f62734..a57894f 100644
34157 --- a/arch/x86/net/bpf_jit_comp.c
34158 +++ b/arch/x86/net/bpf_jit_comp.c
34159 @@ -13,7 +13,11 @@
34160 #include <linux/if_vlan.h>
34161 #include <asm/cacheflush.h>
34162
34163 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34164 +int bpf_jit_enable __read_only;
34165 +#else
34166 int bpf_jit_enable __read_mostly;
34167 +#endif
34168
34169 /*
34170 * assembly code in arch/x86/net/bpf_jit.S
34171 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34172 static void jit_fill_hole(void *area, unsigned int size)
34173 {
34174 /* fill whole space with int3 instructions */
34175 + pax_open_kernel();
34176 memset(area, 0xcc, size);
34177 + pax_close_kernel();
34178 }
34179
34180 struct jit_context {
34181 @@ -894,7 +900,9 @@ common_load:
34182 pr_err("bpf_jit_compile fatal error\n");
34183 return -EFAULT;
34184 }
34185 + pax_open_kernel();
34186 memcpy(image + proglen, temp, ilen);
34187 + pax_close_kernel();
34188 }
34189 proglen += ilen;
34190 addrs[i] = proglen;
34191 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34192
34193 if (image) {
34194 bpf_flush_icache(header, image + proglen);
34195 - set_memory_ro((unsigned long)header, header->pages);
34196 prog->bpf_func = (void *)image;
34197 prog->jited = true;
34198 }
34199 @@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34200 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34201 struct bpf_binary_header *header = (void *)addr;
34202
34203 - if (!fp->jited)
34204 - goto free_filter;
34205 + if (fp->jited)
34206 + bpf_jit_binary_free(header);
34207
34208 - set_memory_rw(addr, header->pages);
34209 - bpf_jit_binary_free(header);
34210 -
34211 -free_filter:
34212 bpf_prog_unlock_free(fp);
34213 }
34214 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34215 index 5d04be5..2beeaa2 100644
34216 --- a/arch/x86/oprofile/backtrace.c
34217 +++ b/arch/x86/oprofile/backtrace.c
34218 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34219 struct stack_frame_ia32 *fp;
34220 unsigned long bytes;
34221
34222 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34223 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34224 if (bytes != 0)
34225 return NULL;
34226
34227 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34228 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34229
34230 oprofile_add_trace(bufhead[0].return_address);
34231
34232 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34233 struct stack_frame bufhead[2];
34234 unsigned long bytes;
34235
34236 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34237 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34238 if (bytes != 0)
34239 return NULL;
34240
34241 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34242 {
34243 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34244
34245 - if (!user_mode_vm(regs)) {
34246 + if (!user_mode(regs)) {
34247 unsigned long stack = kernel_stack_pointer(regs);
34248 if (depth)
34249 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34250 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34251 index 1d2e639..f6ef82a 100644
34252 --- a/arch/x86/oprofile/nmi_int.c
34253 +++ b/arch/x86/oprofile/nmi_int.c
34254 @@ -23,6 +23,7 @@
34255 #include <asm/nmi.h>
34256 #include <asm/msr.h>
34257 #include <asm/apic.h>
34258 +#include <asm/pgtable.h>
34259
34260 #include "op_counter.h"
34261 #include "op_x86_model.h"
34262 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34263 if (ret)
34264 return ret;
34265
34266 - if (!model->num_virt_counters)
34267 - model->num_virt_counters = model->num_counters;
34268 + if (!model->num_virt_counters) {
34269 + pax_open_kernel();
34270 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34271 + pax_close_kernel();
34272 + }
34273
34274 mux_init(ops);
34275
34276 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34277 index 50d86c0..7985318 100644
34278 --- a/arch/x86/oprofile/op_model_amd.c
34279 +++ b/arch/x86/oprofile/op_model_amd.c
34280 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34281 num_counters = AMD64_NUM_COUNTERS;
34282 }
34283
34284 - op_amd_spec.num_counters = num_counters;
34285 - op_amd_spec.num_controls = num_counters;
34286 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34287 + pax_open_kernel();
34288 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34289 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34290 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34291 + pax_close_kernel();
34292
34293 return 0;
34294 }
34295 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34296 index d90528e..0127e2b 100644
34297 --- a/arch/x86/oprofile/op_model_ppro.c
34298 +++ b/arch/x86/oprofile/op_model_ppro.c
34299 @@ -19,6 +19,7 @@
34300 #include <asm/msr.h>
34301 #include <asm/apic.h>
34302 #include <asm/nmi.h>
34303 +#include <asm/pgtable.h>
34304
34305 #include "op_x86_model.h"
34306 #include "op_counter.h"
34307 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34308
34309 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34310
34311 - op_arch_perfmon_spec.num_counters = num_counters;
34312 - op_arch_perfmon_spec.num_controls = num_counters;
34313 + pax_open_kernel();
34314 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34315 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34316 + pax_close_kernel();
34317 }
34318
34319 static int arch_perfmon_init(struct oprofile_operations *ignore)
34320 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34321 index 71e8a67..6a313bb 100644
34322 --- a/arch/x86/oprofile/op_x86_model.h
34323 +++ b/arch/x86/oprofile/op_x86_model.h
34324 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34325 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34326 struct op_msrs const * const msrs);
34327 #endif
34328 -};
34329 +} __do_const;
34330
34331 struct op_counter_config;
34332
34333 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34334 index b9958c3..24229ab 100644
34335 --- a/arch/x86/pci/intel_mid_pci.c
34336 +++ b/arch/x86/pci/intel_mid_pci.c
34337 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34338 pci_mmcfg_late_init();
34339 pcibios_enable_irq = intel_mid_pci_irq_enable;
34340 pcibios_disable_irq = intel_mid_pci_irq_disable;
34341 - pci_root_ops = intel_mid_pci_ops;
34342 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34343 pci_soc_mode = 1;
34344 /* Continue with standard init */
34345 return 1;
34346 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34347 index eb500c2..eab9e70 100644
34348 --- a/arch/x86/pci/irq.c
34349 +++ b/arch/x86/pci/irq.c
34350 @@ -51,7 +51,7 @@ struct irq_router {
34351 struct irq_router_handler {
34352 u16 vendor;
34353 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34354 -};
34355 +} __do_const;
34356
34357 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34358 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34359 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34360 return 0;
34361 }
34362
34363 -static __initdata struct irq_router_handler pirq_routers[] = {
34364 +static __initconst const struct irq_router_handler pirq_routers[] = {
34365 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34366 { PCI_VENDOR_ID_AL, ali_router_probe },
34367 { PCI_VENDOR_ID_ITE, ite_router_probe },
34368 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34369 static void __init pirq_find_router(struct irq_router *r)
34370 {
34371 struct irq_routing_table *rt = pirq_table;
34372 - struct irq_router_handler *h;
34373 + const struct irq_router_handler *h;
34374
34375 #ifdef CONFIG_PCI_BIOS
34376 if (!rt->signature) {
34377 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34378 return 0;
34379 }
34380
34381 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34382 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34383 {
34384 .callback = fix_broken_hp_bios_irq9,
34385 .ident = "HP Pavilion N5400 Series Laptop",
34386 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34387 index 9b83b90..4112152 100644
34388 --- a/arch/x86/pci/pcbios.c
34389 +++ b/arch/x86/pci/pcbios.c
34390 @@ -79,7 +79,7 @@ union bios32 {
34391 static struct {
34392 unsigned long address;
34393 unsigned short segment;
34394 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34395 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34396
34397 /*
34398 * Returns the entry point for the given service, NULL on error
34399 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34400 unsigned long length; /* %ecx */
34401 unsigned long entry; /* %edx */
34402 unsigned long flags;
34403 + struct desc_struct d, *gdt;
34404
34405 local_irq_save(flags);
34406 - __asm__("lcall *(%%edi); cld"
34407 +
34408 + gdt = get_cpu_gdt_table(smp_processor_id());
34409 +
34410 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34411 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34412 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34413 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34414 +
34415 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34416 : "=a" (return_code),
34417 "=b" (address),
34418 "=c" (length),
34419 "=d" (entry)
34420 : "0" (service),
34421 "1" (0),
34422 - "D" (&bios32_indirect));
34423 + "D" (&bios32_indirect),
34424 + "r"(__PCIBIOS_DS)
34425 + : "memory");
34426 +
34427 + pax_open_kernel();
34428 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34429 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34430 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34431 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34432 + pax_close_kernel();
34433 +
34434 local_irq_restore(flags);
34435
34436 switch (return_code) {
34437 - case 0:
34438 - return address + entry;
34439 - case 0x80: /* Not present */
34440 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34441 - return 0;
34442 - default: /* Shouldn't happen */
34443 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34444 - service, return_code);
34445 + case 0: {
34446 + int cpu;
34447 + unsigned char flags;
34448 +
34449 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34450 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34451 + printk(KERN_WARNING "bios32_service: not valid\n");
34452 return 0;
34453 + }
34454 + address = address + PAGE_OFFSET;
34455 + length += 16UL; /* some BIOSs underreport this... */
34456 + flags = 4;
34457 + if (length >= 64*1024*1024) {
34458 + length >>= PAGE_SHIFT;
34459 + flags |= 8;
34460 + }
34461 +
34462 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34463 + gdt = get_cpu_gdt_table(cpu);
34464 + pack_descriptor(&d, address, length, 0x9b, flags);
34465 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34466 + pack_descriptor(&d, address, length, 0x93, flags);
34467 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34468 + }
34469 + return entry;
34470 + }
34471 + case 0x80: /* Not present */
34472 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34473 + return 0;
34474 + default: /* Shouldn't happen */
34475 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34476 + service, return_code);
34477 + return 0;
34478 }
34479 }
34480
34481 static struct {
34482 unsigned long address;
34483 unsigned short segment;
34484 -} pci_indirect = { 0, __KERNEL_CS };
34485 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34486
34487 -static int pci_bios_present;
34488 +static int pci_bios_present __read_only;
34489
34490 static int __init check_pcibios(void)
34491 {
34492 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34493 unsigned long flags, pcibios_entry;
34494
34495 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34496 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34497 + pci_indirect.address = pcibios_entry;
34498
34499 local_irq_save(flags);
34500 - __asm__(
34501 - "lcall *(%%edi); cld\n\t"
34502 + __asm__("movw %w6, %%ds\n\t"
34503 + "lcall *%%ss:(%%edi); cld\n\t"
34504 + "push %%ss\n\t"
34505 + "pop %%ds\n\t"
34506 "jc 1f\n\t"
34507 "xor %%ah, %%ah\n"
34508 "1:"
34509 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34510 "=b" (ebx),
34511 "=c" (ecx)
34512 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34513 - "D" (&pci_indirect)
34514 + "D" (&pci_indirect),
34515 + "r" (__PCIBIOS_DS)
34516 : "memory");
34517 local_irq_restore(flags);
34518
34519 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34520
34521 switch (len) {
34522 case 1:
34523 - __asm__("lcall *(%%esi); cld\n\t"
34524 + __asm__("movw %w6, %%ds\n\t"
34525 + "lcall *%%ss:(%%esi); cld\n\t"
34526 + "push %%ss\n\t"
34527 + "pop %%ds\n\t"
34528 "jc 1f\n\t"
34529 "xor %%ah, %%ah\n"
34530 "1:"
34531 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34532 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34533 "b" (bx),
34534 "D" ((long)reg),
34535 - "S" (&pci_indirect));
34536 + "S" (&pci_indirect),
34537 + "r" (__PCIBIOS_DS));
34538 /*
34539 * Zero-extend the result beyond 8 bits, do not trust the
34540 * BIOS having done it:
34541 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34542 *value &= 0xff;
34543 break;
34544 case 2:
34545 - __asm__("lcall *(%%esi); cld\n\t"
34546 + __asm__("movw %w6, %%ds\n\t"
34547 + "lcall *%%ss:(%%esi); cld\n\t"
34548 + "push %%ss\n\t"
34549 + "pop %%ds\n\t"
34550 "jc 1f\n\t"
34551 "xor %%ah, %%ah\n"
34552 "1:"
34553 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34554 : "1" (PCIBIOS_READ_CONFIG_WORD),
34555 "b" (bx),
34556 "D" ((long)reg),
34557 - "S" (&pci_indirect));
34558 + "S" (&pci_indirect),
34559 + "r" (__PCIBIOS_DS));
34560 /*
34561 * Zero-extend the result beyond 16 bits, do not trust the
34562 * BIOS having done it:
34563 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34564 *value &= 0xffff;
34565 break;
34566 case 4:
34567 - __asm__("lcall *(%%esi); cld\n\t"
34568 + __asm__("movw %w6, %%ds\n\t"
34569 + "lcall *%%ss:(%%esi); cld\n\t"
34570 + "push %%ss\n\t"
34571 + "pop %%ds\n\t"
34572 "jc 1f\n\t"
34573 "xor %%ah, %%ah\n"
34574 "1:"
34575 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34576 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34577 "b" (bx),
34578 "D" ((long)reg),
34579 - "S" (&pci_indirect));
34580 + "S" (&pci_indirect),
34581 + "r" (__PCIBIOS_DS));
34582 break;
34583 }
34584
34585 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34586
34587 switch (len) {
34588 case 1:
34589 - __asm__("lcall *(%%esi); cld\n\t"
34590 + __asm__("movw %w6, %%ds\n\t"
34591 + "lcall *%%ss:(%%esi); cld\n\t"
34592 + "push %%ss\n\t"
34593 + "pop %%ds\n\t"
34594 "jc 1f\n\t"
34595 "xor %%ah, %%ah\n"
34596 "1:"
34597 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34598 "c" (value),
34599 "b" (bx),
34600 "D" ((long)reg),
34601 - "S" (&pci_indirect));
34602 + "S" (&pci_indirect),
34603 + "r" (__PCIBIOS_DS));
34604 break;
34605 case 2:
34606 - __asm__("lcall *(%%esi); cld\n\t"
34607 + __asm__("movw %w6, %%ds\n\t"
34608 + "lcall *%%ss:(%%esi); cld\n\t"
34609 + "push %%ss\n\t"
34610 + "pop %%ds\n\t"
34611 "jc 1f\n\t"
34612 "xor %%ah, %%ah\n"
34613 "1:"
34614 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34615 "c" (value),
34616 "b" (bx),
34617 "D" ((long)reg),
34618 - "S" (&pci_indirect));
34619 + "S" (&pci_indirect),
34620 + "r" (__PCIBIOS_DS));
34621 break;
34622 case 4:
34623 - __asm__("lcall *(%%esi); cld\n\t"
34624 + __asm__("movw %w6, %%ds\n\t"
34625 + "lcall *%%ss:(%%esi); cld\n\t"
34626 + "push %%ss\n\t"
34627 + "pop %%ds\n\t"
34628 "jc 1f\n\t"
34629 "xor %%ah, %%ah\n"
34630 "1:"
34631 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34632 "c" (value),
34633 "b" (bx),
34634 "D" ((long)reg),
34635 - "S" (&pci_indirect));
34636 + "S" (&pci_indirect),
34637 + "r" (__PCIBIOS_DS));
34638 break;
34639 }
34640
34641 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34642
34643 DBG("PCI: Fetching IRQ routing table... ");
34644 __asm__("push %%es\n\t"
34645 + "movw %w8, %%ds\n\t"
34646 "push %%ds\n\t"
34647 "pop %%es\n\t"
34648 - "lcall *(%%esi); cld\n\t"
34649 + "lcall *%%ss:(%%esi); cld\n\t"
34650 "pop %%es\n\t"
34651 + "push %%ss\n\t"
34652 + "pop %%ds\n"
34653 "jc 1f\n\t"
34654 "xor %%ah, %%ah\n"
34655 "1:"
34656 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34657 "1" (0),
34658 "D" ((long) &opt),
34659 "S" (&pci_indirect),
34660 - "m" (opt)
34661 + "m" (opt),
34662 + "r" (__PCIBIOS_DS)
34663 : "memory");
34664 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34665 if (ret & 0xff00)
34666 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34667 {
34668 int ret;
34669
34670 - __asm__("lcall *(%%esi); cld\n\t"
34671 + __asm__("movw %w5, %%ds\n\t"
34672 + "lcall *%%ss:(%%esi); cld\n\t"
34673 + "push %%ss\n\t"
34674 + "pop %%ds\n"
34675 "jc 1f\n\t"
34676 "xor %%ah, %%ah\n"
34677 "1:"
34678 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34679 : "0" (PCIBIOS_SET_PCI_HW_INT),
34680 "b" ((dev->bus->number << 8) | dev->devfn),
34681 "c" ((irq << 8) | (pin + 10)),
34682 - "S" (&pci_indirect));
34683 + "S" (&pci_indirect),
34684 + "r" (__PCIBIOS_DS));
34685 return !(ret & 0xff00);
34686 }
34687 EXPORT_SYMBOL(pcibios_set_irq_routing);
34688 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34689 index 40e7cda..c7e6672 100644
34690 --- a/arch/x86/platform/efi/efi_32.c
34691 +++ b/arch/x86/platform/efi/efi_32.c
34692 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34693 {
34694 struct desc_ptr gdt_descr;
34695
34696 +#ifdef CONFIG_PAX_KERNEXEC
34697 + struct desc_struct d;
34698 +#endif
34699 +
34700 local_irq_save(efi_rt_eflags);
34701
34702 load_cr3(initial_page_table);
34703 __flush_tlb_all();
34704
34705 +#ifdef CONFIG_PAX_KERNEXEC
34706 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34707 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34708 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34709 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34710 +#endif
34711 +
34712 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34713 gdt_descr.size = GDT_SIZE - 1;
34714 load_gdt(&gdt_descr);
34715 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34716 {
34717 struct desc_ptr gdt_descr;
34718
34719 +#ifdef CONFIG_PAX_KERNEXEC
34720 + struct desc_struct d;
34721 +
34722 + memset(&d, 0, sizeof d);
34723 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34724 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34725 +#endif
34726 +
34727 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34728 gdt_descr.size = GDT_SIZE - 1;
34729 load_gdt(&gdt_descr);
34730
34731 +#ifdef CONFIG_PAX_PER_CPU_PGD
34732 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34733 +#else
34734 load_cr3(swapper_pg_dir);
34735 +#endif
34736 +
34737 __flush_tlb_all();
34738
34739 local_irq_restore(efi_rt_eflags);
34740 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34741 index 35aecb6..46177db 100644
34742 --- a/arch/x86/platform/efi/efi_64.c
34743 +++ b/arch/x86/platform/efi/efi_64.c
34744 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34745 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34746 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34747 }
34748 +
34749 +#ifdef CONFIG_PAX_PER_CPU_PGD
34750 + load_cr3(swapper_pg_dir);
34751 +#endif
34752 +
34753 __flush_tlb_all();
34754 }
34755
34756 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34757 for (pgd = 0; pgd < n_pgds; pgd++)
34758 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34759 kfree(save_pgd);
34760 +
34761 +#ifdef CONFIG_PAX_PER_CPU_PGD
34762 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34763 +#endif
34764 +
34765 __flush_tlb_all();
34766 local_irq_restore(efi_flags);
34767 early_code_mapping_set_exec(0);
34768 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34769 unsigned npages;
34770 pgd_t *pgd;
34771
34772 - if (efi_enabled(EFI_OLD_MEMMAP))
34773 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34774 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34775 + * able to execute the EFI services.
34776 + */
34777 + if (__supported_pte_mask & _PAGE_NX) {
34778 + unsigned long addr = (unsigned long) __va(0);
34779 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34780 +
34781 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34782 +#ifdef CONFIG_PAX_PER_CPU_PGD
34783 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34784 +#endif
34785 + set_pgd(pgd_offset_k(addr), pe);
34786 + }
34787 +
34788 return 0;
34789 + }
34790
34791 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34792 pgd = __va(efi_scratch.efi_pgt);
34793 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34794 index 040192b..7d3300f 100644
34795 --- a/arch/x86/platform/efi/efi_stub_32.S
34796 +++ b/arch/x86/platform/efi/efi_stub_32.S
34797 @@ -6,7 +6,9 @@
34798 */
34799
34800 #include <linux/linkage.h>
34801 +#include <linux/init.h>
34802 #include <asm/page_types.h>
34803 +#include <asm/segment.h>
34804
34805 /*
34806 * efi_call_phys(void *, ...) is a function with variable parameters.
34807 @@ -20,7 +22,7 @@
34808 * service functions will comply with gcc calling convention, too.
34809 */
34810
34811 -.text
34812 +__INIT
34813 ENTRY(efi_call_phys)
34814 /*
34815 * 0. The function can only be called in Linux kernel. So CS has been
34816 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34817 * The mapping of lower virtual memory has been created in prolog and
34818 * epilog.
34819 */
34820 - movl $1f, %edx
34821 - subl $__PAGE_OFFSET, %edx
34822 - jmp *%edx
34823 +#ifdef CONFIG_PAX_KERNEXEC
34824 + movl $(__KERNEXEC_EFI_DS), %edx
34825 + mov %edx, %ds
34826 + mov %edx, %es
34827 + mov %edx, %ss
34828 + addl $2f,(1f)
34829 + ljmp *(1f)
34830 +
34831 +__INITDATA
34832 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34833 +.previous
34834 +
34835 +2:
34836 + subl $2b,(1b)
34837 +#else
34838 + jmp 1f-__PAGE_OFFSET
34839 1:
34840 +#endif
34841
34842 /*
34843 * 2. Now on the top of stack is the return
34844 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34845 * parameter 2, ..., param n. To make things easy, we save the return
34846 * address of efi_call_phys in a global variable.
34847 */
34848 - popl %edx
34849 - movl %edx, saved_return_addr
34850 - /* get the function pointer into ECX*/
34851 - popl %ecx
34852 - movl %ecx, efi_rt_function_ptr
34853 - movl $2f, %edx
34854 - subl $__PAGE_OFFSET, %edx
34855 - pushl %edx
34856 + popl (saved_return_addr)
34857 + popl (efi_rt_function_ptr)
34858
34859 /*
34860 * 3. Clear PG bit in %CR0.
34861 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34862 /*
34863 * 5. Call the physical function.
34864 */
34865 - jmp *%ecx
34866 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34867
34868 -2:
34869 /*
34870 * 6. After EFI runtime service returns, control will return to
34871 * following instruction. We'd better readjust stack pointer first.
34872 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34873 movl %cr0, %edx
34874 orl $0x80000000, %edx
34875 movl %edx, %cr0
34876 - jmp 1f
34877 -1:
34878 +
34879 /*
34880 * 8. Now restore the virtual mode from flat mode by
34881 * adding EIP with PAGE_OFFSET.
34882 */
34883 - movl $1f, %edx
34884 - jmp *%edx
34885 +#ifdef CONFIG_PAX_KERNEXEC
34886 + movl $(__KERNEL_DS), %edx
34887 + mov %edx, %ds
34888 + mov %edx, %es
34889 + mov %edx, %ss
34890 + ljmp $(__KERNEL_CS),$1f
34891 +#else
34892 + jmp 1f+__PAGE_OFFSET
34893 +#endif
34894 1:
34895
34896 /*
34897 * 9. Balance the stack. And because EAX contain the return value,
34898 * we'd better not clobber it.
34899 */
34900 - leal efi_rt_function_ptr, %edx
34901 - movl (%edx), %ecx
34902 - pushl %ecx
34903 + pushl (efi_rt_function_ptr)
34904
34905 /*
34906 - * 10. Push the saved return address onto the stack and return.
34907 + * 10. Return to the saved return address.
34908 */
34909 - leal saved_return_addr, %edx
34910 - movl (%edx), %ecx
34911 - pushl %ecx
34912 - ret
34913 + jmpl *(saved_return_addr)
34914 ENDPROC(efi_call_phys)
34915 .previous
34916
34917 -.data
34918 +__INITDATA
34919 saved_return_addr:
34920 .long 0
34921 efi_rt_function_ptr:
34922 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34923 index 5fcda72..cd4dc41 100644
34924 --- a/arch/x86/platform/efi/efi_stub_64.S
34925 +++ b/arch/x86/platform/efi/efi_stub_64.S
34926 @@ -11,6 +11,7 @@
34927 #include <asm/msr.h>
34928 #include <asm/processor-flags.h>
34929 #include <asm/page_types.h>
34930 +#include <asm/alternative-asm.h>
34931
34932 #define SAVE_XMM \
34933 mov %rsp, %rax; \
34934 @@ -88,6 +89,7 @@ ENTRY(efi_call)
34935 RESTORE_PGT
34936 addq $48, %rsp
34937 RESTORE_XMM
34938 + pax_force_retaddr 0, 1
34939 ret
34940 ENDPROC(efi_call)
34941
34942 @@ -245,8 +247,8 @@ efi_gdt64:
34943 .long 0 /* Filled out by user */
34944 .word 0
34945 .quad 0x0000000000000000 /* NULL descriptor */
34946 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
34947 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
34948 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
34949 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
34950 .quad 0x0080890000000000 /* TS descriptor */
34951 .quad 0x0000000000000000 /* TS continued */
34952 efi_gdt64_end:
34953 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34954 index 1bbedc4..eb795b5 100644
34955 --- a/arch/x86/platform/intel-mid/intel-mid.c
34956 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34957 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34958 {
34959 };
34960
34961 -static void intel_mid_reboot(void)
34962 +static void __noreturn intel_mid_reboot(void)
34963 {
34964 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34965 + BUG();
34966 }
34967
34968 static unsigned long __init intel_mid_calibrate_tsc(void)
34969 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34970 index 3c1c386..59a68ed 100644
34971 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34972 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34973 @@ -13,6 +13,6 @@
34974 /* For every CPU addition a new get_<cpuname>_ops interface needs
34975 * to be added.
34976 */
34977 -extern void *get_penwell_ops(void);
34978 -extern void *get_cloverview_ops(void);
34979 -extern void *get_tangier_ops(void);
34980 +extern const void *get_penwell_ops(void);
34981 +extern const void *get_cloverview_ops(void);
34982 +extern const void *get_tangier_ops(void);
34983 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
34984 index 23381d2..8ddc10e 100644
34985 --- a/arch/x86/platform/intel-mid/mfld.c
34986 +++ b/arch/x86/platform/intel-mid/mfld.c
34987 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
34988 pm_power_off = mfld_power_off;
34989 }
34990
34991 -void *get_penwell_ops(void)
34992 +const void *get_penwell_ops(void)
34993 {
34994 return &penwell_ops;
34995 }
34996
34997 -void *get_cloverview_ops(void)
34998 +const void *get_cloverview_ops(void)
34999 {
35000 return &penwell_ops;
35001 }
35002 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35003 index aaca917..66eadbc 100644
35004 --- a/arch/x86/platform/intel-mid/mrfl.c
35005 +++ b/arch/x86/platform/intel-mid/mrfl.c
35006 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35007 .arch_setup = tangier_arch_setup,
35008 };
35009
35010 -void *get_tangier_ops(void)
35011 +const void *get_tangier_ops(void)
35012 {
35013 return &tangier_ops;
35014 }
35015 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35016 index d6ee929..3637cb5 100644
35017 --- a/arch/x86/platform/olpc/olpc_dt.c
35018 +++ b/arch/x86/platform/olpc/olpc_dt.c
35019 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35020 return res;
35021 }
35022
35023 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35024 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35025 .nextprop = olpc_dt_nextprop,
35026 .getproplen = olpc_dt_getproplen,
35027 .getproperty = olpc_dt_getproperty,
35028 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35029 index 6ec7910..ecdbb11 100644
35030 --- a/arch/x86/power/cpu.c
35031 +++ b/arch/x86/power/cpu.c
35032 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35033 static void fix_processor_context(void)
35034 {
35035 int cpu = smp_processor_id();
35036 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35037 -#ifdef CONFIG_X86_64
35038 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35039 - tss_desc tss;
35040 -#endif
35041 + struct tss_struct *t = init_tss + cpu;
35042 +
35043 set_tss_desc(cpu, t); /*
35044 * This just modifies memory; should not be
35045 * necessary. But... This is necessary, because
35046 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35047 */
35048
35049 #ifdef CONFIG_X86_64
35050 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35051 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35052 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35053 -
35054 syscall_init(); /* This sets MSR_*STAR and related */
35055 #endif
35056 load_TR_desc(); /* This does ltr */
35057 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35058 index bad628a..a102610 100644
35059 --- a/arch/x86/realmode/init.c
35060 +++ b/arch/x86/realmode/init.c
35061 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35062 __va(real_mode_header->trampoline_header);
35063
35064 #ifdef CONFIG_X86_32
35065 - trampoline_header->start = __pa_symbol(startup_32_smp);
35066 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35067 +
35068 +#ifdef CONFIG_PAX_KERNEXEC
35069 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35070 +#endif
35071 +
35072 + trampoline_header->boot_cs = __BOOT_CS;
35073 trampoline_header->gdt_limit = __BOOT_DS + 7;
35074 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35075 #else
35076 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35077 *trampoline_cr4_features = read_cr4();
35078
35079 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35080 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35081 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35082 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35083 #endif
35084 }
35085 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35086 index 7c0d7be..d24dc88 100644
35087 --- a/arch/x86/realmode/rm/Makefile
35088 +++ b/arch/x86/realmode/rm/Makefile
35089 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35090
35091 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35092 -I$(srctree)/arch/x86/boot
35093 +ifdef CONSTIFY_PLUGIN
35094 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35095 +endif
35096 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35097 GCOV_PROFILE := n
35098 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35099 index a28221d..93c40f1 100644
35100 --- a/arch/x86/realmode/rm/header.S
35101 +++ b/arch/x86/realmode/rm/header.S
35102 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35103 #endif
35104 /* APM/BIOS reboot */
35105 .long pa_machine_real_restart_asm
35106 -#ifdef CONFIG_X86_64
35107 +#ifdef CONFIG_X86_32
35108 + .long __KERNEL_CS
35109 +#else
35110 .long __KERNEL32_CS
35111 #endif
35112 END(real_mode_header)
35113 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35114 index 48ddd76..c26749f 100644
35115 --- a/arch/x86/realmode/rm/trampoline_32.S
35116 +++ b/arch/x86/realmode/rm/trampoline_32.S
35117 @@ -24,6 +24,12 @@
35118 #include <asm/page_types.h>
35119 #include "realmode.h"
35120
35121 +#ifdef CONFIG_PAX_KERNEXEC
35122 +#define ta(X) (X)
35123 +#else
35124 +#define ta(X) (pa_ ## X)
35125 +#endif
35126 +
35127 .text
35128 .code16
35129
35130 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35131
35132 cli # We should be safe anyway
35133
35134 - movl tr_start, %eax # where we need to go
35135 -
35136 movl $0xA5A5A5A5, trampoline_status
35137 # write marker for master knows we're running
35138
35139 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35140 movw $1, %dx # protected mode (PE) bit
35141 lmsw %dx # into protected mode
35142
35143 - ljmpl $__BOOT_CS, $pa_startup_32
35144 + ljmpl *(trampoline_header)
35145
35146 .section ".text32","ax"
35147 .code32
35148 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35149 .balign 8
35150 GLOBAL(trampoline_header)
35151 tr_start: .space 4
35152 - tr_gdt_pad: .space 2
35153 + tr_boot_cs: .space 2
35154 tr_gdt: .space 6
35155 END(trampoline_header)
35156
35157 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35158 index dac7b20..72dbaca 100644
35159 --- a/arch/x86/realmode/rm/trampoline_64.S
35160 +++ b/arch/x86/realmode/rm/trampoline_64.S
35161 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35162 movl %edx, %gs
35163
35164 movl pa_tr_cr4, %eax
35165 + andl $~X86_CR4_PCIDE, %eax
35166 movl %eax, %cr4 # Enable PAE mode
35167
35168 # Setup trampoline 4 level pagetables
35169 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35170 wrmsr
35171
35172 # Enable paging and in turn activate Long Mode
35173 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35174 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35175 movl %eax, %cr0
35176
35177 /*
35178 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35179 index 9e7e147..25a4158 100644
35180 --- a/arch/x86/realmode/rm/wakeup_asm.S
35181 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35182 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35183 lgdtl pmode_gdt
35184
35185 /* This really couldn't... */
35186 - movl pmode_entry, %eax
35187 movl pmode_cr0, %ecx
35188 movl %ecx, %cr0
35189 - ljmpl $__KERNEL_CS, $pa_startup_32
35190 - /* -> jmp *%eax in trampoline_32.S */
35191 +
35192 + ljmpl *pmode_entry
35193 #else
35194 jmp trampoline_start
35195 #endif
35196 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35197 index 604a37e..e49702a 100644
35198 --- a/arch/x86/tools/Makefile
35199 +++ b/arch/x86/tools/Makefile
35200 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35201
35202 $(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
35203
35204 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35205 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35206 hostprogs-y += relocs
35207 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35208 PHONY += relocs
35209 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35210 index a5efb21..97490e9 100644
35211 --- a/arch/x86/tools/relocs.c
35212 +++ b/arch/x86/tools/relocs.c
35213 @@ -1,5 +1,7 @@
35214 /* This is included from relocs_32/64.c */
35215
35216 +#include "../../../include/generated/autoconf.h"
35217 +
35218 #define ElfW(type) _ElfW(ELF_BITS, type)
35219 #define _ElfW(bits, type) __ElfW(bits, type)
35220 #define __ElfW(bits, type) Elf##bits##_##type
35221 @@ -11,6 +13,7 @@
35222 #define Elf_Sym ElfW(Sym)
35223
35224 static Elf_Ehdr ehdr;
35225 +static Elf_Phdr *phdr;
35226
35227 struct relocs {
35228 uint32_t *offset;
35229 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35230 }
35231 }
35232
35233 +static void read_phdrs(FILE *fp)
35234 +{
35235 + unsigned int i;
35236 +
35237 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35238 + if (!phdr) {
35239 + die("Unable to allocate %d program headers\n",
35240 + ehdr.e_phnum);
35241 + }
35242 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35243 + die("Seek to %d failed: %s\n",
35244 + ehdr.e_phoff, strerror(errno));
35245 + }
35246 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35247 + die("Cannot read ELF program headers: %s\n",
35248 + strerror(errno));
35249 + }
35250 + for(i = 0; i < ehdr.e_phnum; i++) {
35251 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35252 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35253 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35254 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35255 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35256 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35257 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35258 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35259 + }
35260 +
35261 +}
35262 +
35263 static void read_shdrs(FILE *fp)
35264 {
35265 - int i;
35266 + unsigned int i;
35267 Elf_Shdr shdr;
35268
35269 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35270 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35271
35272 static void read_strtabs(FILE *fp)
35273 {
35274 - int i;
35275 + unsigned int i;
35276 for (i = 0; i < ehdr.e_shnum; i++) {
35277 struct section *sec = &secs[i];
35278 if (sec->shdr.sh_type != SHT_STRTAB) {
35279 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35280
35281 static void read_symtabs(FILE *fp)
35282 {
35283 - int i,j;
35284 + unsigned int i,j;
35285 for (i = 0; i < ehdr.e_shnum; i++) {
35286 struct section *sec = &secs[i];
35287 if (sec->shdr.sh_type != SHT_SYMTAB) {
35288 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35289 }
35290
35291
35292 -static void read_relocs(FILE *fp)
35293 +static void read_relocs(FILE *fp, int use_real_mode)
35294 {
35295 - int i,j;
35296 + unsigned int i,j;
35297 + uint32_t base;
35298 +
35299 for (i = 0; i < ehdr.e_shnum; i++) {
35300 struct section *sec = &secs[i];
35301 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35302 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35303 die("Cannot read symbol table: %s\n",
35304 strerror(errno));
35305 }
35306 + base = 0;
35307 +
35308 +#ifdef CONFIG_X86_32
35309 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35310 + if (phdr[j].p_type != PT_LOAD )
35311 + continue;
35312 + 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)
35313 + continue;
35314 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35315 + break;
35316 + }
35317 +#endif
35318 +
35319 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35320 Elf_Rel *rel = &sec->reltab[j];
35321 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35322 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35323 rel->r_info = elf_xword_to_cpu(rel->r_info);
35324 #if (SHT_REL_TYPE == SHT_RELA)
35325 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35326 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35327
35328 static void print_absolute_symbols(void)
35329 {
35330 - int i;
35331 + unsigned int i;
35332 const char *format;
35333
35334 if (ELF_BITS == 64)
35335 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35336 for (i = 0; i < ehdr.e_shnum; i++) {
35337 struct section *sec = &secs[i];
35338 char *sym_strtab;
35339 - int j;
35340 + unsigned int j;
35341
35342 if (sec->shdr.sh_type != SHT_SYMTAB) {
35343 continue;
35344 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35345
35346 static void print_absolute_relocs(void)
35347 {
35348 - int i, printed = 0;
35349 + unsigned int i, printed = 0;
35350 const char *format;
35351
35352 if (ELF_BITS == 64)
35353 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35354 struct section *sec_applies, *sec_symtab;
35355 char *sym_strtab;
35356 Elf_Sym *sh_symtab;
35357 - int j;
35358 + unsigned int j;
35359 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35360 continue;
35361 }
35362 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35363 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35364 Elf_Sym *sym, const char *symname))
35365 {
35366 - int i;
35367 + unsigned int i;
35368 /* Walk through the relocations */
35369 for (i = 0; i < ehdr.e_shnum; i++) {
35370 char *sym_strtab;
35371 Elf_Sym *sh_symtab;
35372 struct section *sec_applies, *sec_symtab;
35373 - int j;
35374 + unsigned int j;
35375 struct section *sec = &secs[i];
35376
35377 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35378 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35379 {
35380 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35381 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35382 + char *sym_strtab = sec->link->link->strtab;
35383 +
35384 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35385 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35386 + return 0;
35387 +
35388 +#ifdef CONFIG_PAX_KERNEXEC
35389 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35390 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35391 + return 0;
35392 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35393 + return 0;
35394 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35395 + return 0;
35396 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35397 + return 0;
35398 +#endif
35399
35400 switch (r_type) {
35401 case R_386_NONE:
35402 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35403
35404 static void emit_relocs(int as_text, int use_real_mode)
35405 {
35406 - int i;
35407 + unsigned int i;
35408 int (*write_reloc)(uint32_t, FILE *) = write32;
35409 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35410 const char *symname);
35411 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35412 {
35413 regex_init(use_real_mode);
35414 read_ehdr(fp);
35415 + read_phdrs(fp);
35416 read_shdrs(fp);
35417 read_strtabs(fp);
35418 read_symtabs(fp);
35419 - read_relocs(fp);
35420 + read_relocs(fp, use_real_mode);
35421 if (ELF_BITS == 64)
35422 percpu_init();
35423 if (show_absolute_syms) {
35424 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35425 index f40281e..92728c9 100644
35426 --- a/arch/x86/um/mem_32.c
35427 +++ b/arch/x86/um/mem_32.c
35428 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35429 gate_vma.vm_start = FIXADDR_USER_START;
35430 gate_vma.vm_end = FIXADDR_USER_END;
35431 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35432 - gate_vma.vm_page_prot = __P101;
35433 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35434
35435 return 0;
35436 }
35437 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35438 index 80ffa5b..a33bd15 100644
35439 --- a/arch/x86/um/tls_32.c
35440 +++ b/arch/x86/um/tls_32.c
35441 @@ -260,7 +260,7 @@ out:
35442 if (unlikely(task == current &&
35443 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35444 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35445 - "without flushed TLS.", current->pid);
35446 + "without flushed TLS.", task_pid_nr(current));
35447 }
35448
35449 return 0;
35450 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35451 index 5a4affe..9e2d522 100644
35452 --- a/arch/x86/vdso/Makefile
35453 +++ b/arch/x86/vdso/Makefile
35454 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35455 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35456 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35457
35458 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35459 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35460 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35461 GCOV_PROFILE := n
35462
35463 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35464 index 0224987..c7d65a5 100644
35465 --- a/arch/x86/vdso/vdso2c.h
35466 +++ b/arch/x86/vdso/vdso2c.h
35467 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35468 unsigned long load_size = -1; /* Work around bogus warning */
35469 unsigned long mapping_size;
35470 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35471 - int i;
35472 + unsigned int i;
35473 unsigned long j;
35474 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35475 *alt_sec = NULL;
35476 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35477 index e904c27..b9eaa03 100644
35478 --- a/arch/x86/vdso/vdso32-setup.c
35479 +++ b/arch/x86/vdso/vdso32-setup.c
35480 @@ -14,6 +14,7 @@
35481 #include <asm/cpufeature.h>
35482 #include <asm/processor.h>
35483 #include <asm/vdso.h>
35484 +#include <asm/mman.h>
35485
35486 #ifdef CONFIG_COMPAT_VDSO
35487 #define VDSO_DEFAULT 0
35488 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35489 index 208c220..54f1447 100644
35490 --- a/arch/x86/vdso/vma.c
35491 +++ b/arch/x86/vdso/vma.c
35492 @@ -16,10 +16,9 @@
35493 #include <asm/vdso.h>
35494 #include <asm/page.h>
35495 #include <asm/hpet.h>
35496 +#include <asm/mman.h>
35497
35498 #if defined(CONFIG_X86_64)
35499 -unsigned int __read_mostly vdso64_enabled = 1;
35500 -
35501 extern unsigned short vdso_sync_cpuid;
35502 #endif
35503
35504 @@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35505 .pages = no_pages,
35506 };
35507
35508 +#ifdef CONFIG_PAX_RANDMMAP
35509 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35510 + calculate_addr = false;
35511 +#endif
35512 +
35513 if (calculate_addr) {
35514 addr = vdso_addr(current->mm->start_stack,
35515 image->size - image->sym_vvar_start);
35516 @@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35517 down_write(&mm->mmap_sem);
35518
35519 addr = get_unmapped_area(NULL, addr,
35520 - image->size - image->sym_vvar_start, 0, 0);
35521 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35522 if (IS_ERR_VALUE(addr)) {
35523 ret = addr;
35524 goto up_fail;
35525 }
35526
35527 text_start = addr - image->sym_vvar_start;
35528 - current->mm->context.vdso = (void __user *)text_start;
35529 + mm->context.vdso = text_start;
35530
35531 /*
35532 * MAYWRITE to allow gdb to COW and set breakpoints
35533 @@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35534 hpet_address >> PAGE_SHIFT,
35535 PAGE_SIZE,
35536 pgprot_noncached(PAGE_READONLY));
35537 -
35538 - if (ret)
35539 - goto up_fail;
35540 }
35541 #endif
35542
35543 up_fail:
35544 if (ret)
35545 - current->mm->context.vdso = NULL;
35546 + current->mm->context.vdso = 0;
35547
35548 up_write(&mm->mmap_sem);
35549 return ret;
35550 @@ -204,8 +205,8 @@ static int load_vdso32(void)
35551
35552 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35553 current_thread_info()->sysenter_return =
35554 - current->mm->context.vdso +
35555 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35556 + (void __force_user *)(current->mm->context.vdso +
35557 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35558
35559 return 0;
35560 }
35561 @@ -214,9 +215,6 @@ static int load_vdso32(void)
35562 #ifdef CONFIG_X86_64
35563 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35564 {
35565 - if (!vdso64_enabled)
35566 - return 0;
35567 -
35568 return map_vdso(&vdso_image_64, true);
35569 }
35570
35571 @@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35572 int uses_interp)
35573 {
35574 #ifdef CONFIG_X86_X32_ABI
35575 - if (test_thread_flag(TIF_X32)) {
35576 - if (!vdso64_enabled)
35577 - return 0;
35578 -
35579 + if (test_thread_flag(TIF_X32))
35580 return map_vdso(&vdso_image_x32, true);
35581 - }
35582 #endif
35583
35584 return load_vdso32();
35585 @@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35586 return load_vdso32();
35587 }
35588 #endif
35589 -
35590 -#ifdef CONFIG_X86_64
35591 -static __init int vdso_setup(char *s)
35592 -{
35593 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35594 - return 0;
35595 -}
35596 -__setup("vdso=", vdso_setup);
35597 -#endif
35598 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35599 index e88fda8..76ce7ce 100644
35600 --- a/arch/x86/xen/Kconfig
35601 +++ b/arch/x86/xen/Kconfig
35602 @@ -9,6 +9,7 @@ config XEN
35603 select XEN_HAVE_PVMMU
35604 depends on X86_64 || (X86_32 && X86_PAE)
35605 depends on X86_TSC
35606 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35607 help
35608 This is the Linux Xen port. Enabling this will allow the
35609 kernel to boot in a paravirtualized environment under the
35610 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35611 index fac5e4f..89c3525 100644
35612 --- a/arch/x86/xen/enlighten.c
35613 +++ b/arch/x86/xen/enlighten.c
35614 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35615
35616 struct shared_info xen_dummy_shared_info;
35617
35618 -void *xen_initial_gdt;
35619 -
35620 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35621 __read_mostly int xen_have_vector_callback;
35622 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35623 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35624 {
35625 unsigned long va = dtr->address;
35626 unsigned int size = dtr->size + 1;
35627 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35628 - unsigned long frames[pages];
35629 + unsigned long frames[65536 / PAGE_SIZE];
35630 int f;
35631
35632 /*
35633 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35634 {
35635 unsigned long va = dtr->address;
35636 unsigned int size = dtr->size + 1;
35637 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35638 - unsigned long frames[pages];
35639 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35640 int f;
35641
35642 /*
35643 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35644 * 8-byte entries, or 16 4k pages..
35645 */
35646
35647 - BUG_ON(size > 65536);
35648 + BUG_ON(size > GDT_SIZE);
35649 BUG_ON(va & ~PAGE_MASK);
35650
35651 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35652 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35653 return 0;
35654 }
35655
35656 -static void set_xen_basic_apic_ops(void)
35657 +static void __init set_xen_basic_apic_ops(void)
35658 {
35659 apic->read = xen_apic_read;
35660 apic->write = xen_apic_write;
35661 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35662 #endif
35663 };
35664
35665 -static void xen_reboot(int reason)
35666 +static __noreturn void xen_reboot(int reason)
35667 {
35668 struct sched_shutdown r = { .reason = reason };
35669
35670 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35671 - BUG();
35672 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35673 + BUG();
35674 }
35675
35676 -static void xen_restart(char *msg)
35677 +static __noreturn void xen_restart(char *msg)
35678 {
35679 xen_reboot(SHUTDOWN_reboot);
35680 }
35681
35682 -static void xen_emergency_restart(void)
35683 +static __noreturn void xen_emergency_restart(void)
35684 {
35685 xen_reboot(SHUTDOWN_reboot);
35686 }
35687
35688 -static void xen_machine_halt(void)
35689 +static __noreturn void xen_machine_halt(void)
35690 {
35691 xen_reboot(SHUTDOWN_poweroff);
35692 }
35693
35694 -static void xen_machine_power_off(void)
35695 +static __noreturn void xen_machine_power_off(void)
35696 {
35697 if (pm_power_off)
35698 pm_power_off();
35699 @@ -1456,8 +1452,11 @@ static void __ref xen_setup_gdt(int cpu)
35700 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35701 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35702
35703 - setup_stack_canary_segment(0);
35704 - switch_to_new_gdt(0);
35705 + setup_stack_canary_segment(cpu);
35706 +#ifdef CONFIG_X86_64
35707 + load_percpu_segment(cpu);
35708 +#endif
35709 + switch_to_new_gdt(cpu);
35710
35711 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35712 pv_cpu_ops.load_gdt = xen_load_gdt;
35713 @@ -1573,7 +1572,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35714 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35715
35716 /* Work out if we support NX */
35717 - x86_configure_nx();
35718 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35719 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35720 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35721 + unsigned l, h;
35722 +
35723 + __supported_pte_mask |= _PAGE_NX;
35724 + rdmsr(MSR_EFER, l, h);
35725 + l |= EFER_NX;
35726 + wrmsr(MSR_EFER, l, h);
35727 + }
35728 +#endif
35729
35730 /* Get mfn list */
35731 xen_build_dynamic_phys_to_machine();
35732 @@ -1601,13 +1610,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35733
35734 machine_ops = xen_machine_ops;
35735
35736 - /*
35737 - * The only reliable way to retain the initial address of the
35738 - * percpu gdt_page is to remember it here, so we can go and
35739 - * mark it RW later, when the initial percpu area is freed.
35740 - */
35741 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35742 -
35743 xen_smp_init();
35744
35745 #ifdef CONFIG_ACPI_NUMA
35746 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35747 index a8a1a3d..8216142 100644
35748 --- a/arch/x86/xen/mmu.c
35749 +++ b/arch/x86/xen/mmu.c
35750 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35751 return val;
35752 }
35753
35754 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35755 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35756 {
35757 if (val & _PAGE_PRESENT) {
35758 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35759 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35760 * L3_k[511] -> level2_fixmap_pgt */
35761 convert_pfn_mfn(level3_kernel_pgt);
35762
35763 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35764 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35765 + convert_pfn_mfn(level3_vmemmap_pgt);
35766 /* L3_k[511][506] -> level1_fixmap_pgt */
35767 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35768 convert_pfn_mfn(level2_fixmap_pgt);
35769 }
35770 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35771 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35772 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35773 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35774 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35775 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35776 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35777 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35778 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35779 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35780 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35781 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35782 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35783 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35784 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35785
35786 /* Pin down new L4 */
35787 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35788 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35789 pv_mmu_ops.set_pud = xen_set_pud;
35790 #if PAGETABLE_LEVELS == 4
35791 pv_mmu_ops.set_pgd = xen_set_pgd;
35792 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35793 #endif
35794
35795 /* This will work as long as patching hasn't happened yet
35796 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35797 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35798 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35799 .set_pgd = xen_set_pgd_hyper,
35800 + .set_pgd_batched = xen_set_pgd_hyper,
35801
35802 .alloc_pud = xen_alloc_pmd_init,
35803 .release_pud = xen_release_pmd_init,
35804 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35805 index 4c071ae..00e7049 100644
35806 --- a/arch/x86/xen/smp.c
35807 +++ b/arch/x86/xen/smp.c
35808 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35809
35810 if (xen_pv_domain()) {
35811 if (!xen_feature(XENFEAT_writable_page_tables))
35812 - /* We've switched to the "real" per-cpu gdt, so make
35813 - * sure the old memory can be recycled. */
35814 - make_lowmem_page_readwrite(xen_initial_gdt);
35815 -
35816 #ifdef CONFIG_X86_32
35817 /*
35818 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35819 * expects __USER_DS
35820 */
35821 - loadsegment(ds, __USER_DS);
35822 - loadsegment(es, __USER_DS);
35823 + loadsegment(ds, __KERNEL_DS);
35824 + loadsegment(es, __KERNEL_DS);
35825 #endif
35826
35827 xen_filter_cpu_maps();
35828 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35829 #ifdef CONFIG_X86_32
35830 /* Note: PVH is not yet supported on x86_32. */
35831 ctxt->user_regs.fs = __KERNEL_PERCPU;
35832 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35833 + savesegment(gs, ctxt->user_regs.gs);
35834 #endif
35835 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35836
35837 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35838 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35839 ctxt->flags = VGCF_IN_KERNEL;
35840 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35841 - ctxt->user_regs.ds = __USER_DS;
35842 - ctxt->user_regs.es = __USER_DS;
35843 + ctxt->user_regs.ds = __KERNEL_DS;
35844 + ctxt->user_regs.es = __KERNEL_DS;
35845 ctxt->user_regs.ss = __KERNEL_DS;
35846
35847 xen_copy_trap_info(ctxt->trap_ctxt);
35848 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35849 int rc;
35850
35851 per_cpu(current_task, cpu) = idle;
35852 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35853 #ifdef CONFIG_X86_32
35854 irq_ctx_init(cpu);
35855 #else
35856 clear_tsk_thread_flag(idle, TIF_FORK);
35857 #endif
35858 - per_cpu(kernel_stack, cpu) =
35859 - (unsigned long)task_stack_page(idle) -
35860 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35861 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35862
35863 xen_setup_runstate_info(cpu);
35864 xen_setup_timer(cpu);
35865 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35866
35867 void __init xen_smp_init(void)
35868 {
35869 - smp_ops = xen_smp_ops;
35870 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35871 xen_fill_possible_map();
35872 }
35873
35874 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35875 index fd92a64..1f72641 100644
35876 --- a/arch/x86/xen/xen-asm_32.S
35877 +++ b/arch/x86/xen/xen-asm_32.S
35878 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35879 pushw %fs
35880 movl $(__KERNEL_PERCPU), %eax
35881 movl %eax, %fs
35882 - movl %fs:xen_vcpu, %eax
35883 + mov PER_CPU_VAR(xen_vcpu), %eax
35884 POP_FS
35885 #else
35886 movl %ss:xen_vcpu, %eax
35887 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35888 index 674b2225..f1f5dc1 100644
35889 --- a/arch/x86/xen/xen-head.S
35890 +++ b/arch/x86/xen/xen-head.S
35891 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35892 #ifdef CONFIG_X86_32
35893 mov %esi,xen_start_info
35894 mov $init_thread_union+THREAD_SIZE,%esp
35895 +#ifdef CONFIG_SMP
35896 + movl $cpu_gdt_table,%edi
35897 + movl $__per_cpu_load,%eax
35898 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35899 + rorl $16,%eax
35900 + movb %al,__KERNEL_PERCPU + 4(%edi)
35901 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35902 + movl $__per_cpu_end - 1,%eax
35903 + subl $__per_cpu_start,%eax
35904 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35905 +#endif
35906 #else
35907 mov %rsi,xen_start_info
35908 mov $init_thread_union+THREAD_SIZE,%rsp
35909 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35910 index 28c7e0b..2acfec7 100644
35911 --- a/arch/x86/xen/xen-ops.h
35912 +++ b/arch/x86/xen/xen-ops.h
35913 @@ -10,8 +10,6 @@
35914 extern const char xen_hypervisor_callback[];
35915 extern const char xen_failsafe_callback[];
35916
35917 -extern void *xen_initial_gdt;
35918 -
35919 struct trap_info;
35920 void xen_copy_trap_info(struct trap_info *traps);
35921
35922 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35923 index 525bd3d..ef888b1 100644
35924 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35925 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35926 @@ -119,9 +119,9 @@
35927 ----------------------------------------------------------------------*/
35928
35929 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35930 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35931 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35932 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35933 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35934
35935 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35936 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35937 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35938 index 2f33760..835e50a 100644
35939 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35940 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35941 @@ -11,6 +11,7 @@
35942 #ifndef _XTENSA_CORE_H
35943 #define _XTENSA_CORE_H
35944
35945 +#include <linux/const.h>
35946
35947 /****************************************************************************
35948 Parameters Useful for Any Code, USER or PRIVILEGED
35949 @@ -112,9 +113,9 @@
35950 ----------------------------------------------------------------------*/
35951
35952 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35953 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35954 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35955 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35956 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35957
35958 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35959 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35960 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35961 index af00795..2bb8105 100644
35962 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35963 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35964 @@ -11,6 +11,7 @@
35965 #ifndef _XTENSA_CORE_CONFIGURATION_H
35966 #define _XTENSA_CORE_CONFIGURATION_H
35967
35968 +#include <linux/const.h>
35969
35970 /****************************************************************************
35971 Parameters Useful for Any Code, USER or PRIVILEGED
35972 @@ -118,9 +119,9 @@
35973 ----------------------------------------------------------------------*/
35974
35975 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35976 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35977 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35978 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35979 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35980
35981 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35982 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35983 diff --git a/block/bio.c b/block/bio.c
35984 index 3e6e198..5c65199 100644
35985 --- a/block/bio.c
35986 +++ b/block/bio.c
35987 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
35988 /*
35989 * Overflow, abort
35990 */
35991 - if (end < start)
35992 + if (end < start || end - start > INT_MAX - nr_pages)
35993 return ERR_PTR(-EINVAL);
35994
35995 nr_pages += end - start;
35996 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
35997 /*
35998 * Overflow, abort
35999 */
36000 - if (end < start)
36001 + if (end < start || end - start > INT_MAX - nr_pages)
36002 return ERR_PTR(-EINVAL);
36003
36004 nr_pages += end - start;
36005 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36006 const int read = bio_data_dir(bio) == READ;
36007 struct bio_map_data *bmd = bio->bi_private;
36008 int i;
36009 - char *p = bmd->sgvecs[0].iov_base;
36010 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36011
36012 bio_for_each_segment_all(bvec, bio, i) {
36013 char *addr = page_address(bvec->bv_page);
36014 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36015 index 0736729..2ec3b48 100644
36016 --- a/block/blk-iopoll.c
36017 +++ b/block/blk-iopoll.c
36018 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36019 }
36020 EXPORT_SYMBOL(blk_iopoll_complete);
36021
36022 -static void blk_iopoll_softirq(struct softirq_action *h)
36023 +static __latent_entropy void blk_iopoll_softirq(void)
36024 {
36025 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36026 int rearm = 0, budget = blk_iopoll_budget;
36027 diff --git a/block/blk-map.c b/block/blk-map.c
36028 index f890d43..97b0482 100644
36029 --- a/block/blk-map.c
36030 +++ b/block/blk-map.c
36031 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36032 if (!len || !kbuf)
36033 return -EINVAL;
36034
36035 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36036 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36037 if (do_copy)
36038 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36039 else
36040 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36041 index 53b1737..08177d2e 100644
36042 --- a/block/blk-softirq.c
36043 +++ b/block/blk-softirq.c
36044 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36045 * Softirq action handler - move entries to local list and loop over them
36046 * while passing them to the queue registered handler.
36047 */
36048 -static void blk_done_softirq(struct softirq_action *h)
36049 +static __latent_entropy void blk_done_softirq(void)
36050 {
36051 struct list_head *cpu_list, local_list;
36052
36053 diff --git a/block/bsg.c b/block/bsg.c
36054 index 276e869..6fe4c61 100644
36055 --- a/block/bsg.c
36056 +++ b/block/bsg.c
36057 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36058 struct sg_io_v4 *hdr, struct bsg_device *bd,
36059 fmode_t has_write_perm)
36060 {
36061 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36062 + unsigned char *cmdptr;
36063 +
36064 if (hdr->request_len > BLK_MAX_CDB) {
36065 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36066 if (!rq->cmd)
36067 return -ENOMEM;
36068 - }
36069 + cmdptr = rq->cmd;
36070 + } else
36071 + cmdptr = tmpcmd;
36072
36073 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36074 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36075 hdr->request_len))
36076 return -EFAULT;
36077
36078 + if (cmdptr != rq->cmd)
36079 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36080 +
36081 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36082 if (blk_verify_command(rq->cmd, has_write_perm))
36083 return -EPERM;
36084 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36085 index f678c73..f35aa18 100644
36086 --- a/block/compat_ioctl.c
36087 +++ b/block/compat_ioctl.c
36088 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36089 cgc = compat_alloc_user_space(sizeof(*cgc));
36090 cgc32 = compat_ptr(arg);
36091
36092 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36093 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36094 get_user(data, &cgc32->buffer) ||
36095 put_user(compat_ptr(data), &cgc->buffer) ||
36096 copy_in_user(&cgc->buflen, &cgc32->buflen,
36097 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36098 err |= __get_user(f->spec1, &uf->spec1);
36099 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36100 err |= __get_user(name, &uf->name);
36101 - f->name = compat_ptr(name);
36102 + f->name = (void __force_kernel *)compat_ptr(name);
36103 if (err) {
36104 err = -EFAULT;
36105 goto out;
36106 diff --git a/block/genhd.c b/block/genhd.c
36107 index 0a536dc..b8f7aca 100644
36108 --- a/block/genhd.c
36109 +++ b/block/genhd.c
36110 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36111
36112 /*
36113 * Register device numbers dev..(dev+range-1)
36114 - * range must be nonzero
36115 + * Noop if @range is zero.
36116 * The hash chain is sorted on range, so that subranges can override.
36117 */
36118 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36119 struct kobject *(*probe)(dev_t, int *, void *),
36120 int (*lock)(dev_t, void *), void *data)
36121 {
36122 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36123 + if (range)
36124 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36125 }
36126
36127 EXPORT_SYMBOL(blk_register_region);
36128
36129 +/* undo blk_register_region(), noop if @range is zero */
36130 void blk_unregister_region(dev_t devt, unsigned long range)
36131 {
36132 - kobj_unmap(bdev_map, devt, range);
36133 + if (range)
36134 + kobj_unmap(bdev_map, devt, range);
36135 }
36136
36137 EXPORT_SYMBOL(blk_unregister_region);
36138 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36139 index 56d08fd..2e07090 100644
36140 --- a/block/partitions/efi.c
36141 +++ b/block/partitions/efi.c
36142 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36143 if (!gpt)
36144 return NULL;
36145
36146 + if (!le32_to_cpu(gpt->num_partition_entries))
36147 + return NULL;
36148 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36149 + if (!pte)
36150 + return NULL;
36151 +
36152 count = le32_to_cpu(gpt->num_partition_entries) *
36153 le32_to_cpu(gpt->sizeof_partition_entry);
36154 - if (!count)
36155 - return NULL;
36156 - pte = kmalloc(count, GFP_KERNEL);
36157 - if (!pte)
36158 - return NULL;
36159 -
36160 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36161 (u8 *) pte, count) < count) {
36162 kfree(pte);
36163 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36164 index b0c2a61..10bb6ec 100644
36165 --- a/block/scsi_ioctl.c
36166 +++ b/block/scsi_ioctl.c
36167 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36168 return put_user(0, p);
36169 }
36170
36171 -static int sg_get_timeout(struct request_queue *q)
36172 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36173 {
36174 return jiffies_to_clock_t(q->sg_timeout);
36175 }
36176 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36177 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36178 struct sg_io_hdr *hdr, fmode_t mode)
36179 {
36180 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36181 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36182 + unsigned char *cmdptr;
36183 +
36184 + if (rq->cmd != rq->__cmd)
36185 + cmdptr = rq->cmd;
36186 + else
36187 + cmdptr = tmpcmd;
36188 +
36189 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36190 return -EFAULT;
36191 +
36192 + if (cmdptr != rq->cmd)
36193 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36194 +
36195 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36196 return -EPERM;
36197
36198 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36199 int err;
36200 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36201 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36202 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36203 + unsigned char *cmdptr;
36204
36205 if (!sic)
36206 return -EINVAL;
36207 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36208 */
36209 err = -EFAULT;
36210 rq->cmd_len = cmdlen;
36211 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36212 +
36213 + if (rq->cmd != rq->__cmd)
36214 + cmdptr = rq->cmd;
36215 + else
36216 + cmdptr = tmpcmd;
36217 +
36218 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36219 goto error;
36220
36221 + if (rq->cmd != cmdptr)
36222 + memcpy(rq->cmd, cmdptr, cmdlen);
36223 +
36224 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36225 goto error;
36226
36227 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36228 index 650afac1..f3307de 100644
36229 --- a/crypto/cryptd.c
36230 +++ b/crypto/cryptd.c
36231 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36232
36233 struct cryptd_blkcipher_request_ctx {
36234 crypto_completion_t complete;
36235 -};
36236 +} __no_const;
36237
36238 struct cryptd_hash_ctx {
36239 struct crypto_shash *child;
36240 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36241
36242 struct cryptd_aead_request_ctx {
36243 crypto_completion_t complete;
36244 -};
36245 +} __no_const;
36246
36247 static void cryptd_queue_worker(struct work_struct *work);
36248
36249 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36250 index c305d41..a96de79 100644
36251 --- a/crypto/pcrypt.c
36252 +++ b/crypto/pcrypt.c
36253 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36254 int ret;
36255
36256 pinst->kobj.kset = pcrypt_kset;
36257 - ret = kobject_add(&pinst->kobj, NULL, name);
36258 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36259 if (!ret)
36260 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36261
36262 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36263 index 6921c7f..78e1af7 100644
36264 --- a/drivers/acpi/acpica/hwxfsleep.c
36265 +++ b/drivers/acpi/acpica/hwxfsleep.c
36266 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36267 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36268
36269 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36270 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36271 - acpi_hw_extended_sleep},
36272 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36273 - acpi_hw_extended_wake_prep},
36274 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36275 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36276 + .extended_function = acpi_hw_extended_sleep},
36277 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36278 + .extended_function = acpi_hw_extended_wake_prep},
36279 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36280 + .extended_function = acpi_hw_extended_wake}
36281 };
36282
36283 /*
36284 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36285 index 16129c7..8b675cd 100644
36286 --- a/drivers/acpi/apei/apei-internal.h
36287 +++ b/drivers/acpi/apei/apei-internal.h
36288 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36289 struct apei_exec_ins_type {
36290 u32 flags;
36291 apei_exec_ins_func_t run;
36292 -};
36293 +} __do_const;
36294
36295 struct apei_exec_context {
36296 u32 ip;
36297 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36298 index fc5f780..e5ac91a 100644
36299 --- a/drivers/acpi/apei/ghes.c
36300 +++ b/drivers/acpi/apei/ghes.c
36301 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36302 const struct acpi_hest_generic *generic,
36303 const struct acpi_hest_generic_status *estatus)
36304 {
36305 - static atomic_t seqno;
36306 + static atomic_unchecked_t seqno;
36307 unsigned int curr_seqno;
36308 char pfx_seq[64];
36309
36310 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36311 else
36312 pfx = KERN_ERR;
36313 }
36314 - curr_seqno = atomic_inc_return(&seqno);
36315 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36316 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36317 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36318 pfx_seq, generic->header.source_id);
36319 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36320 index a83e3c6..c3d617f 100644
36321 --- a/drivers/acpi/bgrt.c
36322 +++ b/drivers/acpi/bgrt.c
36323 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36324 if (!bgrt_image)
36325 return -ENODEV;
36326
36327 - bin_attr_image.private = bgrt_image;
36328 - bin_attr_image.size = bgrt_image_size;
36329 + pax_open_kernel();
36330 + *(void **)&bin_attr_image.private = bgrt_image;
36331 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36332 + pax_close_kernel();
36333
36334 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36335 if (!bgrt_kobj)
36336 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36337 index 7556e7c..89a96bd 100644
36338 --- a/drivers/acpi/blacklist.c
36339 +++ b/drivers/acpi/blacklist.c
36340 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36341 u32 is_critical_error;
36342 };
36343
36344 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36345 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36346
36347 /*
36348 * POLICY: If *anything* doesn't work, put it on the blacklist.
36349 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36350 return 0;
36351 }
36352
36353 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36354 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36355 {
36356 .callback = dmi_disable_osi_vista,
36357 .ident = "Fujitsu Siemens",
36358 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36359 index c68e724..e863008 100644
36360 --- a/drivers/acpi/custom_method.c
36361 +++ b/drivers/acpi/custom_method.c
36362 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36363 struct acpi_table_header table;
36364 acpi_status status;
36365
36366 +#ifdef CONFIG_GRKERNSEC_KMEM
36367 + return -EPERM;
36368 +#endif
36369 +
36370 if (!(*ppos)) {
36371 /* parse the table header to get the table length */
36372 if (count <= sizeof(struct acpi_table_header))
36373 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36374 index 6341e66..ebcf59c 100644
36375 --- a/drivers/acpi/device_pm.c
36376 +++ b/drivers/acpi/device_pm.c
36377 @@ -1029,6 +1029,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36378
36379 #endif /* CONFIG_PM_SLEEP */
36380
36381 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36382 +
36383 static struct dev_pm_domain acpi_general_pm_domain = {
36384 .ops = {
36385 #ifdef CONFIG_PM_RUNTIME
36386 @@ -1047,6 +1049,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36387 .restore_early = acpi_subsys_resume_early,
36388 #endif
36389 },
36390 + .detach = acpi_dev_pm_detach
36391 };
36392
36393 /**
36394 @@ -1116,7 +1119,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36395 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36396 }
36397
36398 - dev->pm_domain->detach = acpi_dev_pm_detach;
36399 return 0;
36400 }
36401 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36402 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36403 index 17f9ec5..d9a455e 100644
36404 --- a/drivers/acpi/processor_idle.c
36405 +++ b/drivers/acpi/processor_idle.c
36406 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36407 {
36408 int i, count = CPUIDLE_DRIVER_STATE_START;
36409 struct acpi_processor_cx *cx;
36410 - struct cpuidle_state *state;
36411 + cpuidle_state_no_const *state;
36412 struct cpuidle_driver *drv = &acpi_idle_driver;
36413
36414 if (!pr->flags.power_setup_done)
36415 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36416 index 13e577c..cef11ee 100644
36417 --- a/drivers/acpi/sysfs.c
36418 +++ b/drivers/acpi/sysfs.c
36419 @@ -423,11 +423,11 @@ static u32 num_counters;
36420 static struct attribute **all_attrs;
36421 static u32 acpi_gpe_count;
36422
36423 -static struct attribute_group interrupt_stats_attr_group = {
36424 +static attribute_group_no_const interrupt_stats_attr_group = {
36425 .name = "interrupts",
36426 };
36427
36428 -static struct kobj_attribute *counter_attrs;
36429 +static kobj_attribute_no_const *counter_attrs;
36430
36431 static void delete_gpe_attr_array(void)
36432 {
36433 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36434 index 97683e4..655f6ba 100644
36435 --- a/drivers/ata/libahci.c
36436 +++ b/drivers/ata/libahci.c
36437 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36438 }
36439 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36440
36441 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36442 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36443 struct ata_taskfile *tf, int is_cmd, u16 flags,
36444 unsigned long timeout_msec)
36445 {
36446 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36447 index 485f7ea..9a8df4a 100644
36448 --- a/drivers/ata/libata-core.c
36449 +++ b/drivers/ata/libata-core.c
36450 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36451 static void ata_dev_xfermask(struct ata_device *dev);
36452 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36453
36454 -atomic_t ata_print_id = ATOMIC_INIT(0);
36455 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36456
36457 struct ata_force_param {
36458 const char *name;
36459 @@ -4800,7 +4800,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36460 struct ata_port *ap;
36461 unsigned int tag;
36462
36463 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36464 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36465 ap = qc->ap;
36466
36467 qc->flags = 0;
36468 @@ -4816,7 +4816,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36469 struct ata_port *ap;
36470 struct ata_link *link;
36471
36472 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36473 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36474 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36475 ap = qc->ap;
36476 link = qc->dev->link;
36477 @@ -5920,6 +5920,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36478 return;
36479
36480 spin_lock(&lock);
36481 + pax_open_kernel();
36482
36483 for (cur = ops->inherits; cur; cur = cur->inherits) {
36484 void **inherit = (void **)cur;
36485 @@ -5933,8 +5934,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36486 if (IS_ERR(*pp))
36487 *pp = NULL;
36488
36489 - ops->inherits = NULL;
36490 + *(struct ata_port_operations **)&ops->inherits = NULL;
36491
36492 + pax_close_kernel();
36493 spin_unlock(&lock);
36494 }
36495
36496 @@ -6130,7 +6132,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36497
36498 /* give ports names and add SCSI hosts */
36499 for (i = 0; i < host->n_ports; i++) {
36500 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36501 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36502 host->ports[i]->local_port_no = i + 1;
36503 }
36504
36505 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36506 index 0586f66..1a8f74a 100644
36507 --- a/drivers/ata/libata-scsi.c
36508 +++ b/drivers/ata/libata-scsi.c
36509 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36510
36511 if (rc)
36512 return rc;
36513 - ap->print_id = atomic_inc_return(&ata_print_id);
36514 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36515 return 0;
36516 }
36517 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36518 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36519 index 5f4e0cc..ff2c347 100644
36520 --- a/drivers/ata/libata.h
36521 +++ b/drivers/ata/libata.h
36522 @@ -53,7 +53,7 @@ enum {
36523 ATA_DNXFER_QUIET = (1 << 31),
36524 };
36525
36526 -extern atomic_t ata_print_id;
36527 +extern atomic_unchecked_t ata_print_id;
36528 extern int atapi_passthru16;
36529 extern int libata_fua;
36530 extern int libata_noacpi;
36531 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36532 index 38216b9..4ec6aeb 100644
36533 --- a/drivers/ata/pata_arasan_cf.c
36534 +++ b/drivers/ata/pata_arasan_cf.c
36535 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36536 /* Handle platform specific quirks */
36537 if (quirk) {
36538 if (quirk & CF_BROKEN_PIO) {
36539 - ap->ops->set_piomode = NULL;
36540 + pax_open_kernel();
36541 + *(void **)&ap->ops->set_piomode = NULL;
36542 + pax_close_kernel();
36543 ap->pio_mask = 0;
36544 }
36545 if (quirk & CF_BROKEN_MWDMA)
36546 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36547 index f9b983a..887b9d8 100644
36548 --- a/drivers/atm/adummy.c
36549 +++ b/drivers/atm/adummy.c
36550 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36551 vcc->pop(vcc, skb);
36552 else
36553 dev_kfree_skb_any(skb);
36554 - atomic_inc(&vcc->stats->tx);
36555 + atomic_inc_unchecked(&vcc->stats->tx);
36556
36557 return 0;
36558 }
36559 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36560 index f1a9198..f466a4a 100644
36561 --- a/drivers/atm/ambassador.c
36562 +++ b/drivers/atm/ambassador.c
36563 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36564 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36565
36566 // VC layer stats
36567 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36568 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36569
36570 // free the descriptor
36571 kfree (tx_descr);
36572 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36573 dump_skb ("<<<", vc, skb);
36574
36575 // VC layer stats
36576 - atomic_inc(&atm_vcc->stats->rx);
36577 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36578 __net_timestamp(skb);
36579 // end of our responsibility
36580 atm_vcc->push (atm_vcc, skb);
36581 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36582 } else {
36583 PRINTK (KERN_INFO, "dropped over-size frame");
36584 // should we count this?
36585 - atomic_inc(&atm_vcc->stats->rx_drop);
36586 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36587 }
36588
36589 } else {
36590 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36591 }
36592
36593 if (check_area (skb->data, skb->len)) {
36594 - atomic_inc(&atm_vcc->stats->tx_err);
36595 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36596 return -ENOMEM; // ?
36597 }
36598
36599 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36600 index 480fa6f..947067c 100644
36601 --- a/drivers/atm/atmtcp.c
36602 +++ b/drivers/atm/atmtcp.c
36603 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36604 if (vcc->pop) vcc->pop(vcc,skb);
36605 else dev_kfree_skb(skb);
36606 if (dev_data) return 0;
36607 - atomic_inc(&vcc->stats->tx_err);
36608 + atomic_inc_unchecked(&vcc->stats->tx_err);
36609 return -ENOLINK;
36610 }
36611 size = skb->len+sizeof(struct atmtcp_hdr);
36612 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36613 if (!new_skb) {
36614 if (vcc->pop) vcc->pop(vcc,skb);
36615 else dev_kfree_skb(skb);
36616 - atomic_inc(&vcc->stats->tx_err);
36617 + atomic_inc_unchecked(&vcc->stats->tx_err);
36618 return -ENOBUFS;
36619 }
36620 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36621 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36622 if (vcc->pop) vcc->pop(vcc,skb);
36623 else dev_kfree_skb(skb);
36624 out_vcc->push(out_vcc,new_skb);
36625 - atomic_inc(&vcc->stats->tx);
36626 - atomic_inc(&out_vcc->stats->rx);
36627 + atomic_inc_unchecked(&vcc->stats->tx);
36628 + atomic_inc_unchecked(&out_vcc->stats->rx);
36629 return 0;
36630 }
36631
36632 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36633 read_unlock(&vcc_sklist_lock);
36634 if (!out_vcc) {
36635 result = -EUNATCH;
36636 - atomic_inc(&vcc->stats->tx_err);
36637 + atomic_inc_unchecked(&vcc->stats->tx_err);
36638 goto done;
36639 }
36640 skb_pull(skb,sizeof(struct atmtcp_hdr));
36641 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36642 __net_timestamp(new_skb);
36643 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36644 out_vcc->push(out_vcc,new_skb);
36645 - atomic_inc(&vcc->stats->tx);
36646 - atomic_inc(&out_vcc->stats->rx);
36647 + atomic_inc_unchecked(&vcc->stats->tx);
36648 + atomic_inc_unchecked(&out_vcc->stats->rx);
36649 done:
36650 if (vcc->pop) vcc->pop(vcc,skb);
36651 else dev_kfree_skb(skb);
36652 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36653 index d65975a..0b87e20 100644
36654 --- a/drivers/atm/eni.c
36655 +++ b/drivers/atm/eni.c
36656 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36657 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36658 vcc->dev->number);
36659 length = 0;
36660 - atomic_inc(&vcc->stats->rx_err);
36661 + atomic_inc_unchecked(&vcc->stats->rx_err);
36662 }
36663 else {
36664 length = ATM_CELL_SIZE-1; /* no HEC */
36665 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36666 size);
36667 }
36668 eff = length = 0;
36669 - atomic_inc(&vcc->stats->rx_err);
36670 + atomic_inc_unchecked(&vcc->stats->rx_err);
36671 }
36672 else {
36673 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36674 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36675 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36676 vcc->dev->number,vcc->vci,length,size << 2,descr);
36677 length = eff = 0;
36678 - atomic_inc(&vcc->stats->rx_err);
36679 + atomic_inc_unchecked(&vcc->stats->rx_err);
36680 }
36681 }
36682 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36683 @@ -767,7 +767,7 @@ rx_dequeued++;
36684 vcc->push(vcc,skb);
36685 pushed++;
36686 }
36687 - atomic_inc(&vcc->stats->rx);
36688 + atomic_inc_unchecked(&vcc->stats->rx);
36689 }
36690 wake_up(&eni_dev->rx_wait);
36691 }
36692 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36693 PCI_DMA_TODEVICE);
36694 if (vcc->pop) vcc->pop(vcc,skb);
36695 else dev_kfree_skb_irq(skb);
36696 - atomic_inc(&vcc->stats->tx);
36697 + atomic_inc_unchecked(&vcc->stats->tx);
36698 wake_up(&eni_dev->tx_wait);
36699 dma_complete++;
36700 }
36701 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36702 index 82f2ae0..f205c02 100644
36703 --- a/drivers/atm/firestream.c
36704 +++ b/drivers/atm/firestream.c
36705 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36706 }
36707 }
36708
36709 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36710 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36711
36712 fs_dprintk (FS_DEBUG_TXMEM, "i");
36713 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36714 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36715 #endif
36716 skb_put (skb, qe->p1 & 0xffff);
36717 ATM_SKB(skb)->vcc = atm_vcc;
36718 - atomic_inc(&atm_vcc->stats->rx);
36719 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36720 __net_timestamp(skb);
36721 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36722 atm_vcc->push (atm_vcc, skb);
36723 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36724 kfree (pe);
36725 }
36726 if (atm_vcc)
36727 - atomic_inc(&atm_vcc->stats->rx_drop);
36728 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36729 break;
36730 case 0x1f: /* Reassembly abort: no buffers. */
36731 /* Silently increment error counter. */
36732 if (atm_vcc)
36733 - atomic_inc(&atm_vcc->stats->rx_drop);
36734 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36735 break;
36736 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36737 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36738 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36739 index d4725fc..2d4ea65 100644
36740 --- a/drivers/atm/fore200e.c
36741 +++ b/drivers/atm/fore200e.c
36742 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36743 #endif
36744 /* check error condition */
36745 if (*entry->status & STATUS_ERROR)
36746 - atomic_inc(&vcc->stats->tx_err);
36747 + atomic_inc_unchecked(&vcc->stats->tx_err);
36748 else
36749 - atomic_inc(&vcc->stats->tx);
36750 + atomic_inc_unchecked(&vcc->stats->tx);
36751 }
36752 }
36753
36754 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36755 if (skb == NULL) {
36756 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36757
36758 - atomic_inc(&vcc->stats->rx_drop);
36759 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36760 return -ENOMEM;
36761 }
36762
36763 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36764
36765 dev_kfree_skb_any(skb);
36766
36767 - atomic_inc(&vcc->stats->rx_drop);
36768 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36769 return -ENOMEM;
36770 }
36771
36772 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36773
36774 vcc->push(vcc, skb);
36775 - atomic_inc(&vcc->stats->rx);
36776 + atomic_inc_unchecked(&vcc->stats->rx);
36777
36778 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36779
36780 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36781 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36782 fore200e->atm_dev->number,
36783 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36784 - atomic_inc(&vcc->stats->rx_err);
36785 + atomic_inc_unchecked(&vcc->stats->rx_err);
36786 }
36787 }
36788
36789 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36790 goto retry_here;
36791 }
36792
36793 - atomic_inc(&vcc->stats->tx_err);
36794 + atomic_inc_unchecked(&vcc->stats->tx_err);
36795
36796 fore200e->tx_sat++;
36797 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36798 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36799 index c39702b..785b73b 100644
36800 --- a/drivers/atm/he.c
36801 +++ b/drivers/atm/he.c
36802 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36803
36804 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36805 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36806 - atomic_inc(&vcc->stats->rx_drop);
36807 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36808 goto return_host_buffers;
36809 }
36810
36811 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36812 RBRQ_LEN_ERR(he_dev->rbrq_head)
36813 ? "LEN_ERR" : "",
36814 vcc->vpi, vcc->vci);
36815 - atomic_inc(&vcc->stats->rx_err);
36816 + atomic_inc_unchecked(&vcc->stats->rx_err);
36817 goto return_host_buffers;
36818 }
36819
36820 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36821 vcc->push(vcc, skb);
36822 spin_lock(&he_dev->global_lock);
36823
36824 - atomic_inc(&vcc->stats->rx);
36825 + atomic_inc_unchecked(&vcc->stats->rx);
36826
36827 return_host_buffers:
36828 ++pdus_assembled;
36829 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36830 tpd->vcc->pop(tpd->vcc, tpd->skb);
36831 else
36832 dev_kfree_skb_any(tpd->skb);
36833 - atomic_inc(&tpd->vcc->stats->tx_err);
36834 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36835 }
36836 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36837 return;
36838 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36839 vcc->pop(vcc, skb);
36840 else
36841 dev_kfree_skb_any(skb);
36842 - atomic_inc(&vcc->stats->tx_err);
36843 + atomic_inc_unchecked(&vcc->stats->tx_err);
36844 return -EINVAL;
36845 }
36846
36847 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36848 vcc->pop(vcc, skb);
36849 else
36850 dev_kfree_skb_any(skb);
36851 - atomic_inc(&vcc->stats->tx_err);
36852 + atomic_inc_unchecked(&vcc->stats->tx_err);
36853 return -EINVAL;
36854 }
36855 #endif
36856 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36857 vcc->pop(vcc, skb);
36858 else
36859 dev_kfree_skb_any(skb);
36860 - atomic_inc(&vcc->stats->tx_err);
36861 + atomic_inc_unchecked(&vcc->stats->tx_err);
36862 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36863 return -ENOMEM;
36864 }
36865 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36866 vcc->pop(vcc, skb);
36867 else
36868 dev_kfree_skb_any(skb);
36869 - atomic_inc(&vcc->stats->tx_err);
36870 + atomic_inc_unchecked(&vcc->stats->tx_err);
36871 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36872 return -ENOMEM;
36873 }
36874 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36875 __enqueue_tpd(he_dev, tpd, cid);
36876 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36877
36878 - atomic_inc(&vcc->stats->tx);
36879 + atomic_inc_unchecked(&vcc->stats->tx);
36880
36881 return 0;
36882 }
36883 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36884 index 1dc0519..1aadaf7 100644
36885 --- a/drivers/atm/horizon.c
36886 +++ b/drivers/atm/horizon.c
36887 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36888 {
36889 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36890 // VC layer stats
36891 - atomic_inc(&vcc->stats->rx);
36892 + atomic_inc_unchecked(&vcc->stats->rx);
36893 __net_timestamp(skb);
36894 // end of our responsibility
36895 vcc->push (vcc, skb);
36896 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36897 dev->tx_iovec = NULL;
36898
36899 // VC layer stats
36900 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36901 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36902
36903 // free the skb
36904 hrz_kfree_skb (skb);
36905 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36906 index 2b24ed0..b3d6acc 100644
36907 --- a/drivers/atm/idt77252.c
36908 +++ b/drivers/atm/idt77252.c
36909 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36910 else
36911 dev_kfree_skb(skb);
36912
36913 - atomic_inc(&vcc->stats->tx);
36914 + atomic_inc_unchecked(&vcc->stats->tx);
36915 }
36916
36917 atomic_dec(&scq->used);
36918 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36919 if ((sb = dev_alloc_skb(64)) == NULL) {
36920 printk("%s: Can't allocate buffers for aal0.\n",
36921 card->name);
36922 - atomic_add(i, &vcc->stats->rx_drop);
36923 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36924 break;
36925 }
36926 if (!atm_charge(vcc, sb->truesize)) {
36927 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36928 card->name);
36929 - atomic_add(i - 1, &vcc->stats->rx_drop);
36930 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36931 dev_kfree_skb(sb);
36932 break;
36933 }
36934 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36935 ATM_SKB(sb)->vcc = vcc;
36936 __net_timestamp(sb);
36937 vcc->push(vcc, sb);
36938 - atomic_inc(&vcc->stats->rx);
36939 + atomic_inc_unchecked(&vcc->stats->rx);
36940
36941 cell += ATM_CELL_PAYLOAD;
36942 }
36943 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36944 "(CDC: %08x)\n",
36945 card->name, len, rpp->len, readl(SAR_REG_CDC));
36946 recycle_rx_pool_skb(card, rpp);
36947 - atomic_inc(&vcc->stats->rx_err);
36948 + atomic_inc_unchecked(&vcc->stats->rx_err);
36949 return;
36950 }
36951 if (stat & SAR_RSQE_CRC) {
36952 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36953 recycle_rx_pool_skb(card, rpp);
36954 - atomic_inc(&vcc->stats->rx_err);
36955 + atomic_inc_unchecked(&vcc->stats->rx_err);
36956 return;
36957 }
36958 if (skb_queue_len(&rpp->queue) > 1) {
36959 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36960 RXPRINTK("%s: Can't alloc RX skb.\n",
36961 card->name);
36962 recycle_rx_pool_skb(card, rpp);
36963 - atomic_inc(&vcc->stats->rx_err);
36964 + atomic_inc_unchecked(&vcc->stats->rx_err);
36965 return;
36966 }
36967 if (!atm_charge(vcc, skb->truesize)) {
36968 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36969 __net_timestamp(skb);
36970
36971 vcc->push(vcc, skb);
36972 - atomic_inc(&vcc->stats->rx);
36973 + atomic_inc_unchecked(&vcc->stats->rx);
36974
36975 return;
36976 }
36977 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36978 __net_timestamp(skb);
36979
36980 vcc->push(vcc, skb);
36981 - atomic_inc(&vcc->stats->rx);
36982 + atomic_inc_unchecked(&vcc->stats->rx);
36983
36984 if (skb->truesize > SAR_FB_SIZE_3)
36985 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36986 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36987 if (vcc->qos.aal != ATM_AAL0) {
36988 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36989 card->name, vpi, vci);
36990 - atomic_inc(&vcc->stats->rx_drop);
36991 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36992 goto drop;
36993 }
36994
36995 if ((sb = dev_alloc_skb(64)) == NULL) {
36996 printk("%s: Can't allocate buffers for AAL0.\n",
36997 card->name);
36998 - atomic_inc(&vcc->stats->rx_err);
36999 + atomic_inc_unchecked(&vcc->stats->rx_err);
37000 goto drop;
37001 }
37002
37003 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37004 ATM_SKB(sb)->vcc = vcc;
37005 __net_timestamp(sb);
37006 vcc->push(vcc, sb);
37007 - atomic_inc(&vcc->stats->rx);
37008 + atomic_inc_unchecked(&vcc->stats->rx);
37009
37010 drop:
37011 skb_pull(queue, 64);
37012 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37013
37014 if (vc == NULL) {
37015 printk("%s: NULL connection in send().\n", card->name);
37016 - atomic_inc(&vcc->stats->tx_err);
37017 + atomic_inc_unchecked(&vcc->stats->tx_err);
37018 dev_kfree_skb(skb);
37019 return -EINVAL;
37020 }
37021 if (!test_bit(VCF_TX, &vc->flags)) {
37022 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37023 - atomic_inc(&vcc->stats->tx_err);
37024 + atomic_inc_unchecked(&vcc->stats->tx_err);
37025 dev_kfree_skb(skb);
37026 return -EINVAL;
37027 }
37028 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37029 break;
37030 default:
37031 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37032 - atomic_inc(&vcc->stats->tx_err);
37033 + atomic_inc_unchecked(&vcc->stats->tx_err);
37034 dev_kfree_skb(skb);
37035 return -EINVAL;
37036 }
37037
37038 if (skb_shinfo(skb)->nr_frags != 0) {
37039 printk("%s: No scatter-gather yet.\n", card->name);
37040 - atomic_inc(&vcc->stats->tx_err);
37041 + atomic_inc_unchecked(&vcc->stats->tx_err);
37042 dev_kfree_skb(skb);
37043 return -EINVAL;
37044 }
37045 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37046
37047 err = queue_skb(card, vc, skb, oam);
37048 if (err) {
37049 - atomic_inc(&vcc->stats->tx_err);
37050 + atomic_inc_unchecked(&vcc->stats->tx_err);
37051 dev_kfree_skb(skb);
37052 return err;
37053 }
37054 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37055 skb = dev_alloc_skb(64);
37056 if (!skb) {
37057 printk("%s: Out of memory in send_oam().\n", card->name);
37058 - atomic_inc(&vcc->stats->tx_err);
37059 + atomic_inc_unchecked(&vcc->stats->tx_err);
37060 return -ENOMEM;
37061 }
37062 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37063 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37064 index 4217f29..88f547a 100644
37065 --- a/drivers/atm/iphase.c
37066 +++ b/drivers/atm/iphase.c
37067 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37068 status = (u_short) (buf_desc_ptr->desc_mode);
37069 if (status & (RX_CER | RX_PTE | RX_OFL))
37070 {
37071 - atomic_inc(&vcc->stats->rx_err);
37072 + atomic_inc_unchecked(&vcc->stats->rx_err);
37073 IF_ERR(printk("IA: bad packet, dropping it");)
37074 if (status & RX_CER) {
37075 IF_ERR(printk(" cause: packet CRC error\n");)
37076 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37077 len = dma_addr - buf_addr;
37078 if (len > iadev->rx_buf_sz) {
37079 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37080 - atomic_inc(&vcc->stats->rx_err);
37081 + atomic_inc_unchecked(&vcc->stats->rx_err);
37082 goto out_free_desc;
37083 }
37084
37085 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37086 ia_vcc = INPH_IA_VCC(vcc);
37087 if (ia_vcc == NULL)
37088 {
37089 - atomic_inc(&vcc->stats->rx_err);
37090 + atomic_inc_unchecked(&vcc->stats->rx_err);
37091 atm_return(vcc, skb->truesize);
37092 dev_kfree_skb_any(skb);
37093 goto INCR_DLE;
37094 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37095 if ((length > iadev->rx_buf_sz) || (length >
37096 (skb->len - sizeof(struct cpcs_trailer))))
37097 {
37098 - atomic_inc(&vcc->stats->rx_err);
37099 + atomic_inc_unchecked(&vcc->stats->rx_err);
37100 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37101 length, skb->len);)
37102 atm_return(vcc, skb->truesize);
37103 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37104
37105 IF_RX(printk("rx_dle_intr: skb push");)
37106 vcc->push(vcc,skb);
37107 - atomic_inc(&vcc->stats->rx);
37108 + atomic_inc_unchecked(&vcc->stats->rx);
37109 iadev->rx_pkt_cnt++;
37110 }
37111 INCR_DLE:
37112 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37113 {
37114 struct k_sonet_stats *stats;
37115 stats = &PRIV(_ia_dev[board])->sonet_stats;
37116 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37117 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37118 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37119 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37120 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37121 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37122 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37123 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37124 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37125 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37126 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37127 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37128 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37129 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37130 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37131 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37132 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37133 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37134 }
37135 ia_cmds.status = 0;
37136 break;
37137 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37138 if ((desc == 0) || (desc > iadev->num_tx_desc))
37139 {
37140 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37141 - atomic_inc(&vcc->stats->tx);
37142 + atomic_inc_unchecked(&vcc->stats->tx);
37143 if (vcc->pop)
37144 vcc->pop(vcc, skb);
37145 else
37146 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37147 ATM_DESC(skb) = vcc->vci;
37148 skb_queue_tail(&iadev->tx_dma_q, skb);
37149
37150 - atomic_inc(&vcc->stats->tx);
37151 + atomic_inc_unchecked(&vcc->stats->tx);
37152 iadev->tx_pkt_cnt++;
37153 /* Increment transaction counter */
37154 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37155
37156 #if 0
37157 /* add flow control logic */
37158 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37159 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37160 if (iavcc->vc_desc_cnt > 10) {
37161 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37162 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37163 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37164 index 93eaf8d..b4ca7da 100644
37165 --- a/drivers/atm/lanai.c
37166 +++ b/drivers/atm/lanai.c
37167 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37168 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37169 lanai_endtx(lanai, lvcc);
37170 lanai_free_skb(lvcc->tx.atmvcc, skb);
37171 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37172 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37173 }
37174
37175 /* Try to fill the buffer - don't call unless there is backlog */
37176 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37177 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37178 __net_timestamp(skb);
37179 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37180 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37181 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37182 out:
37183 lvcc->rx.buf.ptr = end;
37184 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37185 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37186 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37187 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37188 lanai->stats.service_rxnotaal5++;
37189 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37190 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37191 return 0;
37192 }
37193 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37194 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37195 int bytes;
37196 read_unlock(&vcc_sklist_lock);
37197 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37198 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37199 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37200 lvcc->stats.x.aal5.service_trash++;
37201 bytes = (SERVICE_GET_END(s) * 16) -
37202 (((unsigned long) lvcc->rx.buf.ptr) -
37203 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37204 }
37205 if (s & SERVICE_STREAM) {
37206 read_unlock(&vcc_sklist_lock);
37207 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37208 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37209 lvcc->stats.x.aal5.service_stream++;
37210 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37211 "PDU on VCI %d!\n", lanai->number, vci);
37212 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37213 return 0;
37214 }
37215 DPRINTK("got rx crc error on vci %d\n", vci);
37216 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37217 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37218 lvcc->stats.x.aal5.service_rxcrc++;
37219 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37220 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37221 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37222 index 9988ac9..7c52585 100644
37223 --- a/drivers/atm/nicstar.c
37224 +++ b/drivers/atm/nicstar.c
37225 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37226 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37227 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37228 card->index);
37229 - atomic_inc(&vcc->stats->tx_err);
37230 + atomic_inc_unchecked(&vcc->stats->tx_err);
37231 dev_kfree_skb_any(skb);
37232 return -EINVAL;
37233 }
37234 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37235 if (!vc->tx) {
37236 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37237 card->index);
37238 - atomic_inc(&vcc->stats->tx_err);
37239 + atomic_inc_unchecked(&vcc->stats->tx_err);
37240 dev_kfree_skb_any(skb);
37241 return -EINVAL;
37242 }
37243 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37244 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37245 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37246 card->index);
37247 - atomic_inc(&vcc->stats->tx_err);
37248 + atomic_inc_unchecked(&vcc->stats->tx_err);
37249 dev_kfree_skb_any(skb);
37250 return -EINVAL;
37251 }
37252
37253 if (skb_shinfo(skb)->nr_frags != 0) {
37254 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37255 - atomic_inc(&vcc->stats->tx_err);
37256 + atomic_inc_unchecked(&vcc->stats->tx_err);
37257 dev_kfree_skb_any(skb);
37258 return -EINVAL;
37259 }
37260 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37261 }
37262
37263 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37264 - atomic_inc(&vcc->stats->tx_err);
37265 + atomic_inc_unchecked(&vcc->stats->tx_err);
37266 dev_kfree_skb_any(skb);
37267 return -EIO;
37268 }
37269 - atomic_inc(&vcc->stats->tx);
37270 + atomic_inc_unchecked(&vcc->stats->tx);
37271
37272 return 0;
37273 }
37274 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37275 printk
37276 ("nicstar%d: Can't allocate buffers for aal0.\n",
37277 card->index);
37278 - atomic_add(i, &vcc->stats->rx_drop);
37279 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37280 break;
37281 }
37282 if (!atm_charge(vcc, sb->truesize)) {
37283 RXPRINTK
37284 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37285 card->index);
37286 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37287 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37288 dev_kfree_skb_any(sb);
37289 break;
37290 }
37291 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37292 ATM_SKB(sb)->vcc = vcc;
37293 __net_timestamp(sb);
37294 vcc->push(vcc, sb);
37295 - atomic_inc(&vcc->stats->rx);
37296 + atomic_inc_unchecked(&vcc->stats->rx);
37297 cell += ATM_CELL_PAYLOAD;
37298 }
37299
37300 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37301 if (iovb == NULL) {
37302 printk("nicstar%d: Out of iovec buffers.\n",
37303 card->index);
37304 - atomic_inc(&vcc->stats->rx_drop);
37305 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37306 recycle_rx_buf(card, skb);
37307 return;
37308 }
37309 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37310 small or large buffer itself. */
37311 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37312 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37313 - atomic_inc(&vcc->stats->rx_err);
37314 + atomic_inc_unchecked(&vcc->stats->rx_err);
37315 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37316 NS_MAX_IOVECS);
37317 NS_PRV_IOVCNT(iovb) = 0;
37318 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37319 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37320 card->index);
37321 which_list(card, skb);
37322 - atomic_inc(&vcc->stats->rx_err);
37323 + atomic_inc_unchecked(&vcc->stats->rx_err);
37324 recycle_rx_buf(card, skb);
37325 vc->rx_iov = NULL;
37326 recycle_iov_buf(card, iovb);
37327 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37328 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37329 card->index);
37330 which_list(card, skb);
37331 - atomic_inc(&vcc->stats->rx_err);
37332 + atomic_inc_unchecked(&vcc->stats->rx_err);
37333 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37334 NS_PRV_IOVCNT(iovb));
37335 vc->rx_iov = NULL;
37336 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37337 printk(" - PDU size mismatch.\n");
37338 else
37339 printk(".\n");
37340 - atomic_inc(&vcc->stats->rx_err);
37341 + atomic_inc_unchecked(&vcc->stats->rx_err);
37342 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37343 NS_PRV_IOVCNT(iovb));
37344 vc->rx_iov = NULL;
37345 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37346 /* skb points to a small buffer */
37347 if (!atm_charge(vcc, skb->truesize)) {
37348 push_rxbufs(card, skb);
37349 - atomic_inc(&vcc->stats->rx_drop);
37350 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37351 } else {
37352 skb_put(skb, len);
37353 dequeue_sm_buf(card, skb);
37354 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37355 ATM_SKB(skb)->vcc = vcc;
37356 __net_timestamp(skb);
37357 vcc->push(vcc, skb);
37358 - atomic_inc(&vcc->stats->rx);
37359 + atomic_inc_unchecked(&vcc->stats->rx);
37360 }
37361 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37362 struct sk_buff *sb;
37363 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37364 if (len <= NS_SMBUFSIZE) {
37365 if (!atm_charge(vcc, sb->truesize)) {
37366 push_rxbufs(card, sb);
37367 - atomic_inc(&vcc->stats->rx_drop);
37368 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37369 } else {
37370 skb_put(sb, len);
37371 dequeue_sm_buf(card, sb);
37372 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37373 ATM_SKB(sb)->vcc = vcc;
37374 __net_timestamp(sb);
37375 vcc->push(vcc, sb);
37376 - atomic_inc(&vcc->stats->rx);
37377 + atomic_inc_unchecked(&vcc->stats->rx);
37378 }
37379
37380 push_rxbufs(card, skb);
37381 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37382
37383 if (!atm_charge(vcc, skb->truesize)) {
37384 push_rxbufs(card, skb);
37385 - atomic_inc(&vcc->stats->rx_drop);
37386 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37387 } else {
37388 dequeue_lg_buf(card, skb);
37389 #ifdef NS_USE_DESTRUCTORS
37390 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37391 ATM_SKB(skb)->vcc = vcc;
37392 __net_timestamp(skb);
37393 vcc->push(vcc, skb);
37394 - atomic_inc(&vcc->stats->rx);
37395 + atomic_inc_unchecked(&vcc->stats->rx);
37396 }
37397
37398 push_rxbufs(card, sb);
37399 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37400 printk
37401 ("nicstar%d: Out of huge buffers.\n",
37402 card->index);
37403 - atomic_inc(&vcc->stats->rx_drop);
37404 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37405 recycle_iovec_rx_bufs(card,
37406 (struct iovec *)
37407 iovb->data,
37408 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37409 card->hbpool.count++;
37410 } else
37411 dev_kfree_skb_any(hb);
37412 - atomic_inc(&vcc->stats->rx_drop);
37413 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37414 } else {
37415 /* Copy the small buffer to the huge buffer */
37416 sb = (struct sk_buff *)iov->iov_base;
37417 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37418 #endif /* NS_USE_DESTRUCTORS */
37419 __net_timestamp(hb);
37420 vcc->push(vcc, hb);
37421 - atomic_inc(&vcc->stats->rx);
37422 + atomic_inc_unchecked(&vcc->stats->rx);
37423 }
37424 }
37425
37426 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37427 index 21b0bc6..b5f40ba 100644
37428 --- a/drivers/atm/solos-pci.c
37429 +++ b/drivers/atm/solos-pci.c
37430 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37431 }
37432 atm_charge(vcc, skb->truesize);
37433 vcc->push(vcc, skb);
37434 - atomic_inc(&vcc->stats->rx);
37435 + atomic_inc_unchecked(&vcc->stats->rx);
37436 break;
37437
37438 case PKT_STATUS:
37439 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37440 vcc = SKB_CB(oldskb)->vcc;
37441
37442 if (vcc) {
37443 - atomic_inc(&vcc->stats->tx);
37444 + atomic_inc_unchecked(&vcc->stats->tx);
37445 solos_pop(vcc, oldskb);
37446 } else {
37447 dev_kfree_skb_irq(oldskb);
37448 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37449 index 0215934..ce9f5b1 100644
37450 --- a/drivers/atm/suni.c
37451 +++ b/drivers/atm/suni.c
37452 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37453
37454
37455 #define ADD_LIMITED(s,v) \
37456 - atomic_add((v),&stats->s); \
37457 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37458 + atomic_add_unchecked((v),&stats->s); \
37459 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37460
37461
37462 static void suni_hz(unsigned long from_timer)
37463 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37464 index 5120a96..e2572bd 100644
37465 --- a/drivers/atm/uPD98402.c
37466 +++ b/drivers/atm/uPD98402.c
37467 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37468 struct sonet_stats tmp;
37469 int error = 0;
37470
37471 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37472 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37473 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37474 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37475 if (zero && !error) {
37476 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37477
37478
37479 #define ADD_LIMITED(s,v) \
37480 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37481 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37482 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37483 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37484 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37485 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37486
37487
37488 static void stat_event(struct atm_dev *dev)
37489 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37490 if (reason & uPD98402_INT_PFM) stat_event(dev);
37491 if (reason & uPD98402_INT_PCO) {
37492 (void) GET(PCOCR); /* clear interrupt cause */
37493 - atomic_add(GET(HECCT),
37494 + atomic_add_unchecked(GET(HECCT),
37495 &PRIV(dev)->sonet_stats.uncorr_hcs);
37496 }
37497 if ((reason & uPD98402_INT_RFO) &&
37498 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37499 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37500 uPD98402_INT_LOS),PIMR); /* enable them */
37501 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37502 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37503 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37504 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37505 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37506 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37507 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37508 return 0;
37509 }
37510
37511 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37512 index 969c3c2..9b72956 100644
37513 --- a/drivers/atm/zatm.c
37514 +++ b/drivers/atm/zatm.c
37515 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37516 }
37517 if (!size) {
37518 dev_kfree_skb_irq(skb);
37519 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37520 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37521 continue;
37522 }
37523 if (!atm_charge(vcc,skb->truesize)) {
37524 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37525 skb->len = size;
37526 ATM_SKB(skb)->vcc = vcc;
37527 vcc->push(vcc,skb);
37528 - atomic_inc(&vcc->stats->rx);
37529 + atomic_inc_unchecked(&vcc->stats->rx);
37530 }
37531 zout(pos & 0xffff,MTA(mbx));
37532 #if 0 /* probably a stupid idea */
37533 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37534 skb_queue_head(&zatm_vcc->backlog,skb);
37535 break;
37536 }
37537 - atomic_inc(&vcc->stats->tx);
37538 + atomic_inc_unchecked(&vcc->stats->tx);
37539 wake_up(&zatm_vcc->tx_wait);
37540 }
37541
37542 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37543 index 876bae5..8978785 100644
37544 --- a/drivers/base/bus.c
37545 +++ b/drivers/base/bus.c
37546 @@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37547 return -EINVAL;
37548
37549 mutex_lock(&subsys->p->mutex);
37550 - list_add_tail(&sif->node, &subsys->p->interfaces);
37551 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37552 if (sif->add_dev) {
37553 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37554 while ((dev = subsys_dev_iter_next(&iter)))
37555 @@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37556 subsys = sif->subsys;
37557
37558 mutex_lock(&subsys->p->mutex);
37559 - list_del_init(&sif->node);
37560 + pax_list_del_init((struct list_head *)&sif->node);
37561 if (sif->remove_dev) {
37562 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37563 while ((dev = subsys_dev_iter_next(&iter)))
37564 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37565 index 25798db..15f130e 100644
37566 --- a/drivers/base/devtmpfs.c
37567 +++ b/drivers/base/devtmpfs.c
37568 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37569 if (!thread)
37570 return 0;
37571
37572 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37573 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37574 if (err)
37575 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37576 else
37577 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37578 *err = sys_unshare(CLONE_NEWNS);
37579 if (*err)
37580 goto out;
37581 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37582 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37583 if (*err)
37584 goto out;
37585 - sys_chdir("/.."); /* will traverse into overmounted root */
37586 - sys_chroot(".");
37587 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37588 + sys_chroot((char __force_user *)".");
37589 complete(&setup_done);
37590 while (1) {
37591 spin_lock(&req_lock);
37592 diff --git a/drivers/base/node.c b/drivers/base/node.c
37593 index 472168c..4af587e 100644
37594 --- a/drivers/base/node.c
37595 +++ b/drivers/base/node.c
37596 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37597 struct node_attr {
37598 struct device_attribute attr;
37599 enum node_states state;
37600 -};
37601 +} __do_const;
37602
37603 static ssize_t show_node_state(struct device *dev,
37604 struct device_attribute *attr, char *buf)
37605 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37606 index fb83d4a..e1797b3 100644
37607 --- a/drivers/base/power/domain.c
37608 +++ b/drivers/base/power/domain.c
37609 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37610 {
37611 struct cpuidle_driver *cpuidle_drv;
37612 struct gpd_cpuidle_data *cpuidle_data;
37613 - struct cpuidle_state *idle_state;
37614 + cpuidle_state_no_const *idle_state;
37615 int ret = 0;
37616
37617 if (IS_ERR_OR_NULL(genpd) || state < 0)
37618 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37619 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37620 {
37621 struct gpd_cpuidle_data *cpuidle_data;
37622 - struct cpuidle_state *idle_state;
37623 + cpuidle_state_no_const *idle_state;
37624 int ret = 0;
37625
37626 if (IS_ERR_OR_NULL(genpd))
37627 @@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37628 return ret;
37629 }
37630
37631 - dev->pm_domain->detach = genpd_dev_pm_detach;
37632 + pax_open_kernel();
37633 + *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37634 + pax_close_kernel();
37635
37636 return 0;
37637 }
37638 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37639 index a9d26ed..74b8405 100644
37640 --- a/drivers/base/power/sysfs.c
37641 +++ b/drivers/base/power/sysfs.c
37642 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37643 return -EIO;
37644 }
37645 }
37646 - return sprintf(buf, p);
37647 + return sprintf(buf, "%s", p);
37648 }
37649
37650 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37651 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37652 index c2744b3..08fac19 100644
37653 --- a/drivers/base/power/wakeup.c
37654 +++ b/drivers/base/power/wakeup.c
37655 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37656 * They need to be modified together atomically, so it's better to use one
37657 * atomic variable to hold them both.
37658 */
37659 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37660 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37661
37662 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37663 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37664
37665 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37666 {
37667 - unsigned int comb = atomic_read(&combined_event_count);
37668 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37669
37670 *cnt = (comb >> IN_PROGRESS_BITS);
37671 *inpr = comb & MAX_IN_PROGRESS;
37672 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37673 ws->start_prevent_time = ws->last_time;
37674
37675 /* Increment the counter of events in progress. */
37676 - cec = atomic_inc_return(&combined_event_count);
37677 + cec = atomic_inc_return_unchecked(&combined_event_count);
37678
37679 trace_wakeup_source_activate(ws->name, cec);
37680 }
37681 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37682 * Increment the counter of registered wakeup events and decrement the
37683 * couter of wakeup events in progress simultaneously.
37684 */
37685 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37686 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37687 trace_wakeup_source_deactivate(ws->name, cec);
37688
37689 split_counters(&cnt, &inpr);
37690 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37691 index 8d98a32..61d3165 100644
37692 --- a/drivers/base/syscore.c
37693 +++ b/drivers/base/syscore.c
37694 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37695 void register_syscore_ops(struct syscore_ops *ops)
37696 {
37697 mutex_lock(&syscore_ops_lock);
37698 - list_add_tail(&ops->node, &syscore_ops_list);
37699 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37700 mutex_unlock(&syscore_ops_lock);
37701 }
37702 EXPORT_SYMBOL_GPL(register_syscore_ops);
37703 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37704 void unregister_syscore_ops(struct syscore_ops *ops)
37705 {
37706 mutex_lock(&syscore_ops_lock);
37707 - list_del(&ops->node);
37708 + pax_list_del((struct list_head *)&ops->node);
37709 mutex_unlock(&syscore_ops_lock);
37710 }
37711 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37712 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37713 index ff20f19..018f1da 100644
37714 --- a/drivers/block/cciss.c
37715 +++ b/drivers/block/cciss.c
37716 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37717 while (!list_empty(&h->reqQ)) {
37718 c = list_entry(h->reqQ.next, CommandList_struct, list);
37719 /* can't do anything if fifo is full */
37720 - if ((h->access.fifo_full(h))) {
37721 + if ((h->access->fifo_full(h))) {
37722 dev_warn(&h->pdev->dev, "fifo full\n");
37723 break;
37724 }
37725 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37726 h->Qdepth--;
37727
37728 /* Tell the controller execute command */
37729 - h->access.submit_command(h, c);
37730 + h->access->submit_command(h, c);
37731
37732 /* Put job onto the completed Q */
37733 addQ(&h->cmpQ, c);
37734 @@ -3444,17 +3444,17 @@ startio:
37735
37736 static inline unsigned long get_next_completion(ctlr_info_t *h)
37737 {
37738 - return h->access.command_completed(h);
37739 + return h->access->command_completed(h);
37740 }
37741
37742 static inline int interrupt_pending(ctlr_info_t *h)
37743 {
37744 - return h->access.intr_pending(h);
37745 + return h->access->intr_pending(h);
37746 }
37747
37748 static inline long interrupt_not_for_us(ctlr_info_t *h)
37749 {
37750 - return ((h->access.intr_pending(h) == 0) ||
37751 + return ((h->access->intr_pending(h) == 0) ||
37752 (h->interrupts_enabled == 0));
37753 }
37754
37755 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37756 u32 a;
37757
37758 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37759 - return h->access.command_completed(h);
37760 + return h->access->command_completed(h);
37761
37762 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37763 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37764 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37765 trans_support & CFGTBL_Trans_use_short_tags);
37766
37767 /* Change the access methods to the performant access methods */
37768 - h->access = SA5_performant_access;
37769 + h->access = &SA5_performant_access;
37770 h->transMethod = CFGTBL_Trans_Performant;
37771
37772 return;
37773 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37774 if (prod_index < 0)
37775 return -ENODEV;
37776 h->product_name = products[prod_index].product_name;
37777 - h->access = *(products[prod_index].access);
37778 + h->access = products[prod_index].access;
37779
37780 if (cciss_board_disabled(h)) {
37781 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37782 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37783 }
37784
37785 /* make sure the board interrupts are off */
37786 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37787 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37788 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37789 if (rc)
37790 goto clean2;
37791 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37792 * fake ones to scoop up any residual completions.
37793 */
37794 spin_lock_irqsave(&h->lock, flags);
37795 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37796 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37797 spin_unlock_irqrestore(&h->lock, flags);
37798 free_irq(h->intr[h->intr_mode], h);
37799 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37800 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37801 dev_info(&h->pdev->dev, "Board READY.\n");
37802 dev_info(&h->pdev->dev,
37803 "Waiting for stale completions to drain.\n");
37804 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37805 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37806 msleep(10000);
37807 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37808 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37809
37810 rc = controller_reset_failed(h->cfgtable);
37811 if (rc)
37812 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37813 cciss_scsi_setup(h);
37814
37815 /* Turn the interrupts on so we can service requests */
37816 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37817 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37818
37819 /* Get the firmware version */
37820 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37821 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37822 kfree(flush_buf);
37823 if (return_code != IO_OK)
37824 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37825 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37826 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37827 free_irq(h->intr[h->intr_mode], h);
37828 }
37829
37830 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37831 index 7fda30e..2f27946 100644
37832 --- a/drivers/block/cciss.h
37833 +++ b/drivers/block/cciss.h
37834 @@ -101,7 +101,7 @@ struct ctlr_info
37835 /* information about each logical volume */
37836 drive_info_struct *drv[CISS_MAX_LUN];
37837
37838 - struct access_method access;
37839 + struct access_method *access;
37840
37841 /* queue and queue Info */
37842 struct list_head reqQ;
37843 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37844 }
37845
37846 static struct access_method SA5_access = {
37847 - SA5_submit_command,
37848 - SA5_intr_mask,
37849 - SA5_fifo_full,
37850 - SA5_intr_pending,
37851 - SA5_completed,
37852 + .submit_command = SA5_submit_command,
37853 + .set_intr_mask = SA5_intr_mask,
37854 + .fifo_full = SA5_fifo_full,
37855 + .intr_pending = SA5_intr_pending,
37856 + .command_completed = SA5_completed,
37857 };
37858
37859 static struct access_method SA5B_access = {
37860 - SA5_submit_command,
37861 - SA5B_intr_mask,
37862 - SA5_fifo_full,
37863 - SA5B_intr_pending,
37864 - SA5_completed,
37865 + .submit_command = SA5_submit_command,
37866 + .set_intr_mask = SA5B_intr_mask,
37867 + .fifo_full = SA5_fifo_full,
37868 + .intr_pending = SA5B_intr_pending,
37869 + .command_completed = SA5_completed,
37870 };
37871
37872 static struct access_method SA5_performant_access = {
37873 - SA5_submit_command,
37874 - SA5_performant_intr_mask,
37875 - SA5_fifo_full,
37876 - SA5_performant_intr_pending,
37877 - SA5_performant_completed,
37878 + .submit_command = SA5_submit_command,
37879 + .set_intr_mask = SA5_performant_intr_mask,
37880 + .fifo_full = SA5_fifo_full,
37881 + .intr_pending = SA5_performant_intr_pending,
37882 + .command_completed = SA5_performant_completed,
37883 };
37884
37885 struct board_type {
37886 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37887 index 2b94403..fd6ad1f 100644
37888 --- a/drivers/block/cpqarray.c
37889 +++ b/drivers/block/cpqarray.c
37890 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37891 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37892 goto Enomem4;
37893 }
37894 - hba[i]->access.set_intr_mask(hba[i], 0);
37895 + hba[i]->access->set_intr_mask(hba[i], 0);
37896 if (request_irq(hba[i]->intr, do_ida_intr,
37897 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37898 {
37899 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37900 add_timer(&hba[i]->timer);
37901
37902 /* Enable IRQ now that spinlock and rate limit timer are set up */
37903 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37904 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37905
37906 for(j=0; j<NWD; j++) {
37907 struct gendisk *disk = ida_gendisk[i][j];
37908 @@ -694,7 +694,7 @@ DBGINFO(
37909 for(i=0; i<NR_PRODUCTS; i++) {
37910 if (board_id == products[i].board_id) {
37911 c->product_name = products[i].product_name;
37912 - c->access = *(products[i].access);
37913 + c->access = products[i].access;
37914 break;
37915 }
37916 }
37917 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37918 hba[ctlr]->intr = intr;
37919 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37920 hba[ctlr]->product_name = products[j].product_name;
37921 - hba[ctlr]->access = *(products[j].access);
37922 + hba[ctlr]->access = products[j].access;
37923 hba[ctlr]->ctlr = ctlr;
37924 hba[ctlr]->board_id = board_id;
37925 hba[ctlr]->pci_dev = NULL; /* not PCI */
37926 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37927
37928 while((c = h->reqQ) != NULL) {
37929 /* Can't do anything if we're busy */
37930 - if (h->access.fifo_full(h) == 0)
37931 + if (h->access->fifo_full(h) == 0)
37932 return;
37933
37934 /* Get the first entry from the request Q */
37935 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37936 h->Qdepth--;
37937
37938 /* Tell the controller to do our bidding */
37939 - h->access.submit_command(h, c);
37940 + h->access->submit_command(h, c);
37941
37942 /* Get onto the completion Q */
37943 addQ(&h->cmpQ, c);
37944 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37945 unsigned long flags;
37946 __u32 a,a1;
37947
37948 - istat = h->access.intr_pending(h);
37949 + istat = h->access->intr_pending(h);
37950 /* Is this interrupt for us? */
37951 if (istat == 0)
37952 return IRQ_NONE;
37953 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37954 */
37955 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37956 if (istat & FIFO_NOT_EMPTY) {
37957 - while((a = h->access.command_completed(h))) {
37958 + while((a = h->access->command_completed(h))) {
37959 a1 = a; a &= ~3;
37960 if ((c = h->cmpQ) == NULL)
37961 {
37962 @@ -1448,11 +1448,11 @@ static int sendcmd(
37963 /*
37964 * Disable interrupt
37965 */
37966 - info_p->access.set_intr_mask(info_p, 0);
37967 + info_p->access->set_intr_mask(info_p, 0);
37968 /* Make sure there is room in the command FIFO */
37969 /* Actually it should be completely empty at this time. */
37970 for (i = 200000; i > 0; i--) {
37971 - temp = info_p->access.fifo_full(info_p);
37972 + temp = info_p->access->fifo_full(info_p);
37973 if (temp != 0) {
37974 break;
37975 }
37976 @@ -1465,7 +1465,7 @@ DBG(
37977 /*
37978 * Send the cmd
37979 */
37980 - info_p->access.submit_command(info_p, c);
37981 + info_p->access->submit_command(info_p, c);
37982 complete = pollcomplete(ctlr);
37983
37984 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37985 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37986 * we check the new geometry. Then turn interrupts back on when
37987 * we're done.
37988 */
37989 - host->access.set_intr_mask(host, 0);
37990 + host->access->set_intr_mask(host, 0);
37991 getgeometry(ctlr);
37992 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37993 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37994
37995 for(i=0; i<NWD; i++) {
37996 struct gendisk *disk = ida_gendisk[ctlr][i];
37997 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37998 /* Wait (up to 2 seconds) for a command to complete */
37999
38000 for (i = 200000; i > 0; i--) {
38001 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38002 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38003 if (done == 0) {
38004 udelay(10); /* a short fixed delay */
38005 } else
38006 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38007 index be73e9d..7fbf140 100644
38008 --- a/drivers/block/cpqarray.h
38009 +++ b/drivers/block/cpqarray.h
38010 @@ -99,7 +99,7 @@ struct ctlr_info {
38011 drv_info_t drv[NWD];
38012 struct proc_dir_entry *proc;
38013
38014 - struct access_method access;
38015 + struct access_method *access;
38016
38017 cmdlist_t *reqQ;
38018 cmdlist_t *cmpQ;
38019 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38020 index 434c77d..6d3219a 100644
38021 --- a/drivers/block/drbd/drbd_bitmap.c
38022 +++ b/drivers/block/drbd/drbd_bitmap.c
38023 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38024 submit_bio(rw, bio);
38025 /* this should not count as user activity and cause the
38026 * resync to throttle -- see drbd_rs_should_slow_down(). */
38027 - atomic_add(len >> 9, &device->rs_sect_ev);
38028 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38029 }
38030 }
38031
38032 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38033 index 9b22f8f..f2932af 100644
38034 --- a/drivers/block/drbd/drbd_int.h
38035 +++ b/drivers/block/drbd/drbd_int.h
38036 @@ -385,7 +385,7 @@ struct drbd_epoch {
38037 struct drbd_connection *connection;
38038 struct list_head list;
38039 unsigned int barrier_nr;
38040 - atomic_t epoch_size; /* increased on every request added. */
38041 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38042 atomic_t active; /* increased on every req. added, and dec on every finished. */
38043 unsigned long flags;
38044 };
38045 @@ -946,7 +946,7 @@ struct drbd_device {
38046 unsigned int al_tr_number;
38047 int al_tr_cycle;
38048 wait_queue_head_t seq_wait;
38049 - atomic_t packet_seq;
38050 + atomic_unchecked_t packet_seq;
38051 unsigned int peer_seq;
38052 spinlock_t peer_seq_lock;
38053 unsigned long comm_bm_set; /* communicated number of set bits. */
38054 @@ -955,8 +955,8 @@ struct drbd_device {
38055 struct mutex own_state_mutex;
38056 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38057 char congestion_reason; /* Why we where congested... */
38058 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38059 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38060 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38061 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38062 int rs_last_sect_ev; /* counter to compare with */
38063 int rs_last_events; /* counter of read or write "events" (unit sectors)
38064 * on the lower level device when we last looked. */
38065 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38066 char __user *uoptval;
38067 int err;
38068
38069 - uoptval = (char __user __force *)optval;
38070 + uoptval = (char __force_user *)optval;
38071
38072 set_fs(KERNEL_DS);
38073 if (level == SOL_SOCKET)
38074 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38075 index 973c185..05d8b1a 100644
38076 --- a/drivers/block/drbd/drbd_main.c
38077 +++ b/drivers/block/drbd/drbd_main.c
38078 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38079 p->sector = sector;
38080 p->block_id = block_id;
38081 p->blksize = blksize;
38082 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38083 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38084 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38085 }
38086
38087 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38088 return -EIO;
38089 p->sector = cpu_to_be64(req->i.sector);
38090 p->block_id = (unsigned long)req;
38091 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38092 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38093 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38094 if (device->state.conn >= C_SYNC_SOURCE &&
38095 device->state.conn <= C_PAUSED_SYNC_T)
38096 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38097 atomic_set(&device->unacked_cnt, 0);
38098 atomic_set(&device->local_cnt, 0);
38099 atomic_set(&device->pp_in_use_by_net, 0);
38100 - atomic_set(&device->rs_sect_in, 0);
38101 - atomic_set(&device->rs_sect_ev, 0);
38102 + atomic_set_unchecked(&device->rs_sect_in, 0);
38103 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38104 atomic_set(&device->ap_in_flight, 0);
38105 atomic_set(&device->md_io.in_use, 0);
38106
38107 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38108 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38109 struct drbd_resource *resource = connection->resource;
38110
38111 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38112 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38113 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38114 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38115 kfree(connection->current_epoch);
38116
38117 idr_destroy(&connection->peer_devices);
38118 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38119 index 1cd47df..57c53c0 100644
38120 --- a/drivers/block/drbd/drbd_nl.c
38121 +++ b/drivers/block/drbd/drbd_nl.c
38122 @@ -3645,13 +3645,13 @@ finish:
38123
38124 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38125 {
38126 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38127 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38128 struct sk_buff *msg;
38129 struct drbd_genlmsghdr *d_out;
38130 unsigned seq;
38131 int err = -ENOMEM;
38132
38133 - seq = atomic_inc_return(&drbd_genl_seq);
38134 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38135 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38136 if (!msg)
38137 goto failed;
38138 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38139 index 6960fb0..215d76b 100644
38140 --- a/drivers/block/drbd/drbd_receiver.c
38141 +++ b/drivers/block/drbd/drbd_receiver.c
38142 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38143 struct drbd_device *device = peer_device->device;
38144 int err;
38145
38146 - atomic_set(&device->packet_seq, 0);
38147 + atomic_set_unchecked(&device->packet_seq, 0);
38148 device->peer_seq = 0;
38149
38150 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38151 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38152 do {
38153 next_epoch = NULL;
38154
38155 - epoch_size = atomic_read(&epoch->epoch_size);
38156 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38157
38158 switch (ev & ~EV_CLEANUP) {
38159 case EV_PUT:
38160 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38161 rv = FE_DESTROYED;
38162 } else {
38163 epoch->flags = 0;
38164 - atomic_set(&epoch->epoch_size, 0);
38165 + atomic_set_unchecked(&epoch->epoch_size, 0);
38166 /* atomic_set(&epoch->active, 0); is already zero */
38167 if (rv == FE_STILL_LIVE)
38168 rv = FE_RECYCLED;
38169 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38170 conn_wait_active_ee_empty(connection);
38171 drbd_flush(connection);
38172
38173 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38174 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38175 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38176 if (epoch)
38177 break;
38178 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38179 }
38180
38181 epoch->flags = 0;
38182 - atomic_set(&epoch->epoch_size, 0);
38183 + atomic_set_unchecked(&epoch->epoch_size, 0);
38184 atomic_set(&epoch->active, 0);
38185
38186 spin_lock(&connection->epoch_lock);
38187 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38188 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38189 list_add(&epoch->list, &connection->current_epoch->list);
38190 connection->current_epoch = epoch;
38191 connection->epochs++;
38192 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38193 list_add_tail(&peer_req->w.list, &device->sync_ee);
38194 spin_unlock_irq(&device->resource->req_lock);
38195
38196 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38197 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38198 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38199 return 0;
38200
38201 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38202 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38203 }
38204
38205 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38206 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38207
38208 return err;
38209 }
38210 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38211
38212 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38213 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38214 - atomic_inc(&connection->current_epoch->epoch_size);
38215 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38216 err2 = drbd_drain_block(peer_device, pi->size);
38217 if (!err)
38218 err = err2;
38219 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38220
38221 spin_lock(&connection->epoch_lock);
38222 peer_req->epoch = connection->current_epoch;
38223 - atomic_inc(&peer_req->epoch->epoch_size);
38224 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38225 atomic_inc(&peer_req->epoch->active);
38226 spin_unlock(&connection->epoch_lock);
38227
38228 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38229
38230 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38231 (int)part_stat_read(&disk->part0, sectors[1]) -
38232 - atomic_read(&device->rs_sect_ev);
38233 + atomic_read_unchecked(&device->rs_sect_ev);
38234
38235 if (atomic_read(&device->ap_actlog_cnt)
38236 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38237 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38238 device->use_csums = true;
38239 } else if (pi->cmd == P_OV_REPLY) {
38240 /* track progress, we may need to throttle */
38241 - atomic_add(size >> 9, &device->rs_sect_in);
38242 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38243 peer_req->w.cb = w_e_end_ov_reply;
38244 dec_rs_pending(device);
38245 /* drbd_rs_begin_io done when we sent this request,
38246 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38247 goto out_free_e;
38248
38249 submit_for_resync:
38250 - atomic_add(size >> 9, &device->rs_sect_ev);
38251 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38252
38253 submit:
38254 update_receiver_timing_details(connection, drbd_submit_peer_request);
38255 @@ -4564,7 +4564,7 @@ struct data_cmd {
38256 int expect_payload;
38257 size_t pkt_size;
38258 int (*fn)(struct drbd_connection *, struct packet_info *);
38259 -};
38260 +} __do_const;
38261
38262 static struct data_cmd drbd_cmd_handler[] = {
38263 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38264 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38265 if (!list_empty(&connection->current_epoch->list))
38266 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38267 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38268 - atomic_set(&connection->current_epoch->epoch_size, 0);
38269 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38270 connection->send.seen_any_write_yet = false;
38271
38272 drbd_info(connection, "Connection closed\n");
38273 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38274 put_ldev(device);
38275 }
38276 dec_rs_pending(device);
38277 - atomic_add(blksize >> 9, &device->rs_sect_in);
38278 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38279
38280 return 0;
38281 }
38282 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38283 struct asender_cmd {
38284 size_t pkt_size;
38285 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38286 -};
38287 +} __do_const;
38288
38289 static struct asender_cmd asender_tbl[] = {
38290 [P_PING] = { 0, got_Ping },
38291 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38292 index d2d1f97..6a1188f 100644
38293 --- a/drivers/block/drbd/drbd_worker.c
38294 +++ b/drivers/block/drbd/drbd_worker.c
38295 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38296 list_add_tail(&peer_req->w.list, &device->read_ee);
38297 spin_unlock_irq(&device->resource->req_lock);
38298
38299 - atomic_add(size >> 9, &device->rs_sect_ev);
38300 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38301 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38302 return 0;
38303
38304 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38305 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38306 int number, mxb;
38307
38308 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38309 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38310 device->rs_in_flight -= sect_in;
38311
38312 rcu_read_lock();
38313 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38314 {
38315 struct fifo_buffer *plan;
38316
38317 - atomic_set(&device->rs_sect_in, 0);
38318 - atomic_set(&device->rs_sect_ev, 0);
38319 + atomic_set_unchecked(&device->rs_sect_in, 0);
38320 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38321 device->rs_in_flight = 0;
38322
38323 /* Updating the RCU protected object in place is necessary since
38324 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38325 index 6cb1beb..bf490f7 100644
38326 --- a/drivers/block/loop.c
38327 +++ b/drivers/block/loop.c
38328 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38329
38330 file_start_write(file);
38331 set_fs(get_ds());
38332 - bw = file->f_op->write(file, buf, len, &pos);
38333 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38334 set_fs(old_fs);
38335 file_end_write(file);
38336 if (likely(bw == len))
38337 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38338 index e2bb8af..44b8aef 100644
38339 --- a/drivers/block/nvme-core.c
38340 +++ b/drivers/block/nvme-core.c
38341 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38342 static struct task_struct *nvme_thread;
38343 static struct workqueue_struct *nvme_workq;
38344 static wait_queue_head_t nvme_kthread_wait;
38345 -static struct notifier_block nvme_nb;
38346
38347 static void nvme_reset_failed_dev(struct work_struct *ws);
38348
38349 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38350 .err_handler = &nvme_err_handler,
38351 };
38352
38353 +static struct notifier_block nvme_nb = {
38354 + .notifier_call = &nvme_cpu_notify,
38355 +};
38356 +
38357 static int __init nvme_init(void)
38358 {
38359 int result;
38360 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38361 else if (result > 0)
38362 nvme_major = result;
38363
38364 - nvme_nb.notifier_call = &nvme_cpu_notify;
38365 result = register_hotcpu_notifier(&nvme_nb);
38366 if (result)
38367 goto unregister_blkdev;
38368 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38369 index 09e628da..7607aaa 100644
38370 --- a/drivers/block/pktcdvd.c
38371 +++ b/drivers/block/pktcdvd.c
38372 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38373
38374 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38375 {
38376 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38377 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38378 }
38379
38380 /*
38381 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38382 return -EROFS;
38383 }
38384 pd->settings.fp = ti.fp;
38385 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38386 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38387
38388 if (ti.nwa_v) {
38389 pd->nwa = be32_to_cpu(ti.next_writable);
38390 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38391 index e5565fb..71be10b4 100644
38392 --- a/drivers/block/smart1,2.h
38393 +++ b/drivers/block/smart1,2.h
38394 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38395 }
38396
38397 static struct access_method smart4_access = {
38398 - smart4_submit_command,
38399 - smart4_intr_mask,
38400 - smart4_fifo_full,
38401 - smart4_intr_pending,
38402 - smart4_completed,
38403 + .submit_command = smart4_submit_command,
38404 + .set_intr_mask = smart4_intr_mask,
38405 + .fifo_full = smart4_fifo_full,
38406 + .intr_pending = smart4_intr_pending,
38407 + .command_completed = smart4_completed,
38408 };
38409
38410 /*
38411 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38412 }
38413
38414 static struct access_method smart2_access = {
38415 - smart2_submit_command,
38416 - smart2_intr_mask,
38417 - smart2_fifo_full,
38418 - smart2_intr_pending,
38419 - smart2_completed,
38420 + .submit_command = smart2_submit_command,
38421 + .set_intr_mask = smart2_intr_mask,
38422 + .fifo_full = smart2_fifo_full,
38423 + .intr_pending = smart2_intr_pending,
38424 + .command_completed = smart2_completed,
38425 };
38426
38427 /*
38428 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38429 }
38430
38431 static struct access_method smart2e_access = {
38432 - smart2e_submit_command,
38433 - smart2e_intr_mask,
38434 - smart2e_fifo_full,
38435 - smart2e_intr_pending,
38436 - smart2e_completed,
38437 + .submit_command = smart2e_submit_command,
38438 + .set_intr_mask = smart2e_intr_mask,
38439 + .fifo_full = smart2e_fifo_full,
38440 + .intr_pending = smart2e_intr_pending,
38441 + .command_completed = smart2e_completed,
38442 };
38443
38444 /*
38445 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38446 }
38447
38448 static struct access_method smart1_access = {
38449 - smart1_submit_command,
38450 - smart1_intr_mask,
38451 - smart1_fifo_full,
38452 - smart1_intr_pending,
38453 - smart1_completed,
38454 + .submit_command = smart1_submit_command,
38455 + .set_intr_mask = smart1_intr_mask,
38456 + .fifo_full = smart1_fifo_full,
38457 + .intr_pending = smart1_intr_pending,
38458 + .command_completed = smart1_completed,
38459 };
38460 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38461 index f038dba..bb74c08 100644
38462 --- a/drivers/bluetooth/btwilink.c
38463 +++ b/drivers/bluetooth/btwilink.c
38464 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38465
38466 static int bt_ti_probe(struct platform_device *pdev)
38467 {
38468 - static struct ti_st *hst;
38469 + struct ti_st *hst;
38470 struct hci_dev *hdev;
38471 int err;
38472
38473 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38474 index 5d28a45..a538f90 100644
38475 --- a/drivers/cdrom/cdrom.c
38476 +++ b/drivers/cdrom/cdrom.c
38477 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38478 ENSURE(reset, CDC_RESET);
38479 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38480 cdi->mc_flags = 0;
38481 - cdo->n_minors = 0;
38482 cdi->options = CDO_USE_FFLAGS;
38483
38484 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38485 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38486 else
38487 cdi->cdda_method = CDDA_OLD;
38488
38489 - if (!cdo->generic_packet)
38490 - cdo->generic_packet = cdrom_dummy_generic_packet;
38491 + if (!cdo->generic_packet) {
38492 + pax_open_kernel();
38493 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38494 + pax_close_kernel();
38495 + }
38496
38497 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38498 mutex_lock(&cdrom_mutex);
38499 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38500 if (cdi->exit)
38501 cdi->exit(cdi);
38502
38503 - cdi->ops->n_minors--;
38504 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38505 }
38506
38507 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38508 */
38509 nr = nframes;
38510 do {
38511 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38512 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38513 if (cgc.buffer)
38514 break;
38515
38516 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38517 struct cdrom_device_info *cdi;
38518 int ret;
38519
38520 - ret = scnprintf(info + *pos, max_size - *pos, header);
38521 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38522 if (!ret)
38523 return 1;
38524
38525 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38526 index 584bc31..e64a12c 100644
38527 --- a/drivers/cdrom/gdrom.c
38528 +++ b/drivers/cdrom/gdrom.c
38529 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38530 .audio_ioctl = gdrom_audio_ioctl,
38531 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38532 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38533 - .n_minors = 1,
38534 };
38535
38536 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38537 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38538 index efefd12..4f1d494 100644
38539 --- a/drivers/char/Kconfig
38540 +++ b/drivers/char/Kconfig
38541 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38542
38543 config DEVKMEM
38544 bool "/dev/kmem virtual device support"
38545 - default y
38546 + default n
38547 + depends on !GRKERNSEC_KMEM
38548 help
38549 Say Y here if you want to support the /dev/kmem device. The
38550 /dev/kmem device is rarely used, but can be used for certain
38551 @@ -577,6 +578,7 @@ config DEVPORT
38552 bool
38553 depends on !M68K
38554 depends on ISA || PCI
38555 + depends on !GRKERNSEC_KMEM
38556 default y
38557
38558 source "drivers/s390/char/Kconfig"
38559 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38560 index a48e05b..6bac831 100644
38561 --- a/drivers/char/agp/compat_ioctl.c
38562 +++ b/drivers/char/agp/compat_ioctl.c
38563 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38564 return -ENOMEM;
38565 }
38566
38567 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38568 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38569 sizeof(*usegment) * ureserve.seg_count)) {
38570 kfree(usegment);
38571 kfree(ksegment);
38572 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38573 index 09f17eb..8531d2f 100644
38574 --- a/drivers/char/agp/frontend.c
38575 +++ b/drivers/char/agp/frontend.c
38576 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38577 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38578 return -EFAULT;
38579
38580 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38581 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38582 return -EFAULT;
38583
38584 client = agp_find_client_by_pid(reserve.pid);
38585 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38586 if (segment == NULL)
38587 return -ENOMEM;
38588
38589 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38590 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38591 sizeof(struct agp_segment) * reserve.seg_count)) {
38592 kfree(segment);
38593 return -EFAULT;
38594 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38595 index 4f94375..413694e 100644
38596 --- a/drivers/char/genrtc.c
38597 +++ b/drivers/char/genrtc.c
38598 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38599 switch (cmd) {
38600
38601 case RTC_PLL_GET:
38602 + memset(&pll, 0, sizeof(pll));
38603 if (get_rtc_pll(&pll))
38604 return -EINVAL;
38605 else
38606 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38607 index d5d4cd8..22d561d 100644
38608 --- a/drivers/char/hpet.c
38609 +++ b/drivers/char/hpet.c
38610 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38611 }
38612
38613 static int
38614 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38615 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38616 struct hpet_info *info)
38617 {
38618 struct hpet_timer __iomem *timer;
38619 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38620 index f816211..89eadea 100644
38621 --- a/drivers/char/ipmi/ipmi_msghandler.c
38622 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38623 @@ -438,7 +438,7 @@ struct ipmi_smi {
38624 struct proc_dir_entry *proc_dir;
38625 char proc_dir_name[10];
38626
38627 - atomic_t stats[IPMI_NUM_STATS];
38628 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38629
38630 /*
38631 * run_to_completion duplicate of smb_info, smi_info
38632 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38633 static DEFINE_MUTEX(smi_watchers_mutex);
38634
38635 #define ipmi_inc_stat(intf, stat) \
38636 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38637 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38638 #define ipmi_get_stat(intf, stat) \
38639 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38640 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38641
38642 static int is_lan_addr(struct ipmi_addr *addr)
38643 {
38644 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38645 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38646 init_waitqueue_head(&intf->waitq);
38647 for (i = 0; i < IPMI_NUM_STATS; i++)
38648 - atomic_set(&intf->stats[i], 0);
38649 + atomic_set_unchecked(&intf->stats[i], 0);
38650
38651 intf->proc_dir = NULL;
38652
38653 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38654 index 5c4e1f6..0ea58f9 100644
38655 --- a/drivers/char/ipmi/ipmi_si_intf.c
38656 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38657 @@ -285,7 +285,7 @@ struct smi_info {
38658 unsigned char slave_addr;
38659
38660 /* Counters and things for the proc filesystem. */
38661 - atomic_t stats[SI_NUM_STATS];
38662 + atomic_unchecked_t stats[SI_NUM_STATS];
38663
38664 struct task_struct *thread;
38665
38666 @@ -294,9 +294,9 @@ struct smi_info {
38667 };
38668
38669 #define smi_inc_stat(smi, stat) \
38670 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38671 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38672 #define smi_get_stat(smi, stat) \
38673 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38674 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38675
38676 #define SI_MAX_PARMS 4
38677
38678 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38679 atomic_set(&new_smi->req_events, 0);
38680 new_smi->run_to_completion = false;
38681 for (i = 0; i < SI_NUM_STATS; i++)
38682 - atomic_set(&new_smi->stats[i], 0);
38683 + atomic_set_unchecked(&new_smi->stats[i], 0);
38684
38685 new_smi->interrupt_disabled = true;
38686 atomic_set(&new_smi->stop_operation, 0);
38687 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38688 index 524b707..62a3d70 100644
38689 --- a/drivers/char/mem.c
38690 +++ b/drivers/char/mem.c
38691 @@ -18,6 +18,7 @@
38692 #include <linux/raw.h>
38693 #include <linux/tty.h>
38694 #include <linux/capability.h>
38695 +#include <linux/security.h>
38696 #include <linux/ptrace.h>
38697 #include <linux/device.h>
38698 #include <linux/highmem.h>
38699 @@ -36,6 +37,10 @@
38700
38701 #define DEVPORT_MINOR 4
38702
38703 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38704 +extern const struct file_operations grsec_fops;
38705 +#endif
38706 +
38707 static inline unsigned long size_inside_page(unsigned long start,
38708 unsigned long size)
38709 {
38710 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38711
38712 while (cursor < to) {
38713 if (!devmem_is_allowed(pfn)) {
38714 +#ifdef CONFIG_GRKERNSEC_KMEM
38715 + gr_handle_mem_readwrite(from, to);
38716 +#else
38717 printk(KERN_INFO
38718 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38719 current->comm, from, to);
38720 +#endif
38721 return 0;
38722 }
38723 cursor += PAGE_SIZE;
38724 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38725 }
38726 return 1;
38727 }
38728 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38729 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38730 +{
38731 + return 0;
38732 +}
38733 #else
38734 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38735 {
38736 @@ -121,7 +135,8 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38737 #endif
38738
38739 while (count > 0) {
38740 - unsigned long remaining;
38741 + unsigned long remaining = 0;
38742 + char *temp;
38743
38744 sz = size_inside_page(p, count);
38745
38746 @@ -137,7 +152,24 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38747 if (!ptr)
38748 return -EFAULT;
38749
38750 - remaining = copy_to_user(buf, ptr, sz);
38751 +#ifdef CONFIG_PAX_USERCOPY
38752 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38753 + if (!temp) {
38754 + unxlate_dev_mem_ptr(p, ptr);
38755 + return -ENOMEM;
38756 + }
38757 + remaining = probe_kernel_read(temp, ptr, sz);
38758 +#else
38759 + temp = ptr;
38760 +#endif
38761 +
38762 + if (!remaining)
38763 + remaining = copy_to_user(buf, temp, sz);
38764 +
38765 +#ifdef CONFIG_PAX_USERCOPY
38766 + kfree(temp);
38767 +#endif
38768 +
38769 unxlate_dev_mem_ptr(p, ptr);
38770 if (remaining)
38771 return -EFAULT;
38772 @@ -369,9 +401,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38773 size_t count, loff_t *ppos)
38774 {
38775 unsigned long p = *ppos;
38776 - ssize_t low_count, read, sz;
38777 + ssize_t low_count, read, sz, err = 0;
38778 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38779 - int err = 0;
38780
38781 read = 0;
38782 if (p < (unsigned long) high_memory) {
38783 @@ -393,6 +424,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38784 }
38785 #endif
38786 while (low_count > 0) {
38787 + char *temp;
38788 +
38789 sz = size_inside_page(p, low_count);
38790
38791 /*
38792 @@ -402,7 +435,23 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38793 */
38794 kbuf = xlate_dev_kmem_ptr((char *)p);
38795
38796 - if (copy_to_user(buf, kbuf, sz))
38797 +#ifdef CONFIG_PAX_USERCOPY
38798 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38799 + if (!temp)
38800 + return -ENOMEM;
38801 + err = probe_kernel_read(temp, kbuf, sz);
38802 +#else
38803 + temp = kbuf;
38804 +#endif
38805 +
38806 + if (!err)
38807 + err = copy_to_user(buf, temp, sz);
38808 +
38809 +#ifdef CONFIG_PAX_USERCOPY
38810 + kfree(temp);
38811 +#endif
38812 +
38813 + if (err)
38814 return -EFAULT;
38815 buf += sz;
38816 p += sz;
38817 @@ -797,6 +846,9 @@ static const struct memdev {
38818 #ifdef CONFIG_PRINTK
38819 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38820 #endif
38821 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38822 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38823 +#endif
38824 };
38825
38826 static int memory_open(struct inode *inode, struct file *filp)
38827 @@ -868,7 +920,7 @@ static int __init chr_dev_init(void)
38828 continue;
38829
38830 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38831 - NULL, devlist[minor].name);
38832 + NULL, "%s", devlist[minor].name);
38833 }
38834
38835 return tty_init();
38836 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38837 index 9df78e2..01ba9ae 100644
38838 --- a/drivers/char/nvram.c
38839 +++ b/drivers/char/nvram.c
38840 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38841
38842 spin_unlock_irq(&rtc_lock);
38843
38844 - if (copy_to_user(buf, contents, tmp - contents))
38845 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38846 return -EFAULT;
38847
38848 *ppos = i;
38849 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38850 index 0ea9986..e7b07e4 100644
38851 --- a/drivers/char/pcmcia/synclink_cs.c
38852 +++ b/drivers/char/pcmcia/synclink_cs.c
38853 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38854
38855 if (debug_level >= DEBUG_LEVEL_INFO)
38856 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38857 - __FILE__, __LINE__, info->device_name, port->count);
38858 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38859
38860 if (tty_port_close_start(port, tty, filp) == 0)
38861 goto cleanup;
38862 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38863 cleanup:
38864 if (debug_level >= DEBUG_LEVEL_INFO)
38865 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38866 - tty->driver->name, port->count);
38867 + tty->driver->name, atomic_read(&port->count));
38868 }
38869
38870 /* Wait until the transmitter is empty.
38871 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38872
38873 if (debug_level >= DEBUG_LEVEL_INFO)
38874 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38875 - __FILE__, __LINE__, tty->driver->name, port->count);
38876 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38877
38878 /* If port is closing, signal caller to try again */
38879 if (port->flags & ASYNC_CLOSING){
38880 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38881 goto cleanup;
38882 }
38883 spin_lock(&port->lock);
38884 - port->count++;
38885 + atomic_inc(&port->count);
38886 spin_unlock(&port->lock);
38887 spin_unlock_irqrestore(&info->netlock, flags);
38888
38889 - if (port->count == 1) {
38890 + if (atomic_read(&port->count) == 1) {
38891 /* 1st open on this device, init hardware */
38892 retval = startup(info, tty);
38893 if (retval < 0)
38894 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38895 unsigned short new_crctype;
38896
38897 /* return error if TTY interface open */
38898 - if (info->port.count)
38899 + if (atomic_read(&info->port.count))
38900 return -EBUSY;
38901
38902 switch (encoding)
38903 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38904
38905 /* arbitrate between network and tty opens */
38906 spin_lock_irqsave(&info->netlock, flags);
38907 - if (info->port.count != 0 || info->netcount != 0) {
38908 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38909 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38910 spin_unlock_irqrestore(&info->netlock, flags);
38911 return -EBUSY;
38912 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38913 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38914
38915 /* return error if TTY interface open */
38916 - if (info->port.count)
38917 + if (atomic_read(&info->port.count))
38918 return -EBUSY;
38919
38920 if (cmd != SIOCWANDEV)
38921 diff --git a/drivers/char/random.c b/drivers/char/random.c
38922 index 04645c0..6416f00 100644
38923 --- a/drivers/char/random.c
38924 +++ b/drivers/char/random.c
38925 @@ -289,9 +289,6 @@
38926 /*
38927 * To allow fractional bits to be tracked, the entropy_count field is
38928 * denominated in units of 1/8th bits.
38929 - *
38930 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38931 - * credit_entropy_bits() needs to be 64 bits wide.
38932 */
38933 #define ENTROPY_SHIFT 3
38934 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38935 @@ -439,9 +436,9 @@ struct entropy_store {
38936 };
38937
38938 static void push_to_pool(struct work_struct *work);
38939 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38940 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38941 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38942 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38943 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38944 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38945
38946 static struct entropy_store input_pool = {
38947 .poolinfo = &poolinfo_table[0],
38948 @@ -569,19 +566,19 @@ static void fast_mix(struct fast_pool *f)
38949 __u32 c = f->pool[2], d = f->pool[3];
38950
38951 a += b; c += d;
38952 - b = rol32(a, 6); d = rol32(c, 27);
38953 + b = rol32(b, 6); d = rol32(d, 27);
38954 d ^= a; b ^= c;
38955
38956 a += b; c += d;
38957 - b = rol32(a, 16); d = rol32(c, 14);
38958 + b = rol32(b, 16); d = rol32(d, 14);
38959 d ^= a; b ^= c;
38960
38961 a += b; c += d;
38962 - b = rol32(a, 6); d = rol32(c, 27);
38963 + b = rol32(b, 6); d = rol32(d, 27);
38964 d ^= a; b ^= c;
38965
38966 a += b; c += d;
38967 - b = rol32(a, 16); d = rol32(c, 14);
38968 + b = rol32(b, 16); d = rol32(d, 14);
38969 d ^= a; b ^= c;
38970
38971 f->pool[0] = a; f->pool[1] = b;
38972 @@ -635,7 +632,7 @@ retry:
38973 /* The +2 corresponds to the /4 in the denominator */
38974
38975 do {
38976 - unsigned int anfrac = min(pnfrac, pool_size/2);
38977 + u64 anfrac = min(pnfrac, pool_size/2);
38978 unsigned int add =
38979 ((pool_size - entropy_count)*anfrac*3) >> s;
38980
38981 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38982
38983 extract_buf(r, tmp);
38984 i = min_t(int, nbytes, EXTRACT_SIZE);
38985 - if (copy_to_user(buf, tmp, i)) {
38986 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38987 ret = -EFAULT;
38988 break;
38989 }
38990 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
38991 static int proc_do_uuid(struct ctl_table *table, int write,
38992 void __user *buffer, size_t *lenp, loff_t *ppos)
38993 {
38994 - struct ctl_table fake_table;
38995 + ctl_table_no_const fake_table;
38996 unsigned char buf[64], tmp_uuid[16], *uuid;
38997
38998 uuid = table->data;
38999 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39000 static int proc_do_entropy(struct ctl_table *table, int write,
39001 void __user *buffer, size_t *lenp, loff_t *ppos)
39002 {
39003 - struct ctl_table fake_table;
39004 + ctl_table_no_const fake_table;
39005 int entropy_count;
39006
39007 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39008 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39009 index 7cc1fe22..b602d6b 100644
39010 --- a/drivers/char/sonypi.c
39011 +++ b/drivers/char/sonypi.c
39012 @@ -54,6 +54,7 @@
39013
39014 #include <asm/uaccess.h>
39015 #include <asm/io.h>
39016 +#include <asm/local.h>
39017
39018 #include <linux/sonypi.h>
39019
39020 @@ -490,7 +491,7 @@ static struct sonypi_device {
39021 spinlock_t fifo_lock;
39022 wait_queue_head_t fifo_proc_list;
39023 struct fasync_struct *fifo_async;
39024 - int open_count;
39025 + local_t open_count;
39026 int model;
39027 struct input_dev *input_jog_dev;
39028 struct input_dev *input_key_dev;
39029 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39030 static int sonypi_misc_release(struct inode *inode, struct file *file)
39031 {
39032 mutex_lock(&sonypi_device.lock);
39033 - sonypi_device.open_count--;
39034 + local_dec(&sonypi_device.open_count);
39035 mutex_unlock(&sonypi_device.lock);
39036 return 0;
39037 }
39038 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39039 {
39040 mutex_lock(&sonypi_device.lock);
39041 /* Flush input queue on first open */
39042 - if (!sonypi_device.open_count)
39043 + if (!local_read(&sonypi_device.open_count))
39044 kfifo_reset(&sonypi_device.fifo);
39045 - sonypi_device.open_count++;
39046 + local_inc(&sonypi_device.open_count);
39047 mutex_unlock(&sonypi_device.lock);
39048
39049 return 0;
39050 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39051 index 565a947..dcdc06e 100644
39052 --- a/drivers/char/tpm/tpm_acpi.c
39053 +++ b/drivers/char/tpm/tpm_acpi.c
39054 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39055 virt = acpi_os_map_iomem(start, len);
39056 if (!virt) {
39057 kfree(log->bios_event_log);
39058 + log->bios_event_log = NULL;
39059 printk("%s: ERROR - Unable to map memory\n", __func__);
39060 return -EIO;
39061 }
39062
39063 - memcpy_fromio(log->bios_event_log, virt, len);
39064 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39065
39066 acpi_os_unmap_iomem(virt, len);
39067 return 0;
39068 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39069 index 3a56a13..f8cbd25 100644
39070 --- a/drivers/char/tpm/tpm_eventlog.c
39071 +++ b/drivers/char/tpm/tpm_eventlog.c
39072 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39073 event = addr;
39074
39075 if ((event->event_type == 0 && event->event_size == 0) ||
39076 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39077 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39078 return NULL;
39079
39080 return addr;
39081 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39082 return NULL;
39083
39084 if ((event->event_type == 0 && event->event_size == 0) ||
39085 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39086 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39087 return NULL;
39088
39089 (*pos)++;
39090 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39091 int i;
39092
39093 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39094 - seq_putc(m, data[i]);
39095 + if (!seq_putc(m, data[i]))
39096 + return -EFAULT;
39097
39098 return 0;
39099 }
39100 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39101 index cf7a561..c319ce0 100644
39102 --- a/drivers/char/virtio_console.c
39103 +++ b/drivers/char/virtio_console.c
39104 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39105 if (to_user) {
39106 ssize_t ret;
39107
39108 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39109 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39110 if (ret)
39111 return -EFAULT;
39112 } else {
39113 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39114 if (!port_has_data(port) && !port->host_connected)
39115 return 0;
39116
39117 - return fill_readbuf(port, ubuf, count, true);
39118 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39119 }
39120
39121 static int wait_port_writable(struct port *port, bool nonblock)
39122 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39123 index b9355da..9611f4e 100644
39124 --- a/drivers/clk/clk-composite.c
39125 +++ b/drivers/clk/clk-composite.c
39126 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39127 struct clk *clk;
39128 struct clk_init_data init;
39129 struct clk_composite *composite;
39130 - struct clk_ops *clk_composite_ops;
39131 + clk_ops_no_const *clk_composite_ops;
39132
39133 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39134 if (!composite) {
39135 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39136 index dd3a78c..386d49c 100644
39137 --- a/drivers/clk/socfpga/clk-gate.c
39138 +++ b/drivers/clk/socfpga/clk-gate.c
39139 @@ -22,6 +22,7 @@
39140 #include <linux/mfd/syscon.h>
39141 #include <linux/of.h>
39142 #include <linux/regmap.h>
39143 +#include <asm/pgtable.h>
39144
39145 #include "clk.h"
39146
39147 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39148 return 0;
39149 }
39150
39151 -static struct clk_ops gateclk_ops = {
39152 +static clk_ops_no_const gateclk_ops __read_only = {
39153 .prepare = socfpga_clk_prepare,
39154 .recalc_rate = socfpga_clk_recalc_rate,
39155 .get_parent = socfpga_clk_get_parent,
39156 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39157 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39158 socfpga_clk->hw.bit_idx = clk_gate[1];
39159
39160 - gateclk_ops.enable = clk_gate_ops.enable;
39161 - gateclk_ops.disable = clk_gate_ops.disable;
39162 + pax_open_kernel();
39163 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39164 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39165 + pax_close_kernel();
39166 }
39167
39168 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39169 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39170 index de6da95..c98278b 100644
39171 --- a/drivers/clk/socfpga/clk-pll.c
39172 +++ b/drivers/clk/socfpga/clk-pll.c
39173 @@ -21,6 +21,7 @@
39174 #include <linux/io.h>
39175 #include <linux/of.h>
39176 #include <linux/of_address.h>
39177 +#include <asm/pgtable.h>
39178
39179 #include "clk.h"
39180
39181 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39182 CLK_MGR_PLL_CLK_SRC_MASK;
39183 }
39184
39185 -static struct clk_ops clk_pll_ops = {
39186 +static clk_ops_no_const clk_pll_ops __read_only = {
39187 .recalc_rate = clk_pll_recalc_rate,
39188 .get_parent = clk_pll_get_parent,
39189 };
39190 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39191 pll_clk->hw.hw.init = &init;
39192
39193 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39194 - clk_pll_ops.enable = clk_gate_ops.enable;
39195 - clk_pll_ops.disable = clk_gate_ops.disable;
39196 + pax_open_kernel();
39197 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39198 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39199 + pax_close_kernel();
39200
39201 clk = clk_register(NULL, &pll_clk->hw.hw);
39202 if (WARN_ON(IS_ERR(clk))) {
39203 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39204 index b0c18ed..1713a80 100644
39205 --- a/drivers/cpufreq/acpi-cpufreq.c
39206 +++ b/drivers/cpufreq/acpi-cpufreq.c
39207 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39208 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39209 per_cpu(acfreq_data, cpu) = data;
39210
39211 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39212 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39213 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39214 + pax_open_kernel();
39215 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39216 + pax_close_kernel();
39217 + }
39218
39219 result = acpi_processor_register_performance(data->acpi_data, cpu);
39220 if (result)
39221 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39222 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39223 break;
39224 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39225 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39226 + pax_open_kernel();
39227 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39228 + pax_close_kernel();
39229 break;
39230 default:
39231 break;
39232 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39233 if (!msrs)
39234 return;
39235
39236 - acpi_cpufreq_driver.boost_supported = true;
39237 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39238 + pax_open_kernel();
39239 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39240 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39241 + pax_close_kernel();
39242
39243 cpu_notifier_register_begin();
39244
39245 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39246 index f657c57..31d97ae 100644
39247 --- a/drivers/cpufreq/cpufreq-dt.c
39248 +++ b/drivers/cpufreq/cpufreq-dt.c
39249 @@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39250 if (!IS_ERR(cpu_reg))
39251 regulator_put(cpu_reg);
39252
39253 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39254 + pax_open_kernel();
39255 + *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39256 + pax_close_kernel();
39257
39258 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39259 if (ret)
39260 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39261 index 4473eba..a4c9dc2 100644
39262 --- a/drivers/cpufreq/cpufreq.c
39263 +++ b/drivers/cpufreq/cpufreq.c
39264 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39265 }
39266
39267 mutex_lock(&cpufreq_governor_mutex);
39268 - list_del(&governor->governor_list);
39269 + pax_list_del(&governor->governor_list);
39270 mutex_unlock(&cpufreq_governor_mutex);
39271 return;
39272 }
39273 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39274 return NOTIFY_OK;
39275 }
39276
39277 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39278 +static struct notifier_block cpufreq_cpu_notifier = {
39279 .notifier_call = cpufreq_cpu_callback,
39280 };
39281
39282 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39283 return 0;
39284
39285 write_lock_irqsave(&cpufreq_driver_lock, flags);
39286 - cpufreq_driver->boost_enabled = state;
39287 + pax_open_kernel();
39288 + *(bool *)&cpufreq_driver->boost_enabled = state;
39289 + pax_close_kernel();
39290 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39291
39292 ret = cpufreq_driver->set_boost(state);
39293 if (ret) {
39294 write_lock_irqsave(&cpufreq_driver_lock, flags);
39295 - cpufreq_driver->boost_enabled = !state;
39296 + pax_open_kernel();
39297 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39298 + pax_close_kernel();
39299 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39300
39301 pr_err("%s: Cannot %s BOOST\n",
39302 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39303
39304 pr_debug("trying to register driver %s\n", driver_data->name);
39305
39306 - if (driver_data->setpolicy)
39307 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39308 + if (driver_data->setpolicy) {
39309 + pax_open_kernel();
39310 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39311 + pax_close_kernel();
39312 + }
39313
39314 write_lock_irqsave(&cpufreq_driver_lock, flags);
39315 if (cpufreq_driver) {
39316 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39317 * Check if driver provides function to enable boost -
39318 * if not, use cpufreq_boost_set_sw as default
39319 */
39320 - if (!cpufreq_driver->set_boost)
39321 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39322 + if (!cpufreq_driver->set_boost) {
39323 + pax_open_kernel();
39324 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39325 + pax_close_kernel();
39326 + }
39327
39328 ret = cpufreq_sysfs_create_file(&boost.attr);
39329 if (ret) {
39330 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39331 index 1b44496..b80ff5e 100644
39332 --- a/drivers/cpufreq/cpufreq_governor.c
39333 +++ b/drivers/cpufreq/cpufreq_governor.c
39334 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39335 struct dbs_data *dbs_data;
39336 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39337 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39338 - struct od_ops *od_ops = NULL;
39339 + const struct od_ops *od_ops = NULL;
39340 struct od_dbs_tuners *od_tuners = NULL;
39341 struct cs_dbs_tuners *cs_tuners = NULL;
39342 struct cpu_dbs_common_info *cpu_cdbs;
39343 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39344
39345 if ((cdata->governor == GOV_CONSERVATIVE) &&
39346 (!policy->governor->initialized)) {
39347 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39348 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39349
39350 cpufreq_register_notifier(cs_ops->notifier_block,
39351 CPUFREQ_TRANSITION_NOTIFIER);
39352 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39353
39354 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39355 (policy->governor->initialized == 1)) {
39356 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39357 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39358
39359 cpufreq_unregister_notifier(cs_ops->notifier_block,
39360 CPUFREQ_TRANSITION_NOTIFIER);
39361 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39362 index cc401d1..8197340 100644
39363 --- a/drivers/cpufreq/cpufreq_governor.h
39364 +++ b/drivers/cpufreq/cpufreq_governor.h
39365 @@ -212,7 +212,7 @@ struct common_dbs_data {
39366 void (*exit)(struct dbs_data *dbs_data);
39367
39368 /* Governor specific ops, see below */
39369 - void *gov_ops;
39370 + const void *gov_ops;
39371 };
39372
39373 /* Governor Per policy data */
39374 @@ -232,7 +232,7 @@ struct od_ops {
39375 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39376 unsigned int freq_next, unsigned int relation);
39377 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39378 -};
39379 +} __no_const;
39380
39381 struct cs_ops {
39382 struct notifier_block *notifier_block;
39383 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39384 index ad3f38f..8f086cd 100644
39385 --- a/drivers/cpufreq/cpufreq_ondemand.c
39386 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39387 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39388
39389 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39390
39391 -static struct od_ops od_ops = {
39392 +static struct od_ops od_ops __read_only = {
39393 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39394 .powersave_bias_target = generic_powersave_bias_target,
39395 .freq_increase = dbs_freq_increase,
39396 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39397 (struct cpufreq_policy *, unsigned int, unsigned int),
39398 unsigned int powersave_bias)
39399 {
39400 - od_ops.powersave_bias_target = f;
39401 + pax_open_kernel();
39402 + *(void **)&od_ops.powersave_bias_target = f;
39403 + pax_close_kernel();
39404 od_set_powersave_bias(powersave_bias);
39405 }
39406 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39407
39408 void od_unregister_powersave_bias_handler(void)
39409 {
39410 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39411 + pax_open_kernel();
39412 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39413 + pax_close_kernel();
39414 od_set_powersave_bias(0);
39415 }
39416 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39417 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39418 index 27bb6d3..4cf595c 100644
39419 --- a/drivers/cpufreq/intel_pstate.c
39420 +++ b/drivers/cpufreq/intel_pstate.c
39421 @@ -133,10 +133,10 @@ struct pstate_funcs {
39422 struct cpu_defaults {
39423 struct pstate_adjust_policy pid_policy;
39424 struct pstate_funcs funcs;
39425 -};
39426 +} __do_const;
39427
39428 static struct pstate_adjust_policy pid_params;
39429 -static struct pstate_funcs pstate_funcs;
39430 +static struct pstate_funcs *pstate_funcs;
39431
39432 struct perf_limits {
39433 int no_turbo;
39434 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39435
39436 cpu->pstate.current_pstate = pstate;
39437
39438 - pstate_funcs.set(cpu, pstate);
39439 + pstate_funcs->set(cpu, pstate);
39440 }
39441
39442 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39443 {
39444 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39445 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39446 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39447 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39448 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39449 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39450 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39451 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39452
39453 - if (pstate_funcs.get_vid)
39454 - pstate_funcs.get_vid(cpu);
39455 + if (pstate_funcs->get_vid)
39456 + pstate_funcs->get_vid(cpu);
39457 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39458 }
39459
39460 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39461 rdmsrl(MSR_IA32_APERF, aperf);
39462 rdmsrl(MSR_IA32_MPERF, mperf);
39463
39464 - if (!pstate_funcs.get_max() ||
39465 - !pstate_funcs.get_min() ||
39466 - !pstate_funcs.get_turbo())
39467 + if (!pstate_funcs->get_max() ||
39468 + !pstate_funcs->get_min() ||
39469 + !pstate_funcs->get_turbo())
39470 return -ENODEV;
39471
39472 rdmsrl(MSR_IA32_APERF, tmp);
39473 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39474 return 0;
39475 }
39476
39477 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39478 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39479 {
39480 pid_params.sample_rate_ms = policy->sample_rate_ms;
39481 pid_params.p_gain_pct = policy->p_gain_pct;
39482 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39483
39484 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39485 {
39486 - pstate_funcs.get_max = funcs->get_max;
39487 - pstate_funcs.get_min = funcs->get_min;
39488 - pstate_funcs.get_turbo = funcs->get_turbo;
39489 - pstate_funcs.get_scaling = funcs->get_scaling;
39490 - pstate_funcs.set = funcs->set;
39491 - pstate_funcs.get_vid = funcs->get_vid;
39492 + pstate_funcs = funcs;
39493 }
39494
39495 #if IS_ENABLED(CONFIG_ACPI)
39496 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39497 index 529cfd9..0e28fff 100644
39498 --- a/drivers/cpufreq/p4-clockmod.c
39499 +++ b/drivers/cpufreq/p4-clockmod.c
39500 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39501 case 0x0F: /* Core Duo */
39502 case 0x16: /* Celeron Core */
39503 case 0x1C: /* Atom */
39504 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39505 + pax_open_kernel();
39506 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39507 + pax_close_kernel();
39508 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39509 case 0x0D: /* Pentium M (Dothan) */
39510 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39511 + pax_open_kernel();
39512 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39513 + pax_close_kernel();
39514 /* fall through */
39515 case 0x09: /* Pentium M (Banias) */
39516 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39517 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39518
39519 /* on P-4s, the TSC runs with constant frequency independent whether
39520 * throttling is active or not. */
39521 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39522 + pax_open_kernel();
39523 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39524 + pax_close_kernel();
39525
39526 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39527 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39528 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39529 index 9bb42ba..b01b4a2 100644
39530 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39531 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39532 @@ -18,14 +18,12 @@
39533 #include <asm/head.h>
39534 #include <asm/timer.h>
39535
39536 -static struct cpufreq_driver *cpufreq_us3_driver;
39537 -
39538 struct us3_freq_percpu_info {
39539 struct cpufreq_frequency_table table[4];
39540 };
39541
39542 /* Indexed by cpu number. */
39543 -static struct us3_freq_percpu_info *us3_freq_table;
39544 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39545
39546 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39547 * in the Safari config register.
39548 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39549
39550 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39551 {
39552 - if (cpufreq_us3_driver)
39553 - us3_freq_target(policy, 0);
39554 + us3_freq_target(policy, 0);
39555
39556 return 0;
39557 }
39558
39559 +static int __init us3_freq_init(void);
39560 +static void __exit us3_freq_exit(void);
39561 +
39562 +static struct cpufreq_driver cpufreq_us3_driver = {
39563 + .init = us3_freq_cpu_init,
39564 + .verify = cpufreq_generic_frequency_table_verify,
39565 + .target_index = us3_freq_target,
39566 + .get = us3_freq_get,
39567 + .exit = us3_freq_cpu_exit,
39568 + .name = "UltraSPARC-III",
39569 +
39570 +};
39571 +
39572 static int __init us3_freq_init(void)
39573 {
39574 unsigned long manuf, impl, ver;
39575 - int ret;
39576
39577 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39578 return -ENODEV;
39579 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39580 (impl == CHEETAH_IMPL ||
39581 impl == CHEETAH_PLUS_IMPL ||
39582 impl == JAGUAR_IMPL ||
39583 - impl == PANTHER_IMPL)) {
39584 - struct cpufreq_driver *driver;
39585 -
39586 - ret = -ENOMEM;
39587 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39588 - if (!driver)
39589 - goto err_out;
39590 -
39591 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39592 - GFP_KERNEL);
39593 - if (!us3_freq_table)
39594 - goto err_out;
39595 -
39596 - driver->init = us3_freq_cpu_init;
39597 - driver->verify = cpufreq_generic_frequency_table_verify;
39598 - driver->target_index = us3_freq_target;
39599 - driver->get = us3_freq_get;
39600 - driver->exit = us3_freq_cpu_exit;
39601 - strcpy(driver->name, "UltraSPARC-III");
39602 -
39603 - cpufreq_us3_driver = driver;
39604 - ret = cpufreq_register_driver(driver);
39605 - if (ret)
39606 - goto err_out;
39607 -
39608 - return 0;
39609 -
39610 -err_out:
39611 - if (driver) {
39612 - kfree(driver);
39613 - cpufreq_us3_driver = NULL;
39614 - }
39615 - kfree(us3_freq_table);
39616 - us3_freq_table = NULL;
39617 - return ret;
39618 - }
39619 + impl == PANTHER_IMPL))
39620 + return cpufreq_register_driver(&cpufreq_us3_driver);
39621
39622 return -ENODEV;
39623 }
39624
39625 static void __exit us3_freq_exit(void)
39626 {
39627 - if (cpufreq_us3_driver) {
39628 - cpufreq_unregister_driver(cpufreq_us3_driver);
39629 - kfree(cpufreq_us3_driver);
39630 - cpufreq_us3_driver = NULL;
39631 - kfree(us3_freq_table);
39632 - us3_freq_table = NULL;
39633 - }
39634 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39635 }
39636
39637 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39638 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39639 index 7d4a315..21bb886 100644
39640 --- a/drivers/cpufreq/speedstep-centrino.c
39641 +++ b/drivers/cpufreq/speedstep-centrino.c
39642 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39643 !cpu_has(cpu, X86_FEATURE_EST))
39644 return -ENODEV;
39645
39646 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39647 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39648 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39649 + pax_open_kernel();
39650 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39651 + pax_close_kernel();
39652 + }
39653
39654 if (policy->cpu != 0)
39655 return -ENODEV;
39656 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39657 index e431d11..d0b997e 100644
39658 --- a/drivers/cpuidle/driver.c
39659 +++ b/drivers/cpuidle/driver.c
39660 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39661
39662 static void poll_idle_init(struct cpuidle_driver *drv)
39663 {
39664 - struct cpuidle_state *state = &drv->states[0];
39665 + cpuidle_state_no_const *state = &drv->states[0];
39666
39667 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39668 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39669 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39670 index fb9f511..213e6cc 100644
39671 --- a/drivers/cpuidle/governor.c
39672 +++ b/drivers/cpuidle/governor.c
39673 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39674 mutex_lock(&cpuidle_lock);
39675 if (__cpuidle_find_governor(gov->name) == NULL) {
39676 ret = 0;
39677 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39678 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39679 if (!cpuidle_curr_governor ||
39680 cpuidle_curr_governor->rating < gov->rating)
39681 cpuidle_switch_governor(gov);
39682 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39683 index 97c5903..023ad23 100644
39684 --- a/drivers/cpuidle/sysfs.c
39685 +++ b/drivers/cpuidle/sysfs.c
39686 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39687 NULL
39688 };
39689
39690 -static struct attribute_group cpuidle_attr_group = {
39691 +static attribute_group_no_const cpuidle_attr_group = {
39692 .attrs = cpuidle_default_attrs,
39693 .name = "cpuidle",
39694 };
39695 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39696 index 8d2a772..33826c9 100644
39697 --- a/drivers/crypto/hifn_795x.c
39698 +++ b/drivers/crypto/hifn_795x.c
39699 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39700 MODULE_PARM_DESC(hifn_pll_ref,
39701 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39702
39703 -static atomic_t hifn_dev_number;
39704 +static atomic_unchecked_t hifn_dev_number;
39705
39706 #define ACRYPTO_OP_DECRYPT 0
39707 #define ACRYPTO_OP_ENCRYPT 1
39708 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39709 goto err_out_disable_pci_device;
39710
39711 snprintf(name, sizeof(name), "hifn%d",
39712 - atomic_inc_return(&hifn_dev_number)-1);
39713 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39714
39715 err = pci_request_regions(pdev, name);
39716 if (err)
39717 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39718 index 30b538d8..1610d75 100644
39719 --- a/drivers/devfreq/devfreq.c
39720 +++ b/drivers/devfreq/devfreq.c
39721 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39722 goto err_out;
39723 }
39724
39725 - list_add(&governor->node, &devfreq_governor_list);
39726 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39727
39728 list_for_each_entry(devfreq, &devfreq_list, node) {
39729 int ret = 0;
39730 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39731 }
39732 }
39733
39734 - list_del(&governor->node);
39735 + pax_list_del((struct list_head *)&governor->node);
39736 err_out:
39737 mutex_unlock(&devfreq_list_lock);
39738
39739 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39740 index 42d4974..2714f36 100644
39741 --- a/drivers/dma/sh/shdma-base.c
39742 +++ b/drivers/dma/sh/shdma-base.c
39743 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39744 schan->slave_id = -EINVAL;
39745 }
39746
39747 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39748 - sdev->desc_size, GFP_KERNEL);
39749 + schan->desc = kcalloc(sdev->desc_size,
39750 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39751 if (!schan->desc) {
39752 ret = -ENOMEM;
39753 goto edescalloc;
39754 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39755 index 58eb857..d7e42c8 100644
39756 --- a/drivers/dma/sh/shdmac.c
39757 +++ b/drivers/dma/sh/shdmac.c
39758 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39759 return ret;
39760 }
39761
39762 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39763 +static struct notifier_block sh_dmae_nmi_notifier = {
39764 .notifier_call = sh_dmae_nmi_handler,
39765
39766 /* Run before NMI debug handler and KGDB */
39767 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39768 index 592af5f..bb1d583 100644
39769 --- a/drivers/edac/edac_device.c
39770 +++ b/drivers/edac/edac_device.c
39771 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39772 */
39773 int edac_device_alloc_index(void)
39774 {
39775 - static atomic_t device_indexes = ATOMIC_INIT(0);
39776 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39777
39778 - return atomic_inc_return(&device_indexes) - 1;
39779 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39780 }
39781 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39782
39783 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39784 index a6cd361..7bdbf53 100644
39785 --- a/drivers/edac/edac_mc_sysfs.c
39786 +++ b/drivers/edac/edac_mc_sysfs.c
39787 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39788 struct dev_ch_attribute {
39789 struct device_attribute attr;
39790 int channel;
39791 -};
39792 +} __do_const;
39793
39794 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39795 struct dev_ch_attribute dev_attr_legacy_##_name = \
39796 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39797 }
39798
39799 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39800 + pax_open_kernel();
39801 if (mci->get_sdram_scrub_rate) {
39802 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39803 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39804 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39805 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39806 }
39807 if (mci->set_sdram_scrub_rate) {
39808 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39809 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39810 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39811 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39812 }
39813 + pax_close_kernel();
39814 err = device_create_file(&mci->dev,
39815 &dev_attr_sdram_scrub_rate);
39816 if (err) {
39817 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39818 index 2cf44b4d..6dd2dc7 100644
39819 --- a/drivers/edac/edac_pci.c
39820 +++ b/drivers/edac/edac_pci.c
39821 @@ -29,7 +29,7 @@
39822
39823 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39824 static LIST_HEAD(edac_pci_list);
39825 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39826 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39827
39828 /*
39829 * edac_pci_alloc_ctl_info
39830 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39831 */
39832 int edac_pci_alloc_index(void)
39833 {
39834 - return atomic_inc_return(&pci_indexes) - 1;
39835 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39836 }
39837 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39838
39839 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39840 index e8658e4..22746d6 100644
39841 --- a/drivers/edac/edac_pci_sysfs.c
39842 +++ b/drivers/edac/edac_pci_sysfs.c
39843 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39844 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39845 static int edac_pci_poll_msec = 1000; /* one second workq period */
39846
39847 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39848 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39849 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39850 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39851
39852 static struct kobject *edac_pci_top_main_kobj;
39853 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39854 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39855 void *value;
39856 ssize_t(*show) (void *, char *);
39857 ssize_t(*store) (void *, const char *, size_t);
39858 -};
39859 +} __do_const;
39860
39861 /* Set of show/store abstract level functions for PCI Parity object */
39862 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39863 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39864 edac_printk(KERN_CRIT, EDAC_PCI,
39865 "Signaled System Error on %s\n",
39866 pci_name(dev));
39867 - atomic_inc(&pci_nonparity_count);
39868 + atomic_inc_unchecked(&pci_nonparity_count);
39869 }
39870
39871 if (status & (PCI_STATUS_PARITY)) {
39872 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39873 "Master Data Parity Error on %s\n",
39874 pci_name(dev));
39875
39876 - atomic_inc(&pci_parity_count);
39877 + atomic_inc_unchecked(&pci_parity_count);
39878 }
39879
39880 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39881 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39882 "Detected Parity Error on %s\n",
39883 pci_name(dev));
39884
39885 - atomic_inc(&pci_parity_count);
39886 + atomic_inc_unchecked(&pci_parity_count);
39887 }
39888 }
39889
39890 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39891 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39892 "Signaled System Error on %s\n",
39893 pci_name(dev));
39894 - atomic_inc(&pci_nonparity_count);
39895 + atomic_inc_unchecked(&pci_nonparity_count);
39896 }
39897
39898 if (status & (PCI_STATUS_PARITY)) {
39899 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39900 "Master Data Parity Error on "
39901 "%s\n", pci_name(dev));
39902
39903 - atomic_inc(&pci_parity_count);
39904 + atomic_inc_unchecked(&pci_parity_count);
39905 }
39906
39907 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39908 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39909 "Detected Parity Error on %s\n",
39910 pci_name(dev));
39911
39912 - atomic_inc(&pci_parity_count);
39913 + atomic_inc_unchecked(&pci_parity_count);
39914 }
39915 }
39916 }
39917 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39918 if (!check_pci_errors)
39919 return;
39920
39921 - before_count = atomic_read(&pci_parity_count);
39922 + before_count = atomic_read_unchecked(&pci_parity_count);
39923
39924 /* scan all PCI devices looking for a Parity Error on devices and
39925 * bridges.
39926 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39927 /* Only if operator has selected panic on PCI Error */
39928 if (edac_pci_get_panic_on_pe()) {
39929 /* If the count is different 'after' from 'before' */
39930 - if (before_count != atomic_read(&pci_parity_count))
39931 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39932 panic("EDAC: PCI Parity Error");
39933 }
39934 }
39935 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39936 index 51b7e3a..aa8a3e8 100644
39937 --- a/drivers/edac/mce_amd.h
39938 +++ b/drivers/edac/mce_amd.h
39939 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39940 bool (*mc0_mce)(u16, u8);
39941 bool (*mc1_mce)(u16, u8);
39942 bool (*mc2_mce)(u16, u8);
39943 -};
39944 +} __no_const;
39945
39946 void amd_report_gart_errors(bool);
39947 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39948 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39949 index 57ea7f4..af06b76 100644
39950 --- a/drivers/firewire/core-card.c
39951 +++ b/drivers/firewire/core-card.c
39952 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39953 const struct fw_card_driver *driver,
39954 struct device *device)
39955 {
39956 - static atomic_t index = ATOMIC_INIT(-1);
39957 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39958
39959 - card->index = atomic_inc_return(&index);
39960 + card->index = atomic_inc_return_unchecked(&index);
39961 card->driver = driver;
39962 card->device = device;
39963 card->current_tlabel = 0;
39964 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39965
39966 void fw_core_remove_card(struct fw_card *card)
39967 {
39968 - struct fw_card_driver dummy_driver = dummy_driver_template;
39969 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39970
39971 card->driver->update_phy_reg(card, 4,
39972 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39973 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39974 index 2c6d5e1..a2cca6b 100644
39975 --- a/drivers/firewire/core-device.c
39976 +++ b/drivers/firewire/core-device.c
39977 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39978 struct config_rom_attribute {
39979 struct device_attribute attr;
39980 u32 key;
39981 -};
39982 +} __do_const;
39983
39984 static ssize_t show_immediate(struct device *dev,
39985 struct device_attribute *dattr, char *buf)
39986 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39987 index eb6935c..3cc2bfa 100644
39988 --- a/drivers/firewire/core-transaction.c
39989 +++ b/drivers/firewire/core-transaction.c
39990 @@ -38,6 +38,7 @@
39991 #include <linux/timer.h>
39992 #include <linux/types.h>
39993 #include <linux/workqueue.h>
39994 +#include <linux/sched.h>
39995
39996 #include <asm/byteorder.h>
39997
39998 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39999 index e1480ff6..1a429bd 100644
40000 --- a/drivers/firewire/core.h
40001 +++ b/drivers/firewire/core.h
40002 @@ -111,6 +111,7 @@ struct fw_card_driver {
40003
40004 int (*stop_iso)(struct fw_iso_context *ctx);
40005 };
40006 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40007
40008 void fw_card_initialize(struct fw_card *card,
40009 const struct fw_card_driver *driver, struct device *device);
40010 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40011 index a66a321..f6caf20 100644
40012 --- a/drivers/firewire/ohci.c
40013 +++ b/drivers/firewire/ohci.c
40014 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40015 be32_to_cpu(ohci->next_header));
40016 }
40017
40018 +#ifndef CONFIG_GRKERNSEC
40019 if (param_remote_dma) {
40020 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40021 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40022 }
40023 +#endif
40024
40025 spin_unlock_irq(&ohci->lock);
40026
40027 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40028 unsigned long flags;
40029 int n, ret = 0;
40030
40031 +#ifndef CONFIG_GRKERNSEC
40032 if (param_remote_dma)
40033 return 0;
40034 +#endif
40035
40036 /*
40037 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40038 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40039 index 94a58a0..f5eba42 100644
40040 --- a/drivers/firmware/dmi-id.c
40041 +++ b/drivers/firmware/dmi-id.c
40042 @@ -16,7 +16,7 @@
40043 struct dmi_device_attribute{
40044 struct device_attribute dev_attr;
40045 int field;
40046 -};
40047 +} __do_const;
40048 #define to_dmi_dev_attr(_dev_attr) \
40049 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40050
40051 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40052 index 17afc51..0ef90cd 100644
40053 --- a/drivers/firmware/dmi_scan.c
40054 +++ b/drivers/firmware/dmi_scan.c
40055 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40056 if (buf == NULL)
40057 return -1;
40058
40059 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40060 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40061
40062 dmi_unmap(buf);
40063 return 0;
40064 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40065 index 5b53d61..72cee96 100644
40066 --- a/drivers/firmware/efi/cper.c
40067 +++ b/drivers/firmware/efi/cper.c
40068 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40069 */
40070 u64 cper_next_record_id(void)
40071 {
40072 - static atomic64_t seq;
40073 + static atomic64_unchecked_t seq;
40074
40075 - if (!atomic64_read(&seq))
40076 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40077 + if (!atomic64_read_unchecked(&seq))
40078 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40079
40080 - return atomic64_inc_return(&seq);
40081 + return atomic64_inc_return_unchecked(&seq);
40082 }
40083 EXPORT_SYMBOL_GPL(cper_next_record_id);
40084
40085 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40086 index 8590099..d83627a 100644
40087 --- a/drivers/firmware/efi/efi.c
40088 +++ b/drivers/firmware/efi/efi.c
40089 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40090 };
40091
40092 static struct efivars generic_efivars;
40093 -static struct efivar_operations generic_ops;
40094 +static efivar_operations_no_const generic_ops __read_only;
40095
40096 static int generic_ops_register(void)
40097 {
40098 - generic_ops.get_variable = efi.get_variable;
40099 - generic_ops.set_variable = efi.set_variable;
40100 - generic_ops.get_next_variable = efi.get_next_variable;
40101 - generic_ops.query_variable_store = efi_query_variable_store;
40102 + pax_open_kernel();
40103 + *(void **)&generic_ops.get_variable = efi.get_variable;
40104 + *(void **)&generic_ops.set_variable = efi.set_variable;
40105 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40106 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40107 + pax_close_kernel();
40108
40109 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40110 }
40111 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40112 index f256ecd..387dcb1 100644
40113 --- a/drivers/firmware/efi/efivars.c
40114 +++ b/drivers/firmware/efi/efivars.c
40115 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40116 static int
40117 create_efivars_bin_attributes(void)
40118 {
40119 - struct bin_attribute *attr;
40120 + bin_attribute_no_const *attr;
40121 int error;
40122
40123 /* new_var */
40124 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40125 index 2f569aa..c95f4fb 100644
40126 --- a/drivers/firmware/google/memconsole.c
40127 +++ b/drivers/firmware/google/memconsole.c
40128 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40129 if (!found_memconsole())
40130 return -ENODEV;
40131
40132 - memconsole_bin_attr.size = memconsole_length;
40133 + pax_open_kernel();
40134 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40135 + pax_close_kernel();
40136 +
40137 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40138 }
40139
40140 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40141 index fe49ec3..1ade794 100644
40142 --- a/drivers/gpio/gpio-em.c
40143 +++ b/drivers/gpio/gpio-em.c
40144 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40145 struct em_gio_priv *p;
40146 struct resource *io[2], *irq[2];
40147 struct gpio_chip *gpio_chip;
40148 - struct irq_chip *irq_chip;
40149 + irq_chip_no_const *irq_chip;
40150 const char *name = dev_name(&pdev->dev);
40151 int ret;
40152
40153 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40154 index 3784e81..73637b5 100644
40155 --- a/drivers/gpio/gpio-ich.c
40156 +++ b/drivers/gpio/gpio-ich.c
40157 @@ -94,7 +94,7 @@ struct ichx_desc {
40158 * this option allows driver caching written output values
40159 */
40160 bool use_outlvl_cache;
40161 -};
40162 +} __do_const;
40163
40164 static struct {
40165 spinlock_t lock;
40166 diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40167 index 415682f..08438b8 100644
40168 --- a/drivers/gpio/gpio-omap.c
40169 +++ b/drivers/gpio/gpio-omap.c
40170 @@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40171 const struct omap_gpio_platform_data *pdata;
40172 struct resource *res;
40173 struct gpio_bank *bank;
40174 - struct irq_chip *irqc;
40175 + irq_chip_no_const *irqc;
40176 int ret;
40177
40178 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40179 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40180 index bf6c094..6573caf 100644
40181 --- a/drivers/gpio/gpio-rcar.c
40182 +++ b/drivers/gpio/gpio-rcar.c
40183 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40184 struct gpio_rcar_priv *p;
40185 struct resource *io, *irq;
40186 struct gpio_chip *gpio_chip;
40187 - struct irq_chip *irq_chip;
40188 + irq_chip_no_const *irq_chip;
40189 struct device *dev = &pdev->dev;
40190 const char *name = dev_name(dev);
40191 int ret;
40192 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40193 index dbf28fa..04dad4e 100644
40194 --- a/drivers/gpio/gpio-vr41xx.c
40195 +++ b/drivers/gpio/gpio-vr41xx.c
40196 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40197 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40198 maskl, pendl, maskh, pendh);
40199
40200 - atomic_inc(&irq_err_count);
40201 + atomic_inc_unchecked(&irq_err_count);
40202
40203 return -EINVAL;
40204 }
40205 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40206 index c81bda0..a8ccd9f 100644
40207 --- a/drivers/gpio/gpiolib.c
40208 +++ b/drivers/gpio/gpiolib.c
40209 @@ -539,8 +539,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40210 }
40211
40212 if (gpiochip->irqchip) {
40213 - gpiochip->irqchip->irq_request_resources = NULL;
40214 - gpiochip->irqchip->irq_release_resources = NULL;
40215 + pax_open_kernel();
40216 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40217 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40218 + pax_close_kernel();
40219 gpiochip->irqchip = NULL;
40220 }
40221 }
40222 @@ -606,8 +608,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40223 gpiochip->irqchip = NULL;
40224 return -EINVAL;
40225 }
40226 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40227 - irqchip->irq_release_resources = gpiochip_irq_relres;
40228 +
40229 + pax_open_kernel();
40230 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40231 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40232 + pax_close_kernel();
40233
40234 /*
40235 * Prepare the mapping since the irqchip shall be orthogonal to
40236 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40237 index e79c8d3..a9370bc 100644
40238 --- a/drivers/gpu/drm/drm_crtc.c
40239 +++ b/drivers/gpu/drm/drm_crtc.c
40240 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40241 goto done;
40242 }
40243
40244 - if (copy_to_user(&enum_ptr[copied].name,
40245 + if (copy_to_user(enum_ptr[copied].name,
40246 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40247 ret = -EFAULT;
40248 goto done;
40249 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40250 index bc3da32..7289357 100644
40251 --- a/drivers/gpu/drm/drm_drv.c
40252 +++ b/drivers/gpu/drm/drm_drv.c
40253 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40254
40255 drm_device_set_unplugged(dev);
40256
40257 - if (dev->open_count == 0) {
40258 + if (local_read(&dev->open_count) == 0) {
40259 drm_put_dev(dev);
40260 }
40261 mutex_unlock(&drm_global_mutex);
40262 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
40263 index e9a2827..5df4716 100644
40264 --- a/drivers/gpu/drm/drm_fb_helper.c
40265 +++ b/drivers/gpu/drm/drm_fb_helper.c
40266 @@ -771,7 +771,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
40267 int i, j, rc = 0;
40268 int start;
40269
40270 - drm_modeset_lock_all(dev);
40271 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40272 + return -EBUSY;
40273 + }
40274 if (!drm_fb_helper_is_bound(fb_helper)) {
40275 drm_modeset_unlock_all(dev);
40276 return -EBUSY;
40277 @@ -945,7 +947,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
40278 int ret = 0;
40279 int i;
40280
40281 - drm_modeset_lock_all(dev);
40282 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40283 + return -EBUSY;
40284 + }
40285 if (!drm_fb_helper_is_bound(fb_helper)) {
40286 drm_modeset_unlock_all(dev);
40287 return -EBUSY;
40288 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40289 index ed7bc68..0d536af 100644
40290 --- a/drivers/gpu/drm/drm_fops.c
40291 +++ b/drivers/gpu/drm/drm_fops.c
40292 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40293 return PTR_ERR(minor);
40294
40295 dev = minor->dev;
40296 - if (!dev->open_count++)
40297 + if (local_inc_return(&dev->open_count) == 1)
40298 need_setup = 1;
40299
40300 /* share address_space across all char-devs of a single device */
40301 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40302 return 0;
40303
40304 err_undo:
40305 - dev->open_count--;
40306 + local_dec(&dev->open_count);
40307 drm_minor_release(minor);
40308 return retcode;
40309 }
40310 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40311
40312 mutex_lock(&drm_global_mutex);
40313
40314 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40315 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40316
40317 mutex_lock(&dev->struct_mutex);
40318 list_del(&file_priv->lhead);
40319 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40320 * Begin inline drm_release
40321 */
40322
40323 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40324 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40325 task_pid_nr(current),
40326 (long)old_encode_dev(file_priv->minor->kdev->devt),
40327 - dev->open_count);
40328 + local_read(&dev->open_count));
40329
40330 /* Release any auth tokens that might point to this file_priv,
40331 (do that under the drm_global_mutex) */
40332 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40333 * End inline drm_release
40334 */
40335
40336 - if (!--dev->open_count) {
40337 + if (local_dec_and_test(&dev->open_count)) {
40338 retcode = drm_lastclose(dev);
40339 if (drm_device_is_unplugged(dev))
40340 drm_put_dev(dev);
40341 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40342 index 3d2e91c..d31c4c9 100644
40343 --- a/drivers/gpu/drm/drm_global.c
40344 +++ b/drivers/gpu/drm/drm_global.c
40345 @@ -36,7 +36,7 @@
40346 struct drm_global_item {
40347 struct mutex mutex;
40348 void *object;
40349 - int refcount;
40350 + atomic_t refcount;
40351 };
40352
40353 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40354 @@ -49,7 +49,7 @@ void drm_global_init(void)
40355 struct drm_global_item *item = &glob[i];
40356 mutex_init(&item->mutex);
40357 item->object = NULL;
40358 - item->refcount = 0;
40359 + atomic_set(&item->refcount, 0);
40360 }
40361 }
40362
40363 @@ -59,7 +59,7 @@ void drm_global_release(void)
40364 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40365 struct drm_global_item *item = &glob[i];
40366 BUG_ON(item->object != NULL);
40367 - BUG_ON(item->refcount != 0);
40368 + BUG_ON(atomic_read(&item->refcount) != 0);
40369 }
40370 }
40371
40372 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40373 struct drm_global_item *item = &glob[ref->global_type];
40374
40375 mutex_lock(&item->mutex);
40376 - if (item->refcount == 0) {
40377 + if (atomic_read(&item->refcount) == 0) {
40378 item->object = kzalloc(ref->size, GFP_KERNEL);
40379 if (unlikely(item->object == NULL)) {
40380 ret = -ENOMEM;
40381 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40382 goto out_err;
40383
40384 }
40385 - ++item->refcount;
40386 + atomic_inc(&item->refcount);
40387 ref->object = item->object;
40388 mutex_unlock(&item->mutex);
40389 return 0;
40390 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40391 struct drm_global_item *item = &glob[ref->global_type];
40392
40393 mutex_lock(&item->mutex);
40394 - BUG_ON(item->refcount == 0);
40395 + BUG_ON(atomic_read(&item->refcount) == 0);
40396 BUG_ON(ref->object != item->object);
40397 - if (--item->refcount == 0) {
40398 + if (atomic_dec_and_test(&item->refcount)) {
40399 ref->release(ref);
40400 item->object = NULL;
40401 }
40402 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40403 index 51efebd..2b70935 100644
40404 --- a/drivers/gpu/drm/drm_info.c
40405 +++ b/drivers/gpu/drm/drm_info.c
40406 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40407 struct drm_local_map *map;
40408 struct drm_map_list *r_list;
40409
40410 - /* Hardcoded from _DRM_FRAME_BUFFER,
40411 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40412 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40413 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40414 + static const char * const types[] = {
40415 + [_DRM_FRAME_BUFFER] = "FB",
40416 + [_DRM_REGISTERS] = "REG",
40417 + [_DRM_SHM] = "SHM",
40418 + [_DRM_AGP] = "AGP",
40419 + [_DRM_SCATTER_GATHER] = "SG",
40420 + [_DRM_CONSISTENT] = "PCI"};
40421 const char *type;
40422 int i;
40423
40424 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40425 map = r_list->map;
40426 if (!map)
40427 continue;
40428 - if (map->type < 0 || map->type > 5)
40429 + if (map->type >= ARRAY_SIZE(types))
40430 type = "??";
40431 else
40432 type = types[map->type];
40433 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40434 index 2f4c4343..dd12cd2 100644
40435 --- a/drivers/gpu/drm/drm_ioc32.c
40436 +++ b/drivers/gpu/drm/drm_ioc32.c
40437 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40438 request = compat_alloc_user_space(nbytes);
40439 if (!access_ok(VERIFY_WRITE, request, nbytes))
40440 return -EFAULT;
40441 - list = (struct drm_buf_desc *) (request + 1);
40442 + list = (struct drm_buf_desc __user *) (request + 1);
40443
40444 if (__put_user(count, &request->count)
40445 || __put_user(list, &request->list))
40446 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40447 request = compat_alloc_user_space(nbytes);
40448 if (!access_ok(VERIFY_WRITE, request, nbytes))
40449 return -EFAULT;
40450 - list = (struct drm_buf_pub *) (request + 1);
40451 + list = (struct drm_buf_pub __user *) (request + 1);
40452
40453 if (__put_user(count, &request->count)
40454 || __put_user(list, &request->list))
40455 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40456 return 0;
40457 }
40458
40459 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40460 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40461 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40462 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40463 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40464 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40465 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40466 {
40467 unsigned int nr = DRM_IOCTL_NR(cmd);
40468 - drm_ioctl_compat_t *fn;
40469 int ret;
40470
40471 /* Assume that ioctls without an explicit compat routine will just
40472 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40473 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40474 return drm_ioctl(filp, cmd, arg);
40475
40476 - fn = drm_compat_ioctls[nr];
40477 -
40478 - if (fn != NULL)
40479 - ret = (*fn) (filp, cmd, arg);
40480 + if (drm_compat_ioctls[nr] != NULL)
40481 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40482 else
40483 ret = drm_ioctl(filp, cmd, arg);
40484
40485 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40486 index 00587a1..57a65ca 100644
40487 --- a/drivers/gpu/drm/drm_ioctl.c
40488 +++ b/drivers/gpu/drm/drm_ioctl.c
40489 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40490 struct drm_file *file_priv = filp->private_data;
40491 struct drm_device *dev;
40492 const struct drm_ioctl_desc *ioctl = NULL;
40493 - drm_ioctl_t *func;
40494 + drm_ioctl_no_const_t func;
40495 unsigned int nr = DRM_IOCTL_NR(cmd);
40496 int retcode = -EINVAL;
40497 char stack_kdata[128];
40498 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40499 index 93ec5dc..82acbaf 100644
40500 --- a/drivers/gpu/drm/i810/i810_drv.h
40501 +++ b/drivers/gpu/drm/i810/i810_drv.h
40502 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40503 int page_flipping;
40504
40505 wait_queue_head_t irq_queue;
40506 - atomic_t irq_received;
40507 - atomic_t irq_emitted;
40508 + atomic_unchecked_t irq_received;
40509 + atomic_unchecked_t irq_emitted;
40510
40511 int front_offset;
40512 } drm_i810_private_t;
40513 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40514 index 318ade9..1f5de55 100644
40515 --- a/drivers/gpu/drm/i915/i915_dma.c
40516 +++ b/drivers/gpu/drm/i915/i915_dma.c
40517 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40518 * locking inversion with the driver load path. And the access here is
40519 * completely racy anyway. So don't bother with locking for now.
40520 */
40521 - return dev->open_count == 0;
40522 + return local_read(&dev->open_count) == 0;
40523 }
40524
40525 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40526 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40527 index 1a0611b..dd1fbfc 100644
40528 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40529 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40530 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40531 static int
40532 validate_exec_list(struct drm_device *dev,
40533 struct drm_i915_gem_exec_object2 *exec,
40534 - int count)
40535 + unsigned int count)
40536 {
40537 unsigned relocs_total = 0;
40538 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40539 unsigned invalid_flags;
40540 - int i;
40541 + unsigned int i;
40542
40543 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40544 if (USES_FULL_PPGTT(dev))
40545 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40546 index 2e0613e..a8b94d9 100644
40547 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40548 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40549 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40550 (unsigned long)request);
40551 }
40552
40553 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40554 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40555 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40556 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40557 [DRM_I915_GETPARAM] = compat_i915_getparam,
40558 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40559 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40560 {
40561 unsigned int nr = DRM_IOCTL_NR(cmd);
40562 - drm_ioctl_compat_t *fn = NULL;
40563 int ret;
40564
40565 if (nr < DRM_COMMAND_BASE)
40566 return drm_compat_ioctl(filp, cmd, arg);
40567
40568 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40569 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40570 -
40571 - if (fn != NULL)
40572 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40573 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40574 ret = (*fn) (filp, cmd, arg);
40575 - else
40576 + } else
40577 ret = drm_ioctl(filp, cmd, arg);
40578
40579 return ret;
40580 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40581 index 31b9664..5d478d3 100644
40582 --- a/drivers/gpu/drm/i915/intel_display.c
40583 +++ b/drivers/gpu/drm/i915/intel_display.c
40584 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40585 int subsystem_vendor;
40586 int subsystem_device;
40587 void (*hook)(struct drm_device *dev);
40588 -};
40589 +} __do_const;
40590
40591 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40592 struct intel_dmi_quirk {
40593 void (*hook)(struct drm_device *dev);
40594 const struct dmi_system_id (*dmi_id_list)[];
40595 -};
40596 +} __do_const;
40597
40598 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40599 {
40600 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40601 return 1;
40602 }
40603
40604 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40605 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40606 {
40607 - .dmi_id_list = &(const struct dmi_system_id[]) {
40608 - {
40609 - .callback = intel_dmi_reverse_brightness,
40610 - .ident = "NCR Corporation",
40611 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40612 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40613 - },
40614 - },
40615 - { } /* terminating entry */
40616 + .callback = intel_dmi_reverse_brightness,
40617 + .ident = "NCR Corporation",
40618 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40619 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40620 },
40621 + },
40622 + { } /* terminating entry */
40623 +};
40624 +
40625 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40626 + {
40627 + .dmi_id_list = &intel_dmi_quirks_table,
40628 .hook = quirk_invert_brightness,
40629 },
40630 };
40631 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40632 index b4a2014..219ab78 100644
40633 --- a/drivers/gpu/drm/mga/mga_drv.h
40634 +++ b/drivers/gpu/drm/mga/mga_drv.h
40635 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40636 u32 clear_cmd;
40637 u32 maccess;
40638
40639 - atomic_t vbl_received; /**< Number of vblanks received. */
40640 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40641 wait_queue_head_t fence_queue;
40642 - atomic_t last_fence_retired;
40643 + atomic_unchecked_t last_fence_retired;
40644 u32 next_fence_to_post;
40645
40646 unsigned int fb_cpp;
40647 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40648 index 729bfd5..ead8823 100644
40649 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40650 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40651 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40652 return 0;
40653 }
40654
40655 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40656 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40657 [DRM_MGA_INIT] = compat_mga_init,
40658 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40659 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40660 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40661 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40662 {
40663 unsigned int nr = DRM_IOCTL_NR(cmd);
40664 - drm_ioctl_compat_t *fn = NULL;
40665 int ret;
40666
40667 if (nr < DRM_COMMAND_BASE)
40668 return drm_compat_ioctl(filp, cmd, arg);
40669
40670 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40671 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40672 -
40673 - if (fn != NULL)
40674 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40675 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40676 ret = (*fn) (filp, cmd, arg);
40677 - else
40678 + } else
40679 ret = drm_ioctl(filp, cmd, arg);
40680
40681 return ret;
40682 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40683 index 1b071b8..de8601a 100644
40684 --- a/drivers/gpu/drm/mga/mga_irq.c
40685 +++ b/drivers/gpu/drm/mga/mga_irq.c
40686 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40687 if (crtc != 0)
40688 return 0;
40689
40690 - return atomic_read(&dev_priv->vbl_received);
40691 + return atomic_read_unchecked(&dev_priv->vbl_received);
40692 }
40693
40694
40695 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40696 /* VBLANK interrupt */
40697 if (status & MGA_VLINEPEN) {
40698 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40699 - atomic_inc(&dev_priv->vbl_received);
40700 + atomic_inc_unchecked(&dev_priv->vbl_received);
40701 drm_handle_vblank(dev, 0);
40702 handled = 1;
40703 }
40704 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40705 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40706 MGA_WRITE(MGA_PRIMEND, prim_end);
40707
40708 - atomic_inc(&dev_priv->last_fence_retired);
40709 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40710 wake_up(&dev_priv->fence_queue);
40711 handled = 1;
40712 }
40713 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40714 * using fences.
40715 */
40716 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40717 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40718 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40719 - *sequence) <= (1 << 23)));
40720
40721 *sequence = cur_fence;
40722 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40723 index dae2c96..324dbe4 100644
40724 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40725 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40726 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40727 struct bit_table {
40728 const char id;
40729 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40730 -};
40731 +} __no_const;
40732
40733 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40734
40735 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40736 index 8ae36f2..1147a30 100644
40737 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40738 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40739 @@ -121,7 +121,6 @@ struct nouveau_drm {
40740 struct drm_global_reference mem_global_ref;
40741 struct ttm_bo_global_ref bo_global_ref;
40742 struct ttm_bo_device bdev;
40743 - atomic_t validate_sequence;
40744 int (*move)(struct nouveau_channel *,
40745 struct ttm_buffer_object *,
40746 struct ttm_mem_reg *, struct ttm_mem_reg *);
40747 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40748 index 462679a..88e32a7 100644
40749 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40750 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40751 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40752 unsigned long arg)
40753 {
40754 unsigned int nr = DRM_IOCTL_NR(cmd);
40755 - drm_ioctl_compat_t *fn = NULL;
40756 + drm_ioctl_compat_t fn = NULL;
40757 int ret;
40758
40759 if (nr < DRM_COMMAND_BASE)
40760 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40761 index 3d1cfcb..0542700 100644
40762 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40763 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40764 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40765 }
40766
40767 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40768 - nouveau_vram_manager_init,
40769 - nouveau_vram_manager_fini,
40770 - nouveau_vram_manager_new,
40771 - nouveau_vram_manager_del,
40772 - nouveau_vram_manager_debug
40773 + .init = nouveau_vram_manager_init,
40774 + .takedown = nouveau_vram_manager_fini,
40775 + .get_node = nouveau_vram_manager_new,
40776 + .put_node = nouveau_vram_manager_del,
40777 + .debug = nouveau_vram_manager_debug
40778 };
40779
40780 static int
40781 @@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40782 }
40783
40784 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40785 - nouveau_gart_manager_init,
40786 - nouveau_gart_manager_fini,
40787 - nouveau_gart_manager_new,
40788 - nouveau_gart_manager_del,
40789 - nouveau_gart_manager_debug
40790 + .init = nouveau_gart_manager_init,
40791 + .takedown = nouveau_gart_manager_fini,
40792 + .get_node = nouveau_gart_manager_new,
40793 + .put_node = nouveau_gart_manager_del,
40794 + .debug = nouveau_gart_manager_debug
40795 };
40796
40797 /*XXX*/
40798 @@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40799 }
40800
40801 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40802 - nv04_gart_manager_init,
40803 - nv04_gart_manager_fini,
40804 - nv04_gart_manager_new,
40805 - nv04_gart_manager_del,
40806 - nv04_gart_manager_debug
40807 + .init = nv04_gart_manager_init,
40808 + .takedown = nv04_gart_manager_fini,
40809 + .get_node = nv04_gart_manager_new,
40810 + .put_node = nv04_gart_manager_del,
40811 + .debug = nv04_gart_manager_debug
40812 };
40813
40814 int
40815 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40816 index c7592ec..dd45ebc 100644
40817 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40818 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40819 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40820 * locking inversion with the driver load path. And the access here is
40821 * completely racy anyway. So don't bother with locking for now.
40822 */
40823 - return dev->open_count == 0;
40824 + return local_read(&dev->open_count) == 0;
40825 }
40826
40827 static const struct vga_switcheroo_client_ops
40828 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40829 index 9782364..89bd954 100644
40830 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40831 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40832 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40833 int ret;
40834
40835 mutex_lock(&qdev->async_io_mutex);
40836 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40837 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40838 if (qdev->last_sent_io_cmd > irq_num) {
40839 if (intr)
40840 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40841 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40842 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40843 else
40844 ret = wait_event_timeout(qdev->io_cmd_event,
40845 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40846 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40847 /* 0 is timeout, just bail the "hw" has gone away */
40848 if (ret <= 0)
40849 goto out;
40850 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40851 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40852 }
40853 outb(val, addr);
40854 qdev->last_sent_io_cmd = irq_num + 1;
40855 if (intr)
40856 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40857 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40858 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40859 else
40860 ret = wait_event_timeout(qdev->io_cmd_event,
40861 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40862 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40863 out:
40864 if (ret > 0)
40865 ret = 0;
40866 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40867 index 6911b8c..89d6867 100644
40868 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40869 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40870 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40871 struct drm_info_node *node = (struct drm_info_node *) m->private;
40872 struct qxl_device *qdev = node->minor->dev->dev_private;
40873
40874 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40875 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40876 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40877 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40878 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40879 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40880 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40881 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40882 seq_printf(m, "%d\n", qdev->irq_received_error);
40883 return 0;
40884 }
40885 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40886 index 7c6cafe..460f542 100644
40887 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40888 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40889 @@ -290,10 +290,10 @@ struct qxl_device {
40890 unsigned int last_sent_io_cmd;
40891
40892 /* interrupt handling */
40893 - atomic_t irq_received;
40894 - atomic_t irq_received_display;
40895 - atomic_t irq_received_cursor;
40896 - atomic_t irq_received_io_cmd;
40897 + atomic_unchecked_t irq_received;
40898 + atomic_unchecked_t irq_received_display;
40899 + atomic_unchecked_t irq_received_cursor;
40900 + atomic_unchecked_t irq_received_io_cmd;
40901 unsigned irq_received_error;
40902 wait_queue_head_t display_event;
40903 wait_queue_head_t cursor_event;
40904 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40905 index b110883..dd06418 100644
40906 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40907 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40908 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40909
40910 /* TODO copy slow path code from i915 */
40911 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40912 - 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);
40913 + 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);
40914
40915 {
40916 struct qxl_drawable *draw = fb_cmd;
40917 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40918 struct drm_qxl_reloc reloc;
40919
40920 if (copy_from_user(&reloc,
40921 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40922 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40923 sizeof(reloc))) {
40924 ret = -EFAULT;
40925 goto out_free_bos;
40926 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40927
40928 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40929
40930 - struct drm_qxl_command *commands =
40931 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40932 + struct drm_qxl_command __user *commands =
40933 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40934
40935 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40936 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40937 sizeof(user_cmd)))
40938 return -EFAULT;
40939
40940 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40941 index 0bf1e20..42a7310 100644
40942 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40943 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40944 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40945 if (!pending)
40946 return IRQ_NONE;
40947
40948 - atomic_inc(&qdev->irq_received);
40949 + atomic_inc_unchecked(&qdev->irq_received);
40950
40951 if (pending & QXL_INTERRUPT_DISPLAY) {
40952 - atomic_inc(&qdev->irq_received_display);
40953 + atomic_inc_unchecked(&qdev->irq_received_display);
40954 wake_up_all(&qdev->display_event);
40955 qxl_queue_garbage_collect(qdev, false);
40956 }
40957 if (pending & QXL_INTERRUPT_CURSOR) {
40958 - atomic_inc(&qdev->irq_received_cursor);
40959 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40960 wake_up_all(&qdev->cursor_event);
40961 }
40962 if (pending & QXL_INTERRUPT_IO_CMD) {
40963 - atomic_inc(&qdev->irq_received_io_cmd);
40964 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40965 wake_up_all(&qdev->io_cmd_event);
40966 }
40967 if (pending & QXL_INTERRUPT_ERROR) {
40968 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40969 init_waitqueue_head(&qdev->io_cmd_event);
40970 INIT_WORK(&qdev->client_monitors_config_work,
40971 qxl_client_monitors_config_work_func);
40972 - atomic_set(&qdev->irq_received, 0);
40973 - atomic_set(&qdev->irq_received_display, 0);
40974 - atomic_set(&qdev->irq_received_cursor, 0);
40975 - atomic_set(&qdev->irq_received_io_cmd, 0);
40976 + atomic_set_unchecked(&qdev->irq_received, 0);
40977 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40978 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40979 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40980 qdev->irq_received_error = 0;
40981 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40982 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40983 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40984 index 0cbc4c9..0e46686 100644
40985 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40986 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40987 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40988 }
40989 }
40990
40991 -static struct vm_operations_struct qxl_ttm_vm_ops;
40992 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40993 static const struct vm_operations_struct *ttm_vm_ops;
40994
40995 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40996 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40997 return r;
40998 if (unlikely(ttm_vm_ops == NULL)) {
40999 ttm_vm_ops = vma->vm_ops;
41000 + pax_open_kernel();
41001 qxl_ttm_vm_ops = *ttm_vm_ops;
41002 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41003 + pax_close_kernel();
41004 }
41005 vma->vm_ops = &qxl_ttm_vm_ops;
41006 return 0;
41007 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41008 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41009 {
41010 #if defined(CONFIG_DEBUG_FS)
41011 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41012 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41013 - unsigned i;
41014 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41015 + {
41016 + .name = "qxl_mem_mm",
41017 + .show = &qxl_mm_dump_table,
41018 + },
41019 + {
41020 + .name = "qxl_surf_mm",
41021 + .show = &qxl_mm_dump_table,
41022 + }
41023 + };
41024
41025 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41026 - if (i == 0)
41027 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41028 - else
41029 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41030 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41031 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41032 - qxl_mem_types_list[i].driver_features = 0;
41033 - if (i == 0)
41034 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41035 - else
41036 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41037 + pax_open_kernel();
41038 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41039 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41040 + pax_close_kernel();
41041
41042 - }
41043 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41044 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41045 #else
41046 return 0;
41047 #endif
41048 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41049 index 2c45ac9..5d740f8 100644
41050 --- a/drivers/gpu/drm/r128/r128_cce.c
41051 +++ b/drivers/gpu/drm/r128/r128_cce.c
41052 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41053
41054 /* GH: Simple idle check.
41055 */
41056 - atomic_set(&dev_priv->idle_count, 0);
41057 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41058
41059 /* We don't support anything other than bus-mastering ring mode,
41060 * but the ring can be in either AGP or PCI space for the ring
41061 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41062 index 723e5d6..102dbaf 100644
41063 --- a/drivers/gpu/drm/r128/r128_drv.h
41064 +++ b/drivers/gpu/drm/r128/r128_drv.h
41065 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41066 int is_pci;
41067 unsigned long cce_buffers_offset;
41068
41069 - atomic_t idle_count;
41070 + atomic_unchecked_t idle_count;
41071
41072 int page_flipping;
41073 int current_page;
41074 u32 crtc_offset;
41075 u32 crtc_offset_cntl;
41076
41077 - atomic_t vbl_received;
41078 + atomic_unchecked_t vbl_received;
41079
41080 u32 color_fmt;
41081 unsigned int front_offset;
41082 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41083 index 663f38c..c689495 100644
41084 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41085 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41086 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41087 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41088 }
41089
41090 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41091 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41092 [DRM_R128_INIT] = compat_r128_init,
41093 [DRM_R128_DEPTH] = compat_r128_depth,
41094 [DRM_R128_STIPPLE] = compat_r128_stipple,
41095 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41096 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41097 {
41098 unsigned int nr = DRM_IOCTL_NR(cmd);
41099 - drm_ioctl_compat_t *fn = NULL;
41100 int ret;
41101
41102 if (nr < DRM_COMMAND_BASE)
41103 return drm_compat_ioctl(filp, cmd, arg);
41104
41105 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41106 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41107 -
41108 - if (fn != NULL)
41109 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41110 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41111 ret = (*fn) (filp, cmd, arg);
41112 - else
41113 + } else
41114 ret = drm_ioctl(filp, cmd, arg);
41115
41116 return ret;
41117 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41118 index c2ae496..30b5993 100644
41119 --- a/drivers/gpu/drm/r128/r128_irq.c
41120 +++ b/drivers/gpu/drm/r128/r128_irq.c
41121 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41122 if (crtc != 0)
41123 return 0;
41124
41125 - return atomic_read(&dev_priv->vbl_received);
41126 + return atomic_read_unchecked(&dev_priv->vbl_received);
41127 }
41128
41129 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41130 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41131 /* VBLANK interrupt */
41132 if (status & R128_CRTC_VBLANK_INT) {
41133 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41134 - atomic_inc(&dev_priv->vbl_received);
41135 + atomic_inc_unchecked(&dev_priv->vbl_received);
41136 drm_handle_vblank(dev, 0);
41137 return IRQ_HANDLED;
41138 }
41139 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41140 index 575e986..66e62ca 100644
41141 --- a/drivers/gpu/drm/r128/r128_state.c
41142 +++ b/drivers/gpu/drm/r128/r128_state.c
41143 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41144
41145 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41146 {
41147 - if (atomic_read(&dev_priv->idle_count) == 0)
41148 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41149 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41150 else
41151 - atomic_set(&dev_priv->idle_count, 0);
41152 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41153 }
41154
41155 #endif
41156 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41157 index 4a85bb6..aaea819 100644
41158 --- a/drivers/gpu/drm/radeon/mkregtable.c
41159 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41160 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41161 regex_t mask_rex;
41162 regmatch_t match[4];
41163 char buf[1024];
41164 - size_t end;
41165 + long end;
41166 int len;
41167 int done = 0;
41168 int r;
41169 unsigned o;
41170 struct offset *offset;
41171 char last_reg_s[10];
41172 - int last_reg;
41173 + unsigned long last_reg;
41174
41175 if (regcomp
41176 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41177 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41178 index bdf263a..0305446 100644
41179 --- a/drivers/gpu/drm/radeon/radeon_device.c
41180 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41181 @@ -1216,7 +1216,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41182 * locking inversion with the driver load path. And the access here is
41183 * completely racy anyway. So don't bother with locking for now.
41184 */
41185 - return dev->open_count == 0;
41186 + return local_read(&dev->open_count) == 0;
41187 }
41188
41189 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41190 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41191 index 46bd393..6ae4719 100644
41192 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41193 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41194 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41195
41196 /* SW interrupt */
41197 wait_queue_head_t swi_queue;
41198 - atomic_t swi_emitted;
41199 + atomic_unchecked_t swi_emitted;
41200 int vblank_crtc;
41201 uint32_t irq_enable_reg;
41202 uint32_t r500_disp_irq_reg;
41203 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41204 index 0b98ea1..0881827 100644
41205 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41206 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41207 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41208 request = compat_alloc_user_space(sizeof(*request));
41209 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41210 || __put_user(req32.param, &request->param)
41211 - || __put_user((void __user *)(unsigned long)req32.value,
41212 + || __put_user((unsigned long)req32.value,
41213 &request->value))
41214 return -EFAULT;
41215
41216 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41217 #define compat_radeon_cp_setparam NULL
41218 #endif /* X86_64 || IA64 */
41219
41220 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41221 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41222 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41223 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41224 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41225 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41226 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41227 {
41228 unsigned int nr = DRM_IOCTL_NR(cmd);
41229 - drm_ioctl_compat_t *fn = NULL;
41230 int ret;
41231
41232 if (nr < DRM_COMMAND_BASE)
41233 return drm_compat_ioctl(filp, cmd, arg);
41234
41235 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41236 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41237 -
41238 - if (fn != NULL)
41239 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41240 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41241 ret = (*fn) (filp, cmd, arg);
41242 - else
41243 + } else
41244 ret = drm_ioctl(filp, cmd, arg);
41245
41246 return ret;
41247 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41248 index 244b19b..c19226d 100644
41249 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41250 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41251 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41252 unsigned int ret;
41253 RING_LOCALS;
41254
41255 - atomic_inc(&dev_priv->swi_emitted);
41256 - ret = atomic_read(&dev_priv->swi_emitted);
41257 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41258 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41259
41260 BEGIN_RING(4);
41261 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41262 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41263 drm_radeon_private_t *dev_priv =
41264 (drm_radeon_private_t *) dev->dev_private;
41265
41266 - atomic_set(&dev_priv->swi_emitted, 0);
41267 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41268 init_waitqueue_head(&dev_priv->swi_queue);
41269
41270 dev->max_vblank_count = 0x001fffff;
41271 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41272 index 535403e..5dd655b 100644
41273 --- a/drivers/gpu/drm/radeon/radeon_state.c
41274 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41275 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41276 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41277 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41278
41279 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41280 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41281 sarea_priv->nbox * sizeof(depth_boxes[0])))
41282 return -EFAULT;
41283
41284 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41285 {
41286 drm_radeon_private_t *dev_priv = dev->dev_private;
41287 drm_radeon_getparam_t *param = data;
41288 - int value;
41289 + int value = 0;
41290
41291 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41292
41293 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41294 index d2510cf..63bd4ed 100644
41295 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41296 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41297 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41298 man->size = size >> PAGE_SHIFT;
41299 }
41300
41301 -static struct vm_operations_struct radeon_ttm_vm_ops;
41302 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41303 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41304
41305 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41306 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41307 }
41308 if (unlikely(ttm_vm_ops == NULL)) {
41309 ttm_vm_ops = vma->vm_ops;
41310 + pax_open_kernel();
41311 radeon_ttm_vm_ops = *ttm_vm_ops;
41312 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41313 + pax_close_kernel();
41314 }
41315 vma->vm_ops = &radeon_ttm_vm_ops;
41316 return 0;
41317 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41318 index 054a79f..30d9ac4 100644
41319 --- a/drivers/gpu/drm/tegra/dc.c
41320 +++ b/drivers/gpu/drm/tegra/dc.c
41321 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41322 }
41323
41324 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41325 - dc->debugfs_files[i].data = dc;
41326 + *(void **)&dc->debugfs_files[i].data = dc;
41327
41328 err = drm_debugfs_create_files(dc->debugfs_files,
41329 ARRAY_SIZE(debugfs_files),
41330 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41331 index f787445..2df2c65 100644
41332 --- a/drivers/gpu/drm/tegra/dsi.c
41333 +++ b/drivers/gpu/drm/tegra/dsi.c
41334 @@ -41,7 +41,7 @@ struct tegra_dsi {
41335 struct clk *clk_lp;
41336 struct clk *clk;
41337
41338 - struct drm_info_list *debugfs_files;
41339 + drm_info_list_no_const *debugfs_files;
41340 struct drm_minor *minor;
41341 struct dentry *debugfs;
41342
41343 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41344 index ffe2654..03c7b1c 100644
41345 --- a/drivers/gpu/drm/tegra/hdmi.c
41346 +++ b/drivers/gpu/drm/tegra/hdmi.c
41347 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41348 bool stereo;
41349 bool dvi;
41350
41351 - struct drm_info_list *debugfs_files;
41352 + drm_info_list_no_const *debugfs_files;
41353 struct drm_minor *minor;
41354 struct dentry *debugfs;
41355 };
41356 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41357 index 964387f..4eafc00 100644
41358 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41359 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41360 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41361 }
41362
41363 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41364 - ttm_bo_man_init,
41365 - ttm_bo_man_takedown,
41366 - ttm_bo_man_get_node,
41367 - ttm_bo_man_put_node,
41368 - ttm_bo_man_debug
41369 + .init = ttm_bo_man_init,
41370 + .takedown = ttm_bo_man_takedown,
41371 + .get_node = ttm_bo_man_get_node,
41372 + .put_node = ttm_bo_man_put_node,
41373 + .debug = ttm_bo_man_debug
41374 };
41375 EXPORT_SYMBOL(ttm_bo_manager_func);
41376 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41377 index a1803fb..c53f6b0 100644
41378 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41379 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41380 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41381 zone->glob = glob;
41382 glob->zone_kernel = zone;
41383 ret = kobject_init_and_add(
41384 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41385 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41386 if (unlikely(ret != 0)) {
41387 kobject_put(&zone->kobj);
41388 return ret;
41389 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41390 zone->glob = glob;
41391 glob->zone_dma32 = zone;
41392 ret = kobject_init_and_add(
41393 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41394 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41395 if (unlikely(ret != 0)) {
41396 kobject_put(&zone->kobj);
41397 return ret;
41398 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41399 index 025c429..314062f 100644
41400 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41401 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41402 @@ -54,7 +54,7 @@
41403
41404 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41405 #define SMALL_ALLOCATION 16
41406 -#define FREE_ALL_PAGES (~0U)
41407 +#define FREE_ALL_PAGES (~0UL)
41408 /* times are in msecs */
41409 #define PAGE_FREE_INTERVAL 1000
41410
41411 @@ -299,15 +299,14 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41412 * @free_all: If set to true will free all pages in pool
41413 * @use_static: Safe to use static buffer
41414 **/
41415 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41416 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41417 bool use_static)
41418 {
41419 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41420 unsigned long irq_flags;
41421 struct page *p;
41422 struct page **pages_to_free;
41423 - unsigned freed_pages = 0,
41424 - npages_to_free = nr_free;
41425 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41426
41427 if (NUM_PAGES_TO_ALLOC < nr_free)
41428 npages_to_free = NUM_PAGES_TO_ALLOC;
41429 @@ -371,7 +370,8 @@ restart:
41430 __list_del(&p->lru, &pool->list);
41431
41432 ttm_pool_update_free_locked(pool, freed_pages);
41433 - nr_free -= freed_pages;
41434 + if (likely(nr_free != FREE_ALL_PAGES))
41435 + nr_free -= freed_pages;
41436 }
41437
41438 spin_unlock_irqrestore(&pool->lock, irq_flags);
41439 @@ -399,7 +399,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41440 unsigned i;
41441 unsigned pool_offset;
41442 struct ttm_page_pool *pool;
41443 - int shrink_pages = sc->nr_to_scan;
41444 + unsigned long shrink_pages = sc->nr_to_scan;
41445 unsigned long freed = 0;
41446
41447 if (!mutex_trylock(&lock))
41448 @@ -407,7 +407,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41449 pool_offset = ++start_pool % NUM_POOLS;
41450 /* select start pool in round robin fashion */
41451 for (i = 0; i < NUM_POOLS; ++i) {
41452 - unsigned nr_free = shrink_pages;
41453 + unsigned long nr_free = shrink_pages;
41454 if (shrink_pages == 0)
41455 break;
41456 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41457 @@ -673,7 +673,7 @@ out:
41458 }
41459
41460 /* Put all pages in pages list to correct pool to wait for reuse */
41461 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41462 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41463 enum ttm_caching_state cstate)
41464 {
41465 unsigned long irq_flags;
41466 @@ -728,7 +728,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41467 struct list_head plist;
41468 struct page *p = NULL;
41469 gfp_t gfp_flags = GFP_USER;
41470 - unsigned count;
41471 + unsigned long count;
41472 int r;
41473
41474 /* set zero flag for page allocation if required */
41475 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41476 index 01e1d27..aaa018a 100644
41477 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41478 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41479 @@ -56,7 +56,7 @@
41480
41481 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41482 #define SMALL_ALLOCATION 4
41483 -#define FREE_ALL_PAGES (~0U)
41484 +#define FREE_ALL_PAGES (~0UL)
41485 /* times are in msecs */
41486 #define IS_UNDEFINED (0)
41487 #define IS_WC (1<<1)
41488 @@ -413,7 +413,7 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41489 * @nr_free: If set to true will free all pages in pool
41490 * @use_static: Safe to use static buffer
41491 **/
41492 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41493 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41494 bool use_static)
41495 {
41496 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41497 @@ -421,8 +421,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41498 struct dma_page *dma_p, *tmp;
41499 struct page **pages_to_free;
41500 struct list_head d_pages;
41501 - unsigned freed_pages = 0,
41502 - npages_to_free = nr_free;
41503 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41504
41505 if (NUM_PAGES_TO_ALLOC < nr_free)
41506 npages_to_free = NUM_PAGES_TO_ALLOC;
41507 @@ -499,7 +498,8 @@ restart:
41508 /* remove range of pages from the pool */
41509 if (freed_pages) {
41510 ttm_pool_update_free_locked(pool, freed_pages);
41511 - nr_free -= freed_pages;
41512 + if (likely(nr_free != FREE_ALL_PAGES))
41513 + nr_free -= freed_pages;
41514 }
41515
41516 spin_unlock_irqrestore(&pool->lock, irq_flags);
41517 @@ -936,7 +936,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41518 struct dma_page *d_page, *next;
41519 enum pool_type type;
41520 bool is_cached = false;
41521 - unsigned count = 0, i, npages = 0;
41522 + unsigned long count = 0, i, npages = 0;
41523 unsigned long irq_flags;
41524
41525 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41526 @@ -1012,7 +1012,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41527 static unsigned start_pool;
41528 unsigned idx = 0;
41529 unsigned pool_offset;
41530 - unsigned shrink_pages = sc->nr_to_scan;
41531 + unsigned long shrink_pages = sc->nr_to_scan;
41532 struct device_pools *p;
41533 unsigned long freed = 0;
41534
41535 @@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41536 goto out;
41537 pool_offset = ++start_pool % _manager->npools;
41538 list_for_each_entry(p, &_manager->pools, pools) {
41539 - unsigned nr_free;
41540 + unsigned long nr_free;
41541
41542 if (!p->dev)
41543 continue;
41544 @@ -1039,7 +1039,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41545 shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
41546 freed += nr_free - shrink_pages;
41547
41548 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41549 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41550 p->pool->dev_name, p->pool->name, current->pid,
41551 nr_free, shrink_pages);
41552 }
41553 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41554 index 8cbcb45..a4d9cf7 100644
41555 --- a/drivers/gpu/drm/udl/udl_fb.c
41556 +++ b/drivers/gpu/drm/udl/udl_fb.c
41557 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41558 fb_deferred_io_cleanup(info);
41559 kfree(info->fbdefio);
41560 info->fbdefio = NULL;
41561 - info->fbops->fb_mmap = udl_fb_mmap;
41562 }
41563
41564 pr_warn("released /dev/fb%d user=%d count=%d\n",
41565 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41566 index ef8c500..01030c8 100644
41567 --- a/drivers/gpu/drm/via/via_drv.h
41568 +++ b/drivers/gpu/drm/via/via_drv.h
41569 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41570 typedef uint32_t maskarray_t[5];
41571
41572 typedef struct drm_via_irq {
41573 - atomic_t irq_received;
41574 + atomic_unchecked_t irq_received;
41575 uint32_t pending_mask;
41576 uint32_t enable_mask;
41577 wait_queue_head_t irq_queue;
41578 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41579 struct timeval last_vblank;
41580 int last_vblank_valid;
41581 unsigned usec_per_vblank;
41582 - atomic_t vbl_received;
41583 + atomic_unchecked_t vbl_received;
41584 drm_via_state_t hc_state;
41585 char pci_buf[VIA_PCI_BUF_SIZE];
41586 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41587 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41588 index 1319433..a993b0c 100644
41589 --- a/drivers/gpu/drm/via/via_irq.c
41590 +++ b/drivers/gpu/drm/via/via_irq.c
41591 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41592 if (crtc != 0)
41593 return 0;
41594
41595 - return atomic_read(&dev_priv->vbl_received);
41596 + return atomic_read_unchecked(&dev_priv->vbl_received);
41597 }
41598
41599 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41600 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41601
41602 status = VIA_READ(VIA_REG_INTERRUPT);
41603 if (status & VIA_IRQ_VBLANK_PENDING) {
41604 - atomic_inc(&dev_priv->vbl_received);
41605 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41606 + atomic_inc_unchecked(&dev_priv->vbl_received);
41607 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41608 do_gettimeofday(&cur_vblank);
41609 if (dev_priv->last_vblank_valid) {
41610 dev_priv->usec_per_vblank =
41611 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41612 dev_priv->last_vblank = cur_vblank;
41613 dev_priv->last_vblank_valid = 1;
41614 }
41615 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41616 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41617 DRM_DEBUG("US per vblank is: %u\n",
41618 dev_priv->usec_per_vblank);
41619 }
41620 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41621
41622 for (i = 0; i < dev_priv->num_irqs; ++i) {
41623 if (status & cur_irq->pending_mask) {
41624 - atomic_inc(&cur_irq->irq_received);
41625 + atomic_inc_unchecked(&cur_irq->irq_received);
41626 wake_up(&cur_irq->irq_queue);
41627 handled = 1;
41628 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41629 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41630 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41631 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41632 masks[irq][4]));
41633 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41634 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41635 } else {
41636 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41637 (((cur_irq_sequence =
41638 - atomic_read(&cur_irq->irq_received)) -
41639 + atomic_read_unchecked(&cur_irq->irq_received)) -
41640 *sequence) <= (1 << 23)));
41641 }
41642 *sequence = cur_irq_sequence;
41643 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41644 }
41645
41646 for (i = 0; i < dev_priv->num_irqs; ++i) {
41647 - atomic_set(&cur_irq->irq_received, 0);
41648 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41649 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41650 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41651 init_waitqueue_head(&cur_irq->irq_queue);
41652 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41653 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41654 case VIA_IRQ_RELATIVE:
41655 irqwait->request.sequence +=
41656 - atomic_read(&cur_irq->irq_received);
41657 + atomic_read_unchecked(&cur_irq->irq_received);
41658 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41659 case VIA_IRQ_ABSOLUTE:
41660 break;
41661 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41662 index d26a6da..5fa41ed 100644
41663 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41664 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41665 @@ -447,7 +447,7 @@ struct vmw_private {
41666 * Fencing and IRQs.
41667 */
41668
41669 - atomic_t marker_seq;
41670 + atomic_unchecked_t marker_seq;
41671 wait_queue_head_t fence_queue;
41672 wait_queue_head_t fifo_queue;
41673 spinlock_t waiter_lock;
41674 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41675 index 39f2b03..d1b0a64 100644
41676 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41677 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41678 @@ -152,7 +152,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41679 (unsigned int) min,
41680 (unsigned int) fifo->capabilities);
41681
41682 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41683 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41684 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41685 vmw_marker_queue_init(&fifo->marker_queue);
41686 return vmw_fifo_send_fence(dev_priv, &dummy);
41687 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41688 if (reserveable)
41689 iowrite32(bytes, fifo_mem +
41690 SVGA_FIFO_RESERVED);
41691 - return fifo_mem + (next_cmd >> 2);
41692 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41693 } else {
41694 need_bounce = true;
41695 }
41696 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41697
41698 fm = vmw_fifo_reserve(dev_priv, bytes);
41699 if (unlikely(fm == NULL)) {
41700 - *seqno = atomic_read(&dev_priv->marker_seq);
41701 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41702 ret = -ENOMEM;
41703 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41704 false, 3*HZ);
41705 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41706 }
41707
41708 do {
41709 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41710 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41711 } while (*seqno == 0);
41712
41713 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41714 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41715 index 170b61b..fec7348 100644
41716 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41717 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41718 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41719 }
41720
41721 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41722 - vmw_gmrid_man_init,
41723 - vmw_gmrid_man_takedown,
41724 - vmw_gmrid_man_get_node,
41725 - vmw_gmrid_man_put_node,
41726 - vmw_gmrid_man_debug
41727 + .init = vmw_gmrid_man_init,
41728 + .takedown = vmw_gmrid_man_takedown,
41729 + .get_node = vmw_gmrid_man_get_node,
41730 + .put_node = vmw_gmrid_man_put_node,
41731 + .debug = vmw_gmrid_man_debug
41732 };
41733 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41734 index 69c8ce2..cacb0ab 100644
41735 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41736 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41737 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41738 int ret;
41739
41740 num_clips = arg->num_clips;
41741 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41742 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41743
41744 if (unlikely(num_clips == 0))
41745 return 0;
41746 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41747 int ret;
41748
41749 num_clips = arg->num_clips;
41750 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41751 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41752
41753 if (unlikely(num_clips == 0))
41754 return 0;
41755 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41756 index 9fe9827..0aa2fc0 100644
41757 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41758 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41759 @@ -102,7 +102,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41760 * emitted. Then the fence is stale and signaled.
41761 */
41762
41763 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41764 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41765 > VMW_FENCE_WRAP);
41766
41767 return ret;
41768 @@ -133,7 +133,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41769
41770 if (fifo_idle)
41771 down_read(&fifo_state->rwsem);
41772 - signal_seq = atomic_read(&dev_priv->marker_seq);
41773 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41774 ret = 0;
41775
41776 for (;;) {
41777 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41778 index efd1ffd..0ae13ca 100644
41779 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41780 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41781 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41782 while (!vmw_lag_lt(queue, us)) {
41783 spin_lock(&queue->lock);
41784 if (list_empty(&queue->head))
41785 - seqno = atomic_read(&dev_priv->marker_seq);
41786 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41787 else {
41788 marker = list_first_entry(&queue->head,
41789 struct vmw_marker, head);
41790 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41791 index 37ac7b5..d52a5c9 100644
41792 --- a/drivers/gpu/vga/vga_switcheroo.c
41793 +++ b/drivers/gpu/vga/vga_switcheroo.c
41794 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41795
41796 /* this version is for the case where the power switch is separate
41797 to the device being powered down. */
41798 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41799 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41800 {
41801 /* copy over all the bus versions */
41802 if (dev->bus && dev->bus->pm) {
41803 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41804 return ret;
41805 }
41806
41807 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41808 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41809 {
41810 /* copy over all the bus versions */
41811 if (dev->bus && dev->bus->pm) {
41812 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41813 index dfaccfc..bfea740 100644
41814 --- a/drivers/hid/hid-core.c
41815 +++ b/drivers/hid/hid-core.c
41816 @@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41817
41818 int hid_add_device(struct hid_device *hdev)
41819 {
41820 - static atomic_t id = ATOMIC_INIT(0);
41821 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41822 int ret;
41823
41824 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41825 @@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41826 /* XXX hack, any other cleaner solution after the driver core
41827 * is converted to allow more than 20 bytes as the device name? */
41828 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41829 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41830 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41831
41832 hid_debug_register(hdev, dev_name(&hdev->dev));
41833 ret = device_add(&hdev->dev);
41834 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41835 index 71f5692..147d3da 100644
41836 --- a/drivers/hid/hid-logitech-dj.c
41837 +++ b/drivers/hid/hid-logitech-dj.c
41838 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41839 * device (via hid_input_report() ) and return 1 so hid-core does not do
41840 * anything else with it.
41841 */
41842 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41843 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41844 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41845 + __func__, dj_report->device_index);
41846 + return false;
41847 + }
41848
41849 /* case 1) */
41850 if (data[0] != REPORT_ID_DJ_SHORT)
41851 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41852 index bc4269e..b6e6102 100644
41853 --- a/drivers/hid/hid-sony.c
41854 +++ b/drivers/hid/hid-sony.c
41855 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41856 __u8 buf[36];
41857 };
41858
41859 +#define DS4_REPORT_0x02_SIZE 37
41860 +#define DS4_REPORT_0x05_SIZE 32
41861 +#define DS4_REPORT_0x11_SIZE 78
41862 +#define DS4_REPORT_0x81_SIZE 7
41863 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41864 +
41865 static spinlock_t sony_dev_list_lock;
41866 static LIST_HEAD(sony_device_list);
41867 static DEFINE_IDA(sony_device_id_allocator);
41868 @@ -811,6 +817,7 @@ struct sony_sc {
41869 struct work_struct state_worker;
41870 struct power_supply battery;
41871 int device_id;
41872 + __u8 *output_report_dmabuf;
41873
41874 #ifdef CONFIG_SONY_FF
41875 __u8 left;
41876 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41877
41878 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41879 {
41880 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41881 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41882 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41883 + __u8 *buf;
41884 + int ret;
41885 +
41886 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41887 + if (!buf)
41888 + return -ENOMEM;
41889 +
41890 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41891 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41892 +
41893 + kfree(buf);
41894 +
41895 + return ret;
41896 }
41897
41898 /*
41899 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41900 */
41901 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41902 {
41903 - __u8 buf[37] = { 0 };
41904 + __u8 *buf;
41905 + int ret;
41906
41907 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41908 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41909 + if (!buf)
41910 + return -ENOMEM;
41911 +
41912 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41913 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41914 +
41915 + kfree(buf);
41916 +
41917 + return ret;
41918 }
41919
41920 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41921 @@ -1471,9 +1498,7 @@ error_leds:
41922
41923 static void sixaxis_state_worker(struct work_struct *work)
41924 {
41925 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41926 - int n;
41927 - union sixaxis_output_report_01 report = {
41928 + static const union sixaxis_output_report_01 default_report = {
41929 .buf = {
41930 0x01,
41931 0x00, 0xff, 0x00, 0xff, 0x00,
41932 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41933 0x00, 0x00, 0x00, 0x00, 0x00
41934 }
41935 };
41936 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41937 + struct sixaxis_output_report *report =
41938 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
41939 + int n;
41940 +
41941 + /* Initialize the report with default values */
41942 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41943
41944 #ifdef CONFIG_SONY_FF
41945 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41946 - report.data.rumble.left_motor_force = sc->left;
41947 + report->rumble.right_motor_on = sc->right ? 1 : 0;
41948 + report->rumble.left_motor_force = sc->left;
41949 #endif
41950
41951 - report.data.leds_bitmap |= sc->led_state[0] << 1;
41952 - report.data.leds_bitmap |= sc->led_state[1] << 2;
41953 - report.data.leds_bitmap |= sc->led_state[2] << 3;
41954 - report.data.leds_bitmap |= sc->led_state[3] << 4;
41955 + report->leds_bitmap |= sc->led_state[0] << 1;
41956 + report->leds_bitmap |= sc->led_state[1] << 2;
41957 + report->leds_bitmap |= sc->led_state[2] << 3;
41958 + report->leds_bitmap |= sc->led_state[3] << 4;
41959
41960 /* Set flag for all leds off, required for 3rd party INTEC controller */
41961 - if ((report.data.leds_bitmap & 0x1E) == 0)
41962 - report.data.leds_bitmap |= 0x20;
41963 + if ((report->leds_bitmap & 0x1E) == 0)
41964 + report->leds_bitmap |= 0x20;
41965
41966 /*
41967 * The LEDs in the report are indexed in reverse order to their
41968 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41969 */
41970 for (n = 0; n < 4; n++) {
41971 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41972 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41973 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41974 + report->led[3 - n].duty_off = sc->led_delay_off[n];
41975 + report->led[3 - n].duty_on = sc->led_delay_on[n];
41976 }
41977 }
41978
41979 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41980 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41981 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41982 + sizeof(struct sixaxis_output_report),
41983 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41984 }
41985
41986 static void dualshock4_state_worker(struct work_struct *work)
41987 {
41988 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41989 struct hid_device *hdev = sc->hdev;
41990 + __u8 *buf = sc->output_report_dmabuf;
41991 int offset;
41992
41993 - __u8 buf[78] = { 0 };
41994 -
41995 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41996 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
41997 buf[0] = 0x05;
41998 buf[1] = 0xFF;
41999 offset = 4;
42000 } else {
42001 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
42002 buf[0] = 0x11;
42003 buf[1] = 0xB0;
42004 buf[3] = 0x0F;
42005 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
42006 buf[offset++] = sc->led_delay_off[3];
42007
42008 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42009 - hid_hw_output_report(hdev, buf, 32);
42010 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42011 else
42012 - hid_hw_raw_request(hdev, 0x11, buf, 78,
42013 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42014 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42015 }
42016
42017 +static int sony_allocate_output_report(struct sony_sc *sc)
42018 +{
42019 + if (sc->quirks & SIXAXIS_CONTROLLER)
42020 + sc->output_report_dmabuf =
42021 + kmalloc(sizeof(union sixaxis_output_report_01),
42022 + GFP_KERNEL);
42023 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42024 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42025 + GFP_KERNEL);
42026 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42027 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42028 + GFP_KERNEL);
42029 + else
42030 + return 0;
42031 +
42032 + if (!sc->output_report_dmabuf)
42033 + return -ENOMEM;
42034 +
42035 + return 0;
42036 +}
42037 +
42038 #ifdef CONFIG_SONY_FF
42039 static int sony_play_effect(struct input_dev *dev, void *data,
42040 struct ff_effect *effect)
42041 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42042
42043 static int sony_check_add(struct sony_sc *sc)
42044 {
42045 + __u8 *buf = NULL;
42046 int n, ret;
42047
42048 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42049 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42050 return 0;
42051 }
42052 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42053 - __u8 buf[7];
42054 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42055 + if (!buf)
42056 + return -ENOMEM;
42057
42058 /*
42059 * The MAC address of a DS4 controller connected via USB can be
42060 * retrieved with feature report 0x81. The address begins at
42061 * offset 1.
42062 */
42063 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42064 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42065 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42066 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42067 + HID_REQ_GET_REPORT);
42068
42069 - if (ret != 7) {
42070 + if (ret != DS4_REPORT_0x81_SIZE) {
42071 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42072 - return ret < 0 ? ret : -EINVAL;
42073 + ret = ret < 0 ? ret : -EINVAL;
42074 + goto out_free;
42075 }
42076
42077 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42078 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42079 - __u8 buf[18];
42080 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42081 + if (!buf)
42082 + return -ENOMEM;
42083
42084 /*
42085 * The MAC address of a Sixaxis controller connected via USB can
42086 * be retrieved with feature report 0xf2. The address begins at
42087 * offset 4.
42088 */
42089 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42090 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42091 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42092 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42093 + HID_REQ_GET_REPORT);
42094
42095 - if (ret != 18) {
42096 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42097 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42098 - return ret < 0 ? ret : -EINVAL;
42099 + ret = ret < 0 ? ret : -EINVAL;
42100 + goto out_free;
42101 }
42102
42103 /*
42104 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42105 return 0;
42106 }
42107
42108 - return sony_check_add_dev_list(sc);
42109 + ret = sony_check_add_dev_list(sc);
42110 +
42111 +out_free:
42112 +
42113 + kfree(buf);
42114 +
42115 + return ret;
42116 }
42117
42118 static int sony_set_device_id(struct sony_sc *sc)
42119 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42120 return ret;
42121 }
42122
42123 + ret = sony_allocate_output_report(sc);
42124 + if (ret < 0) {
42125 + hid_err(hdev, "failed to allocate the output report buffer\n");
42126 + goto err_stop;
42127 + }
42128 +
42129 ret = sony_set_device_id(sc);
42130 if (ret < 0) {
42131 hid_err(hdev, "failed to allocate the device id\n");
42132 @@ -1984,6 +2060,7 @@ err_stop:
42133 if (sc->quirks & SONY_BATTERY_SUPPORT)
42134 sony_battery_remove(sc);
42135 sony_cancel_work_sync(sc);
42136 + kfree(sc->output_report_dmabuf);
42137 sony_remove_dev_list(sc);
42138 sony_release_device_id(sc);
42139 hid_hw_stop(hdev);
42140 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42141
42142 sony_cancel_work_sync(sc);
42143
42144 + kfree(sc->output_report_dmabuf);
42145 +
42146 sony_remove_dev_list(sc);
42147
42148 sony_release_device_id(sc);
42149 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42150 index c13fb5b..55a3802 100644
42151 --- a/drivers/hid/hid-wiimote-debug.c
42152 +++ b/drivers/hid/hid-wiimote-debug.c
42153 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42154 else if (size == 0)
42155 return -EIO;
42156
42157 - if (copy_to_user(u, buf, size))
42158 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42159 return -EFAULT;
42160
42161 *off += size;
42162 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42163 index 433f72a..2926005 100644
42164 --- a/drivers/hv/channel.c
42165 +++ b/drivers/hv/channel.c
42166 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42167 unsigned long flags;
42168 int ret = 0;
42169
42170 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42171 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42172 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42173 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42174
42175 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42176 if (ret)
42177 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42178 index 3e4235c..877d0e5 100644
42179 --- a/drivers/hv/hv.c
42180 +++ b/drivers/hv/hv.c
42181 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42182 u64 output_address = (output) ? virt_to_phys(output) : 0;
42183 u32 output_address_hi = output_address >> 32;
42184 u32 output_address_lo = output_address & 0xFFFFFFFF;
42185 - void *hypercall_page = hv_context.hypercall_page;
42186 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42187
42188 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42189 "=a"(hv_status_lo) : "d" (control_hi),
42190 @@ -156,7 +156,7 @@ int hv_init(void)
42191 /* See if the hypercall page is already set */
42192 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42193
42194 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42195 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42196
42197 if (!virtaddr)
42198 goto cleanup;
42199 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42200 index 5e90c5d..d8fcefb 100644
42201 --- a/drivers/hv/hv_balloon.c
42202 +++ b/drivers/hv/hv_balloon.c
42203 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42204
42205 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42206 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42207 -static atomic_t trans_id = ATOMIC_INIT(0);
42208 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42209
42210 static int dm_ring_size = (5 * PAGE_SIZE);
42211
42212 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42213 pr_info("Memory hot add failed\n");
42214
42215 dm->state = DM_INITIALIZED;
42216 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42217 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42218 vmbus_sendpacket(dm->dev->channel, &resp,
42219 sizeof(struct dm_hot_add_response),
42220 (unsigned long)NULL,
42221 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42222 memset(&status, 0, sizeof(struct dm_status));
42223 status.hdr.type = DM_STATUS_REPORT;
42224 status.hdr.size = sizeof(struct dm_status);
42225 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42226 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42227
42228 /*
42229 * The host expects the guest to report free memory.
42230 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42231 * send the status. This can happen if we were interrupted
42232 * after we picked our transaction ID.
42233 */
42234 - if (status.hdr.trans_id != atomic_read(&trans_id))
42235 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42236 return;
42237
42238 /*
42239 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42240 */
42241
42242 do {
42243 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42244 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42245 ret = vmbus_sendpacket(dm_device.dev->channel,
42246 bl_resp,
42247 bl_resp->hdr.size,
42248 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42249
42250 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42251 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42252 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42253 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42254 resp.hdr.size = sizeof(struct dm_unballoon_response);
42255
42256 vmbus_sendpacket(dm_device.dev->channel, &resp,
42257 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42258 memset(&version_req, 0, sizeof(struct dm_version_request));
42259 version_req.hdr.type = DM_VERSION_REQUEST;
42260 version_req.hdr.size = sizeof(struct dm_version_request);
42261 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42262 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42263 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42264 version_req.is_last_attempt = 1;
42265
42266 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42267 memset(&version_req, 0, sizeof(struct dm_version_request));
42268 version_req.hdr.type = DM_VERSION_REQUEST;
42269 version_req.hdr.size = sizeof(struct dm_version_request);
42270 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42271 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42272 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42273 version_req.is_last_attempt = 0;
42274
42275 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42276 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42277 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42278 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42279 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42280 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42281
42282 cap_msg.caps.cap_bits.balloon = 1;
42283 cap_msg.caps.cap_bits.hot_add = 1;
42284 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42285 index c386d8d..d6004c4 100644
42286 --- a/drivers/hv/hyperv_vmbus.h
42287 +++ b/drivers/hv/hyperv_vmbus.h
42288 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42289 struct vmbus_connection {
42290 enum vmbus_connect_state conn_state;
42291
42292 - atomic_t next_gpadl_handle;
42293 + atomic_unchecked_t next_gpadl_handle;
42294
42295 /*
42296 * Represents channel interrupts. Each bit position represents a
42297 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42298 index 4d6b269..2e23b86 100644
42299 --- a/drivers/hv/vmbus_drv.c
42300 +++ b/drivers/hv/vmbus_drv.c
42301 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42302 {
42303 int ret = 0;
42304
42305 - static atomic_t device_num = ATOMIC_INIT(0);
42306 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42307
42308 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42309 - atomic_inc_return(&device_num));
42310 + atomic_inc_return_unchecked(&device_num));
42311
42312 child_device_obj->device.bus = &hv_bus;
42313 child_device_obj->device.parent = &hv_acpi_dev->dev;
42314 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42315 index 579bdf9..75118b5 100644
42316 --- a/drivers/hwmon/acpi_power_meter.c
42317 +++ b/drivers/hwmon/acpi_power_meter.c
42318 @@ -116,7 +116,7 @@ struct sensor_template {
42319 struct device_attribute *devattr,
42320 const char *buf, size_t count);
42321 int index;
42322 -};
42323 +} __do_const;
42324
42325 /* Averaging interval */
42326 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42327 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42328 struct sensor_template *attrs)
42329 {
42330 struct device *dev = &resource->acpi_dev->dev;
42331 - struct sensor_device_attribute *sensors =
42332 + sensor_device_attribute_no_const *sensors =
42333 &resource->sensors[resource->num_sensors];
42334 int res = 0;
42335
42336 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42337 index 3288f13..71cfb4e 100644
42338 --- a/drivers/hwmon/applesmc.c
42339 +++ b/drivers/hwmon/applesmc.c
42340 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42341 {
42342 struct applesmc_node_group *grp;
42343 struct applesmc_dev_attr *node;
42344 - struct attribute *attr;
42345 + attribute_no_const *attr;
42346 int ret, i;
42347
42348 for (grp = groups; grp->format; grp++) {
42349 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42350 index cccef87..06ce8ec 100644
42351 --- a/drivers/hwmon/asus_atk0110.c
42352 +++ b/drivers/hwmon/asus_atk0110.c
42353 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42354 struct atk_sensor_data {
42355 struct list_head list;
42356 struct atk_data *data;
42357 - struct device_attribute label_attr;
42358 - struct device_attribute input_attr;
42359 - struct device_attribute limit1_attr;
42360 - struct device_attribute limit2_attr;
42361 + device_attribute_no_const label_attr;
42362 + device_attribute_no_const input_attr;
42363 + device_attribute_no_const limit1_attr;
42364 + device_attribute_no_const limit2_attr;
42365 char label_attr_name[ATTR_NAME_SIZE];
42366 char input_attr_name[ATTR_NAME_SIZE];
42367 char limit1_attr_name[ATTR_NAME_SIZE];
42368 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42369 static struct device_attribute atk_name_attr =
42370 __ATTR(name, 0444, atk_name_show, NULL);
42371
42372 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42373 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42374 sysfs_show_func show)
42375 {
42376 sysfs_attr_init(&attr->attr);
42377 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42378 index d76f0b7..55ae976 100644
42379 --- a/drivers/hwmon/coretemp.c
42380 +++ b/drivers/hwmon/coretemp.c
42381 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42382 return NOTIFY_OK;
42383 }
42384
42385 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42386 +static struct notifier_block coretemp_cpu_notifier = {
42387 .notifier_call = coretemp_cpu_callback,
42388 };
42389
42390 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42391 index 7a8a6fb..015c1fd 100644
42392 --- a/drivers/hwmon/ibmaem.c
42393 +++ b/drivers/hwmon/ibmaem.c
42394 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42395 struct aem_rw_sensor_template *rw)
42396 {
42397 struct device *dev = &data->pdev->dev;
42398 - struct sensor_device_attribute *sensors = data->sensors;
42399 + sensor_device_attribute_no_const *sensors = data->sensors;
42400 int err;
42401
42402 /* Set up read-only sensors */
42403 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42404 index 14c82da..09b25d7 100644
42405 --- a/drivers/hwmon/iio_hwmon.c
42406 +++ b/drivers/hwmon/iio_hwmon.c
42407 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42408 {
42409 struct device *dev = &pdev->dev;
42410 struct iio_hwmon_state *st;
42411 - struct sensor_device_attribute *a;
42412 + sensor_device_attribute_no_const *a;
42413 int ret, i;
42414 int in_i = 1, temp_i = 1, curr_i = 1;
42415 enum iio_chan_type type;
42416 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42417 index 7710f46..427a28d 100644
42418 --- a/drivers/hwmon/nct6683.c
42419 +++ b/drivers/hwmon/nct6683.c
42420 @@ -397,11 +397,11 @@ static struct attribute_group *
42421 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42422 int repeat)
42423 {
42424 - struct sensor_device_attribute_2 *a2;
42425 - struct sensor_device_attribute *a;
42426 + sensor_device_attribute_2_no_const *a2;
42427 + sensor_device_attribute_no_const *a;
42428 struct sensor_device_template **t;
42429 struct sensor_device_attr_u *su;
42430 - struct attribute_group *group;
42431 + attribute_group_no_const *group;
42432 struct attribute **attrs;
42433 int i, j, count;
42434
42435 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42436 index 504cbdd..35d6f25 100644
42437 --- a/drivers/hwmon/nct6775.c
42438 +++ b/drivers/hwmon/nct6775.c
42439 @@ -943,10 +943,10 @@ static struct attribute_group *
42440 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42441 int repeat)
42442 {
42443 - struct attribute_group *group;
42444 + attribute_group_no_const *group;
42445 struct sensor_device_attr_u *su;
42446 - struct sensor_device_attribute *a;
42447 - struct sensor_device_attribute_2 *a2;
42448 + sensor_device_attribute_no_const *a;
42449 + sensor_device_attribute_2_no_const *a2;
42450 struct attribute **attrs;
42451 struct sensor_device_template **t;
42452 int i, count;
42453 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42454 index 291d11f..3f0dbbd 100644
42455 --- a/drivers/hwmon/pmbus/pmbus_core.c
42456 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42457 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42458 return 0;
42459 }
42460
42461 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42462 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42463 const char *name,
42464 umode_t mode,
42465 ssize_t (*show)(struct device *dev,
42466 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42467 dev_attr->store = store;
42468 }
42469
42470 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42471 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42472 const char *name,
42473 umode_t mode,
42474 ssize_t (*show)(struct device *dev,
42475 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42476 u16 reg, u8 mask)
42477 {
42478 struct pmbus_boolean *boolean;
42479 - struct sensor_device_attribute *a;
42480 + sensor_device_attribute_no_const *a;
42481
42482 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42483 if (!boolean)
42484 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42485 bool update, bool readonly)
42486 {
42487 struct pmbus_sensor *sensor;
42488 - struct device_attribute *a;
42489 + device_attribute_no_const *a;
42490
42491 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42492 if (!sensor)
42493 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42494 const char *lstring, int index)
42495 {
42496 struct pmbus_label *label;
42497 - struct device_attribute *a;
42498 + device_attribute_no_const *a;
42499
42500 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42501 if (!label)
42502 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42503 index 97cd45a..ac54d8b 100644
42504 --- a/drivers/hwmon/sht15.c
42505 +++ b/drivers/hwmon/sht15.c
42506 @@ -169,7 +169,7 @@ struct sht15_data {
42507 int supply_uv;
42508 bool supply_uv_valid;
42509 struct work_struct update_supply_work;
42510 - atomic_t interrupt_handled;
42511 + atomic_unchecked_t interrupt_handled;
42512 };
42513
42514 /**
42515 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42516 ret = gpio_direction_input(data->pdata->gpio_data);
42517 if (ret)
42518 return ret;
42519 - atomic_set(&data->interrupt_handled, 0);
42520 + atomic_set_unchecked(&data->interrupt_handled, 0);
42521
42522 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42523 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42524 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42525 /* Only relevant if the interrupt hasn't occurred. */
42526 - if (!atomic_read(&data->interrupt_handled))
42527 + if (!atomic_read_unchecked(&data->interrupt_handled))
42528 schedule_work(&data->read_work);
42529 }
42530 ret = wait_event_timeout(data->wait_queue,
42531 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42532
42533 /* First disable the interrupt */
42534 disable_irq_nosync(irq);
42535 - atomic_inc(&data->interrupt_handled);
42536 + atomic_inc_unchecked(&data->interrupt_handled);
42537 /* Then schedule a reading work struct */
42538 if (data->state != SHT15_READING_NOTHING)
42539 schedule_work(&data->read_work);
42540 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42541 * If not, then start the interrupt again - care here as could
42542 * have gone low in meantime so verify it hasn't!
42543 */
42544 - atomic_set(&data->interrupt_handled, 0);
42545 + atomic_set_unchecked(&data->interrupt_handled, 0);
42546 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42547 /* If still not occurred or another handler was scheduled */
42548 if (gpio_get_value(data->pdata->gpio_data)
42549 - || atomic_read(&data->interrupt_handled))
42550 + || atomic_read_unchecked(&data->interrupt_handled))
42551 return;
42552 }
42553
42554 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42555 index 8df43c5..b07b91d 100644
42556 --- a/drivers/hwmon/via-cputemp.c
42557 +++ b/drivers/hwmon/via-cputemp.c
42558 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42559 return NOTIFY_OK;
42560 }
42561
42562 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42563 +static struct notifier_block via_cputemp_cpu_notifier = {
42564 .notifier_call = via_cputemp_cpu_callback,
42565 };
42566
42567 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42568 index 65e3240..e6c511d 100644
42569 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42570 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42571 @@ -39,7 +39,7 @@
42572 extern struct i2c_adapter amd756_smbus;
42573
42574 static struct i2c_adapter *s4882_adapter;
42575 -static struct i2c_algorithm *s4882_algo;
42576 +static i2c_algorithm_no_const *s4882_algo;
42577
42578 /* Wrapper access functions for multiplexed SMBus */
42579 static DEFINE_MUTEX(amd756_lock);
42580 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42581 index b19a310..d6eece0 100644
42582 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42583 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42584 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42585 /* usb layer */
42586
42587 /* Send command to device, and get response. */
42588 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42589 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42590 {
42591 int ret = 0;
42592 int actual;
42593 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42594 index 88eda09..cf40434 100644
42595 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42596 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42597 @@ -37,7 +37,7 @@
42598 extern struct i2c_adapter *nforce2_smbus;
42599
42600 static struct i2c_adapter *s4985_adapter;
42601 -static struct i2c_algorithm *s4985_algo;
42602 +static i2c_algorithm_no_const *s4985_algo;
42603
42604 /* Wrapper access functions for multiplexed SMBus */
42605 static DEFINE_MUTEX(nforce2_lock);
42606 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42607 index 71c7a39..71dd3e0 100644
42608 --- a/drivers/i2c/i2c-dev.c
42609 +++ b/drivers/i2c/i2c-dev.c
42610 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42611 break;
42612 }
42613
42614 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42615 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42616 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42617 if (IS_ERR(rdwr_pa[i].buf)) {
42618 res = PTR_ERR(rdwr_pa[i].buf);
42619 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42620 index 0b510ba..4fbb5085 100644
42621 --- a/drivers/ide/ide-cd.c
42622 +++ b/drivers/ide/ide-cd.c
42623 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42624 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42625 if ((unsigned long)buf & alignment
42626 || blk_rq_bytes(rq) & q->dma_pad_mask
42627 - || object_is_on_stack(buf))
42628 + || object_starts_on_stack(buf))
42629 drive->dma = 0;
42630 }
42631 }
42632 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42633 index af3e76d..96dfe5e 100644
42634 --- a/drivers/iio/industrialio-core.c
42635 +++ b/drivers/iio/industrialio-core.c
42636 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42637 }
42638
42639 static
42640 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42641 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42642 const char *postfix,
42643 struct iio_chan_spec const *chan,
42644 ssize_t (*readfunc)(struct device *dev,
42645 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42646 index e28a494..f7c2671 100644
42647 --- a/drivers/infiniband/core/cm.c
42648 +++ b/drivers/infiniband/core/cm.c
42649 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42650
42651 struct cm_counter_group {
42652 struct kobject obj;
42653 - atomic_long_t counter[CM_ATTR_COUNT];
42654 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42655 };
42656
42657 struct cm_counter_attribute {
42658 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42659 struct ib_mad_send_buf *msg = NULL;
42660 int ret;
42661
42662 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42663 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42664 counter[CM_REQ_COUNTER]);
42665
42666 /* Quick state check to discard duplicate REQs. */
42667 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42668 if (!cm_id_priv)
42669 return;
42670
42671 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42672 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42673 counter[CM_REP_COUNTER]);
42674 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42675 if (ret)
42676 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42677 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42678 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42679 spin_unlock_irq(&cm_id_priv->lock);
42680 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42681 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42682 counter[CM_RTU_COUNTER]);
42683 goto out;
42684 }
42685 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42686 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42687 dreq_msg->local_comm_id);
42688 if (!cm_id_priv) {
42689 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42690 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42691 counter[CM_DREQ_COUNTER]);
42692 cm_issue_drep(work->port, work->mad_recv_wc);
42693 return -EINVAL;
42694 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42695 case IB_CM_MRA_REP_RCVD:
42696 break;
42697 case IB_CM_TIMEWAIT:
42698 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42699 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42700 counter[CM_DREQ_COUNTER]);
42701 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42702 goto unlock;
42703 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42704 cm_free_msg(msg);
42705 goto deref;
42706 case IB_CM_DREQ_RCVD:
42707 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42708 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42709 counter[CM_DREQ_COUNTER]);
42710 goto unlock;
42711 default:
42712 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42713 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42714 cm_id_priv->msg, timeout)) {
42715 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42716 - atomic_long_inc(&work->port->
42717 + atomic_long_inc_unchecked(&work->port->
42718 counter_group[CM_RECV_DUPLICATES].
42719 counter[CM_MRA_COUNTER]);
42720 goto out;
42721 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42722 break;
42723 case IB_CM_MRA_REQ_RCVD:
42724 case IB_CM_MRA_REP_RCVD:
42725 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42726 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42727 counter[CM_MRA_COUNTER]);
42728 /* fall through */
42729 default:
42730 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42731 case IB_CM_LAP_IDLE:
42732 break;
42733 case IB_CM_MRA_LAP_SENT:
42734 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42735 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42736 counter[CM_LAP_COUNTER]);
42737 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42738 goto unlock;
42739 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42740 cm_free_msg(msg);
42741 goto deref;
42742 case IB_CM_LAP_RCVD:
42743 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42744 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42745 counter[CM_LAP_COUNTER]);
42746 goto unlock;
42747 default:
42748 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42749 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42750 if (cur_cm_id_priv) {
42751 spin_unlock_irq(&cm.lock);
42752 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42753 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42754 counter[CM_SIDR_REQ_COUNTER]);
42755 goto out; /* Duplicate message. */
42756 }
42757 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42758 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42759 msg->retries = 1;
42760
42761 - atomic_long_add(1 + msg->retries,
42762 + atomic_long_add_unchecked(1 + msg->retries,
42763 &port->counter_group[CM_XMIT].counter[attr_index]);
42764 if (msg->retries)
42765 - atomic_long_add(msg->retries,
42766 + atomic_long_add_unchecked(msg->retries,
42767 &port->counter_group[CM_XMIT_RETRIES].
42768 counter[attr_index]);
42769
42770 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42771 }
42772
42773 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42774 - atomic_long_inc(&port->counter_group[CM_RECV].
42775 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42776 counter[attr_id - CM_ATTR_ID_OFFSET]);
42777
42778 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42779 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42780 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42781
42782 return sprintf(buf, "%ld\n",
42783 - atomic_long_read(&group->counter[cm_attr->index]));
42784 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42785 }
42786
42787 static const struct sysfs_ops cm_counter_ops = {
42788 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42789 index 9f5ad7c..588cd84 100644
42790 --- a/drivers/infiniband/core/fmr_pool.c
42791 +++ b/drivers/infiniband/core/fmr_pool.c
42792 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42793
42794 struct task_struct *thread;
42795
42796 - atomic_t req_ser;
42797 - atomic_t flush_ser;
42798 + atomic_unchecked_t req_ser;
42799 + atomic_unchecked_t flush_ser;
42800
42801 wait_queue_head_t force_wait;
42802 };
42803 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42804 struct ib_fmr_pool *pool = pool_ptr;
42805
42806 do {
42807 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42808 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42809 ib_fmr_batch_release(pool);
42810
42811 - atomic_inc(&pool->flush_ser);
42812 + atomic_inc_unchecked(&pool->flush_ser);
42813 wake_up_interruptible(&pool->force_wait);
42814
42815 if (pool->flush_function)
42816 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42817 }
42818
42819 set_current_state(TASK_INTERRUPTIBLE);
42820 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42821 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42822 !kthread_should_stop())
42823 schedule();
42824 __set_current_state(TASK_RUNNING);
42825 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42826 pool->dirty_watermark = params->dirty_watermark;
42827 pool->dirty_len = 0;
42828 spin_lock_init(&pool->pool_lock);
42829 - atomic_set(&pool->req_ser, 0);
42830 - atomic_set(&pool->flush_ser, 0);
42831 + atomic_set_unchecked(&pool->req_ser, 0);
42832 + atomic_set_unchecked(&pool->flush_ser, 0);
42833 init_waitqueue_head(&pool->force_wait);
42834
42835 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42836 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42837 }
42838 spin_unlock_irq(&pool->pool_lock);
42839
42840 - serial = atomic_inc_return(&pool->req_ser);
42841 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42842 wake_up_process(pool->thread);
42843
42844 if (wait_event_interruptible(pool->force_wait,
42845 - atomic_read(&pool->flush_ser) - serial >= 0))
42846 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42847 return -EINTR;
42848
42849 return 0;
42850 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42851 } else {
42852 list_add_tail(&fmr->list, &pool->dirty_list);
42853 if (++pool->dirty_len >= pool->dirty_watermark) {
42854 - atomic_inc(&pool->req_ser);
42855 + atomic_inc_unchecked(&pool->req_ser);
42856 wake_up_process(pool->thread);
42857 }
42858 }
42859 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42860 index ec7a298..8742e59 100644
42861 --- a/drivers/infiniband/hw/cxgb4/mem.c
42862 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42863 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42864 int err;
42865 struct fw_ri_tpte tpt;
42866 u32 stag_idx;
42867 - static atomic_t key;
42868 + static atomic_unchecked_t key;
42869
42870 if (c4iw_fatal_error(rdev))
42871 return -EIO;
42872 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42873 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42874 rdev->stats.stag.max = rdev->stats.stag.cur;
42875 mutex_unlock(&rdev->stats.lock);
42876 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42877 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42878 }
42879 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42880 __func__, stag_state, type, pdid, stag_idx);
42881 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42882 index 79b3dbc..96e5fcc 100644
42883 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42884 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42885 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42886 struct ib_atomic_eth *ateth;
42887 struct ipath_ack_entry *e;
42888 u64 vaddr;
42889 - atomic64_t *maddr;
42890 + atomic64_unchecked_t *maddr;
42891 u64 sdata;
42892 u32 rkey;
42893 u8 next;
42894 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42895 IB_ACCESS_REMOTE_ATOMIC)))
42896 goto nack_acc_unlck;
42897 /* Perform atomic OP and save result. */
42898 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42899 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42900 sdata = be64_to_cpu(ateth->swap_data);
42901 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42902 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42903 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42904 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42905 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42906 be64_to_cpu(ateth->compare_data),
42907 sdata);
42908 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42909 index 1f95bba..9530f87 100644
42910 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42911 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42912 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42913 unsigned long flags;
42914 struct ib_wc wc;
42915 u64 sdata;
42916 - atomic64_t *maddr;
42917 + atomic64_unchecked_t *maddr;
42918 enum ib_wc_status send_status;
42919
42920 /*
42921 @@ -382,11 +382,11 @@ again:
42922 IB_ACCESS_REMOTE_ATOMIC)))
42923 goto acc_err;
42924 /* Perform atomic OP and save result. */
42925 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42926 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42927 sdata = wqe->wr.wr.atomic.compare_add;
42928 *(u64 *) sqp->s_sge.sge.vaddr =
42929 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42930 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42931 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42932 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42933 sdata, wqe->wr.wr.atomic.swap);
42934 goto send_comp;
42935 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42936 index 82a7dd8..8fb6ba6 100644
42937 --- a/drivers/infiniband/hw/mlx4/mad.c
42938 +++ b/drivers/infiniband/hw/mlx4/mad.c
42939 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42940
42941 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42942 {
42943 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42944 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42945 cpu_to_be64(0xff00000000000000LL);
42946 }
42947
42948 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42949 index ed327e6..ca1739e0 100644
42950 --- a/drivers/infiniband/hw/mlx4/mcg.c
42951 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42952 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42953 {
42954 char name[20];
42955
42956 - atomic_set(&ctx->tid, 0);
42957 + atomic_set_unchecked(&ctx->tid, 0);
42958 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42959 ctx->mcg_wq = create_singlethread_workqueue(name);
42960 if (!ctx->mcg_wq)
42961 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42962 index 6eb743f..a7b0f6d 100644
42963 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42964 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42965 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42966 struct list_head mcg_mgid0_list;
42967 struct workqueue_struct *mcg_wq;
42968 struct mlx4_ib_demux_pv_ctx **tun;
42969 - atomic_t tid;
42970 + atomic_unchecked_t tid;
42971 int flushing; /* flushing the work queue */
42972 };
42973
42974 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42975 index 9d3e5c1..6f166df 100644
42976 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42977 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42978 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42979 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42980 }
42981
42982 -int mthca_QUERY_FW(struct mthca_dev *dev)
42983 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42984 {
42985 struct mthca_mailbox *mailbox;
42986 u32 *outbox;
42987 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42988 CMD_TIME_CLASS_B);
42989 }
42990
42991 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42992 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42993 int num_mtt)
42994 {
42995 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42996 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42997 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42998 }
42999
43000 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43001 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43002 int eq_num)
43003 {
43004 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43005 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43006 CMD_TIME_CLASS_B);
43007 }
43008
43009 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43010 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43011 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43012 void *in_mad, void *response_mad)
43013 {
43014 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43015 index ded76c1..0cf0a08 100644
43016 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43017 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43018 @@ -692,7 +692,7 @@ err_close:
43019 return err;
43020 }
43021
43022 -static int mthca_setup_hca(struct mthca_dev *dev)
43023 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43024 {
43025 int err;
43026
43027 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43028 index ed9a989..6aa5dc2 100644
43029 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43030 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43031 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43032 * through the bitmaps)
43033 */
43034
43035 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43036 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43037 {
43038 int o;
43039 int m;
43040 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43041 return key;
43042 }
43043
43044 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43045 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43046 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43047 {
43048 struct mthca_mailbox *mailbox;
43049 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43050 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43051 }
43052
43053 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43054 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43055 u64 *buffer_list, int buffer_size_shift,
43056 int list_len, u64 iova, u64 total_size,
43057 u32 access, struct mthca_mr *mr)
43058 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43059 index 415f8e1..e34214e 100644
43060 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43061 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43062 @@ -764,7 +764,7 @@ unlock:
43063 return 0;
43064 }
43065
43066 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43067 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43068 {
43069 struct mthca_dev *dev = to_mdev(ibcq->device);
43070 struct mthca_cq *cq = to_mcq(ibcq);
43071 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43072 index 3b2a6dc..bce26ff 100644
43073 --- a/drivers/infiniband/hw/nes/nes.c
43074 +++ b/drivers/infiniband/hw/nes/nes.c
43075 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43076 LIST_HEAD(nes_adapter_list);
43077 static LIST_HEAD(nes_dev_list);
43078
43079 -atomic_t qps_destroyed;
43080 +atomic_unchecked_t qps_destroyed;
43081
43082 static unsigned int ee_flsh_adapter;
43083 static unsigned int sysfs_nonidx_addr;
43084 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43085 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43086 struct nes_adapter *nesadapter = nesdev->nesadapter;
43087
43088 - atomic_inc(&qps_destroyed);
43089 + atomic_inc_unchecked(&qps_destroyed);
43090
43091 /* Free the control structures */
43092
43093 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43094 index bd9d132..70d84f4 100644
43095 --- a/drivers/infiniband/hw/nes/nes.h
43096 +++ b/drivers/infiniband/hw/nes/nes.h
43097 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43098 extern unsigned int wqm_quanta;
43099 extern struct list_head nes_adapter_list;
43100
43101 -extern atomic_t cm_connects;
43102 -extern atomic_t cm_accepts;
43103 -extern atomic_t cm_disconnects;
43104 -extern atomic_t cm_closes;
43105 -extern atomic_t cm_connecteds;
43106 -extern atomic_t cm_connect_reqs;
43107 -extern atomic_t cm_rejects;
43108 -extern atomic_t mod_qp_timouts;
43109 -extern atomic_t qps_created;
43110 -extern atomic_t qps_destroyed;
43111 -extern atomic_t sw_qps_destroyed;
43112 +extern atomic_unchecked_t cm_connects;
43113 +extern atomic_unchecked_t cm_accepts;
43114 +extern atomic_unchecked_t cm_disconnects;
43115 +extern atomic_unchecked_t cm_closes;
43116 +extern atomic_unchecked_t cm_connecteds;
43117 +extern atomic_unchecked_t cm_connect_reqs;
43118 +extern atomic_unchecked_t cm_rejects;
43119 +extern atomic_unchecked_t mod_qp_timouts;
43120 +extern atomic_unchecked_t qps_created;
43121 +extern atomic_unchecked_t qps_destroyed;
43122 +extern atomic_unchecked_t sw_qps_destroyed;
43123 extern u32 mh_detected;
43124 extern u32 mh_pauses_sent;
43125 extern u32 cm_packets_sent;
43126 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43127 extern u32 cm_packets_received;
43128 extern u32 cm_packets_dropped;
43129 extern u32 cm_packets_retrans;
43130 -extern atomic_t cm_listens_created;
43131 -extern atomic_t cm_listens_destroyed;
43132 +extern atomic_unchecked_t cm_listens_created;
43133 +extern atomic_unchecked_t cm_listens_destroyed;
43134 extern u32 cm_backlog_drops;
43135 -extern atomic_t cm_loopbacks;
43136 -extern atomic_t cm_nodes_created;
43137 -extern atomic_t cm_nodes_destroyed;
43138 -extern atomic_t cm_accel_dropped_pkts;
43139 -extern atomic_t cm_resets_recvd;
43140 -extern atomic_t pau_qps_created;
43141 -extern atomic_t pau_qps_destroyed;
43142 +extern atomic_unchecked_t cm_loopbacks;
43143 +extern atomic_unchecked_t cm_nodes_created;
43144 +extern atomic_unchecked_t cm_nodes_destroyed;
43145 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43146 +extern atomic_unchecked_t cm_resets_recvd;
43147 +extern atomic_unchecked_t pau_qps_created;
43148 +extern atomic_unchecked_t pau_qps_destroyed;
43149
43150 extern u32 int_mod_timer_init;
43151 extern u32 int_mod_cq_depth_256;
43152 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43153 index 6f09a72..cf4399d 100644
43154 --- a/drivers/infiniband/hw/nes/nes_cm.c
43155 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43156 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43157 u32 cm_packets_retrans;
43158 u32 cm_packets_created;
43159 u32 cm_packets_received;
43160 -atomic_t cm_listens_created;
43161 -atomic_t cm_listens_destroyed;
43162 +atomic_unchecked_t cm_listens_created;
43163 +atomic_unchecked_t cm_listens_destroyed;
43164 u32 cm_backlog_drops;
43165 -atomic_t cm_loopbacks;
43166 -atomic_t cm_nodes_created;
43167 -atomic_t cm_nodes_destroyed;
43168 -atomic_t cm_accel_dropped_pkts;
43169 -atomic_t cm_resets_recvd;
43170 +atomic_unchecked_t cm_loopbacks;
43171 +atomic_unchecked_t cm_nodes_created;
43172 +atomic_unchecked_t cm_nodes_destroyed;
43173 +atomic_unchecked_t cm_accel_dropped_pkts;
43174 +atomic_unchecked_t cm_resets_recvd;
43175
43176 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43177 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43178 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43179 /* instance of function pointers for client API */
43180 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43181 static struct nes_cm_ops nes_cm_api = {
43182 - mini_cm_accelerated,
43183 - mini_cm_listen,
43184 - mini_cm_del_listen,
43185 - mini_cm_connect,
43186 - mini_cm_close,
43187 - mini_cm_accept,
43188 - mini_cm_reject,
43189 - mini_cm_recv_pkt,
43190 - mini_cm_dealloc_core,
43191 - mini_cm_get,
43192 - mini_cm_set
43193 + .accelerated = mini_cm_accelerated,
43194 + .listen = mini_cm_listen,
43195 + .stop_listener = mini_cm_del_listen,
43196 + .connect = mini_cm_connect,
43197 + .close = mini_cm_close,
43198 + .accept = mini_cm_accept,
43199 + .reject = mini_cm_reject,
43200 + .recv_pkt = mini_cm_recv_pkt,
43201 + .destroy_cm_core = mini_cm_dealloc_core,
43202 + .get = mini_cm_get,
43203 + .set = mini_cm_set
43204 };
43205
43206 static struct nes_cm_core *g_cm_core;
43207
43208 -atomic_t cm_connects;
43209 -atomic_t cm_accepts;
43210 -atomic_t cm_disconnects;
43211 -atomic_t cm_closes;
43212 -atomic_t cm_connecteds;
43213 -atomic_t cm_connect_reqs;
43214 -atomic_t cm_rejects;
43215 +atomic_unchecked_t cm_connects;
43216 +atomic_unchecked_t cm_accepts;
43217 +atomic_unchecked_t cm_disconnects;
43218 +atomic_unchecked_t cm_closes;
43219 +atomic_unchecked_t cm_connecteds;
43220 +atomic_unchecked_t cm_connect_reqs;
43221 +atomic_unchecked_t cm_rejects;
43222
43223 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43224 {
43225 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43226 kfree(listener);
43227 listener = NULL;
43228 ret = 0;
43229 - atomic_inc(&cm_listens_destroyed);
43230 + atomic_inc_unchecked(&cm_listens_destroyed);
43231 } else {
43232 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43233 }
43234 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43235 cm_node->rem_mac);
43236
43237 add_hte_node(cm_core, cm_node);
43238 - atomic_inc(&cm_nodes_created);
43239 + atomic_inc_unchecked(&cm_nodes_created);
43240
43241 return cm_node;
43242 }
43243 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43244 }
43245
43246 atomic_dec(&cm_core->node_cnt);
43247 - atomic_inc(&cm_nodes_destroyed);
43248 + atomic_inc_unchecked(&cm_nodes_destroyed);
43249 nesqp = cm_node->nesqp;
43250 if (nesqp) {
43251 nesqp->cm_node = NULL;
43252 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43253
43254 static void drop_packet(struct sk_buff *skb)
43255 {
43256 - atomic_inc(&cm_accel_dropped_pkts);
43257 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43258 dev_kfree_skb_any(skb);
43259 }
43260
43261 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43262 {
43263
43264 int reset = 0; /* whether to send reset in case of err.. */
43265 - atomic_inc(&cm_resets_recvd);
43266 + atomic_inc_unchecked(&cm_resets_recvd);
43267 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43268 " refcnt=%d\n", cm_node, cm_node->state,
43269 atomic_read(&cm_node->ref_count));
43270 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43271 rem_ref_cm_node(cm_node->cm_core, cm_node);
43272 return NULL;
43273 }
43274 - atomic_inc(&cm_loopbacks);
43275 + atomic_inc_unchecked(&cm_loopbacks);
43276 loopbackremotenode->loopbackpartner = cm_node;
43277 loopbackremotenode->tcp_cntxt.rcv_wscale =
43278 NES_CM_DEFAULT_RCV_WND_SCALE;
43279 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43280 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43281 else {
43282 rem_ref_cm_node(cm_core, cm_node);
43283 - atomic_inc(&cm_accel_dropped_pkts);
43284 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43285 dev_kfree_skb_any(skb);
43286 }
43287 break;
43288 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43289
43290 if ((cm_id) && (cm_id->event_handler)) {
43291 if (issue_disconn) {
43292 - atomic_inc(&cm_disconnects);
43293 + atomic_inc_unchecked(&cm_disconnects);
43294 cm_event.event = IW_CM_EVENT_DISCONNECT;
43295 cm_event.status = disconn_status;
43296 cm_event.local_addr = cm_id->local_addr;
43297 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43298 }
43299
43300 if (issue_close) {
43301 - atomic_inc(&cm_closes);
43302 + atomic_inc_unchecked(&cm_closes);
43303 nes_disconnect(nesqp, 1);
43304
43305 cm_id->provider_data = nesqp;
43306 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43307
43308 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43309 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43310 - atomic_inc(&cm_accepts);
43311 + atomic_inc_unchecked(&cm_accepts);
43312
43313 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43314 netdev_refcnt_read(nesvnic->netdev));
43315 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43316 struct nes_cm_core *cm_core;
43317 u8 *start_buff;
43318
43319 - atomic_inc(&cm_rejects);
43320 + atomic_inc_unchecked(&cm_rejects);
43321 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43322 loopback = cm_node->loopbackpartner;
43323 cm_core = cm_node->cm_core;
43324 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43325 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43326 ntohs(laddr->sin_port));
43327
43328 - atomic_inc(&cm_connects);
43329 + atomic_inc_unchecked(&cm_connects);
43330 nesqp->active_conn = 1;
43331
43332 /* cache the cm_id in the qp */
43333 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43334 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43335 return err;
43336 }
43337 - atomic_inc(&cm_listens_created);
43338 + atomic_inc_unchecked(&cm_listens_created);
43339 }
43340
43341 cm_id->add_ref(cm_id);
43342 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43343
43344 if (nesqp->destroyed)
43345 return;
43346 - atomic_inc(&cm_connecteds);
43347 + atomic_inc_unchecked(&cm_connecteds);
43348 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43349 " local port 0x%04X. jiffies = %lu.\n",
43350 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43351 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43352
43353 cm_id->add_ref(cm_id);
43354 ret = cm_id->event_handler(cm_id, &cm_event);
43355 - atomic_inc(&cm_closes);
43356 + atomic_inc_unchecked(&cm_closes);
43357 cm_event.event = IW_CM_EVENT_CLOSE;
43358 cm_event.status = 0;
43359 cm_event.provider_data = cm_id->provider_data;
43360 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43361 return;
43362 cm_id = cm_node->cm_id;
43363
43364 - atomic_inc(&cm_connect_reqs);
43365 + atomic_inc_unchecked(&cm_connect_reqs);
43366 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43367 cm_node, cm_id, jiffies);
43368
43369 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43370 return;
43371 cm_id = cm_node->cm_id;
43372
43373 - atomic_inc(&cm_connect_reqs);
43374 + atomic_inc_unchecked(&cm_connect_reqs);
43375 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43376 cm_node, cm_id, jiffies);
43377
43378 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43379 index 4166452..fc952c3 100644
43380 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43381 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43382 @@ -40,8 +40,8 @@
43383 #include "nes.h"
43384 #include "nes_mgt.h"
43385
43386 -atomic_t pau_qps_created;
43387 -atomic_t pau_qps_destroyed;
43388 +atomic_unchecked_t pau_qps_created;
43389 +atomic_unchecked_t pau_qps_destroyed;
43390
43391 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43392 {
43393 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43394 {
43395 struct sk_buff *skb;
43396 unsigned long flags;
43397 - atomic_inc(&pau_qps_destroyed);
43398 + atomic_inc_unchecked(&pau_qps_destroyed);
43399
43400 /* Free packets that have not yet been forwarded */
43401 /* Lock is acquired by skb_dequeue when removing the skb */
43402 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43403 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43404 skb_queue_head_init(&nesqp->pau_list);
43405 spin_lock_init(&nesqp->pau_lock);
43406 - atomic_inc(&pau_qps_created);
43407 + atomic_inc_unchecked(&pau_qps_created);
43408 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43409 }
43410
43411 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43412 index 49eb511..a774366 100644
43413 --- a/drivers/infiniband/hw/nes/nes_nic.c
43414 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43415 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43416 target_stat_values[++index] = mh_detected;
43417 target_stat_values[++index] = mh_pauses_sent;
43418 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43419 - target_stat_values[++index] = atomic_read(&cm_connects);
43420 - target_stat_values[++index] = atomic_read(&cm_accepts);
43421 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43422 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43423 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43424 - target_stat_values[++index] = atomic_read(&cm_rejects);
43425 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43426 - target_stat_values[++index] = atomic_read(&qps_created);
43427 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43428 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43429 - target_stat_values[++index] = atomic_read(&cm_closes);
43430 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43431 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43432 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43433 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43434 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43435 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43436 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43437 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43438 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43439 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43440 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43441 target_stat_values[++index] = cm_packets_sent;
43442 target_stat_values[++index] = cm_packets_bounced;
43443 target_stat_values[++index] = cm_packets_created;
43444 target_stat_values[++index] = cm_packets_received;
43445 target_stat_values[++index] = cm_packets_dropped;
43446 target_stat_values[++index] = cm_packets_retrans;
43447 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43448 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43449 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43450 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43451 target_stat_values[++index] = cm_backlog_drops;
43452 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43453 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43454 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43455 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43456 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43457 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43458 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43459 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43460 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43461 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43462 target_stat_values[++index] = nesadapter->free_4kpbl;
43463 target_stat_values[++index] = nesadapter->free_256pbl;
43464 target_stat_values[++index] = int_mod_timer_init;
43465 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43466 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43467 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43468 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43469 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43470 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43471 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43472 }
43473
43474 /**
43475 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43476 index fef067c..6a25ccd 100644
43477 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43478 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43479 @@ -46,9 +46,9 @@
43480
43481 #include <rdma/ib_umem.h>
43482
43483 -atomic_t mod_qp_timouts;
43484 -atomic_t qps_created;
43485 -atomic_t sw_qps_destroyed;
43486 +atomic_unchecked_t mod_qp_timouts;
43487 +atomic_unchecked_t qps_created;
43488 +atomic_unchecked_t sw_qps_destroyed;
43489
43490 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43491
43492 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43493 if (init_attr->create_flags)
43494 return ERR_PTR(-EINVAL);
43495
43496 - atomic_inc(&qps_created);
43497 + atomic_inc_unchecked(&qps_created);
43498 switch (init_attr->qp_type) {
43499 case IB_QPT_RC:
43500 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43501 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43502 struct iw_cm_event cm_event;
43503 int ret = 0;
43504
43505 - atomic_inc(&sw_qps_destroyed);
43506 + atomic_inc_unchecked(&sw_qps_destroyed);
43507 nesqp->destroyed = 1;
43508
43509 /* Blow away the connection if it exists. */
43510 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43511 index c00ae09..04e91be 100644
43512 --- a/drivers/infiniband/hw/qib/qib.h
43513 +++ b/drivers/infiniband/hw/qib/qib.h
43514 @@ -52,6 +52,7 @@
43515 #include <linux/kref.h>
43516 #include <linux/sched.h>
43517 #include <linux/kthread.h>
43518 +#include <linux/slab.h>
43519
43520 #include "qib_common.h"
43521 #include "qib_verbs.h"
43522 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43523 index cdc7df4..a2fdfdb 100644
43524 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43525 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43526 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43527 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43528 }
43529
43530 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43531 +static struct rtnl_link_ops ipoib_link_ops = {
43532 .kind = "ipoib",
43533 .maxtype = IFLA_IPOIB_MAX,
43534 .policy = ipoib_policy,
43535 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43536 index e29c04e..adbf68c 100644
43537 --- a/drivers/input/gameport/gameport.c
43538 +++ b/drivers/input/gameport/gameport.c
43539 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43540 */
43541 static void gameport_init_port(struct gameport *gameport)
43542 {
43543 - static atomic_t gameport_no = ATOMIC_INIT(0);
43544 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43545
43546 __module_get(THIS_MODULE);
43547
43548 mutex_init(&gameport->drv_mutex);
43549 device_initialize(&gameport->dev);
43550 dev_set_name(&gameport->dev, "gameport%lu",
43551 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43552 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43553 gameport->dev.bus = &gameport_bus;
43554 gameport->dev.release = gameport_release_port;
43555 if (gameport->parent)
43556 diff --git a/drivers/input/input.c b/drivers/input/input.c
43557 index 0f175f5..4c481c0 100644
43558 --- a/drivers/input/input.c
43559 +++ b/drivers/input/input.c
43560 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43561 */
43562 struct input_dev *input_allocate_device(void)
43563 {
43564 - static atomic_t input_no = ATOMIC_INIT(0);
43565 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43566 struct input_dev *dev;
43567
43568 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43569 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43570 INIT_LIST_HEAD(&dev->node);
43571
43572 dev_set_name(&dev->dev, "input%lu",
43573 - (unsigned long) atomic_inc_return(&input_no) - 1);
43574 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43575
43576 __module_get(THIS_MODULE);
43577 }
43578 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43579 index 4a95b22..874c182 100644
43580 --- a/drivers/input/joystick/sidewinder.c
43581 +++ b/drivers/input/joystick/sidewinder.c
43582 @@ -30,6 +30,7 @@
43583 #include <linux/kernel.h>
43584 #include <linux/module.h>
43585 #include <linux/slab.h>
43586 +#include <linux/sched.h>
43587 #include <linux/input.h>
43588 #include <linux/gameport.h>
43589 #include <linux/jiffies.h>
43590 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43591 index fc55f0d..11e2aa6 100644
43592 --- a/drivers/input/joystick/xpad.c
43593 +++ b/drivers/input/joystick/xpad.c
43594 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43595
43596 static int xpad_led_probe(struct usb_xpad *xpad)
43597 {
43598 - static atomic_t led_seq = ATOMIC_INIT(0);
43599 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43600 long led_no;
43601 struct xpad_led *led;
43602 struct led_classdev *led_cdev;
43603 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43604 if (!led)
43605 return -ENOMEM;
43606
43607 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43608 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43609
43610 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43611 led->xpad = xpad;
43612 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43613 index afed8e2..3aa8a18 100644
43614 --- a/drivers/input/misc/ims-pcu.c
43615 +++ b/drivers/input/misc/ims-pcu.c
43616 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43617
43618 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43619 {
43620 - static atomic_t device_no = ATOMIC_INIT(0);
43621 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43622
43623 const struct ims_pcu_device_info *info;
43624 int error;
43625 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43626 }
43627
43628 /* Device appears to be operable, complete initialization */
43629 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43630 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43631
43632 /*
43633 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43634 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43635 index f4cf664..3204fda 100644
43636 --- a/drivers/input/mouse/psmouse.h
43637 +++ b/drivers/input/mouse/psmouse.h
43638 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43639 ssize_t (*set)(struct psmouse *psmouse, void *data,
43640 const char *buf, size_t count);
43641 bool protect;
43642 -};
43643 +} __do_const;
43644 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43645
43646 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43647 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43648 index b604564..3f14ae4 100644
43649 --- a/drivers/input/mousedev.c
43650 +++ b/drivers/input/mousedev.c
43651 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43652
43653 spin_unlock_irq(&client->packet_lock);
43654
43655 - if (copy_to_user(buffer, data, count))
43656 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43657 return -EFAULT;
43658
43659 return count;
43660 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43661 index d399b8b..4913ede 100644
43662 --- a/drivers/input/serio/serio.c
43663 +++ b/drivers/input/serio/serio.c
43664 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43665 */
43666 static void serio_init_port(struct serio *serio)
43667 {
43668 - static atomic_t serio_no = ATOMIC_INIT(0);
43669 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43670
43671 __module_get(THIS_MODULE);
43672
43673 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43674 mutex_init(&serio->drv_mutex);
43675 device_initialize(&serio->dev);
43676 dev_set_name(&serio->dev, "serio%lu",
43677 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43678 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43679 serio->dev.bus = &serio_bus;
43680 serio->dev.release = serio_release_port;
43681 serio->dev.groups = serio_device_attr_groups;
43682 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43683 index c9a02fe..0debc75 100644
43684 --- a/drivers/input/serio/serio_raw.c
43685 +++ b/drivers/input/serio/serio_raw.c
43686 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43687
43688 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43689 {
43690 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43691 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43692 struct serio_raw *serio_raw;
43693 int err;
43694
43695 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43696 }
43697
43698 snprintf(serio_raw->name, sizeof(serio_raw->name),
43699 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43700 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43701 kref_init(&serio_raw->kref);
43702 INIT_LIST_HEAD(&serio_raw->client_list);
43703 init_waitqueue_head(&serio_raw->wait);
43704 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43705 index 505a9ad..356734c 100644
43706 --- a/drivers/iommu/amd_iommu.c
43707 +++ b/drivers/iommu/amd_iommu.c
43708 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43709
43710 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43711 {
43712 + phys_addr_t physaddr;
43713 WARN_ON(address & 0x7ULL);
43714
43715 memset(cmd, 0, sizeof(*cmd));
43716 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43717 - cmd->data[1] = upper_32_bits(__pa(address));
43718 +
43719 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43720 + if (object_starts_on_stack((void *)address)) {
43721 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43722 + physaddr = __pa((u64)adjbuf);
43723 + } else
43724 +#endif
43725 + physaddr = __pa(address);
43726 +
43727 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43728 + cmd->data[1] = upper_32_bits(physaddr);
43729 cmd->data[2] = 1;
43730 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43731 }
43732 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43733 index 60558f7..5a02369 100644
43734 --- a/drivers/iommu/arm-smmu.c
43735 +++ b/drivers/iommu/arm-smmu.c
43736 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43737 cfg->irptndx = cfg->cbndx;
43738 }
43739
43740 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43741 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43742 arm_smmu_init_context_bank(smmu_domain);
43743 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43744
43745 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43746 index ed8b048..7fbcc01 100644
43747 --- a/drivers/iommu/iommu.c
43748 +++ b/drivers/iommu/iommu.c
43749 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43750 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43751 {
43752 int err;
43753 - struct notifier_block *nb;
43754 + notifier_block_no_const *nb;
43755 struct iommu_callback_data cb = {
43756 .ops = ops,
43757 };
43758 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43759 index 74a1767..5a359e8 100644
43760 --- a/drivers/iommu/irq_remapping.c
43761 +++ b/drivers/iommu/irq_remapping.c
43762 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43763 void panic_if_irq_remap(const char *msg)
43764 {
43765 if (irq_remapping_enabled)
43766 - panic(msg);
43767 + panic("%s", msg);
43768 }
43769
43770 static void ir_ack_apic_edge(struct irq_data *data)
43771 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43772
43773 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43774 {
43775 - chip->irq_print_chip = ir_print_prefix;
43776 - chip->irq_ack = ir_ack_apic_edge;
43777 - chip->irq_eoi = ir_ack_apic_level;
43778 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43779 + pax_open_kernel();
43780 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43781 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43782 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43783 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43784 + pax_close_kernel();
43785 }
43786
43787 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43788 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43789 index 38493ff..001538b 100644
43790 --- a/drivers/irqchip/irq-gic.c
43791 +++ b/drivers/irqchip/irq-gic.c
43792 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43793 * Supported arch specific GIC irq extension.
43794 * Default make them NULL.
43795 */
43796 -struct irq_chip gic_arch_extn = {
43797 +irq_chip_no_const gic_arch_extn = {
43798 .irq_eoi = NULL,
43799 .irq_mask = NULL,
43800 .irq_unmask = NULL,
43801 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43802 chained_irq_exit(chip, desc);
43803 }
43804
43805 -static struct irq_chip gic_chip = {
43806 +static irq_chip_no_const gic_chip __read_only = {
43807 .name = "GIC",
43808 .irq_mask = gic_mask_irq,
43809 .irq_unmask = gic_unmask_irq,
43810 diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43811 index 542e850..1bb094c 100644
43812 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43813 +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43814 @@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43815 struct intc_irqpin_iomem *i;
43816 struct resource *io[INTC_IRQPIN_REG_NR];
43817 struct resource *irq;
43818 - struct irq_chip *irq_chip;
43819 + irq_chip_no_const *irq_chip;
43820 void (*enable_fn)(struct irq_data *d);
43821 void (*disable_fn)(struct irq_data *d);
43822 const char *name = dev_name(dev);
43823 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43824 index 8777065..a4a9967 100644
43825 --- a/drivers/irqchip/irq-renesas-irqc.c
43826 +++ b/drivers/irqchip/irq-renesas-irqc.c
43827 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43828 struct irqc_priv *p;
43829 struct resource *io;
43830 struct resource *irq;
43831 - struct irq_chip *irq_chip;
43832 + irq_chip_no_const *irq_chip;
43833 const char *name = dev_name(&pdev->dev);
43834 int ret;
43835 int k;
43836 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43837 index 6a2df32..dc962f1 100644
43838 --- a/drivers/isdn/capi/capi.c
43839 +++ b/drivers/isdn/capi/capi.c
43840 @@ -81,8 +81,8 @@ struct capiminor {
43841
43842 struct capi20_appl *ap;
43843 u32 ncci;
43844 - atomic_t datahandle;
43845 - atomic_t msgid;
43846 + atomic_unchecked_t datahandle;
43847 + atomic_unchecked_t msgid;
43848
43849 struct tty_port port;
43850 int ttyinstop;
43851 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43852 capimsg_setu16(s, 2, mp->ap->applid);
43853 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43854 capimsg_setu8 (s, 5, CAPI_RESP);
43855 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43856 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43857 capimsg_setu32(s, 8, mp->ncci);
43858 capimsg_setu16(s, 12, datahandle);
43859 }
43860 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43861 mp->outbytes -= len;
43862 spin_unlock_bh(&mp->outlock);
43863
43864 - datahandle = atomic_inc_return(&mp->datahandle);
43865 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43866 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43867 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43868 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43869 capimsg_setu16(skb->data, 2, mp->ap->applid);
43870 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43871 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43872 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43873 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43874 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43875 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43876 capimsg_setu16(skb->data, 16, len); /* Data length */
43877 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43878 index aecec6d..11e13c5 100644
43879 --- a/drivers/isdn/gigaset/bas-gigaset.c
43880 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43881 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43882
43883
43884 static const struct gigaset_ops gigops = {
43885 - gigaset_write_cmd,
43886 - gigaset_write_room,
43887 - gigaset_chars_in_buffer,
43888 - gigaset_brkchars,
43889 - gigaset_init_bchannel,
43890 - gigaset_close_bchannel,
43891 - gigaset_initbcshw,
43892 - gigaset_freebcshw,
43893 - gigaset_reinitbcshw,
43894 - gigaset_initcshw,
43895 - gigaset_freecshw,
43896 - gigaset_set_modem_ctrl,
43897 - gigaset_baud_rate,
43898 - gigaset_set_line_ctrl,
43899 - gigaset_isoc_send_skb,
43900 - gigaset_isoc_input,
43901 + .write_cmd = gigaset_write_cmd,
43902 + .write_room = gigaset_write_room,
43903 + .chars_in_buffer = gigaset_chars_in_buffer,
43904 + .brkchars = gigaset_brkchars,
43905 + .init_bchannel = gigaset_init_bchannel,
43906 + .close_bchannel = gigaset_close_bchannel,
43907 + .initbcshw = gigaset_initbcshw,
43908 + .freebcshw = gigaset_freebcshw,
43909 + .reinitbcshw = gigaset_reinitbcshw,
43910 + .initcshw = gigaset_initcshw,
43911 + .freecshw = gigaset_freecshw,
43912 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43913 + .baud_rate = gigaset_baud_rate,
43914 + .set_line_ctrl = gigaset_set_line_ctrl,
43915 + .send_skb = gigaset_isoc_send_skb,
43916 + .handle_input = gigaset_isoc_input,
43917 };
43918
43919 /* bas_gigaset_init
43920 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43921 index 600c79b..3752bab 100644
43922 --- a/drivers/isdn/gigaset/interface.c
43923 +++ b/drivers/isdn/gigaset/interface.c
43924 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43925 }
43926 tty->driver_data = cs;
43927
43928 - ++cs->port.count;
43929 + atomic_inc(&cs->port.count);
43930
43931 - if (cs->port.count == 1) {
43932 + if (atomic_read(&cs->port.count) == 1) {
43933 tty_port_tty_set(&cs->port, tty);
43934 cs->port.low_latency = 1;
43935 }
43936 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43937
43938 if (!cs->connected)
43939 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43940 - else if (!cs->port.count)
43941 + else if (!atomic_read(&cs->port.count))
43942 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43943 - else if (!--cs->port.count)
43944 + else if (!atomic_dec_return(&cs->port.count))
43945 tty_port_tty_set(&cs->port, NULL);
43946
43947 mutex_unlock(&cs->mutex);
43948 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43949 index 8c91fd5..14f13ce 100644
43950 --- a/drivers/isdn/gigaset/ser-gigaset.c
43951 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43952 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43953 }
43954
43955 static const struct gigaset_ops ops = {
43956 - gigaset_write_cmd,
43957 - gigaset_write_room,
43958 - gigaset_chars_in_buffer,
43959 - gigaset_brkchars,
43960 - gigaset_init_bchannel,
43961 - gigaset_close_bchannel,
43962 - gigaset_initbcshw,
43963 - gigaset_freebcshw,
43964 - gigaset_reinitbcshw,
43965 - gigaset_initcshw,
43966 - gigaset_freecshw,
43967 - gigaset_set_modem_ctrl,
43968 - gigaset_baud_rate,
43969 - gigaset_set_line_ctrl,
43970 - gigaset_m10x_send_skb, /* asyncdata.c */
43971 - gigaset_m10x_input, /* asyncdata.c */
43972 + .write_cmd = gigaset_write_cmd,
43973 + .write_room = gigaset_write_room,
43974 + .chars_in_buffer = gigaset_chars_in_buffer,
43975 + .brkchars = gigaset_brkchars,
43976 + .init_bchannel = gigaset_init_bchannel,
43977 + .close_bchannel = gigaset_close_bchannel,
43978 + .initbcshw = gigaset_initbcshw,
43979 + .freebcshw = gigaset_freebcshw,
43980 + .reinitbcshw = gigaset_reinitbcshw,
43981 + .initcshw = gigaset_initcshw,
43982 + .freecshw = gigaset_freecshw,
43983 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43984 + .baud_rate = gigaset_baud_rate,
43985 + .set_line_ctrl = gigaset_set_line_ctrl,
43986 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43987 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43988 };
43989
43990
43991 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43992 index a8e652d..edadaa4 100644
43993 --- a/drivers/isdn/gigaset/usb-gigaset.c
43994 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43995 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43996 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43997 memcpy(cs->hw.usb->bchars, buf, 6);
43998 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43999 - 0, 0, &buf, 6, 2000);
44000 + 0, 0, buf, 6, 2000);
44001 }
44002
44003 static void gigaset_freebcshw(struct bc_state *bcs)
44004 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44005 }
44006
44007 static const struct gigaset_ops ops = {
44008 - gigaset_write_cmd,
44009 - gigaset_write_room,
44010 - gigaset_chars_in_buffer,
44011 - gigaset_brkchars,
44012 - gigaset_init_bchannel,
44013 - gigaset_close_bchannel,
44014 - gigaset_initbcshw,
44015 - gigaset_freebcshw,
44016 - gigaset_reinitbcshw,
44017 - gigaset_initcshw,
44018 - gigaset_freecshw,
44019 - gigaset_set_modem_ctrl,
44020 - gigaset_baud_rate,
44021 - gigaset_set_line_ctrl,
44022 - gigaset_m10x_send_skb,
44023 - gigaset_m10x_input,
44024 + .write_cmd = gigaset_write_cmd,
44025 + .write_room = gigaset_write_room,
44026 + .chars_in_buffer = gigaset_chars_in_buffer,
44027 + .brkchars = gigaset_brkchars,
44028 + .init_bchannel = gigaset_init_bchannel,
44029 + .close_bchannel = gigaset_close_bchannel,
44030 + .initbcshw = gigaset_initbcshw,
44031 + .freebcshw = gigaset_freebcshw,
44032 + .reinitbcshw = gigaset_reinitbcshw,
44033 + .initcshw = gigaset_initcshw,
44034 + .freecshw = gigaset_freecshw,
44035 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44036 + .baud_rate = gigaset_baud_rate,
44037 + .set_line_ctrl = gigaset_set_line_ctrl,
44038 + .send_skb = gigaset_m10x_send_skb,
44039 + .handle_input = gigaset_m10x_input,
44040 };
44041
44042 /*
44043 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44044 index 4d9b195..455075c 100644
44045 --- a/drivers/isdn/hardware/avm/b1.c
44046 +++ b/drivers/isdn/hardware/avm/b1.c
44047 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44048 }
44049 if (left) {
44050 if (t4file->user) {
44051 - if (copy_from_user(buf, dp, left))
44052 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44053 return -EFAULT;
44054 } else {
44055 memcpy(buf, dp, left);
44056 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44057 }
44058 if (left) {
44059 if (config->user) {
44060 - if (copy_from_user(buf, dp, left))
44061 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44062 return -EFAULT;
44063 } else {
44064 memcpy(buf, dp, left);
44065 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
44066 index a82e542..f766a79 100644
44067 --- a/drivers/isdn/hardware/eicon/message.c
44068 +++ b/drivers/isdn/hardware/eicon/message.c
44069 @@ -1474,7 +1474,7 @@ static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
44070 add_ai(plci, &parms[5]);
44071 sig_req(plci, REJECT, 0);
44072 }
44073 - else if (Reject == 1 || Reject > 9)
44074 + else if (Reject == 1 || Reject >= 9)
44075 {
44076 add_ai(plci, &parms[5]);
44077 sig_req(plci, HANGUP, 0);
44078 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44079 index 9b856e1..fa03c92 100644
44080 --- a/drivers/isdn/i4l/isdn_common.c
44081 +++ b/drivers/isdn/i4l/isdn_common.c
44082 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44083 } else
44084 return -EINVAL;
44085 case IIOCDBGVAR:
44086 + if (!capable(CAP_SYS_RAWIO))
44087 + return -EPERM;
44088 if (arg) {
44089 if (copy_to_user(argp, &dev, sizeof(ulong)))
44090 return -EFAULT;
44091 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44092 index 91d5730..336523e 100644
44093 --- a/drivers/isdn/i4l/isdn_concap.c
44094 +++ b/drivers/isdn/i4l/isdn_concap.c
44095 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44096 }
44097
44098 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44099 - &isdn_concap_dl_data_req,
44100 - &isdn_concap_dl_connect_req,
44101 - &isdn_concap_dl_disconn_req
44102 + .data_req = &isdn_concap_dl_data_req,
44103 + .connect_req = &isdn_concap_dl_connect_req,
44104 + .disconn_req = &isdn_concap_dl_disconn_req
44105 };
44106
44107 /* The following should better go into a dedicated source file such that
44108 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44109 index bc91261..2ef7e36 100644
44110 --- a/drivers/isdn/i4l/isdn_tty.c
44111 +++ b/drivers/isdn/i4l/isdn_tty.c
44112 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44113
44114 #ifdef ISDN_DEBUG_MODEM_OPEN
44115 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44116 - port->count);
44117 + atomic_read(&port->count));
44118 #endif
44119 - port->count++;
44120 + atomic_inc(&port->count);
44121 port->tty = tty;
44122 /*
44123 * Start up serial port
44124 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44125 #endif
44126 return;
44127 }
44128 - if ((tty->count == 1) && (port->count != 1)) {
44129 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44130 /*
44131 * Uh, oh. tty->count is 1, which means that the tty
44132 * structure will be freed. Info->count should always
44133 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44134 * serial port won't be shutdown.
44135 */
44136 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44137 - "info->count is %d\n", port->count);
44138 - port->count = 1;
44139 + "info->count is %d\n", atomic_read(&port->count));
44140 + atomic_set(&port->count, 1);
44141 }
44142 - if (--port->count < 0) {
44143 + if (atomic_dec_return(&port->count) < 0) {
44144 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44145 - info->line, port->count);
44146 - port->count = 0;
44147 + info->line, atomic_read(&port->count));
44148 + atomic_set(&port->count, 0);
44149 }
44150 - if (port->count) {
44151 + if (atomic_read(&port->count)) {
44152 #ifdef ISDN_DEBUG_MODEM_OPEN
44153 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44154 #endif
44155 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44156 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44157 return;
44158 isdn_tty_shutdown(info);
44159 - port->count = 0;
44160 + atomic_set(&port->count, 0);
44161 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44162 port->tty = NULL;
44163 wake_up_interruptible(&port->open_wait);
44164 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44165 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44166 modem_info *info = &dev->mdm.info[i];
44167
44168 - if (info->port.count == 0)
44169 + if (atomic_read(&info->port.count) == 0)
44170 continue;
44171 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44172 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44173 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44174 index e2d4e58..40cd045 100644
44175 --- a/drivers/isdn/i4l/isdn_x25iface.c
44176 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44177 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44178
44179
44180 static struct concap_proto_ops ix25_pops = {
44181 - &isdn_x25iface_proto_new,
44182 - &isdn_x25iface_proto_del,
44183 - &isdn_x25iface_proto_restart,
44184 - &isdn_x25iface_proto_close,
44185 - &isdn_x25iface_xmit,
44186 - &isdn_x25iface_receive,
44187 - &isdn_x25iface_connect_ind,
44188 - &isdn_x25iface_disconn_ind
44189 + .proto_new = &isdn_x25iface_proto_new,
44190 + .proto_del = &isdn_x25iface_proto_del,
44191 + .restart = &isdn_x25iface_proto_restart,
44192 + .close = &isdn_x25iface_proto_close,
44193 + .encap_and_xmit = &isdn_x25iface_xmit,
44194 + .data_ind = &isdn_x25iface_receive,
44195 + .connect_ind = &isdn_x25iface_connect_ind,
44196 + .disconn_ind = &isdn_x25iface_disconn_ind
44197 };
44198
44199 /* error message helper function */
44200 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44201 index 6a7447c..cae33fe 100644
44202 --- a/drivers/isdn/icn/icn.c
44203 +++ b/drivers/isdn/icn/icn.c
44204 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44205 if (count > len)
44206 count = len;
44207 if (user) {
44208 - if (copy_from_user(msg, buf, count))
44209 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44210 return -EFAULT;
44211 } else
44212 memcpy(msg, buf, count);
44213 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44214 index 87f7dff..7300125 100644
44215 --- a/drivers/isdn/mISDN/dsp_cmx.c
44216 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44217 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44218 static u16 dsp_count; /* last sample count */
44219 static int dsp_count_valid; /* if we have last sample count */
44220
44221 -void
44222 +void __intentional_overflow(-1)
44223 dsp_cmx_send(void *arg)
44224 {
44225 struct dsp_conf *conf;
44226 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44227 index f58a354..fbae176 100644
44228 --- a/drivers/leds/leds-clevo-mail.c
44229 +++ b/drivers/leds/leds-clevo-mail.c
44230 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44231 * detected as working, but in reality it is not) as low as
44232 * possible.
44233 */
44234 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44235 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44236 {
44237 .callback = clevo_mail_led_dmi_callback,
44238 .ident = "Clevo D410J",
44239 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44240 index 046cb70..6b20d39 100644
44241 --- a/drivers/leds/leds-ss4200.c
44242 +++ b/drivers/leds/leds-ss4200.c
44243 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44244 * detected as working, but in reality it is not) as low as
44245 * possible.
44246 */
44247 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44248 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44249 {
44250 .callback = ss4200_led_dmi_callback,
44251 .ident = "Intel SS4200-E",
44252 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44253 index 6590558..a74c5dd 100644
44254 --- a/drivers/lguest/core.c
44255 +++ b/drivers/lguest/core.c
44256 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44257 * The end address needs +1 because __get_vm_area allocates an
44258 * extra guard page, so we need space for that.
44259 */
44260 +
44261 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44262 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44263 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44264 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44265 +#else
44266 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44267 VM_ALLOC, switcher_addr, switcher_addr
44268 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44269 +#endif
44270 +
44271 if (!switcher_vma) {
44272 err = -ENOMEM;
44273 printk("lguest: could not map switcher pages high\n");
44274 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44275 * Now the Switcher is mapped at the right address, we can't fail!
44276 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44277 */
44278 - memcpy(switcher_vma->addr, start_switcher_text,
44279 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44280 end_switcher_text - start_switcher_text);
44281
44282 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44283 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44284 index e8b55c3..3514c37 100644
44285 --- a/drivers/lguest/page_tables.c
44286 +++ b/drivers/lguest/page_tables.c
44287 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44288 /*:*/
44289
44290 #ifdef CONFIG_X86_PAE
44291 -static void release_pmd(pmd_t *spmd)
44292 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44293 {
44294 /* If the entry's not present, there's nothing to release. */
44295 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44296 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44297 index 922a1ac..9dd0c2a 100644
44298 --- a/drivers/lguest/x86/core.c
44299 +++ b/drivers/lguest/x86/core.c
44300 @@ -59,7 +59,7 @@ static struct {
44301 /* Offset from where switcher.S was compiled to where we've copied it */
44302 static unsigned long switcher_offset(void)
44303 {
44304 - return switcher_addr - (unsigned long)start_switcher_text;
44305 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44306 }
44307
44308 /* This cpu's struct lguest_pages (after the Switcher text page) */
44309 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44310 * These copies are pretty cheap, so we do them unconditionally: */
44311 /* Save the current Host top-level page directory.
44312 */
44313 +
44314 +#ifdef CONFIG_PAX_PER_CPU_PGD
44315 + pages->state.host_cr3 = read_cr3();
44316 +#else
44317 pages->state.host_cr3 = __pa(current->mm->pgd);
44318 +#endif
44319 +
44320 /*
44321 * Set up the Guest's page tables to see this CPU's pages (and no
44322 * other CPU's pages).
44323 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44324 * compiled-in switcher code and the high-mapped copy we just made.
44325 */
44326 for (i = 0; i < IDT_ENTRIES; i++)
44327 - default_idt_entries[i] += switcher_offset();
44328 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44329
44330 /*
44331 * Set up the Switcher's per-cpu areas.
44332 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44333 * it will be undisturbed when we switch. To change %cs and jump we
44334 * need this structure to feed to Intel's "lcall" instruction.
44335 */
44336 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44337 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44338 lguest_entry.segment = LGUEST_CS;
44339
44340 /*
44341 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44342 index 40634b0..4f5855e 100644
44343 --- a/drivers/lguest/x86/switcher_32.S
44344 +++ b/drivers/lguest/x86/switcher_32.S
44345 @@ -87,6 +87,7 @@
44346 #include <asm/page.h>
44347 #include <asm/segment.h>
44348 #include <asm/lguest.h>
44349 +#include <asm/processor-flags.h>
44350
44351 // We mark the start of the code to copy
44352 // It's placed in .text tho it's never run here
44353 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44354 // Changes type when we load it: damn Intel!
44355 // For after we switch over our page tables
44356 // That entry will be read-only: we'd crash.
44357 +
44358 +#ifdef CONFIG_PAX_KERNEXEC
44359 + mov %cr0, %edx
44360 + xor $X86_CR0_WP, %edx
44361 + mov %edx, %cr0
44362 +#endif
44363 +
44364 movl $(GDT_ENTRY_TSS*8), %edx
44365 ltr %dx
44366
44367 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44368 // Let's clear it again for our return.
44369 // The GDT descriptor of the Host
44370 // Points to the table after two "size" bytes
44371 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44372 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44373 // Clear "used" from type field (byte 5, bit 2)
44374 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44375 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44376 +
44377 +#ifdef CONFIG_PAX_KERNEXEC
44378 + mov %cr0, %eax
44379 + xor $X86_CR0_WP, %eax
44380 + mov %eax, %cr0
44381 +#endif
44382
44383 // Once our page table's switched, the Guest is live!
44384 // The Host fades as we run this final step.
44385 @@ -295,13 +309,12 @@ deliver_to_host:
44386 // I consulted gcc, and it gave
44387 // These instructions, which I gladly credit:
44388 leal (%edx,%ebx,8), %eax
44389 - movzwl (%eax),%edx
44390 - movl 4(%eax), %eax
44391 - xorw %ax, %ax
44392 - orl %eax, %edx
44393 + movl 4(%eax), %edx
44394 + movw (%eax), %dx
44395 // Now the address of the handler's in %edx
44396 // We call it now: its "iret" drops us home.
44397 - jmp *%edx
44398 + ljmp $__KERNEL_CS, $1f
44399 +1: jmp *%edx
44400
44401 // Every interrupt can come to us here
44402 // But we must truly tell each apart.
44403 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44404 index a08e3ee..df8ade2 100644
44405 --- a/drivers/md/bcache/closure.h
44406 +++ b/drivers/md/bcache/closure.h
44407 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44408 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44409 struct workqueue_struct *wq)
44410 {
44411 - BUG_ON(object_is_on_stack(cl));
44412 + BUG_ON(object_starts_on_stack(cl));
44413 closure_set_ip(cl);
44414 cl->fn = fn;
44415 cl->wq = wq;
44416 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44417 index da3604e..7789cb4c 100644
44418 --- a/drivers/md/bitmap.c
44419 +++ b/drivers/md/bitmap.c
44420 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44421 chunk_kb ? "KB" : "B");
44422 if (bitmap->storage.file) {
44423 seq_printf(seq, ", file: ");
44424 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44425 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44426 }
44427
44428 seq_printf(seq, "\n");
44429 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44430 index 0be9381..114262b 100644
44431 --- a/drivers/md/dm-ioctl.c
44432 +++ b/drivers/md/dm-ioctl.c
44433 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44434 cmd == DM_LIST_VERSIONS_CMD)
44435 return 0;
44436
44437 - if ((cmd == DM_DEV_CREATE_CMD)) {
44438 + if (cmd == DM_DEV_CREATE_CMD) {
44439 if (!*param->name) {
44440 DMWARN("name not supplied when creating device");
44441 return -EINVAL;
44442 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44443 index 7dfdb5c..4caada6 100644
44444 --- a/drivers/md/dm-raid1.c
44445 +++ b/drivers/md/dm-raid1.c
44446 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44447
44448 struct mirror {
44449 struct mirror_set *ms;
44450 - atomic_t error_count;
44451 + atomic_unchecked_t error_count;
44452 unsigned long error_type;
44453 struct dm_dev *dev;
44454 sector_t offset;
44455 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44456 struct mirror *m;
44457
44458 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44459 - if (!atomic_read(&m->error_count))
44460 + if (!atomic_read_unchecked(&m->error_count))
44461 return m;
44462
44463 return NULL;
44464 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44465 * simple way to tell if a device has encountered
44466 * errors.
44467 */
44468 - atomic_inc(&m->error_count);
44469 + atomic_inc_unchecked(&m->error_count);
44470
44471 if (test_and_set_bit(error_type, &m->error_type))
44472 return;
44473 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44474 struct mirror *m = get_default_mirror(ms);
44475
44476 do {
44477 - if (likely(!atomic_read(&m->error_count)))
44478 + if (likely(!atomic_read_unchecked(&m->error_count)))
44479 return m;
44480
44481 if (m-- == ms->mirror)
44482 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44483 {
44484 struct mirror *default_mirror = get_default_mirror(m->ms);
44485
44486 - return !atomic_read(&default_mirror->error_count);
44487 + return !atomic_read_unchecked(&default_mirror->error_count);
44488 }
44489
44490 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44491 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44492 */
44493 if (likely(region_in_sync(ms, region, 1)))
44494 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44495 - else if (m && atomic_read(&m->error_count))
44496 + else if (m && atomic_read_unchecked(&m->error_count))
44497 m = NULL;
44498
44499 if (likely(m))
44500 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44501 }
44502
44503 ms->mirror[mirror].ms = ms;
44504 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44505 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44506 ms->mirror[mirror].error_type = 0;
44507 ms->mirror[mirror].offset = offset;
44508
44509 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44510 */
44511 static char device_status_char(struct mirror *m)
44512 {
44513 - if (!atomic_read(&(m->error_count)))
44514 + if (!atomic_read_unchecked(&(m->error_count)))
44515 return 'A';
44516
44517 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44518 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44519 index 87f86c7..a1a4100 100644
44520 --- a/drivers/md/dm-stats.c
44521 +++ b/drivers/md/dm-stats.c
44522 @@ -382,7 +382,7 @@ do_sync_free:
44523 synchronize_rcu_expedited();
44524 dm_stat_free(&s->rcu_head);
44525 } else {
44526 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44527 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44528 call_rcu(&s->rcu_head, dm_stat_free);
44529 }
44530 return 0;
44531 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44532 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44533 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44534 ));
44535 - ACCESS_ONCE(last->last_sector) = end_sector;
44536 - ACCESS_ONCE(last->last_rw) = bi_rw;
44537 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44538 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44539 }
44540
44541 rcu_read_lock();
44542 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44543 index f8b37d4..5c5cafd 100644
44544 --- a/drivers/md/dm-stripe.c
44545 +++ b/drivers/md/dm-stripe.c
44546 @@ -21,7 +21,7 @@ struct stripe {
44547 struct dm_dev *dev;
44548 sector_t physical_start;
44549
44550 - atomic_t error_count;
44551 + atomic_unchecked_t error_count;
44552 };
44553
44554 struct stripe_c {
44555 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44556 kfree(sc);
44557 return r;
44558 }
44559 - atomic_set(&(sc->stripe[i].error_count), 0);
44560 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44561 }
44562
44563 ti->private = sc;
44564 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44565 DMEMIT("%d ", sc->stripes);
44566 for (i = 0; i < sc->stripes; i++) {
44567 DMEMIT("%s ", sc->stripe[i].dev->name);
44568 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44569 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44570 'D' : 'A';
44571 }
44572 buffer[i] = '\0';
44573 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44574 */
44575 for (i = 0; i < sc->stripes; i++)
44576 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44577 - atomic_inc(&(sc->stripe[i].error_count));
44578 - if (atomic_read(&(sc->stripe[i].error_count)) <
44579 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44580 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44581 DM_IO_ERROR_THRESHOLD)
44582 schedule_work(&sc->trigger_event);
44583 }
44584 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44585 index b2bd1eb..38f7a44 100644
44586 --- a/drivers/md/dm-table.c
44587 +++ b/drivers/md/dm-table.c
44588 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44589 if (!dev_size)
44590 return 0;
44591
44592 - if ((start >= dev_size) || (start + len > dev_size)) {
44593 + if ((start >= dev_size) || (len > dev_size - start)) {
44594 DMWARN("%s: %s too small for target: "
44595 "start=%llu, len=%llu, dev_size=%llu",
44596 dm_device_name(ti->table->md), bdevname(bdev, b),
44597 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44598 index e9d33ad..dae9880d 100644
44599 --- a/drivers/md/dm-thin-metadata.c
44600 +++ b/drivers/md/dm-thin-metadata.c
44601 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44602 {
44603 pmd->info.tm = pmd->tm;
44604 pmd->info.levels = 2;
44605 - pmd->info.value_type.context = pmd->data_sm;
44606 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44607 pmd->info.value_type.size = sizeof(__le64);
44608 pmd->info.value_type.inc = data_block_inc;
44609 pmd->info.value_type.dec = data_block_dec;
44610 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44611
44612 pmd->bl_info.tm = pmd->tm;
44613 pmd->bl_info.levels = 1;
44614 - pmd->bl_info.value_type.context = pmd->data_sm;
44615 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44616 pmd->bl_info.value_type.size = sizeof(__le64);
44617 pmd->bl_info.value_type.inc = data_block_inc;
44618 pmd->bl_info.value_type.dec = data_block_dec;
44619 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44620 index 62c5136..aede7f1 100644
44621 --- a/drivers/md/dm.c
44622 +++ b/drivers/md/dm.c
44623 @@ -183,9 +183,9 @@ struct mapped_device {
44624 /*
44625 * Event handling.
44626 */
44627 - atomic_t event_nr;
44628 + atomic_unchecked_t event_nr;
44629 wait_queue_head_t eventq;
44630 - atomic_t uevent_seq;
44631 + atomic_unchecked_t uevent_seq;
44632 struct list_head uevent_list;
44633 spinlock_t uevent_lock; /* Protect access to uevent_list */
44634
44635 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44636 spin_lock_init(&md->deferred_lock);
44637 atomic_set(&md->holders, 1);
44638 atomic_set(&md->open_count, 0);
44639 - atomic_set(&md->event_nr, 0);
44640 - atomic_set(&md->uevent_seq, 0);
44641 + atomic_set_unchecked(&md->event_nr, 0);
44642 + atomic_set_unchecked(&md->uevent_seq, 0);
44643 INIT_LIST_HEAD(&md->uevent_list);
44644 INIT_LIST_HEAD(&md->table_devices);
44645 spin_lock_init(&md->uevent_lock);
44646 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44647
44648 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44649
44650 - atomic_inc(&md->event_nr);
44651 + atomic_inc_unchecked(&md->event_nr);
44652 wake_up(&md->eventq);
44653 }
44654
44655 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44656
44657 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44658 {
44659 - return atomic_add_return(1, &md->uevent_seq);
44660 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44661 }
44662
44663 uint32_t dm_get_event_nr(struct mapped_device *md)
44664 {
44665 - return atomic_read(&md->event_nr);
44666 + return atomic_read_unchecked(&md->event_nr);
44667 }
44668
44669 int dm_wait_event(struct mapped_device *md, int event_nr)
44670 {
44671 return wait_event_interruptible(md->eventq,
44672 - (event_nr != atomic_read(&md->event_nr)));
44673 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44674 }
44675
44676 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44677 diff --git a/drivers/md/md.c b/drivers/md/md.c
44678 index 9233c71..ed5243a 100644
44679 --- a/drivers/md/md.c
44680 +++ b/drivers/md/md.c
44681 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44682 * start build, activate spare
44683 */
44684 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44685 -static atomic_t md_event_count;
44686 +static atomic_unchecked_t md_event_count;
44687 void md_new_event(struct mddev *mddev)
44688 {
44689 - atomic_inc(&md_event_count);
44690 + atomic_inc_unchecked(&md_event_count);
44691 wake_up(&md_event_waiters);
44692 }
44693 EXPORT_SYMBOL_GPL(md_new_event);
44694 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44695 */
44696 static void md_new_event_inintr(struct mddev *mddev)
44697 {
44698 - atomic_inc(&md_event_count);
44699 + atomic_inc_unchecked(&md_event_count);
44700 wake_up(&md_event_waiters);
44701 }
44702
44703 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44704 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44705 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44706 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44707 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44708 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44709
44710 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44711 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44712 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44713 else
44714 sb->resync_offset = cpu_to_le64(0);
44715
44716 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44717 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44718
44719 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44720 sb->size = cpu_to_le64(mddev->dev_sectors);
44721 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44722 static ssize_t
44723 errors_show(struct md_rdev *rdev, char *page)
44724 {
44725 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44726 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44727 }
44728
44729 static ssize_t
44730 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44731 char *e;
44732 unsigned long n = simple_strtoul(buf, &e, 10);
44733 if (*buf && (*e == 0 || *e == '\n')) {
44734 - atomic_set(&rdev->corrected_errors, n);
44735 + atomic_set_unchecked(&rdev->corrected_errors, n);
44736 return len;
44737 }
44738 return -EINVAL;
44739 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44740 rdev->sb_loaded = 0;
44741 rdev->bb_page = NULL;
44742 atomic_set(&rdev->nr_pending, 0);
44743 - atomic_set(&rdev->read_errors, 0);
44744 - atomic_set(&rdev->corrected_errors, 0);
44745 + atomic_set_unchecked(&rdev->read_errors, 0);
44746 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44747
44748 INIT_LIST_HEAD(&rdev->same_set);
44749 init_waitqueue_head(&rdev->blocked_wait);
44750 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44751
44752 spin_unlock(&pers_lock);
44753 seq_printf(seq, "\n");
44754 - seq->poll_event = atomic_read(&md_event_count);
44755 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44756 return 0;
44757 }
44758 if (v == (void*)2) {
44759 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44760 return error;
44761
44762 seq = file->private_data;
44763 - seq->poll_event = atomic_read(&md_event_count);
44764 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44765 return error;
44766 }
44767
44768 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44769 /* always allow read */
44770 mask = POLLIN | POLLRDNORM;
44771
44772 - if (seq->poll_event != atomic_read(&md_event_count))
44773 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44774 mask |= POLLERR | POLLPRI;
44775 return mask;
44776 }
44777 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44778 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44779 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44780 (int)part_stat_read(&disk->part0, sectors[1]) -
44781 - atomic_read(&disk->sync_io);
44782 + atomic_read_unchecked(&disk->sync_io);
44783 /* sync IO will cause sync_io to increase before the disk_stats
44784 * as sync_io is counted when a request starts, and
44785 * disk_stats is counted when it completes.
44786 diff --git a/drivers/md/md.h b/drivers/md/md.h
44787 index 03cec5b..0a658c1 100644
44788 --- a/drivers/md/md.h
44789 +++ b/drivers/md/md.h
44790 @@ -94,13 +94,13 @@ struct md_rdev {
44791 * only maintained for arrays that
44792 * support hot removal
44793 */
44794 - atomic_t read_errors; /* number of consecutive read errors that
44795 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44796 * we have tried to ignore.
44797 */
44798 struct timespec last_read_error; /* monotonic time since our
44799 * last read error
44800 */
44801 - atomic_t corrected_errors; /* number of corrected read errors,
44802 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44803 * for reporting to userspace and storing
44804 * in superblock.
44805 */
44806 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44807
44808 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44809 {
44810 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44811 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44812 }
44813
44814 struct md_personality
44815 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44816 index f4e22bc..8f83114 100644
44817 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44818 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44819 @@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44820 * Flick into a mode where all blocks get allocated in the new area.
44821 */
44822 smm->begin = old_len;
44823 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44824 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44825
44826 /*
44827 * Extend.
44828 @@ -712,7 +712,7 @@ out:
44829 /*
44830 * Switch back to normal behaviour.
44831 */
44832 - memcpy(sm, &ops, sizeof(*sm));
44833 + memcpy((void *)sm, &ops, sizeof(*sm));
44834 return r;
44835 }
44836
44837 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44838 index 3e6d115..ffecdeb 100644
44839 --- a/drivers/md/persistent-data/dm-space-map.h
44840 +++ b/drivers/md/persistent-data/dm-space-map.h
44841 @@ -71,6 +71,7 @@ struct dm_space_map {
44842 dm_sm_threshold_fn fn,
44843 void *context);
44844 };
44845 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44846
44847 /*----------------------------------------------------------------*/
44848
44849 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44850 index 40b35be..a327e11 100644
44851 --- a/drivers/md/raid1.c
44852 +++ b/drivers/md/raid1.c
44853 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44854 if (r1_sync_page_io(rdev, sect, s,
44855 bio->bi_io_vec[idx].bv_page,
44856 READ) != 0)
44857 - atomic_add(s, &rdev->corrected_errors);
44858 + atomic_add_unchecked(s, &rdev->corrected_errors);
44859 }
44860 sectors -= s;
44861 sect += s;
44862 @@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44863 !test_bit(Faulty, &rdev->flags)) {
44864 if (r1_sync_page_io(rdev, sect, s,
44865 conf->tmppage, READ)) {
44866 - atomic_add(s, &rdev->corrected_errors);
44867 + atomic_add_unchecked(s, &rdev->corrected_errors);
44868 printk(KERN_INFO
44869 "md/raid1:%s: read error corrected "
44870 "(%d sectors at %llu on %s)\n",
44871 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44872 index 32e282f..5cec803 100644
44873 --- a/drivers/md/raid10.c
44874 +++ b/drivers/md/raid10.c
44875 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44876 /* The write handler will notice the lack of
44877 * R10BIO_Uptodate and record any errors etc
44878 */
44879 - atomic_add(r10_bio->sectors,
44880 + atomic_add_unchecked(r10_bio->sectors,
44881 &conf->mirrors[d].rdev->corrected_errors);
44882
44883 /* for reconstruct, we always reschedule after a read.
44884 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44885 {
44886 struct timespec cur_time_mon;
44887 unsigned long hours_since_last;
44888 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44889 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44890
44891 ktime_get_ts(&cur_time_mon);
44892
44893 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44894 * overflowing the shift of read_errors by hours_since_last.
44895 */
44896 if (hours_since_last >= 8 * sizeof(read_errors))
44897 - atomic_set(&rdev->read_errors, 0);
44898 + atomic_set_unchecked(&rdev->read_errors, 0);
44899 else
44900 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44901 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44902 }
44903
44904 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44905 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44906 return;
44907
44908 check_decay_read_errors(mddev, rdev);
44909 - atomic_inc(&rdev->read_errors);
44910 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44911 + atomic_inc_unchecked(&rdev->read_errors);
44912 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44913 char b[BDEVNAME_SIZE];
44914 bdevname(rdev->bdev, b);
44915
44916 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44917 "md/raid10:%s: %s: Raid device exceeded "
44918 "read_error threshold [cur %d:max %d]\n",
44919 mdname(mddev), b,
44920 - atomic_read(&rdev->read_errors), max_read_errors);
44921 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44922 printk(KERN_NOTICE
44923 "md/raid10:%s: %s: Failing raid device\n",
44924 mdname(mddev), b);
44925 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44926 sect +
44927 choose_data_offset(r10_bio, rdev)),
44928 bdevname(rdev->bdev, b));
44929 - atomic_add(s, &rdev->corrected_errors);
44930 + atomic_add_unchecked(s, &rdev->corrected_errors);
44931 }
44932
44933 rdev_dec_pending(rdev, mddev);
44934 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44935 index b98765f..09e86d5 100644
44936 --- a/drivers/md/raid5.c
44937 +++ b/drivers/md/raid5.c
44938 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44939 return 1;
44940 }
44941
44942 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44943 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44944 +#endif
44945 +
44946 static int grow_stripes(struct r5conf *conf, int num)
44947 {
44948 struct kmem_cache *sc;
44949 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44950 "raid%d-%s", conf->level, mdname(conf->mddev));
44951 else
44952 sprintf(conf->cache_name[0],
44953 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44954 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44955 +#else
44956 "raid%d-%p", conf->level, conf->mddev);
44957 +#endif
44958 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44959
44960 conf->active_name = 0;
44961 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44962 mdname(conf->mddev), STRIPE_SECTORS,
44963 (unsigned long long)s,
44964 bdevname(rdev->bdev, b));
44965 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44966 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44967 clear_bit(R5_ReadError, &sh->dev[i].flags);
44968 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44969 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44970 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44971
44972 - if (atomic_read(&rdev->read_errors))
44973 - atomic_set(&rdev->read_errors, 0);
44974 + if (atomic_read_unchecked(&rdev->read_errors))
44975 + atomic_set_unchecked(&rdev->read_errors, 0);
44976 } else {
44977 const char *bdn = bdevname(rdev->bdev, b);
44978 int retry = 0;
44979 int set_bad = 0;
44980
44981 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44982 - atomic_inc(&rdev->read_errors);
44983 + atomic_inc_unchecked(&rdev->read_errors);
44984 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44985 printk_ratelimited(
44986 KERN_WARNING
44987 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44988 mdname(conf->mddev),
44989 (unsigned long long)s,
44990 bdn);
44991 - } else if (atomic_read(&rdev->read_errors)
44992 + } else if (atomic_read_unchecked(&rdev->read_errors)
44993 > conf->max_nr_stripes)
44994 printk(KERN_WARNING
44995 "md/raid:%s: Too many read errors, failing device %s.\n",
44996 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44997 index 983db75..ef9248c 100644
44998 --- a/drivers/media/dvb-core/dvbdev.c
44999 +++ b/drivers/media/dvb-core/dvbdev.c
45000 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45001 const struct dvb_device *template, void *priv, int type)
45002 {
45003 struct dvb_device *dvbdev;
45004 - struct file_operations *dvbdevfops;
45005 + file_operations_no_const *dvbdevfops;
45006 struct device *clsdev;
45007 int minor;
45008 int id;
45009 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45010 index 6ad22b6..6e90e2a 100644
45011 --- a/drivers/media/dvb-frontends/af9033.h
45012 +++ b/drivers/media/dvb-frontends/af9033.h
45013 @@ -96,6 +96,6 @@ struct af9033_ops {
45014 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45015 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45016 int onoff);
45017 -};
45018 +} __no_const;
45019
45020 #endif /* AF9033_H */
45021 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45022 index 9b6c3bb..baeb5c7 100644
45023 --- a/drivers/media/dvb-frontends/dib3000.h
45024 +++ b/drivers/media/dvb-frontends/dib3000.h
45025 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45026 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45027 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45028 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45029 -};
45030 +} __no_const;
45031
45032 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45033 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45034 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45035 index 1fea0e9..321ce8f 100644
45036 --- a/drivers/media/dvb-frontends/dib7000p.h
45037 +++ b/drivers/media/dvb-frontends/dib7000p.h
45038 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45039 int (*get_adc_power)(struct dvb_frontend *fe);
45040 int (*slave_reset)(struct dvb_frontend *fe);
45041 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45042 -};
45043 +} __no_const;
45044
45045 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45046 void *dib7000p_attach(struct dib7000p_ops *ops);
45047 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45048 index 84cc103..5780c54 100644
45049 --- a/drivers/media/dvb-frontends/dib8000.h
45050 +++ b/drivers/media/dvb-frontends/dib8000.h
45051 @@ -61,7 +61,7 @@ struct dib8000_ops {
45052 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45053 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45054 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45055 -};
45056 +} __no_const;
45057
45058 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45059 void *dib8000_attach(struct dib8000_ops *ops);
45060 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45061 index ce27e6d..b70435a 100644
45062 --- a/drivers/media/pci/cx88/cx88-video.c
45063 +++ b/drivers/media/pci/cx88/cx88-video.c
45064 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45065
45066 /* ------------------------------------------------------------------ */
45067
45068 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45069 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45070 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45071 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45072 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45073 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45074
45075 module_param_array(video_nr, int, NULL, 0444);
45076 module_param_array(vbi_nr, int, NULL, 0444);
45077 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45078 index 802642d..5534900 100644
45079 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45080 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45081 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45082 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45083
45084 /* ivtv instance counter */
45085 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45086 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45087
45088 /* Parameter declarations */
45089 static int cardtype[IVTV_MAX_CARDS];
45090 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45091 index 8cbe6b4..ea3601c 100644
45092 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45093 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45094 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45095
45096 static int solo_sysfs_init(struct solo_dev *solo_dev)
45097 {
45098 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45099 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45100 struct device *dev = &solo_dev->dev;
45101 const char *driver;
45102 int i;
45103 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45104 index c7141f2..5301fec 100644
45105 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45106 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45107 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45108
45109 int solo_g723_init(struct solo_dev *solo_dev)
45110 {
45111 - static struct snd_device_ops ops = { NULL };
45112 + static struct snd_device_ops ops = { };
45113 struct snd_card *card;
45114 struct snd_kcontrol_new kctl;
45115 char name[32];
45116 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45117 index 8c84846..27b4f83 100644
45118 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45119 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45120 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45121
45122 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45123 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45124 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45125 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45126 if (p2m_id < 0)
45127 p2m_id = -p2m_id;
45128 }
45129 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45130 index 72017b7..dd37ae6 100644
45131 --- a/drivers/media/pci/solo6x10/solo6x10.h
45132 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45133 @@ -219,7 +219,7 @@ struct solo_dev {
45134
45135 /* P2M DMA Engine */
45136 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45137 - atomic_t p2m_count;
45138 + atomic_unchecked_t p2m_count;
45139 int p2m_jiffies;
45140 unsigned int p2m_timeouts;
45141
45142 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45143 index 63f0b64..a017c1c 100644
45144 --- a/drivers/media/pci/tw68/tw68-core.c
45145 +++ b/drivers/media/pci/tw68/tw68-core.c
45146 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45147 module_param_array(card, int, NULL, 0444);
45148 MODULE_PARM_DESC(card, "card type");
45149
45150 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45151 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45152
45153 /* ------------------------------------------------------------------ */
45154
45155 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45156 index 64ab6fb..ef4a8b9 100644
45157 --- a/drivers/media/platform/omap/omap_vout.c
45158 +++ b/drivers/media/platform/omap/omap_vout.c
45159 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45160 OMAP_VIDEO2,
45161 };
45162
45163 -static struct videobuf_queue_ops video_vbq_ops;
45164 /* Variables configurable through module params*/
45165 static u32 video1_numbuffers = 3;
45166 static u32 video2_numbuffers = 3;
45167 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45168 {
45169 struct videobuf_queue *q;
45170 struct omap_vout_device *vout = NULL;
45171 + static struct videobuf_queue_ops video_vbq_ops = {
45172 + .buf_setup = omap_vout_buffer_setup,
45173 + .buf_prepare = omap_vout_buffer_prepare,
45174 + .buf_release = omap_vout_buffer_release,
45175 + .buf_queue = omap_vout_buffer_queue,
45176 + };
45177
45178 vout = video_drvdata(file);
45179 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45180 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45181 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45182
45183 q = &vout->vbq;
45184 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45185 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45186 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45187 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45188 spin_lock_init(&vout->vbq_lock);
45189
45190 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45191 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45192 index fb2acc5..a2fcbdc4 100644
45193 --- a/drivers/media/platform/s5p-tv/mixer.h
45194 +++ b/drivers/media/platform/s5p-tv/mixer.h
45195 @@ -156,7 +156,7 @@ struct mxr_layer {
45196 /** layer index (unique identifier) */
45197 int idx;
45198 /** callbacks for layer methods */
45199 - struct mxr_layer_ops ops;
45200 + struct mxr_layer_ops *ops;
45201 /** format array */
45202 const struct mxr_format **fmt_array;
45203 /** size of format array */
45204 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45205 index 74344c7..a39e70e 100644
45206 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45207 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45208 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45209 {
45210 struct mxr_layer *layer;
45211 int ret;
45212 - struct mxr_layer_ops ops = {
45213 + static struct mxr_layer_ops ops = {
45214 .release = mxr_graph_layer_release,
45215 .buffer_set = mxr_graph_buffer_set,
45216 .stream_set = mxr_graph_stream_set,
45217 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45218 index b713403..53cb5ad 100644
45219 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45220 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45221 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45222 layer->update_buf = next;
45223 }
45224
45225 - layer->ops.buffer_set(layer, layer->update_buf);
45226 + layer->ops->buffer_set(layer, layer->update_buf);
45227
45228 if (done && done != layer->shadow_buf)
45229 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45230 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45231 index b4d2696..91df48e 100644
45232 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45233 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45234 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45235 layer->geo.src.height = layer->geo.src.full_height;
45236
45237 mxr_geometry_dump(mdev, &layer->geo);
45238 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45239 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45240 mxr_geometry_dump(mdev, &layer->geo);
45241 }
45242
45243 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45244 layer->geo.dst.full_width = mbus_fmt.width;
45245 layer->geo.dst.full_height = mbus_fmt.height;
45246 layer->geo.dst.field = mbus_fmt.field;
45247 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45248 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45249
45250 mxr_geometry_dump(mdev, &layer->geo);
45251 }
45252 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45253 /* set source size to highest accepted value */
45254 geo->src.full_width = max(geo->dst.full_width, pix->width);
45255 geo->src.full_height = max(geo->dst.full_height, pix->height);
45256 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45257 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45258 mxr_geometry_dump(mdev, &layer->geo);
45259 /* set cropping to total visible screen */
45260 geo->src.width = pix->width;
45261 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45262 geo->src.x_offset = 0;
45263 geo->src.y_offset = 0;
45264 /* assure consistency of geometry */
45265 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45266 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45267 mxr_geometry_dump(mdev, &layer->geo);
45268 /* set full size to lowest possible value */
45269 geo->src.full_width = 0;
45270 geo->src.full_height = 0;
45271 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45272 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45273 mxr_geometry_dump(mdev, &layer->geo);
45274
45275 /* returning results */
45276 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45277 target->width = s->r.width;
45278 target->height = s->r.height;
45279
45280 - layer->ops.fix_geometry(layer, stage, s->flags);
45281 + layer->ops->fix_geometry(layer, stage, s->flags);
45282
45283 /* retrieve update selection rectangle */
45284 res.left = target->x_offset;
45285 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45286 mxr_output_get(mdev);
45287
45288 mxr_layer_update_output(layer);
45289 - layer->ops.format_set(layer);
45290 + layer->ops->format_set(layer);
45291 /* enabling layer in hardware */
45292 spin_lock_irqsave(&layer->enq_slock, flags);
45293 layer->state = MXR_LAYER_STREAMING;
45294 spin_unlock_irqrestore(&layer->enq_slock, flags);
45295
45296 - layer->ops.stream_set(layer, MXR_ENABLE);
45297 + layer->ops->stream_set(layer, MXR_ENABLE);
45298 mxr_streamer_get(mdev);
45299
45300 return 0;
45301 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45302 spin_unlock_irqrestore(&layer->enq_slock, flags);
45303
45304 /* disabling layer in hardware */
45305 - layer->ops.stream_set(layer, MXR_DISABLE);
45306 + layer->ops->stream_set(layer, MXR_DISABLE);
45307 /* remove one streamer */
45308 mxr_streamer_put(mdev);
45309 /* allow changes in output configuration */
45310 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45311
45312 void mxr_layer_release(struct mxr_layer *layer)
45313 {
45314 - if (layer->ops.release)
45315 - layer->ops.release(layer);
45316 + if (layer->ops->release)
45317 + layer->ops->release(layer);
45318 }
45319
45320 void mxr_base_layer_release(struct mxr_layer *layer)
45321 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45322
45323 layer->mdev = mdev;
45324 layer->idx = idx;
45325 - layer->ops = *ops;
45326 + layer->ops = ops;
45327
45328 spin_lock_init(&layer->enq_slock);
45329 INIT_LIST_HEAD(&layer->enq_list);
45330 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45331 index c9388c4..ce71ece 100644
45332 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45333 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45334 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45335 {
45336 struct mxr_layer *layer;
45337 int ret;
45338 - struct mxr_layer_ops ops = {
45339 + static struct mxr_layer_ops ops = {
45340 .release = mxr_vp_layer_release,
45341 .buffer_set = mxr_vp_buffer_set,
45342 .stream_set = mxr_vp_stream_set,
45343 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45344 index 82affae..42833ec 100644
45345 --- a/drivers/media/radio/radio-cadet.c
45346 +++ b/drivers/media/radio/radio-cadet.c
45347 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45348 unsigned char readbuf[RDS_BUFFER];
45349 int i = 0;
45350
45351 + if (count > RDS_BUFFER)
45352 + return -EFAULT;
45353 mutex_lock(&dev->lock);
45354 if (dev->rdsstat == 0)
45355 cadet_start_rds(dev);
45356 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45357 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45358 mutex_unlock(&dev->lock);
45359
45360 - if (i && copy_to_user(data, readbuf, i))
45361 - return -EFAULT;
45362 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45363 + i = -EFAULT;
45364 +
45365 return i;
45366 }
45367
45368 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45369 index 5236035..c622c74 100644
45370 --- a/drivers/media/radio/radio-maxiradio.c
45371 +++ b/drivers/media/radio/radio-maxiradio.c
45372 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45373 /* TEA5757 pin mappings */
45374 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45375
45376 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45377 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45378
45379 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45380 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45381 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45382 index 050b3bb..79f62b9 100644
45383 --- a/drivers/media/radio/radio-shark.c
45384 +++ b/drivers/media/radio/radio-shark.c
45385 @@ -79,7 +79,7 @@ struct shark_device {
45386 u32 last_val;
45387 };
45388
45389 -static atomic_t shark_instance = ATOMIC_INIT(0);
45390 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45391
45392 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45393 {
45394 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45395 index 8654e0d..0608a64 100644
45396 --- a/drivers/media/radio/radio-shark2.c
45397 +++ b/drivers/media/radio/radio-shark2.c
45398 @@ -74,7 +74,7 @@ struct shark_device {
45399 u8 *transfer_buffer;
45400 };
45401
45402 -static atomic_t shark_instance = ATOMIC_INIT(0);
45403 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45404
45405 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45406 {
45407 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45408 index 633022b..7f10754 100644
45409 --- a/drivers/media/radio/radio-si476x.c
45410 +++ b/drivers/media/radio/radio-si476x.c
45411 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45412 struct si476x_radio *radio;
45413 struct v4l2_ctrl *ctrl;
45414
45415 - static atomic_t instance = ATOMIC_INIT(0);
45416 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45417
45418 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45419 if (!radio)
45420 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45421 index 9fd1527..8927230 100644
45422 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45423 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45424 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45425
45426 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45427 {
45428 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45429 - char result[64];
45430 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45431 - sizeof(result), 0);
45432 + char *buf;
45433 + char *result;
45434 + int retval;
45435 +
45436 + buf = kmalloc(2, GFP_KERNEL);
45437 + if (buf == NULL)
45438 + return -ENOMEM;
45439 + result = kmalloc(64, GFP_KERNEL);
45440 + if (result == NULL) {
45441 + kfree(buf);
45442 + return -ENOMEM;
45443 + }
45444 +
45445 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45446 + buf[1] = enable ? 1 : 0;
45447 +
45448 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45449 +
45450 + kfree(buf);
45451 + kfree(result);
45452 + return retval;
45453 }
45454
45455 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45456 {
45457 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45458 - char state[3];
45459 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45460 + char *buf;
45461 + char *state;
45462 + int retval;
45463 +
45464 + buf = kmalloc(2, GFP_KERNEL);
45465 + if (buf == NULL)
45466 + return -ENOMEM;
45467 + state = kmalloc(3, GFP_KERNEL);
45468 + if (state == NULL) {
45469 + kfree(buf);
45470 + return -ENOMEM;
45471 + }
45472 +
45473 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45474 + buf[1] = enable ? 1 : 0;
45475 +
45476 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45477 +
45478 + kfree(buf);
45479 + kfree(state);
45480 + return retval;
45481 }
45482
45483 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45484 {
45485 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45486 - char state[3];
45487 + char *query;
45488 + char *state;
45489 int ret;
45490 + query = kmalloc(1, GFP_KERNEL);
45491 + if (query == NULL)
45492 + return -ENOMEM;
45493 + state = kmalloc(3, GFP_KERNEL);
45494 + if (state == NULL) {
45495 + kfree(query);
45496 + return -ENOMEM;
45497 + }
45498 +
45499 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45500
45501 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45502
45503 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45504 - sizeof(state), 0);
45505 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45506 if (ret < 0) {
45507 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45508 "state info\n");
45509 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45510
45511 /* Copy this pointer as we are gonna need it in the release phase */
45512 cinergyt2_usb_device = adap->dev;
45513 -
45514 + kfree(query);
45515 + kfree(state);
45516 return 0;
45517 }
45518
45519 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45520 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45521 {
45522 struct cinergyt2_state *st = d->priv;
45523 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45524 + u8 *key, *cmd;
45525 int i;
45526
45527 + cmd = kmalloc(1, GFP_KERNEL);
45528 + if (cmd == NULL)
45529 + return -EINVAL;
45530 + key = kzalloc(5, GFP_KERNEL);
45531 + if (key == NULL) {
45532 + kfree(cmd);
45533 + return -EINVAL;
45534 + }
45535 +
45536 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45537 +
45538 *state = REMOTE_NO_KEY_PRESSED;
45539
45540 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45541 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45542 if (key[4] == 0xff) {
45543 /* key repeat */
45544 st->rc_counter++;
45545 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45546 *event = d->last_event;
45547 deb_rc("repeat key, event %x\n",
45548 *event);
45549 - return 0;
45550 + goto out;
45551 }
45552 }
45553 deb_rc("repeated key (non repeatable)\n");
45554 }
45555 - return 0;
45556 + goto out;
45557 }
45558
45559 /* hack to pass checksum on the custom field */
45560 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45561
45562 deb_rc("key: %*ph\n", 5, key);
45563 }
45564 +out:
45565 + kfree(cmd);
45566 + kfree(key);
45567 return 0;
45568 }
45569
45570 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45571 index c890fe4..f9b2ae6 100644
45572 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45573 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45574 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45575 fe_status_t *status)
45576 {
45577 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45578 - struct dvbt_get_status_msg result;
45579 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45580 + struct dvbt_get_status_msg *result;
45581 + u8 *cmd;
45582 int ret;
45583
45584 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45585 - sizeof(result), 0);
45586 + cmd = kmalloc(1, GFP_KERNEL);
45587 + if (cmd == NULL)
45588 + return -ENOMEM;
45589 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45590 + if (result == NULL) {
45591 + kfree(cmd);
45592 + return -ENOMEM;
45593 + }
45594 +
45595 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45596 +
45597 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45598 + sizeof(*result), 0);
45599 if (ret < 0)
45600 - return ret;
45601 + goto out;
45602
45603 *status = 0;
45604
45605 - if (0xffff - le16_to_cpu(result.gain) > 30)
45606 + if (0xffff - le16_to_cpu(result->gain) > 30)
45607 *status |= FE_HAS_SIGNAL;
45608 - if (result.lock_bits & (1 << 6))
45609 + if (result->lock_bits & (1 << 6))
45610 *status |= FE_HAS_LOCK;
45611 - if (result.lock_bits & (1 << 5))
45612 + if (result->lock_bits & (1 << 5))
45613 *status |= FE_HAS_SYNC;
45614 - if (result.lock_bits & (1 << 4))
45615 + if (result->lock_bits & (1 << 4))
45616 *status |= FE_HAS_CARRIER;
45617 - if (result.lock_bits & (1 << 1))
45618 + if (result->lock_bits & (1 << 1))
45619 *status |= FE_HAS_VITERBI;
45620
45621 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45622 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45623 *status &= ~FE_HAS_LOCK;
45624
45625 - return 0;
45626 +out:
45627 + kfree(cmd);
45628 + kfree(result);
45629 + return ret;
45630 }
45631
45632 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45633 {
45634 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45635 - struct dvbt_get_status_msg status;
45636 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45637 + struct dvbt_get_status_msg *status;
45638 + char *cmd;
45639 int ret;
45640
45641 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45642 - sizeof(status), 0);
45643 + cmd = kmalloc(1, GFP_KERNEL);
45644 + if (cmd == NULL)
45645 + return -ENOMEM;
45646 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45647 + if (status == NULL) {
45648 + kfree(cmd);
45649 + return -ENOMEM;
45650 + }
45651 +
45652 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45653 +
45654 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45655 + sizeof(*status), 0);
45656 if (ret < 0)
45657 - return ret;
45658 + goto out;
45659
45660 - *ber = le32_to_cpu(status.viterbi_error_rate);
45661 + *ber = le32_to_cpu(status->viterbi_error_rate);
45662 +out:
45663 + kfree(cmd);
45664 + kfree(status);
45665 return 0;
45666 }
45667
45668 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45669 {
45670 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45671 - struct dvbt_get_status_msg status;
45672 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45673 + struct dvbt_get_status_msg *status;
45674 + u8 *cmd;
45675 int ret;
45676
45677 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45678 - sizeof(status), 0);
45679 + cmd = kmalloc(1, GFP_KERNEL);
45680 + if (cmd == NULL)
45681 + return -ENOMEM;
45682 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45683 + if (status == NULL) {
45684 + kfree(cmd);
45685 + return -ENOMEM;
45686 + }
45687 +
45688 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45689 +
45690 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45691 + sizeof(*status), 0);
45692 if (ret < 0) {
45693 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45694 ret);
45695 - return ret;
45696 + goto out;
45697 }
45698 - *unc = le32_to_cpu(status.uncorrected_block_count);
45699 - return 0;
45700 + *unc = le32_to_cpu(status->uncorrected_block_count);
45701 +
45702 +out:
45703 + kfree(cmd);
45704 + kfree(status);
45705 + return ret;
45706 }
45707
45708 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45709 u16 *strength)
45710 {
45711 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45712 - struct dvbt_get_status_msg status;
45713 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45714 + struct dvbt_get_status_msg *status;
45715 + char *cmd;
45716 int ret;
45717
45718 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45719 - sizeof(status), 0);
45720 + cmd = kmalloc(1, GFP_KERNEL);
45721 + if (cmd == NULL)
45722 + return -ENOMEM;
45723 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45724 + if (status == NULL) {
45725 + kfree(cmd);
45726 + return -ENOMEM;
45727 + }
45728 +
45729 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45730 +
45731 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45732 + sizeof(*status), 0);
45733 if (ret < 0) {
45734 err("cinergyt2_fe_read_signal_strength() Failed!"
45735 " (Error=%d)\n", ret);
45736 - return ret;
45737 + goto out;
45738 }
45739 - *strength = (0xffff - le16_to_cpu(status.gain));
45740 + *strength = (0xffff - le16_to_cpu(status->gain));
45741 +
45742 +out:
45743 + kfree(cmd);
45744 + kfree(status);
45745 return 0;
45746 }
45747
45748 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45749 {
45750 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45751 - struct dvbt_get_status_msg status;
45752 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45753 + struct dvbt_get_status_msg *status;
45754 + char *cmd;
45755 int ret;
45756
45757 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45758 - sizeof(status), 0);
45759 + cmd = kmalloc(1, GFP_KERNEL);
45760 + if (cmd == NULL)
45761 + return -ENOMEM;
45762 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45763 + if (status == NULL) {
45764 + kfree(cmd);
45765 + return -ENOMEM;
45766 + }
45767 +
45768 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45769 +
45770 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45771 + sizeof(*status), 0);
45772 if (ret < 0) {
45773 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45774 - return ret;
45775 + goto out;
45776 }
45777 - *snr = (status.snr << 8) | status.snr;
45778 - return 0;
45779 + *snr = (status->snr << 8) | status->snr;
45780 +
45781 +out:
45782 + kfree(cmd);
45783 + kfree(status);
45784 + return ret;
45785 }
45786
45787 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45788 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45789 {
45790 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45791 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45792 - struct dvbt_set_parameters_msg param;
45793 - char result[2];
45794 + struct dvbt_set_parameters_msg *param;
45795 + char *result;
45796 int err;
45797
45798 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45799 - param.tps = cpu_to_le16(compute_tps(fep));
45800 - param.freq = cpu_to_le32(fep->frequency / 1000);
45801 - param.flags = 0;
45802 + result = kmalloc(2, GFP_KERNEL);
45803 + if (result == NULL)
45804 + return -ENOMEM;
45805 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45806 + if (param == NULL) {
45807 + kfree(result);
45808 + return -ENOMEM;
45809 + }
45810 +
45811 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45812 + param->tps = cpu_to_le16(compute_tps(fep));
45813 + param->freq = cpu_to_le32(fep->frequency / 1000);
45814 + param->flags = 0;
45815
45816 switch (fep->bandwidth_hz) {
45817 default:
45818 case 8000000:
45819 - param.bandwidth = 8;
45820 + param->bandwidth = 8;
45821 break;
45822 case 7000000:
45823 - param.bandwidth = 7;
45824 + param->bandwidth = 7;
45825 break;
45826 case 6000000:
45827 - param.bandwidth = 6;
45828 + param->bandwidth = 6;
45829 break;
45830 }
45831
45832 err = dvb_usb_generic_rw(state->d,
45833 - (char *)&param, sizeof(param),
45834 - result, sizeof(result), 0);
45835 + (char *)param, sizeof(*param),
45836 + result, 2, 0);
45837 if (err < 0)
45838 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45839
45840 - return (err < 0) ? err : 0;
45841 + kfree(result);
45842 + kfree(param);
45843 + return err;
45844 }
45845
45846 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45847 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45848 index 733a7ff..f8b52e3 100644
45849 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45850 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45851 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45852
45853 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45854 {
45855 - struct hexline hx;
45856 - u8 reset;
45857 + struct hexline *hx;
45858 + u8 *reset;
45859 int ret,pos=0;
45860
45861 + reset = kmalloc(1, GFP_KERNEL);
45862 + if (reset == NULL)
45863 + return -ENOMEM;
45864 +
45865 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45866 + if (hx == NULL) {
45867 + kfree(reset);
45868 + return -ENOMEM;
45869 + }
45870 +
45871 /* stop the CPU */
45872 - reset = 1;
45873 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45874 + reset[0] = 1;
45875 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45876 err("could not stop the USB controller CPU.");
45877
45878 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45879 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45880 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45881 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45882 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45883 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45884
45885 - if (ret != hx.len) {
45886 + if (ret != hx->len) {
45887 err("error while transferring firmware "
45888 "(transferred size: %d, block size: %d)",
45889 - ret,hx.len);
45890 + ret,hx->len);
45891 ret = -EINVAL;
45892 break;
45893 }
45894 }
45895 if (ret < 0) {
45896 err("firmware download failed at %d with %d",pos,ret);
45897 + kfree(reset);
45898 + kfree(hx);
45899 return ret;
45900 }
45901
45902 if (ret == 0) {
45903 /* restart the CPU */
45904 - reset = 0;
45905 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45906 + reset[0] = 0;
45907 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45908 err("could not restart the USB controller CPU.");
45909 ret = -EINVAL;
45910 }
45911 } else
45912 ret = -EIO;
45913
45914 + kfree(reset);
45915 + kfree(hx);
45916 +
45917 return ret;
45918 }
45919 EXPORT_SYMBOL(usb_cypress_load_firmware);
45920 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45921 index 1a3df10..57997a5 100644
45922 --- a/drivers/media/usb/dvb-usb/dw2102.c
45923 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45924 @@ -118,7 +118,7 @@ struct su3000_state {
45925
45926 struct s6x0_state {
45927 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45928 -};
45929 +} __no_const;
45930
45931 /* debug */
45932 static int dvb_usb_dw2102_debug;
45933 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45934 index 6b0b8b6b..4038398 100644
45935 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45936 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45937 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
45938 static int technisat_usb2_i2c_access(struct usb_device *udev,
45939 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45940 {
45941 - u8 b[64];
45942 - int ret, actual_length;
45943 + u8 *b = kmalloc(64, GFP_KERNEL);
45944 + int ret, actual_length, error = 0;
45945 +
45946 + if (b == NULL)
45947 + return -ENOMEM;
45948
45949 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45950 debug_dump(tx, txlen, deb_i2c);
45951 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45952
45953 if (ret < 0) {
45954 err("i2c-error: out failed %02x = %d", device_addr, ret);
45955 - return -ENODEV;
45956 + error = -ENODEV;
45957 + goto out;
45958 }
45959
45960 ret = usb_bulk_msg(udev,
45961 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45962 b, 64, &actual_length, 1000);
45963 if (ret < 0) {
45964 err("i2c-error: in failed %02x = %d", device_addr, ret);
45965 - return -ENODEV;
45966 + error = -ENODEV;
45967 + goto out;
45968 }
45969
45970 if (b[0] != I2C_STATUS_OK) {
45971 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45972 /* handle tuner-i2c-nak */
45973 if (!(b[0] == I2C_STATUS_NAK &&
45974 device_addr == 0x60
45975 - /* && device_is_technisat_usb2 */))
45976 - return -ENODEV;
45977 + /* && device_is_technisat_usb2 */)) {
45978 + error = -ENODEV;
45979 + goto out;
45980 + }
45981 }
45982
45983 deb_i2c("status: %d, ", b[0]);
45984 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45985
45986 deb_i2c("\n");
45987
45988 - return 0;
45989 +out:
45990 + kfree(b);
45991 + return error;
45992 }
45993
45994 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45995 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45996 {
45997 int ret;
45998
45999 - u8 led[8] = {
46000 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46001 - 0
46002 - };
46003 + u8 *led = kzalloc(8, GFP_KERNEL);
46004 +
46005 + if (led == NULL)
46006 + return -ENOMEM;
46007
46008 if (disable_led_control && state != TECH_LED_OFF)
46009 return 0;
46010
46011 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46012 +
46013 switch (state) {
46014 case TECH_LED_ON:
46015 led[1] = 0x82;
46016 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46017 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46018 USB_TYPE_VENDOR | USB_DIR_OUT,
46019 0, 0,
46020 - led, sizeof(led), 500);
46021 + led, 8, 500);
46022
46023 mutex_unlock(&d->i2c_mutex);
46024 +
46025 + kfree(led);
46026 +
46027 return ret;
46028 }
46029
46030 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46031 {
46032 int ret;
46033 - u8 b = 0;
46034 + u8 *b = kzalloc(1, GFP_KERNEL);
46035 +
46036 + if (b == NULL)
46037 + return -ENOMEM;
46038
46039 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46040 return -EAGAIN;
46041 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46042 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46043 USB_TYPE_VENDOR | USB_DIR_OUT,
46044 (red << 8) | green, 0,
46045 - &b, 1, 500);
46046 + b, 1, 500);
46047
46048 mutex_unlock(&d->i2c_mutex);
46049
46050 + kfree(b);
46051 +
46052 return ret;
46053 }
46054
46055 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46056 struct dvb_usb_device_description **desc, int *cold)
46057 {
46058 int ret;
46059 - u8 version[3];
46060 + u8 *version = kmalloc(3, GFP_KERNEL);
46061
46062 /* first select the interface */
46063 if (usb_set_interface(udev, 0, 1) != 0)
46064 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46065
46066 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46067
46068 + if (version == NULL)
46069 + return 0;
46070 +
46071 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46072 GET_VERSION_INFO_VENDOR_REQUEST,
46073 USB_TYPE_VENDOR | USB_DIR_IN,
46074 0, 0,
46075 - version, sizeof(version), 500);
46076 + version, 3, 500);
46077
46078 if (ret < 0)
46079 *cold = 1;
46080 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46081 *cold = 0;
46082 }
46083
46084 + kfree(version);
46085 +
46086 return 0;
46087 }
46088
46089 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46090
46091 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46092 {
46093 - u8 buf[62], *b;
46094 + u8 *buf, *b;
46095 int ret;
46096 struct ir_raw_event ev;
46097
46098 + buf = kmalloc(62, GFP_KERNEL);
46099 +
46100 + if (buf == NULL)
46101 + return -ENOMEM;
46102 +
46103 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46104 buf[1] = 0x08;
46105 buf[2] = 0x8f;
46106 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46107 GET_IR_DATA_VENDOR_REQUEST,
46108 USB_TYPE_VENDOR | USB_DIR_IN,
46109 0x8080, 0,
46110 - buf, sizeof(buf), 500);
46111 + buf, 62, 500);
46112
46113 unlock:
46114 mutex_unlock(&d->i2c_mutex);
46115
46116 - if (ret < 0)
46117 + if (ret < 0) {
46118 + kfree(buf);
46119 return ret;
46120 + }
46121
46122 - if (ret == 1)
46123 + if (ret == 1) {
46124 + kfree(buf);
46125 return 0; /* no key pressed */
46126 + }
46127
46128 /* decoding */
46129 b = buf+1;
46130 @@ -653,6 +686,8 @@ unlock:
46131
46132 ir_raw_event_handle(d->rc_dev);
46133
46134 + kfree(buf);
46135 +
46136 return 1;
46137 }
46138
46139 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46140 index e502a5f..2a27f40 100644
46141 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46142 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46143 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46144 * by passing a very big num_planes value */
46145 uplane = compat_alloc_user_space(num_planes *
46146 sizeof(struct v4l2_plane));
46147 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46148 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46149
46150 while (--num_planes >= 0) {
46151 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46152 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46153 if (num_planes == 0)
46154 return 0;
46155
46156 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46157 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46158 if (get_user(p, &up->m.planes))
46159 return -EFAULT;
46160 uplane32 = compat_ptr(p);
46161 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46162 get_user(kp->flags, &up->flags) ||
46163 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46164 return -EFAULT;
46165 - kp->base = (__force void *)compat_ptr(tmp);
46166 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46167 return 0;
46168 }
46169
46170 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46171 n * sizeof(struct v4l2_ext_control32)))
46172 return -EFAULT;
46173 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46174 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46175 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46176 while (--n >= 0) {
46177 u32 id;
46178
46179 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46180 {
46181 struct v4l2_ext_control32 __user *ucontrols;
46182 struct v4l2_ext_control __user *kcontrols =
46183 - (__force struct v4l2_ext_control __user *)kp->controls;
46184 + (struct v4l2_ext_control __force_user *)kp->controls;
46185 int n = kp->count;
46186 compat_caddr_t p;
46187
46188 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46189 get_user(tmp, &up->edid) ||
46190 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46191 return -EFAULT;
46192 - kp->edid = (__force u8 *)compat_ptr(tmp);
46193 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46194 return 0;
46195 }
46196
46197 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46198 index 015f92a..59e311e 100644
46199 --- a/drivers/media/v4l2-core/v4l2-device.c
46200 +++ b/drivers/media/v4l2-core/v4l2-device.c
46201 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46202 EXPORT_SYMBOL_GPL(v4l2_device_put);
46203
46204 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46205 - atomic_t *instance)
46206 + atomic_unchecked_t *instance)
46207 {
46208 - int num = atomic_inc_return(instance) - 1;
46209 + int num = atomic_inc_return_unchecked(instance) - 1;
46210 int len = strlen(basename);
46211
46212 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46213 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46214 index 9ccb19a..d131468 100644
46215 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46216 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46217 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46218 struct file *file, void *fh, void *p);
46219 } u;
46220 void (*debug)(const void *arg, bool write_only);
46221 -};
46222 +} __do_const;
46223 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46224
46225 /* This control needs a priority check */
46226 #define INFO_FL_PRIO (1 << 0)
46227 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46228 struct video_device *vfd = video_devdata(file);
46229 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46230 bool write_only = false;
46231 - struct v4l2_ioctl_info default_info;
46232 + v4l2_ioctl_info_no_const default_info;
46233 const struct v4l2_ioctl_info *info;
46234 void *fh = file->private_data;
46235 struct v4l2_fh *vfh = NULL;
46236 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46237 ret = -EINVAL;
46238 break;
46239 }
46240 - *user_ptr = (void __user *)buf->m.planes;
46241 + *user_ptr = (void __force_user *)buf->m.planes;
46242 *kernel_ptr = (void **)&buf->m.planes;
46243 *array_size = sizeof(struct v4l2_plane) * buf->length;
46244 ret = 1;
46245 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46246 ret = -EINVAL;
46247 break;
46248 }
46249 - *user_ptr = (void __user *)edid->edid;
46250 + *user_ptr = (void __force_user *)edid->edid;
46251 *kernel_ptr = (void **)&edid->edid;
46252 *array_size = edid->blocks * 128;
46253 ret = 1;
46254 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46255 ret = -EINVAL;
46256 break;
46257 }
46258 - *user_ptr = (void __user *)ctrls->controls;
46259 + *user_ptr = (void __force_user *)ctrls->controls;
46260 *kernel_ptr = (void **)&ctrls->controls;
46261 *array_size = sizeof(struct v4l2_ext_control)
46262 * ctrls->count;
46263 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46264 }
46265
46266 if (has_array_args) {
46267 - *kernel_ptr = (void __force *)user_ptr;
46268 + *kernel_ptr = (void __force_kernel *)user_ptr;
46269 if (copy_to_user(user_ptr, mbuf, array_size))
46270 err = -EFAULT;
46271 goto out_array_args;
46272 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46273 index 187f836..679544b 100644
46274 --- a/drivers/message/fusion/mptbase.c
46275 +++ b/drivers/message/fusion/mptbase.c
46276 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46277 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46278 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46279
46280 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46281 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46282 +#else
46283 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46284 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46285 +#endif
46286 +
46287 /*
46288 * Rounding UP to nearest 4-kB boundary here...
46289 */
46290 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46291 ioc->facts.GlobalCredits);
46292
46293 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46294 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46295 + NULL, NULL);
46296 +#else
46297 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46298 +#endif
46299 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46300 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46301 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46302 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46303 index 0707fa2..70ca794 100644
46304 --- a/drivers/message/fusion/mptsas.c
46305 +++ b/drivers/message/fusion/mptsas.c
46306 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46307 return 0;
46308 }
46309
46310 +static inline void
46311 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46312 +{
46313 + if (phy_info->port_details) {
46314 + phy_info->port_details->rphy = rphy;
46315 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46316 + ioc->name, rphy));
46317 + }
46318 +
46319 + if (rphy) {
46320 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46321 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46322 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46323 + ioc->name, rphy, rphy->dev.release));
46324 + }
46325 +}
46326 +
46327 /* no mutex */
46328 static void
46329 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46330 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46331 return NULL;
46332 }
46333
46334 -static inline void
46335 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46336 -{
46337 - if (phy_info->port_details) {
46338 - phy_info->port_details->rphy = rphy;
46339 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46340 - ioc->name, rphy));
46341 - }
46342 -
46343 - if (rphy) {
46344 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46345 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46346 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46347 - ioc->name, rphy, rphy->dev.release));
46348 - }
46349 -}
46350 -
46351 static inline struct sas_port *
46352 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46353 {
46354 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46355 index b7d87cd..3fb36da 100644
46356 --- a/drivers/message/i2o/i2o_proc.c
46357 +++ b/drivers/message/i2o/i2o_proc.c
46358 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46359 "Array Controller Device"
46360 };
46361
46362 -static char *chtostr(char *tmp, u8 *chars, int n)
46363 -{
46364 - tmp[0] = 0;
46365 - return strncat(tmp, (char *)chars, n);
46366 -}
46367 -
46368 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46369 char *group)
46370 {
46371 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46372 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46373 {
46374 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46375 - static u32 work32[5];
46376 - static u8 *work8 = (u8 *) work32;
46377 - static u16 *work16 = (u16 *) work32;
46378 + u32 work32[5];
46379 + u8 *work8 = (u8 *) work32;
46380 + u16 *work16 = (u16 *) work32;
46381 int token;
46382 u32 hwcap;
46383
46384 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46385 } *result;
46386
46387 i2o_exec_execute_ddm_table ddm_table;
46388 - char tmp[28 + 1];
46389
46390 result = kmalloc(sizeof(*result), GFP_KERNEL);
46391 if (!result)
46392 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46393
46394 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46395 seq_printf(seq, "%-#8x", ddm_table.module_id);
46396 - seq_printf(seq, "%-29s",
46397 - chtostr(tmp, ddm_table.module_name_version, 28));
46398 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46399 seq_printf(seq, "%9d ", ddm_table.data_size);
46400 seq_printf(seq, "%8d", ddm_table.code_size);
46401
46402 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46403
46404 i2o_driver_result_table *result;
46405 i2o_driver_store_table *dst;
46406 - char tmp[28 + 1];
46407
46408 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46409 if (result == NULL)
46410 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46411
46412 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46413 seq_printf(seq, "%-#8x", dst->module_id);
46414 - seq_printf(seq, "%-29s",
46415 - chtostr(tmp, dst->module_name_version, 28));
46416 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46417 + seq_printf(seq, "%-.28s", dst->module_name_version);
46418 + seq_printf(seq, "%-.8s", dst->date);
46419 seq_printf(seq, "%8d ", dst->module_size);
46420 seq_printf(seq, "%8d ", dst->mpb_size);
46421 seq_printf(seq, "0x%04x", dst->module_flags);
46422 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46423 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46424 {
46425 struct i2o_device *d = (struct i2o_device *)seq->private;
46426 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46427 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46428 // == (allow) 512d bytes (max)
46429 - static u16 *work16 = (u16 *) work32;
46430 + u16 *work16 = (u16 *) work32;
46431 int token;
46432 - char tmp[16 + 1];
46433
46434 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46435
46436 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46437 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46438 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46439 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46440 - seq_printf(seq, "Vendor info : %s\n",
46441 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46442 - seq_printf(seq, "Product info : %s\n",
46443 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46444 - seq_printf(seq, "Description : %s\n",
46445 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46446 - seq_printf(seq, "Product rev. : %s\n",
46447 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46448 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46449 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46450 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46451 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46452
46453 seq_printf(seq, "Serial number : ");
46454 print_serial_number(seq, (u8 *) (work32 + 16),
46455 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46456 u8 pad[256]; // allow up to 256 byte (max) serial number
46457 } result;
46458
46459 - char tmp[24 + 1];
46460 -
46461 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46462
46463 if (token < 0) {
46464 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46465 }
46466
46467 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46468 - seq_printf(seq, "Module name : %s\n",
46469 - chtostr(tmp, result.module_name, 24));
46470 - seq_printf(seq, "Module revision : %s\n",
46471 - chtostr(tmp, result.module_rev, 8));
46472 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46473 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46474
46475 seq_printf(seq, "Serial number : ");
46476 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46477 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46478 u8 instance_number[4];
46479 } result;
46480
46481 - char tmp[64 + 1];
46482 -
46483 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46484
46485 if (token < 0) {
46486 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46487 return 0;
46488 }
46489
46490 - seq_printf(seq, "Device name : %s\n",
46491 - chtostr(tmp, result.device_name, 64));
46492 - seq_printf(seq, "Service name : %s\n",
46493 - chtostr(tmp, result.service_name, 64));
46494 - seq_printf(seq, "Physical name : %s\n",
46495 - chtostr(tmp, result.physical_location, 64));
46496 - seq_printf(seq, "Instance number : %s\n",
46497 - chtostr(tmp, result.instance_number, 4));
46498 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46499 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46500 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46501 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46502
46503 return 0;
46504 }
46505 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46506 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46507 {
46508 struct i2o_device *d = (struct i2o_device *)seq->private;
46509 - static u32 work32[12];
46510 - static u16 *work16 = (u16 *) work32;
46511 - static u8 *work8 = (u8 *) work32;
46512 + u32 work32[12];
46513 + u16 *work16 = (u16 *) work32;
46514 + u8 *work8 = (u8 *) work32;
46515 int token;
46516
46517 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46518 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46519 index 92752fb..a7494f6 100644
46520 --- a/drivers/message/i2o/iop.c
46521 +++ b/drivers/message/i2o/iop.c
46522 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46523
46524 spin_lock_irqsave(&c->context_list_lock, flags);
46525
46526 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46527 - atomic_inc(&c->context_list_counter);
46528 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46529 + atomic_inc_unchecked(&c->context_list_counter);
46530
46531 - entry->context = atomic_read(&c->context_list_counter);
46532 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46533
46534 list_add(&entry->list, &c->context_list);
46535
46536 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46537
46538 #if BITS_PER_LONG == 64
46539 spin_lock_init(&c->context_list_lock);
46540 - atomic_set(&c->context_list_counter, 0);
46541 + atomic_set_unchecked(&c->context_list_counter, 0);
46542 INIT_LIST_HEAD(&c->context_list);
46543 #endif
46544
46545 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46546 index b2c7e3b..85aa4764 100644
46547 --- a/drivers/mfd/ab8500-debugfs.c
46548 +++ b/drivers/mfd/ab8500-debugfs.c
46549 @@ -100,7 +100,7 @@ static int irq_last;
46550 static u32 *irq_count;
46551 static int num_irqs;
46552
46553 -static struct device_attribute **dev_attr;
46554 +static device_attribute_no_const **dev_attr;
46555 static char **event_name;
46556
46557 static u8 avg_sample = SAMPLE_16;
46558 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46559 index c880c89..45a7c68 100644
46560 --- a/drivers/mfd/max8925-i2c.c
46561 +++ b/drivers/mfd/max8925-i2c.c
46562 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46563 const struct i2c_device_id *id)
46564 {
46565 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46566 - static struct max8925_chip *chip;
46567 + struct max8925_chip *chip;
46568 struct device_node *node = client->dev.of_node;
46569
46570 if (node && !pdata) {
46571 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46572 index 7612d89..70549c2 100644
46573 --- a/drivers/mfd/tps65910.c
46574 +++ b/drivers/mfd/tps65910.c
46575 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46576 struct tps65910_platform_data *pdata)
46577 {
46578 int ret = 0;
46579 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46580 + struct regmap_irq_chip *tps6591x_irqs_chip;
46581
46582 if (!irq) {
46583 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46584 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46585 index 1b772ef..01e77d33 100644
46586 --- a/drivers/mfd/twl4030-irq.c
46587 +++ b/drivers/mfd/twl4030-irq.c
46588 @@ -34,6 +34,7 @@
46589 #include <linux/of.h>
46590 #include <linux/irqdomain.h>
46591 #include <linux/i2c/twl.h>
46592 +#include <asm/pgtable.h>
46593
46594 #include "twl-core.h"
46595
46596 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46597 * Install an irq handler for each of the SIH modules;
46598 * clone dummy irq_chip since PIH can't *do* anything
46599 */
46600 - twl4030_irq_chip = dummy_irq_chip;
46601 - twl4030_irq_chip.name = "twl4030";
46602 + pax_open_kernel();
46603 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46604 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46605
46606 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46607 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46608 + pax_close_kernel();
46609
46610 for (i = irq_base; i < irq_end; i++) {
46611 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46612 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46613 index 464419b..64bae8d 100644
46614 --- a/drivers/misc/c2port/core.c
46615 +++ b/drivers/misc/c2port/core.c
46616 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46617 goto error_idr_alloc;
46618 c2dev->id = ret;
46619
46620 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46621 + pax_open_kernel();
46622 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46623 + pax_close_kernel();
46624
46625 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46626 "c2port%d", c2dev->id);
46627 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46628 index 3f2b625..945e179 100644
46629 --- a/drivers/misc/eeprom/sunxi_sid.c
46630 +++ b/drivers/misc/eeprom/sunxi_sid.c
46631 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46632
46633 platform_set_drvdata(pdev, sid_data);
46634
46635 - sid_bin_attr.size = sid_data->keysize;
46636 + pax_open_kernel();
46637 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46638 + pax_close_kernel();
46639 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46640 return -ENODEV;
46641
46642 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46643 index 36f5d52..32311c3 100644
46644 --- a/drivers/misc/kgdbts.c
46645 +++ b/drivers/misc/kgdbts.c
46646 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46647 char before[BREAK_INSTR_SIZE];
46648 char after[BREAK_INSTR_SIZE];
46649
46650 - probe_kernel_read(before, (char *)kgdbts_break_test,
46651 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46652 BREAK_INSTR_SIZE);
46653 init_simple_test();
46654 ts.tst = plant_and_detach_test;
46655 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46656 /* Activate test with initial breakpoint */
46657 if (!is_early)
46658 kgdb_breakpoint();
46659 - probe_kernel_read(after, (char *)kgdbts_break_test,
46660 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46661 BREAK_INSTR_SIZE);
46662 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46663 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46664 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46665 index 3ef4627..8d00486 100644
46666 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46667 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46668 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46669 * the lid is closed. This leads to interrupts as soon as a little move
46670 * is done.
46671 */
46672 - atomic_inc(&lis3->count);
46673 + atomic_inc_unchecked(&lis3->count);
46674
46675 wake_up_interruptible(&lis3->misc_wait);
46676 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46677 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46678 if (lis3->pm_dev)
46679 pm_runtime_get_sync(lis3->pm_dev);
46680
46681 - atomic_set(&lis3->count, 0);
46682 + atomic_set_unchecked(&lis3->count, 0);
46683 return 0;
46684 }
46685
46686 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46687 add_wait_queue(&lis3->misc_wait, &wait);
46688 while (true) {
46689 set_current_state(TASK_INTERRUPTIBLE);
46690 - data = atomic_xchg(&lis3->count, 0);
46691 + data = atomic_xchg_unchecked(&lis3->count, 0);
46692 if (data)
46693 break;
46694
46695 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46696 struct lis3lv02d, miscdev);
46697
46698 poll_wait(file, &lis3->misc_wait, wait);
46699 - if (atomic_read(&lis3->count))
46700 + if (atomic_read_unchecked(&lis3->count))
46701 return POLLIN | POLLRDNORM;
46702 return 0;
46703 }
46704 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46705 index c439c82..1f20f57 100644
46706 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46707 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46708 @@ -297,7 +297,7 @@ struct lis3lv02d {
46709 struct input_polled_dev *idev; /* input device */
46710 struct platform_device *pdev; /* platform device */
46711 struct regulator_bulk_data regulators[2];
46712 - atomic_t count; /* interrupt count after last read */
46713 + atomic_unchecked_t count; /* interrupt count after last read */
46714 union axis_conversion ac; /* hw -> logical axis */
46715 int mapped_btns[3];
46716
46717 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46718 index 2f30bad..c4c13d0 100644
46719 --- a/drivers/misc/sgi-gru/gruhandles.c
46720 +++ b/drivers/misc/sgi-gru/gruhandles.c
46721 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46722 unsigned long nsec;
46723
46724 nsec = CLKS2NSEC(clks);
46725 - atomic_long_inc(&mcs_op_statistics[op].count);
46726 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46727 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46728 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46729 if (mcs_op_statistics[op].max < nsec)
46730 mcs_op_statistics[op].max = nsec;
46731 }
46732 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46733 index 4f76359..cdfcb2e 100644
46734 --- a/drivers/misc/sgi-gru/gruprocfs.c
46735 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46736 @@ -32,9 +32,9 @@
46737
46738 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46739
46740 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46741 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46742 {
46743 - unsigned long val = atomic_long_read(v);
46744 + unsigned long val = atomic_long_read_unchecked(v);
46745
46746 seq_printf(s, "%16lu %s\n", val, id);
46747 }
46748 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46749
46750 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46751 for (op = 0; op < mcsop_last; op++) {
46752 - count = atomic_long_read(&mcs_op_statistics[op].count);
46753 - total = atomic_long_read(&mcs_op_statistics[op].total);
46754 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46755 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46756 max = mcs_op_statistics[op].max;
46757 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46758 count ? total / count : 0, max);
46759 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46760 index 5c3ce24..4915ccb 100644
46761 --- a/drivers/misc/sgi-gru/grutables.h
46762 +++ b/drivers/misc/sgi-gru/grutables.h
46763 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46764 * GRU statistics.
46765 */
46766 struct gru_stats_s {
46767 - atomic_long_t vdata_alloc;
46768 - atomic_long_t vdata_free;
46769 - atomic_long_t gts_alloc;
46770 - atomic_long_t gts_free;
46771 - atomic_long_t gms_alloc;
46772 - atomic_long_t gms_free;
46773 - atomic_long_t gts_double_allocate;
46774 - atomic_long_t assign_context;
46775 - atomic_long_t assign_context_failed;
46776 - atomic_long_t free_context;
46777 - atomic_long_t load_user_context;
46778 - atomic_long_t load_kernel_context;
46779 - atomic_long_t lock_kernel_context;
46780 - atomic_long_t unlock_kernel_context;
46781 - atomic_long_t steal_user_context;
46782 - atomic_long_t steal_kernel_context;
46783 - atomic_long_t steal_context_failed;
46784 - atomic_long_t nopfn;
46785 - atomic_long_t asid_new;
46786 - atomic_long_t asid_next;
46787 - atomic_long_t asid_wrap;
46788 - atomic_long_t asid_reuse;
46789 - atomic_long_t intr;
46790 - atomic_long_t intr_cbr;
46791 - atomic_long_t intr_tfh;
46792 - atomic_long_t intr_spurious;
46793 - atomic_long_t intr_mm_lock_failed;
46794 - atomic_long_t call_os;
46795 - atomic_long_t call_os_wait_queue;
46796 - atomic_long_t user_flush_tlb;
46797 - atomic_long_t user_unload_context;
46798 - atomic_long_t user_exception;
46799 - atomic_long_t set_context_option;
46800 - atomic_long_t check_context_retarget_intr;
46801 - atomic_long_t check_context_unload;
46802 - atomic_long_t tlb_dropin;
46803 - atomic_long_t tlb_preload_page;
46804 - atomic_long_t tlb_dropin_fail_no_asid;
46805 - atomic_long_t tlb_dropin_fail_upm;
46806 - atomic_long_t tlb_dropin_fail_invalid;
46807 - atomic_long_t tlb_dropin_fail_range_active;
46808 - atomic_long_t tlb_dropin_fail_idle;
46809 - atomic_long_t tlb_dropin_fail_fmm;
46810 - atomic_long_t tlb_dropin_fail_no_exception;
46811 - atomic_long_t tfh_stale_on_fault;
46812 - atomic_long_t mmu_invalidate_range;
46813 - atomic_long_t mmu_invalidate_page;
46814 - atomic_long_t flush_tlb;
46815 - atomic_long_t flush_tlb_gru;
46816 - atomic_long_t flush_tlb_gru_tgh;
46817 - atomic_long_t flush_tlb_gru_zero_asid;
46818 + atomic_long_unchecked_t vdata_alloc;
46819 + atomic_long_unchecked_t vdata_free;
46820 + atomic_long_unchecked_t gts_alloc;
46821 + atomic_long_unchecked_t gts_free;
46822 + atomic_long_unchecked_t gms_alloc;
46823 + atomic_long_unchecked_t gms_free;
46824 + atomic_long_unchecked_t gts_double_allocate;
46825 + atomic_long_unchecked_t assign_context;
46826 + atomic_long_unchecked_t assign_context_failed;
46827 + atomic_long_unchecked_t free_context;
46828 + atomic_long_unchecked_t load_user_context;
46829 + atomic_long_unchecked_t load_kernel_context;
46830 + atomic_long_unchecked_t lock_kernel_context;
46831 + atomic_long_unchecked_t unlock_kernel_context;
46832 + atomic_long_unchecked_t steal_user_context;
46833 + atomic_long_unchecked_t steal_kernel_context;
46834 + atomic_long_unchecked_t steal_context_failed;
46835 + atomic_long_unchecked_t nopfn;
46836 + atomic_long_unchecked_t asid_new;
46837 + atomic_long_unchecked_t asid_next;
46838 + atomic_long_unchecked_t asid_wrap;
46839 + atomic_long_unchecked_t asid_reuse;
46840 + atomic_long_unchecked_t intr;
46841 + atomic_long_unchecked_t intr_cbr;
46842 + atomic_long_unchecked_t intr_tfh;
46843 + atomic_long_unchecked_t intr_spurious;
46844 + atomic_long_unchecked_t intr_mm_lock_failed;
46845 + atomic_long_unchecked_t call_os;
46846 + atomic_long_unchecked_t call_os_wait_queue;
46847 + atomic_long_unchecked_t user_flush_tlb;
46848 + atomic_long_unchecked_t user_unload_context;
46849 + atomic_long_unchecked_t user_exception;
46850 + atomic_long_unchecked_t set_context_option;
46851 + atomic_long_unchecked_t check_context_retarget_intr;
46852 + atomic_long_unchecked_t check_context_unload;
46853 + atomic_long_unchecked_t tlb_dropin;
46854 + atomic_long_unchecked_t tlb_preload_page;
46855 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46856 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46857 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46858 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46859 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46860 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46861 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46862 + atomic_long_unchecked_t tfh_stale_on_fault;
46863 + atomic_long_unchecked_t mmu_invalidate_range;
46864 + atomic_long_unchecked_t mmu_invalidate_page;
46865 + atomic_long_unchecked_t flush_tlb;
46866 + atomic_long_unchecked_t flush_tlb_gru;
46867 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46868 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46869
46870 - atomic_long_t copy_gpa;
46871 - atomic_long_t read_gpa;
46872 + atomic_long_unchecked_t copy_gpa;
46873 + atomic_long_unchecked_t read_gpa;
46874
46875 - atomic_long_t mesq_receive;
46876 - atomic_long_t mesq_receive_none;
46877 - atomic_long_t mesq_send;
46878 - atomic_long_t mesq_send_failed;
46879 - atomic_long_t mesq_noop;
46880 - atomic_long_t mesq_send_unexpected_error;
46881 - atomic_long_t mesq_send_lb_overflow;
46882 - atomic_long_t mesq_send_qlimit_reached;
46883 - atomic_long_t mesq_send_amo_nacked;
46884 - atomic_long_t mesq_send_put_nacked;
46885 - atomic_long_t mesq_page_overflow;
46886 - atomic_long_t mesq_qf_locked;
46887 - atomic_long_t mesq_qf_noop_not_full;
46888 - atomic_long_t mesq_qf_switch_head_failed;
46889 - atomic_long_t mesq_qf_unexpected_error;
46890 - atomic_long_t mesq_noop_unexpected_error;
46891 - atomic_long_t mesq_noop_lb_overflow;
46892 - atomic_long_t mesq_noop_qlimit_reached;
46893 - atomic_long_t mesq_noop_amo_nacked;
46894 - atomic_long_t mesq_noop_put_nacked;
46895 - atomic_long_t mesq_noop_page_overflow;
46896 + atomic_long_unchecked_t mesq_receive;
46897 + atomic_long_unchecked_t mesq_receive_none;
46898 + atomic_long_unchecked_t mesq_send;
46899 + atomic_long_unchecked_t mesq_send_failed;
46900 + atomic_long_unchecked_t mesq_noop;
46901 + atomic_long_unchecked_t mesq_send_unexpected_error;
46902 + atomic_long_unchecked_t mesq_send_lb_overflow;
46903 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46904 + atomic_long_unchecked_t mesq_send_amo_nacked;
46905 + atomic_long_unchecked_t mesq_send_put_nacked;
46906 + atomic_long_unchecked_t mesq_page_overflow;
46907 + atomic_long_unchecked_t mesq_qf_locked;
46908 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46909 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46910 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46911 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46912 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46913 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46914 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46915 + atomic_long_unchecked_t mesq_noop_put_nacked;
46916 + atomic_long_unchecked_t mesq_noop_page_overflow;
46917
46918 };
46919
46920 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46921 tghop_invalidate, mcsop_last};
46922
46923 struct mcs_op_statistic {
46924 - atomic_long_t count;
46925 - atomic_long_t total;
46926 + atomic_long_unchecked_t count;
46927 + atomic_long_unchecked_t total;
46928 unsigned long max;
46929 };
46930
46931 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46932
46933 #define STAT(id) do { \
46934 if (gru_options & OPT_STATS) \
46935 - atomic_long_inc(&gru_stats.id); \
46936 + atomic_long_inc_unchecked(&gru_stats.id); \
46937 } while (0)
46938
46939 #ifdef CONFIG_SGI_GRU_DEBUG
46940 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46941 index c862cd4..0d176fe 100644
46942 --- a/drivers/misc/sgi-xp/xp.h
46943 +++ b/drivers/misc/sgi-xp/xp.h
46944 @@ -288,7 +288,7 @@ struct xpc_interface {
46945 xpc_notify_func, void *);
46946 void (*received) (short, int, void *);
46947 enum xp_retval (*partid_to_nasids) (short, void *);
46948 -};
46949 +} __no_const;
46950
46951 extern struct xpc_interface xpc_interface;
46952
46953 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46954 index 01be66d..e3a0c7e 100644
46955 --- a/drivers/misc/sgi-xp/xp_main.c
46956 +++ b/drivers/misc/sgi-xp/xp_main.c
46957 @@ -78,13 +78,13 @@ xpc_notloaded(void)
46958 }
46959
46960 struct xpc_interface xpc_interface = {
46961 - (void (*)(int))xpc_notloaded,
46962 - (void (*)(int))xpc_notloaded,
46963 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46964 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46965 + .connect = (void (*)(int))xpc_notloaded,
46966 + .disconnect = (void (*)(int))xpc_notloaded,
46967 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46968 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46969 void *))xpc_notloaded,
46970 - (void (*)(short, int, void *))xpc_notloaded,
46971 - (enum xp_retval(*)(short, void *))xpc_notloaded
46972 + .received = (void (*)(short, int, void *))xpc_notloaded,
46973 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46974 };
46975 EXPORT_SYMBOL_GPL(xpc_interface);
46976
46977 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46978 index b94d5f7..7f494c5 100644
46979 --- a/drivers/misc/sgi-xp/xpc.h
46980 +++ b/drivers/misc/sgi-xp/xpc.h
46981 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
46982 void (*received_payload) (struct xpc_channel *, void *);
46983 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46984 };
46985 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46986
46987 /* struct xpc_partition act_state values (for XPC HB) */
46988
46989 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46990 /* found in xpc_main.c */
46991 extern struct device *xpc_part;
46992 extern struct device *xpc_chan;
46993 -extern struct xpc_arch_operations xpc_arch_ops;
46994 +extern xpc_arch_operations_no_const xpc_arch_ops;
46995 extern int xpc_disengage_timelimit;
46996 extern int xpc_disengage_timedout;
46997 extern int xpc_activate_IRQ_rcvd;
46998 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46999 index 82dc574..8539ab2 100644
47000 --- a/drivers/misc/sgi-xp/xpc_main.c
47001 +++ b/drivers/misc/sgi-xp/xpc_main.c
47002 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47003 .notifier_call = xpc_system_die,
47004 };
47005
47006 -struct xpc_arch_operations xpc_arch_ops;
47007 +xpc_arch_operations_no_const xpc_arch_ops;
47008
47009 /*
47010 * Timer function to enforce the timelimit on the partition disengage.
47011 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47012
47013 if (((die_args->trapnr == X86_TRAP_MF) ||
47014 (die_args->trapnr == X86_TRAP_XF)) &&
47015 - !user_mode_vm(die_args->regs))
47016 + !user_mode(die_args->regs))
47017 xpc_die_deactivate();
47018
47019 break;
47020 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47021 index a11451f..9e1bbad 100644
47022 --- a/drivers/mmc/card/block.c
47023 +++ b/drivers/mmc/card/block.c
47024 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47025 if (idata->ic.postsleep_min_us)
47026 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47027
47028 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47029 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47030 err = -EFAULT;
47031 goto cmd_rel_host;
47032 }
47033 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47034 index 7911e05..d0f9dda 100644
47035 --- a/drivers/mmc/core/mmc_ops.c
47036 +++ b/drivers/mmc/core/mmc_ops.c
47037 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47038 void *data_buf;
47039 int is_on_stack;
47040
47041 - is_on_stack = object_is_on_stack(buf);
47042 + is_on_stack = object_starts_on_stack(buf);
47043 if (is_on_stack) {
47044 /*
47045 * dma onto stack is unsafe/nonportable, but callers to this
47046 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47047 index 01b99e8..5c325e3 100644
47048 --- a/drivers/mmc/host/dw_mmc.h
47049 +++ b/drivers/mmc/host/dw_mmc.h
47050 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47051 int (*parse_dt)(struct dw_mci *host);
47052 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47053 struct dw_mci_tuning_data *tuning_data);
47054 -};
47055 +} __do_const;
47056 #endif /* _DW_MMC_H_ */
47057 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47058 index 43af791..86f4c48 100644
47059 --- a/drivers/mmc/host/mmci.c
47060 +++ b/drivers/mmc/host/mmci.c
47061 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47062 mmc->caps |= MMC_CAP_CMD23;
47063
47064 if (variant->busy_detect) {
47065 - mmci_ops.card_busy = mmci_card_busy;
47066 + pax_open_kernel();
47067 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47068 + pax_close_kernel();
47069 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47070 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47071 mmc->max_busy_timeout = 0;
47072 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47073 index 9c2b9cb..cebb09a 100644
47074 --- a/drivers/mmc/host/omap_hsmmc.c
47075 +++ b/drivers/mmc/host/omap_hsmmc.c
47076 @@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47077
47078 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47079 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47080 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47081 + pax_open_kernel();
47082 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47083 + pax_close_kernel();
47084 }
47085
47086 pm_runtime_enable(host->dev);
47087 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47088 index 587ee0e..b3bbcab 100644
47089 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47090 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47091 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47092 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47093 }
47094
47095 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47096 - sdhci_esdhc_ops.platform_execute_tuning =
47097 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47098 + pax_open_kernel();
47099 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47100 esdhc_executing_tuning;
47101 + pax_close_kernel();
47102 + }
47103
47104 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47105 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47106 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47107 index 0ce6eb1..8dcce1b 100644
47108 --- a/drivers/mmc/host/sdhci-s3c.c
47109 +++ b/drivers/mmc/host/sdhci-s3c.c
47110 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47111 * we can use overriding functions instead of default.
47112 */
47113 if (sc->no_divider) {
47114 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47115 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47116 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47117 + pax_open_kernel();
47118 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47119 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47120 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47121 + pax_close_kernel();
47122 }
47123
47124 /* It supports additional host capabilities if needed */
47125 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47126 index 423666b..81ff5eb 100644
47127 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47128 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47129 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47130 size_t totlen = 0, thislen;
47131 int ret = 0;
47132 size_t buflen = 0;
47133 - static char *buffer;
47134 + char *buffer;
47135
47136 if (!ECCBUF_SIZE) {
47137 /* We should fall back to a general writev implementation.
47138 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47139 index b3b7ca1..5dd4634 100644
47140 --- a/drivers/mtd/nand/denali.c
47141 +++ b/drivers/mtd/nand/denali.c
47142 @@ -24,6 +24,7 @@
47143 #include <linux/slab.h>
47144 #include <linux/mtd/mtd.h>
47145 #include <linux/module.h>
47146 +#include <linux/slab.h>
47147
47148 #include "denali.h"
47149
47150 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47151 index 959cb9b..8520fe5 100644
47152 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47153 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47154 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47155
47156 /* first try to map the upper buffer directly */
47157 if (virt_addr_valid(this->upper_buf) &&
47158 - !object_is_on_stack(this->upper_buf)) {
47159 + !object_starts_on_stack(this->upper_buf)) {
47160 sg_init_one(sgl, this->upper_buf, this->upper_len);
47161 ret = dma_map_sg(this->dev, sgl, 1, dr);
47162 if (ret == 0)
47163 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47164 index 51b9d6a..52af9a7 100644
47165 --- a/drivers/mtd/nftlmount.c
47166 +++ b/drivers/mtd/nftlmount.c
47167 @@ -24,6 +24,7 @@
47168 #include <asm/errno.h>
47169 #include <linux/delay.h>
47170 #include <linux/slab.h>
47171 +#include <linux/sched.h>
47172 #include <linux/mtd/mtd.h>
47173 #include <linux/mtd/nand.h>
47174 #include <linux/mtd/nftl.h>
47175 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47176 index c23184a..4115c41 100644
47177 --- a/drivers/mtd/sm_ftl.c
47178 +++ b/drivers/mtd/sm_ftl.c
47179 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47180 #define SM_CIS_VENDOR_OFFSET 0x59
47181 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47182 {
47183 - struct attribute_group *attr_group;
47184 + attribute_group_no_const *attr_group;
47185 struct attribute **attributes;
47186 struct sm_sysfs_attribute *vendor_attribute;
47187 char *vendor;
47188 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47189 index a5115fb..81b03f6 100644
47190 --- a/drivers/net/bonding/bond_main.c
47191 +++ b/drivers/net/bonding/bond_main.c
47192 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47193 bond_dev_queue_xmit(bond, skb, slave->dev);
47194 } else {
47195 dev_kfree_skb_any(skb);
47196 - atomic_long_inc(&dev->tx_dropped);
47197 + atomic_long_inc_unchecked(&dev->tx_dropped);
47198 }
47199
47200 return NETDEV_TX_OK;
47201 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47202 index 45f09a6..f154f8d 100644
47203 --- a/drivers/net/bonding/bond_netlink.c
47204 +++ b/drivers/net/bonding/bond_netlink.c
47205 @@ -585,7 +585,7 @@ nla_put_failure:
47206 return -EMSGSIZE;
47207 }
47208
47209 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47210 +struct rtnl_link_ops bond_link_ops = {
47211 .kind = "bond",
47212 .priv_size = sizeof(struct bonding),
47213 .setup = bond_setup,
47214 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47215 index 5e40a8b..126bfda 100644
47216 --- a/drivers/net/caif/caif_hsi.c
47217 +++ b/drivers/net/caif/caif_hsi.c
47218 @@ -1445,7 +1445,7 @@ err:
47219 return -ENODEV;
47220 }
47221
47222 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47223 +static struct rtnl_link_ops caif_hsi_link_ops = {
47224 .kind = "cfhsi",
47225 .priv_size = sizeof(struct cfhsi),
47226 .setup = cfhsi_setup,
47227 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47228 index 98d73aa..63ef9da 100644
47229 --- a/drivers/net/can/Kconfig
47230 +++ b/drivers/net/can/Kconfig
47231 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47232
47233 config CAN_FLEXCAN
47234 tristate "Support for Freescale FLEXCAN based chips"
47235 - depends on ARM || PPC
47236 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47237 ---help---
47238 Say Y here if you want to support for Freescale FlexCAN.
47239
47240 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47241 index 4b008c9..2b1151f 100644
47242 --- a/drivers/net/can/dev.c
47243 +++ b/drivers/net/can/dev.c
47244 @@ -872,7 +872,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47245 return -EOPNOTSUPP;
47246 }
47247
47248 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47249 +static struct rtnl_link_ops can_link_ops = {
47250 .kind = "can",
47251 .maxtype = IFLA_CAN_MAX,
47252 .policy = can_policy,
47253 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47254 index 4e94057..32032ff 100644
47255 --- a/drivers/net/can/vcan.c
47256 +++ b/drivers/net/can/vcan.c
47257 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47258 dev->destructor = free_netdev;
47259 }
47260
47261 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47262 +static struct rtnl_link_ops vcan_link_ops = {
47263 .kind = "vcan",
47264 .setup = vcan_setup,
47265 };
47266 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47267 index ff435fb..d408b1f 100644
47268 --- a/drivers/net/dummy.c
47269 +++ b/drivers/net/dummy.c
47270 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47271 return 0;
47272 }
47273
47274 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47275 +static struct rtnl_link_ops dummy_link_ops = {
47276 .kind = "dummy",
47277 .setup = dummy_setup,
47278 .validate = dummy_validate,
47279 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47280 index 1d162cc..b546a75 100644
47281 --- a/drivers/net/ethernet/8390/ax88796.c
47282 +++ b/drivers/net/ethernet/8390/ax88796.c
47283 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47284 if (ax->plat->reg_offsets)
47285 ei_local->reg_offset = ax->plat->reg_offsets;
47286 else {
47287 + resource_size_t _mem_size = mem_size;
47288 + do_div(_mem_size, 0x18);
47289 ei_local->reg_offset = ax->reg_offsets;
47290 for (ret = 0; ret < 0x18; ret++)
47291 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47292 + ax->reg_offsets[ret] = _mem_size * ret;
47293 }
47294
47295 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47296 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47297 index 4efc435..4ab9e14 100644
47298 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47299 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47300 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47301 return 0;
47302 }
47303
47304 -static struct net_device_ops altera_tse_netdev_ops = {
47305 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47306 .ndo_open = tse_open,
47307 .ndo_stop = tse_shutdown,
47308 .ndo_start_xmit = tse_start_xmit,
47309 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47310 ndev->netdev_ops = &altera_tse_netdev_ops;
47311 altera_tse_set_ethtool_ops(ndev);
47312
47313 + pax_open_kernel();
47314 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47315
47316 if (priv->hash_filter)
47317 altera_tse_netdev_ops.ndo_set_rx_mode =
47318 tse_set_rx_mode_hashfilter;
47319 + pax_close_kernel();
47320
47321 /* Scatter/gather IO is not supported,
47322 * so it is turned off
47323 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47324 index caade30..3e257d9 100644
47325 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47326 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47327 @@ -1072,14 +1072,14 @@ do { \
47328 * operations, everything works on mask values.
47329 */
47330 #define XMDIO_READ(_pdata, _mmd, _reg) \
47331 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47332 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47333 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47334
47335 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47336 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47337
47338 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47339 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47340 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47341 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47342
47343 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47344 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47345 index 8a50b01..39c1ad0 100644
47346 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47347 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47348 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47349
47350 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47351
47352 - pdata->hw_if.config_dcb_tc(pdata);
47353 + pdata->hw_if->config_dcb_tc(pdata);
47354
47355 return 0;
47356 }
47357 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47358
47359 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47360
47361 - pdata->hw_if.config_dcb_pfc(pdata);
47362 + pdata->hw_if->config_dcb_pfc(pdata);
47363
47364 return 0;
47365 }
47366 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47367 index 6fc5da0..61ac2cb 100644
47368 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47369 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47370 @@ -235,7 +235,7 @@ err_ring:
47371
47372 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47373 {
47374 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47375 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47376 struct xgbe_channel *channel;
47377 struct xgbe_ring *ring;
47378 struct xgbe_ring_data *rdata;
47379 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47380
47381 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47382 {
47383 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47384 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47385 struct xgbe_channel *channel;
47386 struct xgbe_ring *ring;
47387 struct xgbe_ring_desc *rdesc;
47388 @@ -505,7 +505,7 @@ err_out:
47389 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47390 {
47391 struct xgbe_prv_data *pdata = channel->pdata;
47392 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47393 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47394 struct xgbe_ring *ring = channel->rx_ring;
47395 struct xgbe_ring_data *rdata;
47396 struct sk_buff *skb = NULL;
47397 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47398 DBGPR("<--xgbe_realloc_skb\n");
47399 }
47400
47401 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47402 -{
47403 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47404 -
47405 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47406 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47407 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47408 - desc_if->realloc_skb = xgbe_realloc_skb;
47409 - desc_if->unmap_skb = xgbe_unmap_skb;
47410 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47411 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47412 -
47413 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47414 -}
47415 +const struct xgbe_desc_if default_xgbe_desc_if = {
47416 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47417 + .free_ring_resources = xgbe_free_ring_resources,
47418 + .map_tx_skb = xgbe_map_tx_skb,
47419 + .realloc_skb = xgbe_realloc_skb,
47420 + .unmap_skb = xgbe_unmap_skb,
47421 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47422 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47423 +};
47424 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47425 index 9da3a03..022f15c 100644
47426 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47427 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47428 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47429
47430 static int xgbe_init(struct xgbe_prv_data *pdata)
47431 {
47432 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47433 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47434 int ret;
47435
47436 DBGPR("-->xgbe_init\n");
47437 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47438 return 0;
47439 }
47440
47441 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47442 -{
47443 - DBGPR("-->xgbe_init_function_ptrs\n");
47444 -
47445 - hw_if->tx_complete = xgbe_tx_complete;
47446 -
47447 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47448 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47449 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47450 - hw_if->set_mac_address = xgbe_set_mac_address;
47451 -
47452 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47453 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47454 -
47455 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47456 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47457 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47458 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47459 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47460 -
47461 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47462 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47463 -
47464 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47465 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47466 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47467 -
47468 - hw_if->enable_tx = xgbe_enable_tx;
47469 - hw_if->disable_tx = xgbe_disable_tx;
47470 - hw_if->enable_rx = xgbe_enable_rx;
47471 - hw_if->disable_rx = xgbe_disable_rx;
47472 -
47473 - hw_if->powerup_tx = xgbe_powerup_tx;
47474 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47475 - hw_if->powerup_rx = xgbe_powerup_rx;
47476 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47477 -
47478 - hw_if->pre_xmit = xgbe_pre_xmit;
47479 - hw_if->dev_read = xgbe_dev_read;
47480 - hw_if->enable_int = xgbe_enable_int;
47481 - hw_if->disable_int = xgbe_disable_int;
47482 - hw_if->init = xgbe_init;
47483 - hw_if->exit = xgbe_exit;
47484 +const struct xgbe_hw_if default_xgbe_hw_if = {
47485 + .tx_complete = xgbe_tx_complete,
47486 +
47487 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47488 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47489 + .add_mac_addresses = xgbe_add_mac_addresses,
47490 + .set_mac_address = xgbe_set_mac_address,
47491 +
47492 + .enable_rx_csum = xgbe_enable_rx_csum,
47493 + .disable_rx_csum = xgbe_disable_rx_csum,
47494 +
47495 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47496 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47497 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47498 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47499 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47500 +
47501 + .read_mmd_regs = xgbe_read_mmd_regs,
47502 + .write_mmd_regs = xgbe_write_mmd_regs,
47503 +
47504 + .set_gmii_speed = xgbe_set_gmii_speed,
47505 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47506 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47507 +
47508 + .enable_tx = xgbe_enable_tx,
47509 + .disable_tx = xgbe_disable_tx,
47510 + .enable_rx = xgbe_enable_rx,
47511 + .disable_rx = xgbe_disable_rx,
47512 +
47513 + .powerup_tx = xgbe_powerup_tx,
47514 + .powerdown_tx = xgbe_powerdown_tx,
47515 + .powerup_rx = xgbe_powerup_rx,
47516 + .powerdown_rx = xgbe_powerdown_rx,
47517 +
47518 + .pre_xmit = xgbe_pre_xmit,
47519 + .dev_read = xgbe_dev_read,
47520 + .enable_int = xgbe_enable_int,
47521 + .disable_int = xgbe_disable_int,
47522 + .init = xgbe_init,
47523 + .exit = xgbe_exit,
47524
47525 /* Descriptor related Sequences have to be initialized here */
47526 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47527 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47528 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47529 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47530 - hw_if->is_last_desc = xgbe_is_last_desc;
47531 - hw_if->is_context_desc = xgbe_is_context_desc;
47532 + .tx_desc_init = xgbe_tx_desc_init,
47533 + .rx_desc_init = xgbe_rx_desc_init,
47534 + .tx_desc_reset = xgbe_tx_desc_reset,
47535 + .rx_desc_reset = xgbe_rx_desc_reset,
47536 + .is_last_desc = xgbe_is_last_desc,
47537 + .is_context_desc = xgbe_is_context_desc,
47538
47539 /* For FLOW ctrl */
47540 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47541 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47542 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47543 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47544
47545 /* For RX coalescing */
47546 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47547 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47548 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47549 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47550 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47551 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47552 + .usec_to_riwt = xgbe_usec_to_riwt,
47553 + .riwt_to_usec = xgbe_riwt_to_usec,
47554
47555 /* For RX and TX threshold config */
47556 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47557 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47558 + .config_rx_threshold = xgbe_config_rx_threshold,
47559 + .config_tx_threshold = xgbe_config_tx_threshold,
47560
47561 /* For RX and TX Store and Forward Mode config */
47562 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47563 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47564 + .config_rsf_mode = xgbe_config_rsf_mode,
47565 + .config_tsf_mode = xgbe_config_tsf_mode,
47566
47567 /* For TX DMA Operating on Second Frame config */
47568 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47569 + .config_osp_mode = xgbe_config_osp_mode,
47570
47571 /* For RX and TX PBL config */
47572 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47573 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47574 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47575 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47576 - hw_if->config_pblx8 = xgbe_config_pblx8;
47577 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47578 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47579 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47580 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47581 + .config_pblx8 = xgbe_config_pblx8,
47582
47583 /* For MMC statistics support */
47584 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47585 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47586 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47587 + .tx_mmc_int = xgbe_tx_mmc_int,
47588 + .rx_mmc_int = xgbe_rx_mmc_int,
47589 + .read_mmc_stats = xgbe_read_mmc_stats,
47590
47591 /* For PTP config */
47592 - hw_if->config_tstamp = xgbe_config_tstamp;
47593 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47594 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47595 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47596 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47597 + .config_tstamp = xgbe_config_tstamp,
47598 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47599 + .set_tstamp_time = xgbe_set_tstamp_time,
47600 + .get_tstamp_time = xgbe_get_tstamp_time,
47601 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47602
47603 /* For Data Center Bridging config */
47604 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47605 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47606 -
47607 - DBGPR("<--xgbe_init_function_ptrs\n");
47608 -}
47609 + .config_dcb_tc = xgbe_config_dcb_tc,
47610 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47611 +};
47612 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47613 index 2349ea9..a83a677 100644
47614 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47615 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47616 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47617
47618 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47619 {
47620 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47621 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47622 struct xgbe_channel *channel;
47623 enum xgbe_int int_id;
47624 unsigned int i;
47625 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47626
47627 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47628 {
47629 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47630 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47631 struct xgbe_channel *channel;
47632 enum xgbe_int int_id;
47633 unsigned int i;
47634 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47635 static irqreturn_t xgbe_isr(int irq, void *data)
47636 {
47637 struct xgbe_prv_data *pdata = data;
47638 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47639 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47640 struct xgbe_channel *channel;
47641 unsigned int dma_isr, dma_ch_isr;
47642 unsigned int mac_isr, mac_tssr;
47643 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47644
47645 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47646 {
47647 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47648 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47649
47650 DBGPR("-->xgbe_init_tx_coalesce\n");
47651
47652 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47653
47654 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47655 {
47656 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47657 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47658
47659 DBGPR("-->xgbe_init_rx_coalesce\n");
47660
47661 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47662
47663 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47664 {
47665 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47666 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47667 struct xgbe_channel *channel;
47668 struct xgbe_ring *ring;
47669 struct xgbe_ring_data *rdata;
47670 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47671
47672 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47673 {
47674 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47675 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47676 struct xgbe_channel *channel;
47677 struct xgbe_ring *ring;
47678 struct xgbe_ring_data *rdata;
47679 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47680 static void xgbe_adjust_link(struct net_device *netdev)
47681 {
47682 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47683 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47684 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47685 struct phy_device *phydev = pdata->phydev;
47686 int new_state = 0;
47687
47688 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47689 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47690 {
47691 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47692 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47693 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47694 unsigned long flags;
47695
47696 DBGPR("-->xgbe_powerdown\n");
47697 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47698 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47699 {
47700 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47701 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47702 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47703 unsigned long flags;
47704
47705 DBGPR("-->xgbe_powerup\n");
47706 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47707
47708 static int xgbe_start(struct xgbe_prv_data *pdata)
47709 {
47710 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47711 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47712 struct net_device *netdev = pdata->netdev;
47713
47714 DBGPR("-->xgbe_start\n");
47715 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47716
47717 static void xgbe_stop(struct xgbe_prv_data *pdata)
47718 {
47719 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47720 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47721 struct net_device *netdev = pdata->netdev;
47722
47723 DBGPR("-->xgbe_stop\n");
47724 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47725
47726 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47727 {
47728 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47729 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47730
47731 DBGPR("-->xgbe_restart_dev\n");
47732
47733 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47734 return -ERANGE;
47735 }
47736
47737 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47738 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47739
47740 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47741
47742 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47743 static int xgbe_open(struct net_device *netdev)
47744 {
47745 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47746 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47747 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47748 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47749 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47750 int ret;
47751
47752 DBGPR("-->xgbe_open\n");
47753 @@ -1170,8 +1170,8 @@ err_phy_init:
47754 static int xgbe_close(struct net_device *netdev)
47755 {
47756 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47757 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47758 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47759 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47760 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47761
47762 DBGPR("-->xgbe_close\n");
47763
47764 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47765 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47766 {
47767 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47768 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47769 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47770 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47771 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47772 struct xgbe_channel *channel;
47773 struct xgbe_ring *ring;
47774 struct xgbe_packet_data *packet;
47775 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47776 static void xgbe_set_rx_mode(struct net_device *netdev)
47777 {
47778 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47779 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47780 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47781 unsigned int pr_mode, am_mode;
47782
47783 DBGPR("-->xgbe_set_rx_mode\n");
47784 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47785 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47786 {
47787 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47788 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47789 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47790 struct sockaddr *saddr = addr;
47791
47792 DBGPR("-->xgbe_set_mac_address\n");
47793 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47794
47795 DBGPR("-->%s\n", __func__);
47796
47797 - pdata->hw_if.read_mmc_stats(pdata);
47798 + pdata->hw_if->read_mmc_stats(pdata);
47799
47800 s->rx_packets = pstats->rxframecount_gb;
47801 s->rx_bytes = pstats->rxoctetcount_gb;
47802 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47803 u16 vid)
47804 {
47805 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47806 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47807 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47808
47809 DBGPR("-->%s\n", __func__);
47810
47811 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47812 u16 vid)
47813 {
47814 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47815 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47816 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47817
47818 DBGPR("-->%s\n", __func__);
47819
47820 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47821 netdev_features_t features)
47822 {
47823 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47824 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47825 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47826 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47827
47828 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47829 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47830 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47831 {
47832 struct xgbe_prv_data *pdata = channel->pdata;
47833 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47834 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47835 struct xgbe_ring *ring = channel->rx_ring;
47836 struct xgbe_ring_data *rdata;
47837
47838 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47839 static int xgbe_tx_poll(struct xgbe_channel *channel)
47840 {
47841 struct xgbe_prv_data *pdata = channel->pdata;
47842 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47843 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47844 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47845 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47846 struct xgbe_ring *ring = channel->tx_ring;
47847 struct xgbe_ring_data *rdata;
47848 struct xgbe_ring_desc *rdesc;
47849 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47850 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47851 {
47852 struct xgbe_prv_data *pdata = channel->pdata;
47853 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47854 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47855 struct xgbe_ring *ring = channel->rx_ring;
47856 struct xgbe_ring_data *rdata;
47857 struct xgbe_packet_data *packet;
47858 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47859 index 49508ec..2617cca 100644
47860 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47861 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47862 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47863
47864 DBGPR("-->%s\n", __func__);
47865
47866 - pdata->hw_if.read_mmc_stats(pdata);
47867 + pdata->hw_if->read_mmc_stats(pdata);
47868 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47869 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47870 *data++ = *(u64 *)stat;
47871 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47872 struct ethtool_coalesce *ec)
47873 {
47874 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47875 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47876 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47877 unsigned int riwt;
47878
47879 DBGPR("-->xgbe_get_coalesce\n");
47880 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47881 struct ethtool_coalesce *ec)
47882 {
47883 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47884 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47885 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47886 unsigned int rx_frames, rx_riwt, rx_usecs;
47887 unsigned int tx_frames, tx_usecs;
47888
47889 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47890 index f5a8fa0..0bb58ff 100644
47891 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47892 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47893 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47894 DBGPR("<--xgbe_default_config\n");
47895 }
47896
47897 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47898 -{
47899 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47900 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47901 -}
47902 -
47903 static int xgbe_probe(struct platform_device *pdev)
47904 {
47905 struct xgbe_prv_data *pdata;
47906 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47907 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47908
47909 /* Set all the function pointers */
47910 - xgbe_init_all_fptrs(pdata);
47911 - hw_if = &pdata->hw_if;
47912 - desc_if = &pdata->desc_if;
47913 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47914 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47915
47916 /* Issue software reset to device */
47917 hw_if->exit(pdata);
47918 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47919 index 363b210..b241389 100644
47920 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47921 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47922 @@ -126,7 +126,7 @@
47923 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47924 {
47925 struct xgbe_prv_data *pdata = mii->priv;
47926 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47927 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47928 int mmd_data;
47929
47930 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47931 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47932 u16 mmd_val)
47933 {
47934 struct xgbe_prv_data *pdata = mii->priv;
47935 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47936 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47937 int mmd_data = mmd_val;
47938
47939 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47940 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47941 index a1bf9d1c..84adcab 100644
47942 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47943 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47944 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47945 tstamp_cc);
47946 u64 nsec;
47947
47948 - nsec = pdata->hw_if.get_tstamp_time(pdata);
47949 + nsec = pdata->hw_if->get_tstamp_time(pdata);
47950
47951 return nsec;
47952 }
47953 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47954
47955 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47956
47957 - pdata->hw_if.update_tstamp_addend(pdata, addend);
47958 + pdata->hw_if->update_tstamp_addend(pdata, addend);
47959
47960 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47961
47962 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47963 index 789957d..d7d0245 100644
47964 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47965 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47966 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
47967
47968 int irq_number;
47969
47970 - struct xgbe_hw_if hw_if;
47971 - struct xgbe_desc_if desc_if;
47972 + const struct xgbe_hw_if *hw_if;
47973 + const struct xgbe_desc_if *desc_if;
47974
47975 /* AXI DMA settings */
47976 unsigned int axdomain;
47977 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
47978 #endif
47979 };
47980
47981 +extern const struct xgbe_hw_if default_xgbe_hw_if;
47982 +extern const struct xgbe_desc_if default_xgbe_desc_if;
47983 +
47984 /* Function prototypes*/
47985
47986 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47987 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47988 index adcacda..fa6e0ae 100644
47989 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47990 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47991 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47992 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47993 {
47994 /* RX_MODE controlling object */
47995 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47996 + bnx2x_init_rx_mode_obj(bp);
47997
47998 /* multicast configuration controlling object */
47999 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48000 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48001 index 7bc2924..2112002 100644
48002 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48003 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48004 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48005 return rc;
48006 }
48007
48008 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48009 - struct bnx2x_rx_mode_obj *o)
48010 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48011 {
48012 if (CHIP_IS_E1x(bp)) {
48013 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48014 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48015 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48016 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48017 } else {
48018 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48019 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48020 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48021 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48022 }
48023 }
48024
48025 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48026 index e97275f..52e28bc 100644
48027 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48028 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48029 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48030
48031 /********************* RX MODE ****************/
48032
48033 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48034 - struct bnx2x_rx_mode_obj *o);
48035 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48036
48037 /**
48038 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48039 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48040 index 31c9f82..e65e986 100644
48041 --- a/drivers/net/ethernet/broadcom/tg3.h
48042 +++ b/drivers/net/ethernet/broadcom/tg3.h
48043 @@ -150,6 +150,7 @@
48044 #define CHIPREV_ID_5750_A0 0x4000
48045 #define CHIPREV_ID_5750_A1 0x4001
48046 #define CHIPREV_ID_5750_A3 0x4003
48047 +#define CHIPREV_ID_5750_C1 0x4201
48048 #define CHIPREV_ID_5750_C2 0x4202
48049 #define CHIPREV_ID_5752_A0_HW 0x5000
48050 #define CHIPREV_ID_5752_A0 0x6000
48051 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48052 index 903466e..b285864 100644
48053 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48054 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48055 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48056 }
48057
48058 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48059 - bna_cb_ioceth_enable,
48060 - bna_cb_ioceth_disable,
48061 - bna_cb_ioceth_hbfail,
48062 - bna_cb_ioceth_reset
48063 + .enable_cbfn = bna_cb_ioceth_enable,
48064 + .disable_cbfn = bna_cb_ioceth_disable,
48065 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48066 + .reset_cbfn = bna_cb_ioceth_reset
48067 };
48068
48069 static void bna_attr_init(struct bna_ioceth *ioceth)
48070 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48071 index 8cffcdf..aadf043 100644
48072 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48073 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48074 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48075 */
48076 struct l2t_skb_cb {
48077 arp_failure_handler_func arp_failure_handler;
48078 -};
48079 +} __no_const;
48080
48081 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48082
48083 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48084 index 279873c..11e1921 100644
48085 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48086 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48087 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48088
48089 int i;
48090 struct adapter *ap = netdev2adap(dev);
48091 - static const unsigned int *reg_ranges;
48092 + const unsigned int *reg_ranges;
48093 int arr_size = 0, buf_size = 0;
48094
48095 if (is_t4(ap->params.chip)) {
48096 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48097 index cf8b6ff..274271e 100644
48098 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48099 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48100 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48101 for (i=0; i<ETH_ALEN; i++) {
48102 tmp.addr[i] = dev->dev_addr[i];
48103 }
48104 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48105 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48106 break;
48107
48108 case DE4X5_SET_HWADDR: /* Set the hardware address */
48109 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48110 spin_lock_irqsave(&lp->lock, flags);
48111 memcpy(&statbuf, &lp->pktStats, ioc->len);
48112 spin_unlock_irqrestore(&lp->lock, flags);
48113 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48114 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48115 return -EFAULT;
48116 break;
48117 }
48118 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48119 index d2975fa..8aaec07 100644
48120 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48121 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48122 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48123
48124 if (wrapped)
48125 newacc += 65536;
48126 - ACCESS_ONCE(*acc) = newacc;
48127 + ACCESS_ONCE_RW(*acc) = newacc;
48128 }
48129
48130 static void populate_erx_stats(struct be_adapter *adapter,
48131 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48132 index c77fa4a..7fd42fc 100644
48133 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48134 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48135 @@ -30,6 +30,8 @@
48136 #include <linux/netdevice.h>
48137 #include <linux/phy.h>
48138 #include <linux/platform_device.h>
48139 +#include <linux/interrupt.h>
48140 +#include <linux/irqreturn.h>
48141 #include <net/ip.h>
48142
48143 #include "ftgmac100.h"
48144 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48145 index 4ff1adc..0ea6bf4 100644
48146 --- a/drivers/net/ethernet/faraday/ftmac100.c
48147 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48148 @@ -31,6 +31,8 @@
48149 #include <linux/module.h>
48150 #include <linux/netdevice.h>
48151 #include <linux/platform_device.h>
48152 +#include <linux/interrupt.h>
48153 +#include <linux/irqreturn.h>
48154
48155 #include "ftmac100.h"
48156
48157 diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48158 index 76d7070..f6971182 100644
48159 --- a/drivers/net/ethernet/freescale/gianfar_ethtool.c
48160 +++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48161 @@ -1581,7 +1581,7 @@ static int gfar_write_filer_table(struct gfar_private *priv,
48162 return -EBUSY;
48163
48164 /* Fill regular entries */
48165 - for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
48166 + for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].prop);
48167 i++)
48168 gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
48169 /* Fill the rest with fall-troughs */
48170 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48171 index 537b621..07f87ce 100644
48172 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48173 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48174 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48175 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48176
48177 /* Update the base adjustement value. */
48178 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48179 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48180 smp_mb(); /* Force the above update. */
48181 }
48182
48183 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48184 index 5fd4b52..87aa34b 100644
48185 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48186 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48187 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48188 }
48189
48190 /* update the base incval used to calculate frequency adjustment */
48191 - ACCESS_ONCE(adapter->base_incval) = incval;
48192 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48193 smp_mb();
48194
48195 /* need lock to prevent incorrect read while modifying cyclecounter */
48196 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48197 index 11ff28b..375d659 100644
48198 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48199 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48200 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48201 wmb();
48202
48203 /* we want to dirty this cache line once */
48204 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48205 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48206 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48207 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48208
48209 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48210
48211 diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48212 index de10dbb..8b54f29 100644
48213 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48214 +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48215 @@ -233,7 +233,8 @@ do { \
48216 extern int mlx4_log_num_mgm_entry_size;
48217 extern int log_mtts_per_seg;
48218
48219 -#define MLX4_MAX_NUM_SLAVES (MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF)
48220 +#define MLX4_MAX_NUM_SLAVES (min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
48221 + MLX4_MFUNC_MAX))
48222 #define ALL_SLAVES 0xff
48223
48224 struct mlx4_bitmap {
48225 diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
48226 index f5e4b82..db0c7a9 100644
48227 --- a/drivers/net/ethernet/neterion/s2io.c
48228 +++ b/drivers/net/ethernet/neterion/s2io.c
48229 @@ -6987,7 +6987,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48230 if (sp->s2io_entries[i].in_use == MSIX_FLG) {
48231 if (sp->s2io_entries[i].type ==
48232 MSIX_RING_TYPE) {
48233 - sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
48234 + snprintf(sp->desc[i],
48235 + sizeof(sp->desc[i]),
48236 + "%s:MSI-X-%d-RX",
48237 dev->name, i);
48238 err = request_irq(sp->entries[i].vector,
48239 s2io_msix_ring_handle,
48240 @@ -6996,7 +6998,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48241 sp->s2io_entries[i].arg);
48242 } else if (sp->s2io_entries[i].type ==
48243 MSIX_ALARM_TYPE) {
48244 - sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
48245 + snprintf(sp->desc[i],
48246 + sizeof(sp->desc[i]),
48247 + "%s:MSI-X-%d-TX",
48248 dev->name, i);
48249 err = request_irq(sp->entries[i].vector,
48250 s2io_msix_fifo_handle,
48251 @@ -8154,7 +8158,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
48252 "%s: UDP Fragmentation Offload(UFO) enabled\n",
48253 dev->name);
48254 /* Initialize device name */
48255 - sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
48256 + snprintf(sp->name, sizeof(sp->name), "%s Neterion %s", dev->name,
48257 + sp->product_name);
48258
48259 if (vlan_tag_strip)
48260 sp->vlan_strip_flag = 1;
48261 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48262 index 2bbd01f..e8baa64 100644
48263 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48264 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48265 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48266 struct __vxge_hw_fifo *fifo;
48267 struct vxge_hw_fifo_config *config;
48268 u32 txdl_size, txdl_per_memblock;
48269 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48270 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48271 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48272 + };
48273 +
48274 struct __vxge_hw_virtualpath *vpath;
48275
48276 if ((vp == NULL) || (attr == NULL)) {
48277 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48278 goto exit;
48279 }
48280
48281 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48282 -
48283 fifo->mempool =
48284 __vxge_hw_mempool_create(vpath->hldev,
48285 fifo->config->memblock_size,
48286 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48287 index 2bb48d5..d1a865d 100644
48288 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48289 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48290 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48291 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48292 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48293 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48294 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48295 + pax_open_kernel();
48296 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48297 + pax_close_kernel();
48298 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48299 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48300 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48301 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48302 index be7d7a6..a8983f8 100644
48303 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48304 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48305 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48306 case QLCNIC_NON_PRIV_FUNC:
48307 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48308 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48309 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48310 + pax_open_kernel();
48311 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48312 + pax_close_kernel();
48313 break;
48314 case QLCNIC_PRIV_FUNC:
48315 ahw->op_mode = QLCNIC_PRIV_FUNC;
48316 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48317 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48318 + pax_open_kernel();
48319 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48320 + pax_close_kernel();
48321 break;
48322 case QLCNIC_MGMT_FUNC:
48323 ahw->op_mode = QLCNIC_MGMT_FUNC;
48324 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48325 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48326 + pax_open_kernel();
48327 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48328 + pax_close_kernel();
48329 break;
48330 default:
48331 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48332 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48333 index c9f57fb..208bdc1 100644
48334 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48335 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48336 @@ -1285,7 +1285,7 @@ flash_temp:
48337 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48338 {
48339 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48340 - static const struct qlcnic_dump_operations *fw_dump_ops;
48341 + const struct qlcnic_dump_operations *fw_dump_ops;
48342 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48343 u32 entry_offset, dump, no_entries, buf_offset = 0;
48344 int i, k, ops_cnt, ops_index, dump_size = 0;
48345 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48346 index cf154f7..c948d1b 100644
48347 --- a/drivers/net/ethernet/realtek/r8169.c
48348 +++ b/drivers/net/ethernet/realtek/r8169.c
48349 @@ -788,22 +788,22 @@ struct rtl8169_private {
48350 struct mdio_ops {
48351 void (*write)(struct rtl8169_private *, int, int);
48352 int (*read)(struct rtl8169_private *, int);
48353 - } mdio_ops;
48354 + } __no_const mdio_ops;
48355
48356 struct pll_power_ops {
48357 void (*down)(struct rtl8169_private *);
48358 void (*up)(struct rtl8169_private *);
48359 - } pll_power_ops;
48360 + } __no_const pll_power_ops;
48361
48362 struct jumbo_ops {
48363 void (*enable)(struct rtl8169_private *);
48364 void (*disable)(struct rtl8169_private *);
48365 - } jumbo_ops;
48366 + } __no_const jumbo_ops;
48367
48368 struct csi_ops {
48369 void (*write)(struct rtl8169_private *, int, int);
48370 u32 (*read)(struct rtl8169_private *, int);
48371 - } csi_ops;
48372 + } __no_const csi_ops;
48373
48374 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48375 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48376 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48377 index 6b861e3..204ac86 100644
48378 --- a/drivers/net/ethernet/sfc/ptp.c
48379 +++ b/drivers/net/ethernet/sfc/ptp.c
48380 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48381 ptp->start.dma_addr);
48382
48383 /* Clear flag that signals MC ready */
48384 - ACCESS_ONCE(*start) = 0;
48385 + ACCESS_ONCE_RW(*start) = 0;
48386 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48387 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48388 EFX_BUG_ON_PARANOID(rc);
48389 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48390 index 08c483b..2c4a553 100644
48391 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48392 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48393 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48394
48395 writel(value, ioaddr + MMC_CNTRL);
48396
48397 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48398 - MMC_CNTRL, value);
48399 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48400 +// MMC_CNTRL, value);
48401 }
48402
48403 /* To mask all all interrupts.*/
48404 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48405 index 2f48f79..8ae1a1a 100644
48406 --- a/drivers/net/hyperv/hyperv_net.h
48407 +++ b/drivers/net/hyperv/hyperv_net.h
48408 @@ -171,7 +171,7 @@ struct rndis_device {
48409 enum rndis_device_state state;
48410 bool link_state;
48411 bool link_change;
48412 - atomic_t new_req_id;
48413 + atomic_unchecked_t new_req_id;
48414
48415 spinlock_t request_lock;
48416 struct list_head req_list;
48417 diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
48418 index 7d76c95..63d7a64 100644
48419 --- a/drivers/net/hyperv/netvsc.c
48420 +++ b/drivers/net/hyperv/netvsc.c
48421 @@ -716,7 +716,7 @@ int netvsc_send(struct hv_device *device,
48422 u64 req_id;
48423 unsigned int section_index = NETVSC_INVALID_INDEX;
48424 u32 msg_size = 0;
48425 - struct sk_buff *skb;
48426 + struct sk_buff *skb = NULL;
48427 u16 q_idx = packet->q_idx;
48428
48429
48430 @@ -743,8 +743,6 @@ int netvsc_send(struct hv_device *device,
48431 packet);
48432 skb = (struct sk_buff *)
48433 (unsigned long)packet->send_completion_tid;
48434 - if (skb)
48435 - dev_kfree_skb_any(skb);
48436 packet->page_buf_cnt = 0;
48437 }
48438 }
48439 @@ -807,6 +805,13 @@ int netvsc_send(struct hv_device *device,
48440 packet, ret);
48441 }
48442
48443 + if (ret != 0) {
48444 + if (section_index != NETVSC_INVALID_INDEX)
48445 + netvsc_free_send_slot(net_device, section_index);
48446 + } else if (skb) {
48447 + dev_kfree_skb_any(skb);
48448 + }
48449 +
48450 return ret;
48451 }
48452
48453 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48454 index 2b86f0b..ecc996f 100644
48455 --- a/drivers/net/hyperv/rndis_filter.c
48456 +++ b/drivers/net/hyperv/rndis_filter.c
48457 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48458 * template
48459 */
48460 set = &rndis_msg->msg.set_req;
48461 - set->req_id = atomic_inc_return(&dev->new_req_id);
48462 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48463
48464 /* Add to the request list */
48465 spin_lock_irqsave(&dev->request_lock, flags);
48466 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48467
48468 /* Setup the rndis set */
48469 halt = &request->request_msg.msg.halt_req;
48470 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48471 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48472
48473 /* Ignore return since this msg is optional. */
48474 rndis_filter_send_request(dev, request);
48475 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48476 index 6cbc56a..5f7e6c8 100644
48477 --- a/drivers/net/ieee802154/fakehard.c
48478 +++ b/drivers/net/ieee802154/fakehard.c
48479 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48480 phy->transmit_power = 0xbf;
48481
48482 dev->netdev_ops = &fake_ops;
48483 - dev->ml_priv = &fake_mlme;
48484 + dev->ml_priv = (void *)&fake_mlme;
48485
48486 priv = netdev_priv(dev);
48487 priv->phy = phy;
48488 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48489 index 34f846b..4a0d5b1 100644
48490 --- a/drivers/net/ifb.c
48491 +++ b/drivers/net/ifb.c
48492 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48493 return 0;
48494 }
48495
48496 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48497 +static struct rtnl_link_ops ifb_link_ops = {
48498 .kind = "ifb",
48499 .priv_size = sizeof(struct ifb_private),
48500 .setup = ifb_setup,
48501 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48502 index bfb0b6e..5c396ce 100644
48503 --- a/drivers/net/macvlan.c
48504 +++ b/drivers/net/macvlan.c
48505 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48506 free_nskb:
48507 kfree_skb(nskb);
48508 err:
48509 - atomic_long_inc(&skb->dev->rx_dropped);
48510 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48511 }
48512
48513 static void macvlan_flush_sources(struct macvlan_port *port,
48514 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48515 int macvlan_link_register(struct rtnl_link_ops *ops)
48516 {
48517 /* common fields */
48518 - ops->priv_size = sizeof(struct macvlan_dev);
48519 - ops->validate = macvlan_validate;
48520 - ops->maxtype = IFLA_MACVLAN_MAX;
48521 - ops->policy = macvlan_policy;
48522 - ops->changelink = macvlan_changelink;
48523 - ops->get_size = macvlan_get_size;
48524 - ops->fill_info = macvlan_fill_info;
48525 + pax_open_kernel();
48526 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48527 + *(void **)&ops->validate = macvlan_validate;
48528 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48529 + *(const void **)&ops->policy = macvlan_policy;
48530 + *(void **)&ops->changelink = macvlan_changelink;
48531 + *(void **)&ops->get_size = macvlan_get_size;
48532 + *(void **)&ops->fill_info = macvlan_fill_info;
48533 + pax_close_kernel();
48534
48535 return rtnl_link_register(ops);
48536 };
48537 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48538 return NOTIFY_DONE;
48539 }
48540
48541 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48542 +static struct notifier_block macvlan_notifier_block = {
48543 .notifier_call = macvlan_device_event,
48544 };
48545
48546 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48547 index 880cc09..6a68ba6 100644
48548 --- a/drivers/net/macvtap.c
48549 +++ b/drivers/net/macvtap.c
48550 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48551 dev->tx_queue_len = TUN_READQ_SIZE;
48552 }
48553
48554 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48555 +static struct rtnl_link_ops macvtap_link_ops = {
48556 .kind = "macvtap",
48557 .setup = macvtap_setup,
48558 .newlink = macvtap_newlink,
48559 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48560 }
48561
48562 ret = 0;
48563 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48564 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48565 put_user(q->flags, &ifr->ifr_flags))
48566 ret = -EFAULT;
48567 macvtap_put_vlan(vlan);
48568 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48569 return NOTIFY_DONE;
48570 }
48571
48572 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48573 +static struct notifier_block macvtap_notifier_block = {
48574 .notifier_call = macvtap_device_event,
48575 };
48576
48577 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48578 index 34924df..a747360 100644
48579 --- a/drivers/net/nlmon.c
48580 +++ b/drivers/net/nlmon.c
48581 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48582 return 0;
48583 }
48584
48585 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48586 +static struct rtnl_link_ops nlmon_link_ops = {
48587 .kind = "nlmon",
48588 .priv_size = sizeof(struct nlmon),
48589 .setup = nlmon_setup,
48590 diff --git a/drivers/net/ppp/ppp_deflate.c b/drivers/net/ppp/ppp_deflate.c
48591 index 602c625..b5edc7f 100644
48592 --- a/drivers/net/ppp/ppp_deflate.c
48593 +++ b/drivers/net/ppp/ppp_deflate.c
48594 @@ -246,7 +246,7 @@ static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
48595 /*
48596 * See if we managed to reduce the size of the packet.
48597 */
48598 - if (olen < isize) {
48599 + if (olen < isize && olen <= osize) {
48600 state->stats.comp_bytes += olen;
48601 state->stats.comp_packets++;
48602 } else {
48603 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48604 index 794a473..9fd437b 100644
48605 --- a/drivers/net/ppp/ppp_generic.c
48606 +++ b/drivers/net/ppp/ppp_generic.c
48607 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48608 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48609 struct ppp_stats stats;
48610 struct ppp_comp_stats cstats;
48611 - char *vers;
48612
48613 switch (cmd) {
48614 case SIOCGPPPSTATS:
48615 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48616 break;
48617
48618 case SIOCGPPPVER:
48619 - vers = PPP_VERSION;
48620 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48621 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48622 break;
48623 err = 0;
48624 break;
48625 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48626 index 079f7ad..b2a2bfa7 100644
48627 --- a/drivers/net/slip/slhc.c
48628 +++ b/drivers/net/slip/slhc.c
48629 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48630 register struct tcphdr *thp;
48631 register struct iphdr *ip;
48632 register struct cstate *cs;
48633 - int len, hdrlen;
48634 + long len, hdrlen;
48635 unsigned char *cp = icp;
48636
48637 /* We've got a compressed packet; read the change byte */
48638 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48639 index 9c505c4..5d0c879 100644
48640 --- a/drivers/net/team/team.c
48641 +++ b/drivers/net/team/team.c
48642 @@ -2102,7 +2102,7 @@ static unsigned int team_get_num_rx_queues(void)
48643 return TEAM_DEFAULT_NUM_RX_QUEUES;
48644 }
48645
48646 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48647 +static struct rtnl_link_ops team_link_ops = {
48648 .kind = DRV_NAME,
48649 .priv_size = sizeof(struct team),
48650 .setup = team_setup,
48651 @@ -2892,7 +2892,7 @@ static int team_device_event(struct notifier_block *unused,
48652 return NOTIFY_DONE;
48653 }
48654
48655 -static struct notifier_block team_notifier_block __read_mostly = {
48656 +static struct notifier_block team_notifier_block = {
48657 .notifier_call = team_device_event,
48658 };
48659
48660 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48661 index 9dd3746..74f191e 100644
48662 --- a/drivers/net/tun.c
48663 +++ b/drivers/net/tun.c
48664 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48665 return -EINVAL;
48666 }
48667
48668 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48669 +static struct rtnl_link_ops tun_link_ops = {
48670 .kind = DRV_NAME,
48671 .priv_size = sizeof(struct tun_struct),
48672 .setup = tun_setup,
48673 @@ -1868,7 +1868,7 @@ unlock:
48674 }
48675
48676 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48677 - unsigned long arg, int ifreq_len)
48678 + unsigned long arg, size_t ifreq_len)
48679 {
48680 struct tun_file *tfile = file->private_data;
48681 struct tun_struct *tun;
48682 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48683 unsigned int ifindex;
48684 int ret;
48685
48686 + if (ifreq_len > sizeof ifr)
48687 + return -EFAULT;
48688 +
48689 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48690 if (copy_from_user(&ifr, argp, ifreq_len))
48691 return -EFAULT;
48692 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48693 index babda7d..e40c90a 100644
48694 --- a/drivers/net/usb/hso.c
48695 +++ b/drivers/net/usb/hso.c
48696 @@ -71,7 +71,7 @@
48697 #include <asm/byteorder.h>
48698 #include <linux/serial_core.h>
48699 #include <linux/serial.h>
48700 -
48701 +#include <asm/local.h>
48702
48703 #define MOD_AUTHOR "Option Wireless"
48704 #define MOD_DESCRIPTION "USB High Speed Option driver"
48705 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48706 struct urb *urb;
48707
48708 urb = serial->rx_urb[0];
48709 - if (serial->port.count > 0) {
48710 + if (atomic_read(&serial->port.count) > 0) {
48711 count = put_rxbuf_data(urb, serial);
48712 if (count == -1)
48713 return;
48714 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48715 DUMP1(urb->transfer_buffer, urb->actual_length);
48716
48717 /* Anyone listening? */
48718 - if (serial->port.count == 0)
48719 + if (atomic_read(&serial->port.count) == 0)
48720 return;
48721
48722 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48723 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48724 tty_port_tty_set(&serial->port, tty);
48725
48726 /* check for port already opened, if not set the termios */
48727 - serial->port.count++;
48728 - if (serial->port.count == 1) {
48729 + if (atomic_inc_return(&serial->port.count) == 1) {
48730 serial->rx_state = RX_IDLE;
48731 /* Force default termio settings */
48732 _hso_serial_set_termios(tty, NULL);
48733 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48734 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48735 if (result) {
48736 hso_stop_serial_device(serial->parent);
48737 - serial->port.count--;
48738 + atomic_dec(&serial->port.count);
48739 kref_put(&serial->parent->ref, hso_serial_ref_free);
48740 }
48741 } else {
48742 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48743
48744 /* reset the rts and dtr */
48745 /* do the actual close */
48746 - serial->port.count--;
48747 + atomic_dec(&serial->port.count);
48748
48749 - if (serial->port.count <= 0) {
48750 - serial->port.count = 0;
48751 + if (atomic_read(&serial->port.count) <= 0) {
48752 + atomic_set(&serial->port.count, 0);
48753 tty_port_tty_set(&serial->port, NULL);
48754 if (!usb_gone)
48755 hso_stop_serial_device(serial->parent);
48756 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48757
48758 /* the actual setup */
48759 spin_lock_irqsave(&serial->serial_lock, flags);
48760 - if (serial->port.count)
48761 + if (atomic_read(&serial->port.count))
48762 _hso_serial_set_termios(tty, old);
48763 else
48764 tty->termios = *old;
48765 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48766 D1("Pending read interrupt on port %d\n", i);
48767 spin_lock(&serial->serial_lock);
48768 if (serial->rx_state == RX_IDLE &&
48769 - serial->port.count > 0) {
48770 + atomic_read(&serial->port.count) > 0) {
48771 /* Setup and send a ctrl req read on
48772 * port i */
48773 if (!serial->rx_urb_filled[0]) {
48774 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48775 /* Start all serial ports */
48776 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48777 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48778 - if (dev2ser(serial_table[i])->port.count) {
48779 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48780 result =
48781 hso_start_serial_device(serial_table[i], GFP_NOIO);
48782 hso_kick_transmit(dev2ser(serial_table[i]));
48783 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48784 index c6554c7..7e2ebd7 100644
48785 --- a/drivers/net/usb/r8152.c
48786 +++ b/drivers/net/usb/r8152.c
48787 @@ -577,7 +577,7 @@ struct r8152 {
48788 void (*unload)(struct r8152 *);
48789 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48790 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48791 - } rtl_ops;
48792 + } __no_const rtl_ops;
48793
48794 int intr_interval;
48795 u32 saved_wolopts;
48796 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48797 index a2515887..6d13233 100644
48798 --- a/drivers/net/usb/sierra_net.c
48799 +++ b/drivers/net/usb/sierra_net.c
48800 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48801 /* atomic counter partially included in MAC address to make sure 2 devices
48802 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48803 */
48804 -static atomic_t iface_counter = ATOMIC_INIT(0);
48805 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48806
48807 /*
48808 * SYNC Timer Delay definition used to set the expiry time
48809 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48810 dev->net->netdev_ops = &sierra_net_device_ops;
48811
48812 /* change MAC addr to include, ifacenum, and to be unique */
48813 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48814 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48815 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48816
48817 /* we will have to manufacture ethernet headers, prepare template */
48818 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48819 index b0bc8ea..3af931b5 100644
48820 --- a/drivers/net/virtio_net.c
48821 +++ b/drivers/net/virtio_net.c
48822 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48823 #define RECEIVE_AVG_WEIGHT 64
48824
48825 /* Minimum alignment for mergeable packet buffers. */
48826 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48827 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48828
48829 #define VIRTNET_DRIVER_VERSION "1.0.0"
48830
48831 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48832 index 42b2d6a5..2a2cb41 100644
48833 --- a/drivers/net/vxlan.c
48834 +++ b/drivers/net/vxlan.c
48835 @@ -2695,7 +2695,7 @@ nla_put_failure:
48836 return -EMSGSIZE;
48837 }
48838
48839 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48840 +static struct rtnl_link_ops vxlan_link_ops = {
48841 .kind = "vxlan",
48842 .maxtype = IFLA_VXLAN_MAX,
48843 .policy = vxlan_policy,
48844 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48845 return NOTIFY_DONE;
48846 }
48847
48848 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48849 +static struct notifier_block vxlan_notifier_block = {
48850 .notifier_call = vxlan_lowerdev_event,
48851 };
48852
48853 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48854 index 5920c99..ff2e4a5 100644
48855 --- a/drivers/net/wan/lmc/lmc_media.c
48856 +++ b/drivers/net/wan/lmc/lmc_media.c
48857 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48858 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48859
48860 lmc_media_t lmc_ds3_media = {
48861 - lmc_ds3_init, /* special media init stuff */
48862 - lmc_ds3_default, /* reset to default state */
48863 - lmc_ds3_set_status, /* reset status to state provided */
48864 - lmc_dummy_set_1, /* set clock source */
48865 - lmc_dummy_set2_1, /* set line speed */
48866 - lmc_ds3_set_100ft, /* set cable length */
48867 - lmc_ds3_set_scram, /* set scrambler */
48868 - lmc_ds3_get_link_status, /* get link status */
48869 - lmc_dummy_set_1, /* set link status */
48870 - lmc_ds3_set_crc_length, /* set CRC length */
48871 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48872 - lmc_ds3_watchdog
48873 + .init = lmc_ds3_init, /* special media init stuff */
48874 + .defaults = lmc_ds3_default, /* reset to default state */
48875 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48876 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48877 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48878 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48879 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48880 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48881 + .set_link_status = lmc_dummy_set_1, /* set link status */
48882 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48883 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48884 + .watchdog = lmc_ds3_watchdog
48885 };
48886
48887 lmc_media_t lmc_hssi_media = {
48888 - lmc_hssi_init, /* special media init stuff */
48889 - lmc_hssi_default, /* reset to default state */
48890 - lmc_hssi_set_status, /* reset status to state provided */
48891 - lmc_hssi_set_clock, /* set clock source */
48892 - lmc_dummy_set2_1, /* set line speed */
48893 - lmc_dummy_set_1, /* set cable length */
48894 - lmc_dummy_set_1, /* set scrambler */
48895 - lmc_hssi_get_link_status, /* get link status */
48896 - lmc_hssi_set_link_status, /* set link status */
48897 - lmc_hssi_set_crc_length, /* set CRC length */
48898 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48899 - lmc_hssi_watchdog
48900 + .init = lmc_hssi_init, /* special media init stuff */
48901 + .defaults = lmc_hssi_default, /* reset to default state */
48902 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48903 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48904 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48905 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48906 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48907 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48908 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48909 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48910 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48911 + .watchdog = lmc_hssi_watchdog
48912 };
48913
48914 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48915 - lmc_ssi_default, /* reset to default state */
48916 - lmc_ssi_set_status, /* reset status to state provided */
48917 - lmc_ssi_set_clock, /* set clock source */
48918 - lmc_ssi_set_speed, /* set line speed */
48919 - lmc_dummy_set_1, /* set cable length */
48920 - lmc_dummy_set_1, /* set scrambler */
48921 - lmc_ssi_get_link_status, /* get link status */
48922 - lmc_ssi_set_link_status, /* set link status */
48923 - lmc_ssi_set_crc_length, /* set CRC length */
48924 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48925 - lmc_ssi_watchdog
48926 +lmc_media_t lmc_ssi_media = {
48927 + .init = lmc_ssi_init, /* special media init stuff */
48928 + .defaults = lmc_ssi_default, /* reset to default state */
48929 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48930 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48931 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48932 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48933 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48934 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48935 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48936 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48937 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48938 + .watchdog = lmc_ssi_watchdog
48939 };
48940
48941 lmc_media_t lmc_t1_media = {
48942 - lmc_t1_init, /* special media init stuff */
48943 - lmc_t1_default, /* reset to default state */
48944 - lmc_t1_set_status, /* reset status to state provided */
48945 - lmc_t1_set_clock, /* set clock source */
48946 - lmc_dummy_set2_1, /* set line speed */
48947 - lmc_dummy_set_1, /* set cable length */
48948 - lmc_dummy_set_1, /* set scrambler */
48949 - lmc_t1_get_link_status, /* get link status */
48950 - lmc_dummy_set_1, /* set link status */
48951 - lmc_t1_set_crc_length, /* set CRC length */
48952 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48953 - lmc_t1_watchdog
48954 + .init = lmc_t1_init, /* special media init stuff */
48955 + .defaults = lmc_t1_default, /* reset to default state */
48956 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48957 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48958 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48959 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48960 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48961 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48962 + .set_link_status = lmc_dummy_set_1, /* set link status */
48963 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48964 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48965 + .watchdog = lmc_t1_watchdog
48966 };
48967
48968 static void
48969 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48970 index feacc3b..5bac0de 100644
48971 --- a/drivers/net/wan/z85230.c
48972 +++ b/drivers/net/wan/z85230.c
48973 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48974
48975 struct z8530_irqhandler z8530_sync =
48976 {
48977 - z8530_rx,
48978 - z8530_tx,
48979 - z8530_status
48980 + .rx = z8530_rx,
48981 + .tx = z8530_tx,
48982 + .status = z8530_status
48983 };
48984
48985 EXPORT_SYMBOL(z8530_sync);
48986 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48987 }
48988
48989 static struct z8530_irqhandler z8530_dma_sync = {
48990 - z8530_dma_rx,
48991 - z8530_dma_tx,
48992 - z8530_dma_status
48993 + .rx = z8530_dma_rx,
48994 + .tx = z8530_dma_tx,
48995 + .status = z8530_dma_status
48996 };
48997
48998 static struct z8530_irqhandler z8530_txdma_sync = {
48999 - z8530_rx,
49000 - z8530_dma_tx,
49001 - z8530_dma_status
49002 + .rx = z8530_rx,
49003 + .tx = z8530_dma_tx,
49004 + .status = z8530_dma_status
49005 };
49006
49007 /**
49008 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49009
49010 struct z8530_irqhandler z8530_nop=
49011 {
49012 - z8530_rx_clear,
49013 - z8530_tx_clear,
49014 - z8530_status_clear
49015 + .rx = z8530_rx_clear,
49016 + .tx = z8530_tx_clear,
49017 + .status = z8530_status_clear
49018 };
49019
49020
49021 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49022 index 0b60295..b8bfa5b 100644
49023 --- a/drivers/net/wimax/i2400m/rx.c
49024 +++ b/drivers/net/wimax/i2400m/rx.c
49025 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49026 if (i2400m->rx_roq == NULL)
49027 goto error_roq_alloc;
49028
49029 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49030 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49031 GFP_KERNEL);
49032 if (rd == NULL) {
49033 result = -ENOMEM;
49034 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49035 index e71a2ce..2268d61 100644
49036 --- a/drivers/net/wireless/airo.c
49037 +++ b/drivers/net/wireless/airo.c
49038 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49039 struct airo_info *ai = dev->ml_priv;
49040 int ridcode;
49041 int enabled;
49042 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49043 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49044 unsigned char *iobuf;
49045
49046 /* Only super-user can write RIDs */
49047 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49048 index da92bfa..5a9001a 100644
49049 --- a/drivers/net/wireless/at76c50x-usb.c
49050 +++ b/drivers/net/wireless/at76c50x-usb.c
49051 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49052 }
49053
49054 /* Convert timeout from the DFU status to jiffies */
49055 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49056 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49057 {
49058 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49059 | (s->poll_timeout[1] << 8)
49060 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49061 index 676bd4e..0b807a3 100644
49062 --- a/drivers/net/wireless/ath/ath10k/htc.c
49063 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49064 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
49065 /* registered target arrival callback from the HIF layer */
49066 int ath10k_htc_init(struct ath10k *ar)
49067 {
49068 - struct ath10k_hif_cb htc_callbacks;
49069 + static struct ath10k_hif_cb htc_callbacks = {
49070 + .rx_completion = ath10k_htc_rx_completion_handler,
49071 + .tx_completion = ath10k_htc_tx_completion_handler,
49072 + };
49073 struct ath10k_htc_ep *ep = NULL;
49074 struct ath10k_htc *htc = &ar->htc;
49075
49076 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
49077 ath10k_htc_reset_endpoint_states(htc);
49078
49079 /* setup HIF layer callbacks */
49080 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49081 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49082 htc->ar = ar;
49083
49084 /* Get HIF default pipe for HTC message exchange */
49085 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49086 index 527179c..a890150 100644
49087 --- a/drivers/net/wireless/ath/ath10k/htc.h
49088 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49089 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
49090
49091 struct ath10k_htc_ops {
49092 void (*target_send_suspend_complete)(struct ath10k *ar);
49093 -};
49094 +} __no_const;
49095
49096 struct ath10k_htc_ep_ops {
49097 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49098 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49099 void (*ep_tx_credits)(struct ath10k *);
49100 -};
49101 +} __no_const;
49102
49103 /* service connection information */
49104 struct ath10k_htc_svc_conn_req {
49105 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49106 index 2a93519..7052786 100644
49107 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49108 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49109 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49110 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49111 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49112
49113 - ACCESS_ONCE(ads->ds_link) = i->link;
49114 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49115 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49116 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49117
49118 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49119 ctl6 = SM(i->keytype, AR_EncrType);
49120 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49121
49122 if ((i->is_first || i->is_last) &&
49123 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49124 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49125 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49126 | set11nTries(i->rates, 1)
49127 | set11nTries(i->rates, 2)
49128 | set11nTries(i->rates, 3)
49129 | (i->dur_update ? AR_DurUpdateEna : 0)
49130 | SM(0, AR_BurstDur);
49131
49132 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49133 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49134 | set11nRate(i->rates, 1)
49135 | set11nRate(i->rates, 2)
49136 | set11nRate(i->rates, 3);
49137 } else {
49138 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49139 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49140 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49141 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49142 }
49143
49144 if (!i->is_first) {
49145 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49146 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49147 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49148 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49149 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49150 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49151 return;
49152 }
49153
49154 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49155 break;
49156 }
49157
49158 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49159 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49160 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49161 | SM(i->txpower, AR_XmitPower0)
49162 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49163 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49164 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49165 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49166
49167 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49168 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49169 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49170 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49171
49172 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49173 return;
49174
49175 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49176 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49177 | set11nPktDurRTSCTS(i->rates, 1);
49178
49179 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49180 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49181 | set11nPktDurRTSCTS(i->rates, 3);
49182
49183 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49184 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49185 | set11nRateFlags(i->rates, 1)
49186 | set11nRateFlags(i->rates, 2)
49187 | set11nRateFlags(i->rates, 3)
49188 | SM(i->rtscts_rate, AR_RTSCTSRate);
49189
49190 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49191 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49192 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49193 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49194 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49195 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49196 }
49197
49198 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49199 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49200 index 057b165..98ae88f 100644
49201 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49202 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49203 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49204 (i->qcu << AR_TxQcuNum_S) | desc_len;
49205
49206 checksum += val;
49207 - ACCESS_ONCE(ads->info) = val;
49208 + ACCESS_ONCE_RW(ads->info) = val;
49209
49210 checksum += i->link;
49211 - ACCESS_ONCE(ads->link) = i->link;
49212 + ACCESS_ONCE_RW(ads->link) = i->link;
49213
49214 checksum += i->buf_addr[0];
49215 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49216 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49217 checksum += i->buf_addr[1];
49218 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49219 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49220 checksum += i->buf_addr[2];
49221 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49222 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49223 checksum += i->buf_addr[3];
49224 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49225 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49226
49227 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49228 - ACCESS_ONCE(ads->ctl3) = val;
49229 + ACCESS_ONCE_RW(ads->ctl3) = val;
49230 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49231 - ACCESS_ONCE(ads->ctl5) = val;
49232 + ACCESS_ONCE_RW(ads->ctl5) = val;
49233 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49234 - ACCESS_ONCE(ads->ctl7) = val;
49235 + ACCESS_ONCE_RW(ads->ctl7) = val;
49236 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49237 - ACCESS_ONCE(ads->ctl9) = val;
49238 + ACCESS_ONCE_RW(ads->ctl9) = val;
49239
49240 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49241 - ACCESS_ONCE(ads->ctl10) = checksum;
49242 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49243
49244 if (i->is_first || i->is_last) {
49245 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49246 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49247 | set11nTries(i->rates, 1)
49248 | set11nTries(i->rates, 2)
49249 | set11nTries(i->rates, 3)
49250 | (i->dur_update ? AR_DurUpdateEna : 0)
49251 | SM(0, AR_BurstDur);
49252
49253 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49254 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49255 | set11nRate(i->rates, 1)
49256 | set11nRate(i->rates, 2)
49257 | set11nRate(i->rates, 3);
49258 } else {
49259 - ACCESS_ONCE(ads->ctl13) = 0;
49260 - ACCESS_ONCE(ads->ctl14) = 0;
49261 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49262 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49263 }
49264
49265 ads->ctl20 = 0;
49266 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49267
49268 ctl17 = SM(i->keytype, AR_EncrType);
49269 if (!i->is_first) {
49270 - ACCESS_ONCE(ads->ctl11) = 0;
49271 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49272 - ACCESS_ONCE(ads->ctl15) = 0;
49273 - ACCESS_ONCE(ads->ctl16) = 0;
49274 - ACCESS_ONCE(ads->ctl17) = ctl17;
49275 - ACCESS_ONCE(ads->ctl18) = 0;
49276 - ACCESS_ONCE(ads->ctl19) = 0;
49277 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49278 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49279 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49280 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49281 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49282 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49283 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49284 return;
49285 }
49286
49287 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49288 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49289 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49290 | SM(i->txpower, AR_XmitPower0)
49291 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49292 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49293 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49294 ctl12 |= SM(val, AR_PAPRDChainMask);
49295
49296 - ACCESS_ONCE(ads->ctl12) = ctl12;
49297 - ACCESS_ONCE(ads->ctl17) = ctl17;
49298 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49299 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49300
49301 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49302 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49303 | set11nPktDurRTSCTS(i->rates, 1);
49304
49305 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49306 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49307 | set11nPktDurRTSCTS(i->rates, 3);
49308
49309 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49310 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49311 | set11nRateFlags(i->rates, 1)
49312 | set11nRateFlags(i->rates, 2)
49313 | set11nRateFlags(i->rates, 3)
49314 | SM(i->rtscts_rate, AR_RTSCTSRate);
49315
49316 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49317 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49318
49319 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49320 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49321 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49322 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49323 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49324 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49325 }
49326
49327 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49328 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49329 index e8e8dd2..030f80e 100644
49330 --- a/drivers/net/wireless/ath/ath9k/hw.h
49331 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49332 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49333
49334 /* ANI */
49335 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49336 -};
49337 +} __no_const;
49338
49339 /**
49340 * struct ath_spec_scan - parameters for Atheros spectral scan
49341 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49342 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49343 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49344 #endif
49345 -};
49346 +} __no_const;
49347
49348 struct ath_nf_limits {
49349 s16 max;
49350 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49351 index 4f18a6b..b07d92f 100644
49352 --- a/drivers/net/wireless/ath/ath9k/main.c
49353 +++ b/drivers/net/wireless/ath/ath9k/main.c
49354 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49355 if (!ath9k_is_chanctx_enabled())
49356 return;
49357
49358 - ath9k_ops.hw_scan = ath9k_hw_scan;
49359 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49360 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49361 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49362 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49363 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49364 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49365 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49366 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49367 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49368 + pax_open_kernel();
49369 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49370 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49371 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49372 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49373 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49374 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49375 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49376 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49377 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49378 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49379 + pax_close_kernel();
49380 }
49381
49382 #endif
49383 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49384 index 058a9f2..d5cb1ba 100644
49385 --- a/drivers/net/wireless/b43/phy_lp.c
49386 +++ b/drivers/net/wireless/b43/phy_lp.c
49387 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49388 {
49389 struct ssb_bus *bus = dev->dev->sdev->bus;
49390
49391 - static const struct b206x_channel *chandata = NULL;
49392 + const struct b206x_channel *chandata = NULL;
49393 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49394 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49395 u16 old_comm15, scale;
49396 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49397 index dc1d20c..f7a4f06 100644
49398 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49399 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49400 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49401 */
49402 if (il3945_mod_params.disable_hw_scan) {
49403 D_INFO("Disabling hw_scan\n");
49404 - il3945_mac_ops.hw_scan = NULL;
49405 + pax_open_kernel();
49406 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49407 + pax_close_kernel();
49408 }
49409
49410 D_INFO("*** LOAD DRIVER ***\n");
49411 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49412 index 0ffb6ff..c0b7f0e 100644
49413 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49414 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49415 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49416 {
49417 struct iwl_priv *priv = file->private_data;
49418 char buf[64];
49419 - int buf_size;
49420 + size_t buf_size;
49421 u32 offset, len;
49422
49423 memset(buf, 0, sizeof(buf));
49424 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49425 struct iwl_priv *priv = file->private_data;
49426
49427 char buf[8];
49428 - int buf_size;
49429 + size_t buf_size;
49430 u32 reset_flag;
49431
49432 memset(buf, 0, sizeof(buf));
49433 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49434 {
49435 struct iwl_priv *priv = file->private_data;
49436 char buf[8];
49437 - int buf_size;
49438 + size_t buf_size;
49439 int ht40;
49440
49441 memset(buf, 0, sizeof(buf));
49442 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49443 {
49444 struct iwl_priv *priv = file->private_data;
49445 char buf[8];
49446 - int buf_size;
49447 + size_t buf_size;
49448 int value;
49449
49450 memset(buf, 0, sizeof(buf));
49451 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49452 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49453 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49454
49455 -static const char *fmt_value = " %-30s %10u\n";
49456 -static const char *fmt_hex = " %-30s 0x%02X\n";
49457 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49458 -static const char *fmt_header =
49459 +static const char fmt_value[] = " %-30s %10u\n";
49460 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49461 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49462 +static const char fmt_header[] =
49463 "%-32s current cumulative delta max\n";
49464
49465 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49466 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49467 {
49468 struct iwl_priv *priv = file->private_data;
49469 char buf[8];
49470 - int buf_size;
49471 + size_t buf_size;
49472 int clear;
49473
49474 memset(buf, 0, sizeof(buf));
49475 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49476 {
49477 struct iwl_priv *priv = file->private_data;
49478 char buf[8];
49479 - int buf_size;
49480 + size_t buf_size;
49481 int trace;
49482
49483 memset(buf, 0, sizeof(buf));
49484 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49485 {
49486 struct iwl_priv *priv = file->private_data;
49487 char buf[8];
49488 - int buf_size;
49489 + size_t buf_size;
49490 int missed;
49491
49492 memset(buf, 0, sizeof(buf));
49493 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49494
49495 struct iwl_priv *priv = file->private_data;
49496 char buf[8];
49497 - int buf_size;
49498 + size_t buf_size;
49499 int plcp;
49500
49501 memset(buf, 0, sizeof(buf));
49502 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49503
49504 struct iwl_priv *priv = file->private_data;
49505 char buf[8];
49506 - int buf_size;
49507 + size_t buf_size;
49508 int flush;
49509
49510 memset(buf, 0, sizeof(buf));
49511 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49512
49513 struct iwl_priv *priv = file->private_data;
49514 char buf[8];
49515 - int buf_size;
49516 + size_t buf_size;
49517 int rts;
49518
49519 if (!priv->cfg->ht_params)
49520 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49521 {
49522 struct iwl_priv *priv = file->private_data;
49523 char buf[8];
49524 - int buf_size;
49525 + size_t buf_size;
49526
49527 memset(buf, 0, sizeof(buf));
49528 buf_size = min(count, sizeof(buf) - 1);
49529 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49530 struct iwl_priv *priv = file->private_data;
49531 u32 event_log_flag;
49532 char buf[8];
49533 - int buf_size;
49534 + size_t buf_size;
49535
49536 /* check that the interface is up */
49537 if (!iwl_is_ready(priv))
49538 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49539 struct iwl_priv *priv = file->private_data;
49540 char buf[8];
49541 u32 calib_disabled;
49542 - int buf_size;
49543 + size_t buf_size;
49544
49545 memset(buf, 0, sizeof(buf));
49546 buf_size = min(count, sizeof(buf) - 1);
49547 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49548 index dd2f3f8..fb1ae88 100644
49549 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49550 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49551 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49552 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49553
49554 char buf[8];
49555 - int buf_size;
49556 + size_t buf_size;
49557 u32 reset_flag;
49558
49559 memset(buf, 0, sizeof(buf));
49560 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49561 {
49562 struct iwl_trans *trans = file->private_data;
49563 char buf[8];
49564 - int buf_size;
49565 + size_t buf_size;
49566 int csr;
49567
49568 memset(buf, 0, sizeof(buf));
49569 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49570 index c9ad4cf..49a2fa0 100644
49571 --- a/drivers/net/wireless/mac80211_hwsim.c
49572 +++ b/drivers/net/wireless/mac80211_hwsim.c
49573 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49574 if (channels < 1)
49575 return -EINVAL;
49576
49577 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49578 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49579 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49580 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49581 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49582 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49583 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49584 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49585 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49586 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49587 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49588 - mac80211_hwsim_assign_vif_chanctx;
49589 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49590 - mac80211_hwsim_unassign_vif_chanctx;
49591 + pax_open_kernel();
49592 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49593 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49594 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49595 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49596 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49597 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49598 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49599 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49600 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49601 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49602 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49603 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49604 + pax_close_kernel();
49605
49606 spin_lock_init(&hwsim_radio_lock);
49607 INIT_LIST_HEAD(&hwsim_radios);
49608 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49609 index 1a4facd..a2ecbbd 100644
49610 --- a/drivers/net/wireless/rndis_wlan.c
49611 +++ b/drivers/net/wireless/rndis_wlan.c
49612 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49613
49614 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49615
49616 - if (rts_threshold < 0 || rts_threshold > 2347)
49617 + if (rts_threshold > 2347)
49618 rts_threshold = 2347;
49619
49620 tmp = cpu_to_le32(rts_threshold);
49621 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49622 index d13f25c..2573994 100644
49623 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49624 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49625 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49626 * for hardware which doesn't support hardware
49627 * sequence counting.
49628 */
49629 - atomic_t seqno;
49630 + atomic_unchecked_t seqno;
49631 };
49632
49633 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49634 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49635 index 66ff364..3ce34f7 100644
49636 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49637 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49638 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49639 * sequence counter given by mac80211.
49640 */
49641 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49642 - seqno = atomic_add_return(0x10, &intf->seqno);
49643 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49644 else
49645 - seqno = atomic_read(&intf->seqno);
49646 + seqno = atomic_read_unchecked(&intf->seqno);
49647
49648 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49649 hdr->seq_ctrl |= cpu_to_le16(seqno);
49650 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49651 index b661f896..ddf7d2b 100644
49652 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49653 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49654 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49655
49656 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49657
49658 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49659 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49660 + pax_open_kernel();
49661 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49662 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49663 + pax_close_kernel();
49664
49665 wl1251_info("using dedicated interrupt line");
49666 } else {
49667 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49668 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49669 + pax_open_kernel();
49670 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49671 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49672 + pax_close_kernel();
49673
49674 wl1251_info("using SDIO interrupt");
49675 }
49676 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49677 index 0bccf12..3d95068 100644
49678 --- a/drivers/net/wireless/ti/wl12xx/main.c
49679 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49680 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49681 sizeof(wl->conf.mem));
49682
49683 /* read data preparation is only needed by wl127x */
49684 - wl->ops->prepare_read = wl127x_prepare_read;
49685 + pax_open_kernel();
49686 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49687 + pax_close_kernel();
49688
49689 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49690 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49691 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49692 sizeof(wl->conf.mem));
49693
49694 /* read data preparation is only needed by wl127x */
49695 - wl->ops->prepare_read = wl127x_prepare_read;
49696 + pax_open_kernel();
49697 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49698 + pax_close_kernel();
49699
49700 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49701 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49702 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49703 index 7af1936..128bb35 100644
49704 --- a/drivers/net/wireless/ti/wl18xx/main.c
49705 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49706 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49707 }
49708
49709 if (!checksum_param) {
49710 - wl18xx_ops.set_rx_csum = NULL;
49711 - wl18xx_ops.init_vif = NULL;
49712 + pax_open_kernel();
49713 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49714 + *(void **)&wl18xx_ops.init_vif = NULL;
49715 + pax_close_kernel();
49716 }
49717
49718 /* Enable 11a Band only if we have 5G antennas */
49719 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49720 index a912dc0..a8225ba 100644
49721 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49722 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49723 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49724 {
49725 struct zd_usb *usb = urb->context;
49726 struct zd_usb_interrupt *intr = &usb->intr;
49727 - int len;
49728 + unsigned int len;
49729 u16 int_num;
49730
49731 ZD_ASSERT(in_interrupt());
49732 diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
49733 index d752d1c..23e3203 100644
49734 --- a/drivers/net/xen-netback/interface.c
49735 +++ b/drivers/net/xen-netback/interface.c
49736 @@ -578,6 +578,7 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
49737 goto err_rx_unbind;
49738 }
49739 queue->task = task;
49740 + get_task_struct(task);
49741
49742 task = kthread_create(xenvif_dealloc_kthread,
49743 (void *)queue, "%s-dealloc", queue->name);
49744 @@ -634,6 +635,7 @@ void xenvif_disconnect(struct xenvif *vif)
49745
49746 if (queue->task) {
49747 kthread_stop(queue->task);
49748 + put_task_struct(queue->task);
49749 queue->task = NULL;
49750 }
49751
49752 diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
49753 index c39aace..e18728d 100644
49754 --- a/drivers/net/xen-netback/netback.c
49755 +++ b/drivers/net/xen-netback/netback.c
49756 @@ -2111,8 +2111,7 @@ int xenvif_kthread_guest_rx(void *data)
49757 */
49758 if (unlikely(vif->disabled && queue->id == 0)) {
49759 xenvif_carrier_off(vif);
49760 - xenvif_rx_queue_purge(queue);
49761 - continue;
49762 + break;
49763 }
49764
49765 if (!skb_queue_empty(&queue->rx_queue))
49766 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49767 index 683671a..4519fc2 100644
49768 --- a/drivers/nfc/nfcwilink.c
49769 +++ b/drivers/nfc/nfcwilink.c
49770 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49771
49772 static int nfcwilink_probe(struct platform_device *pdev)
49773 {
49774 - static struct nfcwilink *drv;
49775 + struct nfcwilink *drv;
49776 int rc;
49777 __u32 protocols;
49778
49779 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49780 index d93b2b6..ae50401 100644
49781 --- a/drivers/oprofile/buffer_sync.c
49782 +++ b/drivers/oprofile/buffer_sync.c
49783 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49784 if (cookie == NO_COOKIE)
49785 offset = pc;
49786 if (cookie == INVALID_COOKIE) {
49787 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49788 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49789 offset = pc;
49790 }
49791 if (cookie != last_cookie) {
49792 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49793 /* add userspace sample */
49794
49795 if (!mm) {
49796 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49797 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49798 return 0;
49799 }
49800
49801 cookie = lookup_dcookie(mm, s->eip, &offset);
49802
49803 if (cookie == INVALID_COOKIE) {
49804 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49805 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49806 return 0;
49807 }
49808
49809 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49810 /* ignore backtraces if failed to add a sample */
49811 if (state == sb_bt_start) {
49812 state = sb_bt_ignore;
49813 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49814 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49815 }
49816 }
49817 release_mm(mm);
49818 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49819 index c0cc4e7..44d4e54 100644
49820 --- a/drivers/oprofile/event_buffer.c
49821 +++ b/drivers/oprofile/event_buffer.c
49822 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49823 }
49824
49825 if (buffer_pos == buffer_size) {
49826 - atomic_inc(&oprofile_stats.event_lost_overflow);
49827 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49828 return;
49829 }
49830
49831 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49832 index ed2c3ec..deda85a 100644
49833 --- a/drivers/oprofile/oprof.c
49834 +++ b/drivers/oprofile/oprof.c
49835 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49836 if (oprofile_ops.switch_events())
49837 return;
49838
49839 - atomic_inc(&oprofile_stats.multiplex_counter);
49840 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49841 start_switch_worker();
49842 }
49843
49844 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49845 index ee2cfce..7f8f699 100644
49846 --- a/drivers/oprofile/oprofile_files.c
49847 +++ b/drivers/oprofile/oprofile_files.c
49848 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49849
49850 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49851
49852 -static ssize_t timeout_read(struct file *file, char __user *buf,
49853 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49854 size_t count, loff_t *offset)
49855 {
49856 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49857 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49858 index 59659ce..6c860a0 100644
49859 --- a/drivers/oprofile/oprofile_stats.c
49860 +++ b/drivers/oprofile/oprofile_stats.c
49861 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49862 cpu_buf->sample_invalid_eip = 0;
49863 }
49864
49865 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49866 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49867 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49868 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49869 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49870 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49871 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49872 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49873 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49874 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49875 }
49876
49877
49878 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49879 index 1fc622b..8c48fc3 100644
49880 --- a/drivers/oprofile/oprofile_stats.h
49881 +++ b/drivers/oprofile/oprofile_stats.h
49882 @@ -13,11 +13,11 @@
49883 #include <linux/atomic.h>
49884
49885 struct oprofile_stat_struct {
49886 - atomic_t sample_lost_no_mm;
49887 - atomic_t sample_lost_no_mapping;
49888 - atomic_t bt_lost_no_mapping;
49889 - atomic_t event_lost_overflow;
49890 - atomic_t multiplex_counter;
49891 + atomic_unchecked_t sample_lost_no_mm;
49892 + atomic_unchecked_t sample_lost_no_mapping;
49893 + atomic_unchecked_t bt_lost_no_mapping;
49894 + atomic_unchecked_t event_lost_overflow;
49895 + atomic_unchecked_t multiplex_counter;
49896 };
49897
49898 extern struct oprofile_stat_struct oprofile_stats;
49899 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49900 index 3f49345..c750d0b 100644
49901 --- a/drivers/oprofile/oprofilefs.c
49902 +++ b/drivers/oprofile/oprofilefs.c
49903 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49904
49905 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49906 {
49907 - atomic_t *val = file->private_data;
49908 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49909 + atomic_unchecked_t *val = file->private_data;
49910 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49911 }
49912
49913
49914 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49915
49916
49917 int oprofilefs_create_ro_atomic(struct dentry *root,
49918 - char const *name, atomic_t *val)
49919 + char const *name, atomic_unchecked_t *val)
49920 {
49921 return __oprofilefs_create_file(root, name,
49922 &atomic_ro_fops, 0444, val);
49923 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49924 index bdef916..88c7dee 100644
49925 --- a/drivers/oprofile/timer_int.c
49926 +++ b/drivers/oprofile/timer_int.c
49927 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49928 return NOTIFY_OK;
49929 }
49930
49931 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49932 +static struct notifier_block oprofile_cpu_notifier = {
49933 .notifier_call = oprofile_cpu_notify,
49934 };
49935
49936 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49937 index 3b47080..6cd05dd 100644
49938 --- a/drivers/parport/procfs.c
49939 +++ b/drivers/parport/procfs.c
49940 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49941
49942 *ppos += len;
49943
49944 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49945 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49946 }
49947
49948 #ifdef CONFIG_PARPORT_1284
49949 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49950
49951 *ppos += len;
49952
49953 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49954 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49955 }
49956 #endif /* IEEE1284.3 support. */
49957
49958 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49959 index 6ca2399..68d866b 100644
49960 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49961 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49962 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49963 goto init_cleanup;
49964 }
49965
49966 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49967 + pax_open_kernel();
49968 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49969 + pax_close_kernel();
49970 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49971
49972 return retval;
49973 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49974 index 66b7bbe..26bee78 100644
49975 --- a/drivers/pci/hotplug/cpcihp_generic.c
49976 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49977 @@ -73,7 +73,6 @@ static u16 port;
49978 static unsigned int enum_bit;
49979 static u8 enum_mask;
49980
49981 -static struct cpci_hp_controller_ops generic_hpc_ops;
49982 static struct cpci_hp_controller generic_hpc;
49983
49984 static int __init validate_parameters(void)
49985 @@ -139,6 +138,10 @@ static int query_enum(void)
49986 return ((value & enum_mask) == enum_mask);
49987 }
49988
49989 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49990 + .query_enum = query_enum,
49991 +};
49992 +
49993 static int __init cpcihp_generic_init(void)
49994 {
49995 int status;
49996 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49997 pci_dev_put(dev);
49998
49999 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50000 - generic_hpc_ops.query_enum = query_enum;
50001 generic_hpc.ops = &generic_hpc_ops;
50002
50003 status = cpci_hp_register_controller(&generic_hpc);
50004 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50005 index 7ecf34e..effed62 100644
50006 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50007 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50008 @@ -59,7 +59,6 @@
50009 /* local variables */
50010 static bool debug;
50011 static bool poll;
50012 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50013 static struct cpci_hp_controller zt5550_hpc;
50014
50015 /* Primary cPCI bus bridge device */
50016 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
50017 return 0;
50018 }
50019
50020 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50021 + .query_enum = zt5550_hc_query_enum,
50022 +};
50023 +
50024 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50025 {
50026 int status;
50027 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50028 dbg("returned from zt5550_hc_config");
50029
50030 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50031 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50032 zt5550_hpc.ops = &zt5550_hpc_ops;
50033 if (!poll) {
50034 zt5550_hpc.irq = hc_dev->irq;
50035 zt5550_hpc.irq_flags = IRQF_SHARED;
50036 zt5550_hpc.dev_id = hc_dev;
50037
50038 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50039 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50040 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50041 + pax_open_kernel();
50042 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50043 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50044 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50045 + pax_open_kernel();
50046 } else {
50047 info("using ENUM# polling mode");
50048 }
50049 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50050 index 1e08ff8c..3cd145f 100644
50051 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50052 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50053 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
50054
50055 void compaq_nvram_init (void __iomem *rom_start)
50056 {
50057 +#ifndef CONFIG_PAX_KERNEXEC
50058 if (rom_start)
50059 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50060 +#endif
50061
50062 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50063
50064 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50065 index 56d8486..f26113f 100644
50066 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50067 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50068 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50069 return -EINVAL;
50070 }
50071
50072 - slot->ops->owner = owner;
50073 - slot->ops->mod_name = mod_name;
50074 + pax_open_kernel();
50075 + *(struct module **)&slot->ops->owner = owner;
50076 + *(const char **)&slot->ops->mod_name = mod_name;
50077 + pax_close_kernel();
50078
50079 mutex_lock(&pci_hp_mutex);
50080 /*
50081 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50082 index 07aa722..84514b4 100644
50083 --- a/drivers/pci/hotplug/pciehp_core.c
50084 +++ b/drivers/pci/hotplug/pciehp_core.c
50085 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50086 struct slot *slot = ctrl->slot;
50087 struct hotplug_slot *hotplug = NULL;
50088 struct hotplug_slot_info *info = NULL;
50089 - struct hotplug_slot_ops *ops = NULL;
50090 + hotplug_slot_ops_no_const *ops = NULL;
50091 char name[SLOT_NAME_SIZE];
50092 int retval = -ENOMEM;
50093
50094 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50095 index 084587d..4a8f9df 100644
50096 --- a/drivers/pci/msi.c
50097 +++ b/drivers/pci/msi.c
50098 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50099 {
50100 struct attribute **msi_attrs;
50101 struct attribute *msi_attr;
50102 - struct device_attribute *msi_dev_attr;
50103 - struct attribute_group *msi_irq_group;
50104 + device_attribute_no_const *msi_dev_attr;
50105 + attribute_group_no_const *msi_irq_group;
50106 const struct attribute_group **msi_irq_groups;
50107 struct msi_desc *entry;
50108 int ret = -ENOMEM;
50109 @@ -549,7 +549,7 @@ error_attrs:
50110 count = 0;
50111 msi_attr = msi_attrs[count];
50112 while (msi_attr) {
50113 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50114 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50115 kfree(msi_attr->name);
50116 kfree(msi_dev_attr);
50117 ++count;
50118 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50119 index 2c6643f..3a6d8e0 100644
50120 --- a/drivers/pci/pci-sysfs.c
50121 +++ b/drivers/pci/pci-sysfs.c
50122 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50123 {
50124 /* allocate attribute structure, piggyback attribute name */
50125 int name_len = write_combine ? 13 : 10;
50126 - struct bin_attribute *res_attr;
50127 + bin_attribute_no_const *res_attr;
50128 int retval;
50129
50130 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50131 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50132 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50133 {
50134 int retval;
50135 - struct bin_attribute *attr;
50136 + bin_attribute_no_const *attr;
50137
50138 /* If the device has VPD, try to expose it in sysfs. */
50139 if (dev->vpd) {
50140 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50141 {
50142 int retval;
50143 int rom_size = 0;
50144 - struct bin_attribute *attr;
50145 + bin_attribute_no_const *attr;
50146
50147 if (!sysfs_initialized)
50148 return -EACCES;
50149 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50150 index b5defca..e3664cc 100644
50151 --- a/drivers/pci/pci.h
50152 +++ b/drivers/pci/pci.h
50153 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
50154 struct pci_vpd {
50155 unsigned int len;
50156 const struct pci_vpd_ops *ops;
50157 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50158 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50159 };
50160
50161 int pci_vpd_pci22_init(struct pci_dev *dev);
50162 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50163 index e1e7026..d28dd33 100644
50164 --- a/drivers/pci/pcie/aspm.c
50165 +++ b/drivers/pci/pcie/aspm.c
50166 @@ -27,9 +27,9 @@
50167 #define MODULE_PARAM_PREFIX "pcie_aspm."
50168
50169 /* Note: those are not register definitions */
50170 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50171 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50172 -#define ASPM_STATE_L1 (4) /* L1 state */
50173 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50174 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50175 +#define ASPM_STATE_L1 (4U) /* L1 state */
50176 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50177 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50178
50179 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50180 index 3010ffc..5e2e133 100644
50181 --- a/drivers/pci/probe.c
50182 +++ b/drivers/pci/probe.c
50183 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50184 struct pci_bus_region region, inverted_region;
50185 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50186
50187 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50188 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50189
50190 /* No printks while decoding is disabled! */
50191 if (!dev->mmio_always_on) {
50192 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50193 index 3f155e7..0f4b1f0 100644
50194 --- a/drivers/pci/proc.c
50195 +++ b/drivers/pci/proc.c
50196 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50197 static int __init pci_proc_init(void)
50198 {
50199 struct pci_dev *dev = NULL;
50200 +
50201 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50202 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50203 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50204 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50205 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50206 +#endif
50207 +#else
50208 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50209 +#endif
50210 proc_create("devices", 0, proc_bus_pci_dir,
50211 &proc_bus_pci_dev_operations);
50212 proc_initialized = 1;
50213 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50214 index d866db8..c827d1f 100644
50215 --- a/drivers/platform/chrome/chromeos_laptop.c
50216 +++ b/drivers/platform/chrome/chromeos_laptop.c
50217 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50218 .callback = chromeos_laptop_dmi_matched, \
50219 .driver_data = (void *)&board_
50220
50221 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50222 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50223 {
50224 .ident = "Samsung Series 5 550",
50225 .matches = {
50226 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50227 index c5af23b..3d62d5e 100644
50228 --- a/drivers/platform/x86/alienware-wmi.c
50229 +++ b/drivers/platform/x86/alienware-wmi.c
50230 @@ -150,7 +150,7 @@ struct wmax_led_args {
50231 } __packed;
50232
50233 static struct platform_device *platform_device;
50234 -static struct device_attribute *zone_dev_attrs;
50235 +static device_attribute_no_const *zone_dev_attrs;
50236 static struct attribute **zone_attrs;
50237 static struct platform_zone *zone_data;
50238
50239 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50240 }
50241 };
50242
50243 -static struct attribute_group zone_attribute_group = {
50244 +static attribute_group_no_const zone_attribute_group = {
50245 .name = "rgb_zones",
50246 };
50247
50248 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50249 index 21fc932..ee9394a 100644
50250 --- a/drivers/platform/x86/asus-wmi.c
50251 +++ b/drivers/platform/x86/asus-wmi.c
50252 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50253 int err;
50254 u32 retval = -1;
50255
50256 +#ifdef CONFIG_GRKERNSEC_KMEM
50257 + return -EPERM;
50258 +#endif
50259 +
50260 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50261
50262 if (err < 0)
50263 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50264 int err;
50265 u32 retval = -1;
50266
50267 +#ifdef CONFIG_GRKERNSEC_KMEM
50268 + return -EPERM;
50269 +#endif
50270 +
50271 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50272 &retval);
50273
50274 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50275 union acpi_object *obj;
50276 acpi_status status;
50277
50278 +#ifdef CONFIG_GRKERNSEC_KMEM
50279 + return -EPERM;
50280 +#endif
50281 +
50282 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50283 1, asus->debug.method_id,
50284 &input, &output);
50285 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50286 index 62f8030..c7f2a45 100644
50287 --- a/drivers/platform/x86/msi-laptop.c
50288 +++ b/drivers/platform/x86/msi-laptop.c
50289 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50290
50291 if (!quirks->ec_read_only) {
50292 /* allow userland write sysfs file */
50293 - dev_attr_bluetooth.store = store_bluetooth;
50294 - dev_attr_wlan.store = store_wlan;
50295 - dev_attr_threeg.store = store_threeg;
50296 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50297 - dev_attr_wlan.attr.mode |= S_IWUSR;
50298 - dev_attr_threeg.attr.mode |= S_IWUSR;
50299 + pax_open_kernel();
50300 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50301 + *(void **)&dev_attr_wlan.store = store_wlan;
50302 + *(void **)&dev_attr_threeg.store = store_threeg;
50303 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50304 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50305 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50306 + pax_close_kernel();
50307 }
50308
50309 /* disable hardware control by fn key */
50310 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50311 index 70222f2..8c8ce66 100644
50312 --- a/drivers/platform/x86/msi-wmi.c
50313 +++ b/drivers/platform/x86/msi-wmi.c
50314 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50315 static void msi_wmi_notify(u32 value, void *context)
50316 {
50317 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50318 - static struct key_entry *key;
50319 + struct key_entry *key;
50320 union acpi_object *obj;
50321 acpi_status status;
50322
50323 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50324 index 26ad9ff..7c52909 100644
50325 --- a/drivers/platform/x86/sony-laptop.c
50326 +++ b/drivers/platform/x86/sony-laptop.c
50327 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50328 }
50329
50330 /* High speed charging function */
50331 -static struct device_attribute *hsc_handle;
50332 +static device_attribute_no_const *hsc_handle;
50333
50334 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50335 struct device_attribute *attr,
50336 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50337 }
50338
50339 /* low battery function */
50340 -static struct device_attribute *lowbatt_handle;
50341 +static device_attribute_no_const *lowbatt_handle;
50342
50343 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50344 struct device_attribute *attr,
50345 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50346 }
50347
50348 /* fan speed function */
50349 -static struct device_attribute *fan_handle, *hsf_handle;
50350 +static device_attribute_no_const *fan_handle, *hsf_handle;
50351
50352 static ssize_t sony_nc_hsfan_store(struct device *dev,
50353 struct device_attribute *attr,
50354 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50355 }
50356
50357 /* USB charge function */
50358 -static struct device_attribute *uc_handle;
50359 +static device_attribute_no_const *uc_handle;
50360
50361 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50362 struct device_attribute *attr,
50363 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50364 }
50365
50366 /* Panel ID function */
50367 -static struct device_attribute *panel_handle;
50368 +static device_attribute_no_const *panel_handle;
50369
50370 static ssize_t sony_nc_panelid_show(struct device *dev,
50371 struct device_attribute *attr, char *buffer)
50372 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50373 }
50374
50375 /* smart connect function */
50376 -static struct device_attribute *sc_handle;
50377 +static device_attribute_no_const *sc_handle;
50378
50379 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50380 struct device_attribute *attr,
50381 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50382 index cf0f893..5955997 100644
50383 --- a/drivers/platform/x86/thinkpad_acpi.c
50384 +++ b/drivers/platform/x86/thinkpad_acpi.c
50385 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50386 return 0;
50387 }
50388
50389 -void static hotkey_mask_warn_incomplete_mask(void)
50390 +static void hotkey_mask_warn_incomplete_mask(void)
50391 {
50392 /* log only what the user can fix... */
50393 const u32 wantedmask = hotkey_driver_mask &
50394 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50395 && !tp_features.bright_unkfw)
50396 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50397 }
50398 +}
50399
50400 #undef TPACPI_COMPARE_KEY
50401 #undef TPACPI_MAY_SEND_KEY
50402 -}
50403
50404 /*
50405 * Polling driver
50406 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50407 index 438d4c7..ca8a2fb 100644
50408 --- a/drivers/pnp/pnpbios/bioscalls.c
50409 +++ b/drivers/pnp/pnpbios/bioscalls.c
50410 @@ -59,7 +59,7 @@ do { \
50411 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50412 } while(0)
50413
50414 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50415 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50416 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50417
50418 /*
50419 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50420
50421 cpu = get_cpu();
50422 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50423 +
50424 + pax_open_kernel();
50425 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50426 + pax_close_kernel();
50427
50428 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50429 spin_lock_irqsave(&pnp_bios_lock, flags);
50430 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50431 :"memory");
50432 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50433
50434 + pax_open_kernel();
50435 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50436 + pax_close_kernel();
50437 +
50438 put_cpu();
50439
50440 /* If we get here and this is set then the PnP BIOS faulted on us. */
50441 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50442 return status;
50443 }
50444
50445 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50446 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50447 {
50448 int i;
50449
50450 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50451 pnp_bios_callpoint.offset = header->fields.pm16offset;
50452 pnp_bios_callpoint.segment = PNP_CS16;
50453
50454 + pax_open_kernel();
50455 +
50456 for_each_possible_cpu(i) {
50457 struct desc_struct *gdt = get_cpu_gdt_table(i);
50458 if (!gdt)
50459 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50460 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50461 (unsigned long)__va(header->fields.pm16dseg));
50462 }
50463 +
50464 + pax_close_kernel();
50465 }
50466 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50467 index 0c52e2a..3421ab7 100644
50468 --- a/drivers/power/pda_power.c
50469 +++ b/drivers/power/pda_power.c
50470 @@ -37,7 +37,11 @@ static int polling;
50471
50472 #if IS_ENABLED(CONFIG_USB_PHY)
50473 static struct usb_phy *transceiver;
50474 -static struct notifier_block otg_nb;
50475 +static int otg_handle_notification(struct notifier_block *nb,
50476 + unsigned long event, void *unused);
50477 +static struct notifier_block otg_nb = {
50478 + .notifier_call = otg_handle_notification
50479 +};
50480 #endif
50481
50482 static struct regulator *ac_draw;
50483 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50484
50485 #if IS_ENABLED(CONFIG_USB_PHY)
50486 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50487 - otg_nb.notifier_call = otg_handle_notification;
50488 ret = usb_register_notifier(transceiver, &otg_nb);
50489 if (ret) {
50490 dev_err(dev, "failure to register otg notifier\n");
50491 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50492 index cc439fd..8fa30df 100644
50493 --- a/drivers/power/power_supply.h
50494 +++ b/drivers/power/power_supply.h
50495 @@ -16,12 +16,12 @@ struct power_supply;
50496
50497 #ifdef CONFIG_SYSFS
50498
50499 -extern void power_supply_init_attrs(struct device_type *dev_type);
50500 +extern void power_supply_init_attrs(void);
50501 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50502
50503 #else
50504
50505 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50506 +static inline void power_supply_init_attrs(void) {}
50507 #define power_supply_uevent NULL
50508
50509 #endif /* CONFIG_SYSFS */
50510 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50511 index 694e8cd..9f03483 100644
50512 --- a/drivers/power/power_supply_core.c
50513 +++ b/drivers/power/power_supply_core.c
50514 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50515 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50516 EXPORT_SYMBOL_GPL(power_supply_notifier);
50517
50518 -static struct device_type power_supply_dev_type;
50519 +extern const struct attribute_group *power_supply_attr_groups[];
50520 +static struct device_type power_supply_dev_type = {
50521 + .groups = power_supply_attr_groups,
50522 +};
50523
50524 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50525 struct power_supply *supply)
50526 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50527 return PTR_ERR(power_supply_class);
50528
50529 power_supply_class->dev_uevent = power_supply_uevent;
50530 - power_supply_init_attrs(&power_supply_dev_type);
50531 + power_supply_init_attrs();
50532
50533 return 0;
50534 }
50535 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50536 index 62653f5..d0bb485 100644
50537 --- a/drivers/power/power_supply_sysfs.c
50538 +++ b/drivers/power/power_supply_sysfs.c
50539 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50540 .is_visible = power_supply_attr_is_visible,
50541 };
50542
50543 -static const struct attribute_group *power_supply_attr_groups[] = {
50544 +const struct attribute_group *power_supply_attr_groups[] = {
50545 &power_supply_attr_group,
50546 NULL,
50547 };
50548
50549 -void power_supply_init_attrs(struct device_type *dev_type)
50550 +void power_supply_init_attrs(void)
50551 {
50552 int i;
50553
50554 - dev_type->groups = power_supply_attr_groups;
50555 -
50556 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50557 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50558 }
50559 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50560 index 84419af..268ede8 100644
50561 --- a/drivers/powercap/powercap_sys.c
50562 +++ b/drivers/powercap/powercap_sys.c
50563 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50564 struct device_attribute name_attr;
50565 };
50566
50567 +static ssize_t show_constraint_name(struct device *dev,
50568 + struct device_attribute *dev_attr,
50569 + char *buf);
50570 +
50571 static struct powercap_constraint_attr
50572 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50573 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50574 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50575 + .power_limit_attr = {
50576 + .attr = {
50577 + .name = NULL,
50578 + .mode = S_IWUSR | S_IRUGO
50579 + },
50580 + .show = show_constraint_power_limit_uw,
50581 + .store = store_constraint_power_limit_uw
50582 + },
50583 +
50584 + .time_window_attr = {
50585 + .attr = {
50586 + .name = NULL,
50587 + .mode = S_IWUSR | S_IRUGO
50588 + },
50589 + .show = show_constraint_time_window_us,
50590 + .store = store_constraint_time_window_us
50591 + },
50592 +
50593 + .max_power_attr = {
50594 + .attr = {
50595 + .name = NULL,
50596 + .mode = S_IRUGO
50597 + },
50598 + .show = show_constraint_max_power_uw,
50599 + .store = NULL
50600 + },
50601 +
50602 + .min_power_attr = {
50603 + .attr = {
50604 + .name = NULL,
50605 + .mode = S_IRUGO
50606 + },
50607 + .show = show_constraint_min_power_uw,
50608 + .store = NULL
50609 + },
50610 +
50611 + .max_time_window_attr = {
50612 + .attr = {
50613 + .name = NULL,
50614 + .mode = S_IRUGO
50615 + },
50616 + .show = show_constraint_max_time_window_us,
50617 + .store = NULL
50618 + },
50619 +
50620 + .min_time_window_attr = {
50621 + .attr = {
50622 + .name = NULL,
50623 + .mode = S_IRUGO
50624 + },
50625 + .show = show_constraint_min_time_window_us,
50626 + .store = NULL
50627 + },
50628 +
50629 + .name_attr = {
50630 + .attr = {
50631 + .name = NULL,
50632 + .mode = S_IRUGO
50633 + },
50634 + .show = show_constraint_name,
50635 + .store = NULL
50636 + }
50637 + }
50638 +};
50639
50640 /* A list of powercap control_types */
50641 static LIST_HEAD(powercap_cntrl_list);
50642 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50643 }
50644
50645 static int create_constraint_attribute(int id, const char *name,
50646 - int mode,
50647 - struct device_attribute *dev_attr,
50648 - ssize_t (*show)(struct device *,
50649 - struct device_attribute *, char *),
50650 - ssize_t (*store)(struct device *,
50651 - struct device_attribute *,
50652 - const char *, size_t)
50653 - )
50654 + struct device_attribute *dev_attr)
50655 {
50656 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50657
50658 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50659 - id, name);
50660 - if (!dev_attr->attr.name)
50661 + if (!name)
50662 return -ENOMEM;
50663 - dev_attr->attr.mode = mode;
50664 - dev_attr->show = show;
50665 - dev_attr->store = store;
50666 +
50667 + pax_open_kernel();
50668 + *(const char **)&dev_attr->attr.name = name;
50669 + pax_close_kernel();
50670
50671 return 0;
50672 }
50673 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50674
50675 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50676 ret = create_constraint_attribute(i, "power_limit_uw",
50677 - S_IWUSR | S_IRUGO,
50678 - &constraint_attrs[i].power_limit_attr,
50679 - show_constraint_power_limit_uw,
50680 - store_constraint_power_limit_uw);
50681 + &constraint_attrs[i].power_limit_attr);
50682 if (ret)
50683 goto err_alloc;
50684 ret = create_constraint_attribute(i, "time_window_us",
50685 - S_IWUSR | S_IRUGO,
50686 - &constraint_attrs[i].time_window_attr,
50687 - show_constraint_time_window_us,
50688 - store_constraint_time_window_us);
50689 + &constraint_attrs[i].time_window_attr);
50690 if (ret)
50691 goto err_alloc;
50692 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50693 - &constraint_attrs[i].name_attr,
50694 - show_constraint_name,
50695 - NULL);
50696 + ret = create_constraint_attribute(i, "name",
50697 + &constraint_attrs[i].name_attr);
50698 if (ret)
50699 goto err_alloc;
50700 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50701 - &constraint_attrs[i].max_power_attr,
50702 - show_constraint_max_power_uw,
50703 - NULL);
50704 + ret = create_constraint_attribute(i, "max_power_uw",
50705 + &constraint_attrs[i].max_power_attr);
50706 if (ret)
50707 goto err_alloc;
50708 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50709 - &constraint_attrs[i].min_power_attr,
50710 - show_constraint_min_power_uw,
50711 - NULL);
50712 + ret = create_constraint_attribute(i, "min_power_uw",
50713 + &constraint_attrs[i].min_power_attr);
50714 if (ret)
50715 goto err_alloc;
50716 ret = create_constraint_attribute(i, "max_time_window_us",
50717 - S_IRUGO,
50718 - &constraint_attrs[i].max_time_window_attr,
50719 - show_constraint_max_time_window_us,
50720 - NULL);
50721 + &constraint_attrs[i].max_time_window_attr);
50722 if (ret)
50723 goto err_alloc;
50724 ret = create_constraint_attribute(i, "min_time_window_us",
50725 - S_IRUGO,
50726 - &constraint_attrs[i].min_time_window_attr,
50727 - show_constraint_min_time_window_us,
50728 - NULL);
50729 + &constraint_attrs[i].min_time_window_attr);
50730 if (ret)
50731 goto err_alloc;
50732
50733 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50734 power_zone->zone_dev_attrs[count++] =
50735 &dev_attr_max_energy_range_uj.attr;
50736 if (power_zone->ops->get_energy_uj) {
50737 + pax_open_kernel();
50738 if (power_zone->ops->reset_energy_uj)
50739 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50740 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50741 else
50742 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50743 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50744 + pax_close_kernel();
50745 power_zone->zone_dev_attrs[count++] =
50746 &dev_attr_energy_uj.attr;
50747 }
50748 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50749 index 9c5d414..c7900ce 100644
50750 --- a/drivers/ptp/ptp_private.h
50751 +++ b/drivers/ptp/ptp_private.h
50752 @@ -51,7 +51,7 @@ struct ptp_clock {
50753 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50754 wait_queue_head_t tsev_wq;
50755 int defunct; /* tells readers to go away when clock is being removed */
50756 - struct device_attribute *pin_dev_attr;
50757 + device_attribute_no_const *pin_dev_attr;
50758 struct attribute **pin_attr;
50759 struct attribute_group pin_attr_group;
50760 };
50761 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50762 index 302e626..12579af 100644
50763 --- a/drivers/ptp/ptp_sysfs.c
50764 +++ b/drivers/ptp/ptp_sysfs.c
50765 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50766 goto no_pin_attr;
50767
50768 for (i = 0; i < n_pins; i++) {
50769 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50770 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50771 sysfs_attr_init(&da->attr);
50772 da->attr.name = info->pin_config[i].name;
50773 da->attr.mode = 0644;
50774 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50775 index fc6fb54..b8c794ba 100644
50776 --- a/drivers/regulator/core.c
50777 +++ b/drivers/regulator/core.c
50778 @@ -3569,7 +3569,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50779 {
50780 const struct regulation_constraints *constraints = NULL;
50781 const struct regulator_init_data *init_data;
50782 - static atomic_t regulator_no = ATOMIC_INIT(0);
50783 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50784 struct regulator_dev *rdev;
50785 struct device *dev;
50786 int ret, i;
50787 @@ -3643,7 +3643,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50788 rdev->dev.class = &regulator_class;
50789 rdev->dev.parent = dev;
50790 dev_set_name(&rdev->dev, "regulator.%d",
50791 - atomic_inc_return(&regulator_no) - 1);
50792 + atomic_inc_return_unchecked(&regulator_no) - 1);
50793 ret = device_register(&rdev->dev);
50794 if (ret != 0) {
50795 put_device(&rdev->dev);
50796 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50797 index 7eee2ca..4024513 100644
50798 --- a/drivers/regulator/max8660.c
50799 +++ b/drivers/regulator/max8660.c
50800 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50801 max8660->shadow_regs[MAX8660_OVER1] = 5;
50802 } else {
50803 /* Otherwise devices can be toggled via software */
50804 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50805 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50806 + pax_open_kernel();
50807 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50808 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50809 + pax_close_kernel();
50810 }
50811
50812 /*
50813 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50814 index dbedf17..18ff6b7 100644
50815 --- a/drivers/regulator/max8973-regulator.c
50816 +++ b/drivers/regulator/max8973-regulator.c
50817 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50818 if (!pdata || !pdata->enable_ext_control) {
50819 max->desc.enable_reg = MAX8973_VOUT;
50820 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50821 - max->ops.enable = regulator_enable_regmap;
50822 - max->ops.disable = regulator_disable_regmap;
50823 - max->ops.is_enabled = regulator_is_enabled_regmap;
50824 + pax_open_kernel();
50825 + *(void **)&max->ops.enable = regulator_enable_regmap;
50826 + *(void **)&max->ops.disable = regulator_disable_regmap;
50827 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50828 + pax_close_kernel();
50829 }
50830
50831 if (pdata) {
50832 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50833 index 793b662..01c20fc 100644
50834 --- a/drivers/regulator/mc13892-regulator.c
50835 +++ b/drivers/regulator/mc13892-regulator.c
50836 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50837 mc13xxx_unlock(mc13892);
50838
50839 /* update mc13892_vcam ops */
50840 - memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50841 + pax_open_kernel();
50842 + memcpy((void *)&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50843 sizeof(struct regulator_ops));
50844 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50845 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50846 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50847 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50848 + pax_close_kernel();
50849 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50850
50851 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50852 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50853 index 5b2e761..c8c8a4a 100644
50854 --- a/drivers/rtc/rtc-cmos.c
50855 +++ b/drivers/rtc/rtc-cmos.c
50856 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50857 hpet_rtc_timer_init();
50858
50859 /* export at least the first block of NVRAM */
50860 - nvram.size = address_space - NVRAM_OFFSET;
50861 + pax_open_kernel();
50862 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50863 + pax_close_kernel();
50864 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50865 if (retval < 0) {
50866 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50867 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50868 index d049393..bb20be0 100644
50869 --- a/drivers/rtc/rtc-dev.c
50870 +++ b/drivers/rtc/rtc-dev.c
50871 @@ -16,6 +16,7 @@
50872 #include <linux/module.h>
50873 #include <linux/rtc.h>
50874 #include <linux/sched.h>
50875 +#include <linux/grsecurity.h>
50876 #include "rtc-core.h"
50877
50878 static dev_t rtc_devt;
50879 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50880 if (copy_from_user(&tm, uarg, sizeof(tm)))
50881 return -EFAULT;
50882
50883 + gr_log_timechange();
50884 +
50885 return rtc_set_time(rtc, &tm);
50886
50887 case RTC_PIE_ON:
50888 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50889 index bb43cf7..ee4d274 100644
50890 --- a/drivers/rtc/rtc-ds1307.c
50891 +++ b/drivers/rtc/rtc-ds1307.c
50892 @@ -107,7 +107,7 @@ struct ds1307 {
50893 u8 offset; /* register's offset */
50894 u8 regs[11];
50895 u16 nvram_offset;
50896 - struct bin_attribute *nvram;
50897 + bin_attribute_no_const *nvram;
50898 enum ds_type type;
50899 unsigned long flags;
50900 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50901 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50902 index 11880c1..b823aa4 100644
50903 --- a/drivers/rtc/rtc-m48t59.c
50904 +++ b/drivers/rtc/rtc-m48t59.c
50905 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50906 if (IS_ERR(m48t59->rtc))
50907 return PTR_ERR(m48t59->rtc);
50908
50909 - m48t59_nvram_attr.size = pdata->offset;
50910 + pax_open_kernel();
50911 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50912 + pax_close_kernel();
50913
50914 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50915 if (ret)
50916 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50917 index e693af6..2e525b6 100644
50918 --- a/drivers/scsi/bfa/bfa_fcpim.h
50919 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50920 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50921
50922 struct bfa_itn_s {
50923 bfa_isr_func_t isr;
50924 -};
50925 +} __no_const;
50926
50927 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50928 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50929 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50930 index 0f19455..ef7adb5 100644
50931 --- a/drivers/scsi/bfa/bfa_fcs.c
50932 +++ b/drivers/scsi/bfa/bfa_fcs.c
50933 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50934 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50935
50936 static struct bfa_fcs_mod_s fcs_modules[] = {
50937 - { bfa_fcs_port_attach, NULL, NULL },
50938 - { bfa_fcs_uf_attach, NULL, NULL },
50939 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50940 - bfa_fcs_fabric_modexit },
50941 + {
50942 + .attach = bfa_fcs_port_attach,
50943 + .modinit = NULL,
50944 + .modexit = NULL
50945 + },
50946 + {
50947 + .attach = bfa_fcs_uf_attach,
50948 + .modinit = NULL,
50949 + .modexit = NULL
50950 + },
50951 + {
50952 + .attach = bfa_fcs_fabric_attach,
50953 + .modinit = bfa_fcs_fabric_modinit,
50954 + .modexit = bfa_fcs_fabric_modexit
50955 + },
50956 };
50957
50958 /*
50959 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50960 index ff75ef8..2dfe00a 100644
50961 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50962 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50963 @@ -89,15 +89,26 @@ static struct {
50964 void (*offline) (struct bfa_fcs_lport_s *port);
50965 } __port_action[] = {
50966 {
50967 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50968 - bfa_fcs_lport_unknown_offline}, {
50969 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50970 - bfa_fcs_lport_fab_offline}, {
50971 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50972 - bfa_fcs_lport_n2n_offline}, {
50973 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50974 - bfa_fcs_lport_loop_offline},
50975 - };
50976 + .init = bfa_fcs_lport_unknown_init,
50977 + .online = bfa_fcs_lport_unknown_online,
50978 + .offline = bfa_fcs_lport_unknown_offline
50979 + },
50980 + {
50981 + .init = bfa_fcs_lport_fab_init,
50982 + .online = bfa_fcs_lport_fab_online,
50983 + .offline = bfa_fcs_lport_fab_offline
50984 + },
50985 + {
50986 + .init = bfa_fcs_lport_n2n_init,
50987 + .online = bfa_fcs_lport_n2n_online,
50988 + .offline = bfa_fcs_lport_n2n_offline
50989 + },
50990 + {
50991 + .init = bfa_fcs_lport_loop_init,
50992 + .online = bfa_fcs_lport_loop_online,
50993 + .offline = bfa_fcs_lport_loop_offline
50994 + },
50995 +};
50996
50997 /*
50998 * fcs_port_sm FCS logical port state machine
50999 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51000 index a38aafa0..fe8f03b 100644
51001 --- a/drivers/scsi/bfa/bfa_ioc.h
51002 +++ b/drivers/scsi/bfa/bfa_ioc.h
51003 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51004 bfa_ioc_disable_cbfn_t disable_cbfn;
51005 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51006 bfa_ioc_reset_cbfn_t reset_cbfn;
51007 -};
51008 +} __no_const;
51009
51010 /*
51011 * IOC event notification mechanism.
51012 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51013 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51014 enum bfi_ioc_state fwstate);
51015 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51016 -};
51017 +} __no_const;
51018
51019 /*
51020 * Queue element to wait for room in request queue. FIFO order is
51021 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51022 index a14c784..6de6790 100644
51023 --- a/drivers/scsi/bfa/bfa_modules.h
51024 +++ b/drivers/scsi/bfa/bfa_modules.h
51025 @@ -78,12 +78,12 @@ enum {
51026 \
51027 extern struct bfa_module_s hal_mod_ ## __mod; \
51028 struct bfa_module_s hal_mod_ ## __mod = { \
51029 - bfa_ ## __mod ## _meminfo, \
51030 - bfa_ ## __mod ## _attach, \
51031 - bfa_ ## __mod ## _detach, \
51032 - bfa_ ## __mod ## _start, \
51033 - bfa_ ## __mod ## _stop, \
51034 - bfa_ ## __mod ## _iocdisable, \
51035 + .meminfo = bfa_ ## __mod ## _meminfo, \
51036 + .attach = bfa_ ## __mod ## _attach, \
51037 + .detach = bfa_ ## __mod ## _detach, \
51038 + .start = bfa_ ## __mod ## _start, \
51039 + .stop = bfa_ ## __mod ## _stop, \
51040 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51041 }
51042
51043 #define BFA_CACHELINE_SZ (256)
51044 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51045 index 045c4e1..13de803 100644
51046 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51047 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51048 @@ -33,8 +33,8 @@
51049 */
51050 #include "libfcoe.h"
51051
51052 -static atomic_t ctlr_num;
51053 -static atomic_t fcf_num;
51054 +static atomic_unchecked_t ctlr_num;
51055 +static atomic_unchecked_t fcf_num;
51056
51057 /*
51058 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51059 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51060 if (!ctlr)
51061 goto out;
51062
51063 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51064 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51065 ctlr->f = f;
51066 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51067 INIT_LIST_HEAD(&ctlr->fcfs);
51068 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51069 fcf->dev.parent = &ctlr->dev;
51070 fcf->dev.bus = &fcoe_bus_type;
51071 fcf->dev.type = &fcoe_fcf_device_type;
51072 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51073 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51074 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51075
51076 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51077 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51078 {
51079 int error;
51080
51081 - atomic_set(&ctlr_num, 0);
51082 - atomic_set(&fcf_num, 0);
51083 + atomic_set_unchecked(&ctlr_num, 0);
51084 + atomic_set_unchecked(&fcf_num, 0);
51085
51086 error = bus_register(&fcoe_bus_type);
51087 if (error)
51088 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51089 index 6de80e3..a11e0ac 100644
51090 --- a/drivers/scsi/hosts.c
51091 +++ b/drivers/scsi/hosts.c
51092 @@ -42,7 +42,7 @@
51093 #include "scsi_logging.h"
51094
51095
51096 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51097 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51098
51099
51100 static void scsi_host_cls_release(struct device *dev)
51101 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51102 * subtract one because we increment first then return, but we need to
51103 * know what the next host number was before increment
51104 */
51105 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51106 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51107 shost->dma_channel = 0xff;
51108
51109 /* These three are default values which can be overridden */
51110 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51111 index cef5d49..01e280e 100644
51112 --- a/drivers/scsi/hpsa.c
51113 +++ b/drivers/scsi/hpsa.c
51114 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51115 unsigned long flags;
51116
51117 if (h->transMethod & CFGTBL_Trans_io_accel1)
51118 - return h->access.command_completed(h, q);
51119 + return h->access->command_completed(h, q);
51120
51121 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51122 - return h->access.command_completed(h, q);
51123 + return h->access->command_completed(h, q);
51124
51125 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51126 a = rq->head[rq->current_entry];
51127 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51128 while (!list_empty(&h->reqQ)) {
51129 c = list_entry(h->reqQ.next, struct CommandList, list);
51130 /* can't do anything if fifo is full */
51131 - if ((h->access.fifo_full(h))) {
51132 + if ((h->access->fifo_full(h))) {
51133 h->fifo_recently_full = 1;
51134 dev_warn(&h->pdev->dev, "fifo full\n");
51135 break;
51136 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51137
51138 /* Tell the controller execute command */
51139 spin_unlock_irqrestore(&h->lock, *flags);
51140 - h->access.submit_command(h, c);
51141 + h->access->submit_command(h, c);
51142 spin_lock_irqsave(&h->lock, *flags);
51143 }
51144 }
51145 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51146
51147 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51148 {
51149 - return h->access.command_completed(h, q);
51150 + return h->access->command_completed(h, q);
51151 }
51152
51153 static inline bool interrupt_pending(struct ctlr_info *h)
51154 {
51155 - return h->access.intr_pending(h);
51156 + return h->access->intr_pending(h);
51157 }
51158
51159 static inline long interrupt_not_for_us(struct ctlr_info *h)
51160 {
51161 - return (h->access.intr_pending(h) == 0) ||
51162 + return (h->access->intr_pending(h) == 0) ||
51163 (h->interrupts_enabled == 0);
51164 }
51165
51166 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51167 if (prod_index < 0)
51168 return -ENODEV;
51169 h->product_name = products[prod_index].product_name;
51170 - h->access = *(products[prod_index].access);
51171 + h->access = products[prod_index].access;
51172
51173 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51174 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51175 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51176 unsigned long flags;
51177 u32 lockup_detected;
51178
51179 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51180 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51181 spin_lock_irqsave(&h->lock, flags);
51182 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51183 if (!lockup_detected) {
51184 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51185 }
51186
51187 /* make sure the board interrupts are off */
51188 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51189 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51190
51191 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51192 goto clean2;
51193 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51194 * fake ones to scoop up any residual completions.
51195 */
51196 spin_lock_irqsave(&h->lock, flags);
51197 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51198 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51199 spin_unlock_irqrestore(&h->lock, flags);
51200 free_irqs(h);
51201 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51202 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51203 dev_info(&h->pdev->dev, "Board READY.\n");
51204 dev_info(&h->pdev->dev,
51205 "Waiting for stale completions to drain.\n");
51206 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51207 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51208 msleep(10000);
51209 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51210 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51211
51212 rc = controller_reset_failed(h->cfgtable);
51213 if (rc)
51214 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51215 h->drv_req_rescan = 0;
51216
51217 /* Turn the interrupts on so we can service requests */
51218 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51219 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51220
51221 hpsa_hba_inquiry(h);
51222 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51223 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51224 * To write all data in the battery backed cache to disks
51225 */
51226 hpsa_flush_cache(h);
51227 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51228 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51229 hpsa_free_irqs_and_disable_msix(h);
51230 }
51231
51232 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51233 CFGTBL_Trans_enable_directed_msix |
51234 (trans_support & (CFGTBL_Trans_io_accel1 |
51235 CFGTBL_Trans_io_accel2));
51236 - struct access_method access = SA5_performant_access;
51237 + struct access_method *access = &SA5_performant_access;
51238
51239 /* This is a bit complicated. There are 8 registers on
51240 * the controller which we write to to tell it 8 different
51241 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51242 * perform the superfluous readl() after each command submission.
51243 */
51244 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51245 - access = SA5_performant_access_no_read;
51246 + access = &SA5_performant_access_no_read;
51247
51248 /* Controller spec: zero out this buffer. */
51249 for (i = 0; i < h->nreply_queues; i++)
51250 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51251 * enable outbound interrupt coalescing in accelerator mode;
51252 */
51253 if (trans_support & CFGTBL_Trans_io_accel1) {
51254 - access = SA5_ioaccel_mode1_access;
51255 + access = &SA5_ioaccel_mode1_access;
51256 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51257 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51258 } else {
51259 if (trans_support & CFGTBL_Trans_io_accel2) {
51260 - access = SA5_ioaccel_mode2_access;
51261 + access = &SA5_ioaccel_mode2_access;
51262 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51263 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51264 }
51265 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51266 index 24472ce..8782caf 100644
51267 --- a/drivers/scsi/hpsa.h
51268 +++ b/drivers/scsi/hpsa.h
51269 @@ -127,7 +127,7 @@ struct ctlr_info {
51270 unsigned int msix_vector;
51271 unsigned int msi_vector;
51272 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51273 - struct access_method access;
51274 + struct access_method *access;
51275 char hba_mode_enabled;
51276
51277 /* queue and queue Info */
51278 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51279 }
51280
51281 static struct access_method SA5_access = {
51282 - SA5_submit_command,
51283 - SA5_intr_mask,
51284 - SA5_fifo_full,
51285 - SA5_intr_pending,
51286 - SA5_completed,
51287 + .submit_command = SA5_submit_command,
51288 + .set_intr_mask = SA5_intr_mask,
51289 + .fifo_full = SA5_fifo_full,
51290 + .intr_pending = SA5_intr_pending,
51291 + .command_completed = SA5_completed,
51292 };
51293
51294 static struct access_method SA5_ioaccel_mode1_access = {
51295 - SA5_submit_command,
51296 - SA5_performant_intr_mask,
51297 - SA5_fifo_full,
51298 - SA5_ioaccel_mode1_intr_pending,
51299 - SA5_ioaccel_mode1_completed,
51300 + .submit_command = SA5_submit_command,
51301 + .set_intr_mask = SA5_performant_intr_mask,
51302 + .fifo_full = SA5_fifo_full,
51303 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51304 + .command_completed = SA5_ioaccel_mode1_completed,
51305 };
51306
51307 static struct access_method SA5_ioaccel_mode2_access = {
51308 - SA5_submit_command_ioaccel2,
51309 - SA5_performant_intr_mask,
51310 - SA5_fifo_full,
51311 - SA5_performant_intr_pending,
51312 - SA5_performant_completed,
51313 + .submit_command = SA5_submit_command_ioaccel2,
51314 + .set_intr_mask = SA5_performant_intr_mask,
51315 + .fifo_full = SA5_fifo_full,
51316 + .intr_pending = SA5_performant_intr_pending,
51317 + .command_completed = SA5_performant_completed,
51318 };
51319
51320 static struct access_method SA5_performant_access = {
51321 - SA5_submit_command,
51322 - SA5_performant_intr_mask,
51323 - SA5_fifo_full,
51324 - SA5_performant_intr_pending,
51325 - SA5_performant_completed,
51326 + .submit_command = SA5_submit_command,
51327 + .set_intr_mask = SA5_performant_intr_mask,
51328 + .fifo_full = SA5_fifo_full,
51329 + .intr_pending = SA5_performant_intr_pending,
51330 + .command_completed = SA5_performant_completed,
51331 };
51332
51333 static struct access_method SA5_performant_access_no_read = {
51334 - SA5_submit_command_no_read,
51335 - SA5_performant_intr_mask,
51336 - SA5_fifo_full,
51337 - SA5_performant_intr_pending,
51338 - SA5_performant_completed,
51339 + .submit_command = SA5_submit_command_no_read,
51340 + .set_intr_mask = SA5_performant_intr_mask,
51341 + .fifo_full = SA5_fifo_full,
51342 + .intr_pending = SA5_performant_intr_pending,
51343 + .command_completed = SA5_performant_completed,
51344 };
51345
51346 struct board_type {
51347 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51348 index 1b3a094..068e683 100644
51349 --- a/drivers/scsi/libfc/fc_exch.c
51350 +++ b/drivers/scsi/libfc/fc_exch.c
51351 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51352 u16 pool_max_index;
51353
51354 struct {
51355 - atomic_t no_free_exch;
51356 - atomic_t no_free_exch_xid;
51357 - atomic_t xid_not_found;
51358 - atomic_t xid_busy;
51359 - atomic_t seq_not_found;
51360 - atomic_t non_bls_resp;
51361 + atomic_unchecked_t no_free_exch;
51362 + atomic_unchecked_t no_free_exch_xid;
51363 + atomic_unchecked_t xid_not_found;
51364 + atomic_unchecked_t xid_busy;
51365 + atomic_unchecked_t seq_not_found;
51366 + atomic_unchecked_t non_bls_resp;
51367 } stats;
51368 };
51369
51370 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51371 /* allocate memory for exchange */
51372 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51373 if (!ep) {
51374 - atomic_inc(&mp->stats.no_free_exch);
51375 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51376 goto out;
51377 }
51378 memset(ep, 0, sizeof(*ep));
51379 @@ -874,7 +874,7 @@ out:
51380 return ep;
51381 err:
51382 spin_unlock_bh(&pool->lock);
51383 - atomic_inc(&mp->stats.no_free_exch_xid);
51384 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51385 mempool_free(ep, mp->ep_pool);
51386 return NULL;
51387 }
51388 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51389 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51390 ep = fc_exch_find(mp, xid);
51391 if (!ep) {
51392 - atomic_inc(&mp->stats.xid_not_found);
51393 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51394 reject = FC_RJT_OX_ID;
51395 goto out;
51396 }
51397 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51398 ep = fc_exch_find(mp, xid);
51399 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51400 if (ep) {
51401 - atomic_inc(&mp->stats.xid_busy);
51402 + atomic_inc_unchecked(&mp->stats.xid_busy);
51403 reject = FC_RJT_RX_ID;
51404 goto rel;
51405 }
51406 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51407 }
51408 xid = ep->xid; /* get our XID */
51409 } else if (!ep) {
51410 - atomic_inc(&mp->stats.xid_not_found);
51411 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51412 reject = FC_RJT_RX_ID; /* XID not found */
51413 goto out;
51414 }
51415 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51416 } else {
51417 sp = &ep->seq;
51418 if (sp->id != fh->fh_seq_id) {
51419 - atomic_inc(&mp->stats.seq_not_found);
51420 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51421 if (f_ctl & FC_FC_END_SEQ) {
51422 /*
51423 * Update sequence_id based on incoming last
51424 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51425
51426 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51427 if (!ep) {
51428 - atomic_inc(&mp->stats.xid_not_found);
51429 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51430 goto out;
51431 }
51432 if (ep->esb_stat & ESB_ST_COMPLETE) {
51433 - atomic_inc(&mp->stats.xid_not_found);
51434 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51435 goto rel;
51436 }
51437 if (ep->rxid == FC_XID_UNKNOWN)
51438 ep->rxid = ntohs(fh->fh_rx_id);
51439 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51440 - atomic_inc(&mp->stats.xid_not_found);
51441 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51442 goto rel;
51443 }
51444 if (ep->did != ntoh24(fh->fh_s_id) &&
51445 ep->did != FC_FID_FLOGI) {
51446 - atomic_inc(&mp->stats.xid_not_found);
51447 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51448 goto rel;
51449 }
51450 sof = fr_sof(fp);
51451 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51452 sp->ssb_stat |= SSB_ST_RESP;
51453 sp->id = fh->fh_seq_id;
51454 } else if (sp->id != fh->fh_seq_id) {
51455 - atomic_inc(&mp->stats.seq_not_found);
51456 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51457 goto rel;
51458 }
51459
51460 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51461 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51462
51463 if (!sp)
51464 - atomic_inc(&mp->stats.xid_not_found);
51465 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51466 else
51467 - atomic_inc(&mp->stats.non_bls_resp);
51468 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51469
51470 fc_frame_free(fp);
51471 }
51472 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51473
51474 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51475 mp = ema->mp;
51476 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51477 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51478 st->fc_no_free_exch_xid +=
51479 - atomic_read(&mp->stats.no_free_exch_xid);
51480 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51481 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51482 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51483 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51484 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51485 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51486 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51487 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51488 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51489 }
51490 }
51491 EXPORT_SYMBOL(fc_exch_update_stats);
51492 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51493 index 766098a..1c6c971 100644
51494 --- a/drivers/scsi/libsas/sas_ata.c
51495 +++ b/drivers/scsi/libsas/sas_ata.c
51496 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51497 .postreset = ata_std_postreset,
51498 .error_handler = ata_std_error_handler,
51499 .post_internal_cmd = sas_ata_post_internal,
51500 - .qc_defer = ata_std_qc_defer,
51501 + .qc_defer = ata_std_qc_defer,
51502 .qc_prep = ata_noop_qc_prep,
51503 .qc_issue = sas_ata_qc_issue,
51504 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51505 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51506 index 434e903..5a4a79b 100644
51507 --- a/drivers/scsi/lpfc/lpfc.h
51508 +++ b/drivers/scsi/lpfc/lpfc.h
51509 @@ -430,7 +430,7 @@ struct lpfc_vport {
51510 struct dentry *debug_nodelist;
51511 struct dentry *vport_debugfs_root;
51512 struct lpfc_debugfs_trc *disc_trc;
51513 - atomic_t disc_trc_cnt;
51514 + atomic_unchecked_t disc_trc_cnt;
51515 #endif
51516 uint8_t stat_data_enabled;
51517 uint8_t stat_data_blocked;
51518 @@ -880,8 +880,8 @@ struct lpfc_hba {
51519 struct timer_list fabric_block_timer;
51520 unsigned long bit_flags;
51521 #define FABRIC_COMANDS_BLOCKED 0
51522 - atomic_t num_rsrc_err;
51523 - atomic_t num_cmd_success;
51524 + atomic_unchecked_t num_rsrc_err;
51525 + atomic_unchecked_t num_cmd_success;
51526 unsigned long last_rsrc_error_time;
51527 unsigned long last_ramp_down_time;
51528 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51529 @@ -916,7 +916,7 @@ struct lpfc_hba {
51530
51531 struct dentry *debug_slow_ring_trc;
51532 struct lpfc_debugfs_trc *slow_ring_trc;
51533 - atomic_t slow_ring_trc_cnt;
51534 + atomic_unchecked_t slow_ring_trc_cnt;
51535 /* iDiag debugfs sub-directory */
51536 struct dentry *idiag_root;
51537 struct dentry *idiag_pci_cfg;
51538 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51539 index 786a2af..562c6a2 100644
51540 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51541 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51542 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51543
51544 #include <linux/debugfs.h>
51545
51546 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51547 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51548 static unsigned long lpfc_debugfs_start_time = 0L;
51549
51550 /* iDiag */
51551 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51552 lpfc_debugfs_enable = 0;
51553
51554 len = 0;
51555 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51556 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51557 (lpfc_debugfs_max_disc_trc - 1);
51558 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51559 dtp = vport->disc_trc + i;
51560 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51561 lpfc_debugfs_enable = 0;
51562
51563 len = 0;
51564 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51565 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51566 (lpfc_debugfs_max_slow_ring_trc - 1);
51567 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51568 dtp = phba->slow_ring_trc + i;
51569 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51570 !vport || !vport->disc_trc)
51571 return;
51572
51573 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51574 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51575 (lpfc_debugfs_max_disc_trc - 1);
51576 dtp = vport->disc_trc + index;
51577 dtp->fmt = fmt;
51578 dtp->data1 = data1;
51579 dtp->data2 = data2;
51580 dtp->data3 = data3;
51581 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51582 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51583 dtp->jif = jiffies;
51584 #endif
51585 return;
51586 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51587 !phba || !phba->slow_ring_trc)
51588 return;
51589
51590 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51591 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51592 (lpfc_debugfs_max_slow_ring_trc - 1);
51593 dtp = phba->slow_ring_trc + index;
51594 dtp->fmt = fmt;
51595 dtp->data1 = data1;
51596 dtp->data2 = data2;
51597 dtp->data3 = data3;
51598 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51599 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51600 dtp->jif = jiffies;
51601 #endif
51602 return;
51603 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51604 "slow_ring buffer\n");
51605 goto debug_failed;
51606 }
51607 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51608 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51609 memset(phba->slow_ring_trc, 0,
51610 (sizeof(struct lpfc_debugfs_trc) *
51611 lpfc_debugfs_max_slow_ring_trc));
51612 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51613 "buffer\n");
51614 goto debug_failed;
51615 }
51616 - atomic_set(&vport->disc_trc_cnt, 0);
51617 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51618
51619 snprintf(name, sizeof(name), "discovery_trace");
51620 vport->debug_disc_trc =
51621 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51622 index 0b2c53a..aec2b45 100644
51623 --- a/drivers/scsi/lpfc/lpfc_init.c
51624 +++ b/drivers/scsi/lpfc/lpfc_init.c
51625 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51626 "misc_register returned with status %d", error);
51627
51628 if (lpfc_enable_npiv) {
51629 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51630 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51631 + pax_open_kernel();
51632 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51633 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51634 + pax_close_kernel();
51635 }
51636 lpfc_transport_template =
51637 fc_attach_transport(&lpfc_transport_functions);
51638 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51639 index b99399f..d29dc75 100644
51640 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51641 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51642 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51643 unsigned long expires;
51644
51645 spin_lock_irqsave(&phba->hbalock, flags);
51646 - atomic_inc(&phba->num_rsrc_err);
51647 + atomic_inc_unchecked(&phba->num_rsrc_err);
51648 phba->last_rsrc_error_time = jiffies;
51649
51650 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51651 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51652 unsigned long num_rsrc_err, num_cmd_success;
51653 int i;
51654
51655 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51656 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51657 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51658 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51659
51660 /*
51661 * The error and success command counters are global per
51662 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51663 }
51664 }
51665 lpfc_destroy_vport_work_array(phba, vports);
51666 - atomic_set(&phba->num_rsrc_err, 0);
51667 - atomic_set(&phba->num_cmd_success, 0);
51668 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51669 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51670 }
51671
51672 /**
51673 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51674 index c80ed04..e674f01 100644
51675 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51676 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51677 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51678 {
51679 struct scsi_device *sdev = to_scsi_device(dev);
51680 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51681 - static struct _raid_device *raid_device;
51682 + struct _raid_device *raid_device;
51683 unsigned long flags;
51684 Mpi2RaidVolPage0_t vol_pg0;
51685 Mpi2ConfigReply_t mpi_reply;
51686 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51687 {
51688 struct scsi_device *sdev = to_scsi_device(dev);
51689 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51690 - static struct _raid_device *raid_device;
51691 + struct _raid_device *raid_device;
51692 unsigned long flags;
51693 Mpi2RaidVolPage0_t vol_pg0;
51694 Mpi2ConfigReply_t mpi_reply;
51695 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51696 Mpi2EventDataIrOperationStatus_t *event_data =
51697 (Mpi2EventDataIrOperationStatus_t *)
51698 fw_event->event_data;
51699 - static struct _raid_device *raid_device;
51700 + struct _raid_device *raid_device;
51701 unsigned long flags;
51702 u16 handle;
51703
51704 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51705 u64 sas_address;
51706 struct _sas_device *sas_device;
51707 struct _sas_node *expander_device;
51708 - static struct _raid_device *raid_device;
51709 + struct _raid_device *raid_device;
51710 u8 retry_count;
51711 unsigned long flags;
51712
51713 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51714 index bcb64eb..f08cf71 100644
51715 --- a/drivers/scsi/pmcraid.c
51716 +++ b/drivers/scsi/pmcraid.c
51717 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51718 res->scsi_dev = scsi_dev;
51719 scsi_dev->hostdata = res;
51720 res->change_detected = 0;
51721 - atomic_set(&res->read_failures, 0);
51722 - atomic_set(&res->write_failures, 0);
51723 + atomic_set_unchecked(&res->read_failures, 0);
51724 + atomic_set_unchecked(&res->write_failures, 0);
51725 rc = 0;
51726 }
51727 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51728 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51729
51730 /* If this was a SCSI read/write command keep count of errors */
51731 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51732 - atomic_inc(&res->read_failures);
51733 + atomic_inc_unchecked(&res->read_failures);
51734 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51735 - atomic_inc(&res->write_failures);
51736 + atomic_inc_unchecked(&res->write_failures);
51737
51738 if (!RES_IS_GSCSI(res->cfg_entry) &&
51739 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51740 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51741 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51742 * hrrq_id assigned here in queuecommand
51743 */
51744 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51745 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51746 pinstance->num_hrrq;
51747 cmd->cmd_done = pmcraid_io_done;
51748
51749 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51750 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51751 * hrrq_id assigned here in queuecommand
51752 */
51753 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51754 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51755 pinstance->num_hrrq;
51756
51757 if (request_size) {
51758 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51759
51760 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51761 /* add resources only after host is added into system */
51762 - if (!atomic_read(&pinstance->expose_resources))
51763 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51764 return;
51765
51766 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51767 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51768 init_waitqueue_head(&pinstance->reset_wait_q);
51769
51770 atomic_set(&pinstance->outstanding_cmds, 0);
51771 - atomic_set(&pinstance->last_message_id, 0);
51772 - atomic_set(&pinstance->expose_resources, 0);
51773 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51774 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51775
51776 INIT_LIST_HEAD(&pinstance->free_res_q);
51777 INIT_LIST_HEAD(&pinstance->used_res_q);
51778 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51779 /* Schedule worker thread to handle CCN and take care of adding and
51780 * removing devices to OS
51781 */
51782 - atomic_set(&pinstance->expose_resources, 1);
51783 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51784 schedule_work(&pinstance->worker_q);
51785 return rc;
51786
51787 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51788 index e1d150f..6c6df44 100644
51789 --- a/drivers/scsi/pmcraid.h
51790 +++ b/drivers/scsi/pmcraid.h
51791 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51792 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51793
51794 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51795 - atomic_t last_message_id;
51796 + atomic_unchecked_t last_message_id;
51797
51798 /* configuration table */
51799 struct pmcraid_config_table *cfg_table;
51800 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51801 atomic_t outstanding_cmds;
51802
51803 /* should add/delete resources to mid-layer now ?*/
51804 - atomic_t expose_resources;
51805 + atomic_unchecked_t expose_resources;
51806
51807
51808
51809 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51810 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51811 };
51812 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51813 - atomic_t read_failures; /* count of failed READ commands */
51814 - atomic_t write_failures; /* count of failed WRITE commands */
51815 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51816 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51817
51818 /* To indicate add/delete/modify during CCN */
51819 u8 change_detected;
51820 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51821 index 82b92c4..3178171 100644
51822 --- a/drivers/scsi/qla2xxx/qla_attr.c
51823 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51824 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51825 return 0;
51826 }
51827
51828 -struct fc_function_template qla2xxx_transport_functions = {
51829 +fc_function_template_no_const qla2xxx_transport_functions = {
51830
51831 .show_host_node_name = 1,
51832 .show_host_port_name = 1,
51833 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51834 .bsg_timeout = qla24xx_bsg_timeout,
51835 };
51836
51837 -struct fc_function_template qla2xxx_transport_vport_functions = {
51838 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51839
51840 .show_host_node_name = 1,
51841 .show_host_port_name = 1,
51842 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51843 index b1865a7..a7723d3 100644
51844 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51845 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51846 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51847 struct device_attribute;
51848 extern struct device_attribute *qla2x00_host_attrs[];
51849 struct fc_function_template;
51850 -extern struct fc_function_template qla2xxx_transport_functions;
51851 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51852 +extern fc_function_template_no_const qla2xxx_transport_functions;
51853 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51854 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51855 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51856 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51857 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51858 index db3dbd9..2492392 100644
51859 --- a/drivers/scsi/qla2xxx/qla_os.c
51860 +++ b/drivers/scsi/qla2xxx/qla_os.c
51861 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51862 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51863 /* Ok, a 64bit DMA mask is applicable. */
51864 ha->flags.enable_64bit_addressing = 1;
51865 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51866 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51867 + pax_open_kernel();
51868 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51869 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51870 + pax_close_kernel();
51871 return;
51872 }
51873 }
51874 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51875 index 8f6d0fb..1b21097 100644
51876 --- a/drivers/scsi/qla4xxx/ql4_def.h
51877 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51878 @@ -305,7 +305,7 @@ struct ddb_entry {
51879 * (4000 only) */
51880 atomic_t relogin_timer; /* Max Time to wait for
51881 * relogin to complete */
51882 - atomic_t relogin_retry_count; /* Num of times relogin has been
51883 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51884 * retried */
51885 uint32_t default_time2wait; /* Default Min time between
51886 * relogins (+aens) */
51887 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51888 index 199fcf7..3c3a918 100644
51889 --- a/drivers/scsi/qla4xxx/ql4_os.c
51890 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51891 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51892 */
51893 if (!iscsi_is_session_online(cls_sess)) {
51894 /* Reset retry relogin timer */
51895 - atomic_inc(&ddb_entry->relogin_retry_count);
51896 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51897 DEBUG2(ql4_printk(KERN_INFO, ha,
51898 "%s: index[%d] relogin timed out-retrying"
51899 " relogin (%d), retry (%d)\n", __func__,
51900 ddb_entry->fw_ddb_index,
51901 - atomic_read(&ddb_entry->relogin_retry_count),
51902 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51903 ddb_entry->default_time2wait + 4));
51904 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51905 atomic_set(&ddb_entry->retry_relogin_timer,
51906 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51907
51908 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51909 atomic_set(&ddb_entry->relogin_timer, 0);
51910 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51911 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51912 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51913 ddb_entry->default_relogin_timeout =
51914 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51915 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51916 index 79c77b4..ef6ec0b 100644
51917 --- a/drivers/scsi/scsi.c
51918 +++ b/drivers/scsi/scsi.c
51919 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51920 struct Scsi_Host *host = cmd->device->host;
51921 int rtn = 0;
51922
51923 - atomic_inc(&cmd->device->iorequest_cnt);
51924 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51925
51926 /* check if the device is still usable */
51927 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51928 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51929 index 17fb051..937fbbd 100644
51930 --- a/drivers/scsi/scsi_lib.c
51931 +++ b/drivers/scsi/scsi_lib.c
51932 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51933 shost = sdev->host;
51934 scsi_init_cmd_errh(cmd);
51935 cmd->result = DID_NO_CONNECT << 16;
51936 - atomic_inc(&cmd->device->iorequest_cnt);
51937 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51938
51939 /*
51940 * SCSI request completion path will do scsi_device_unbusy(),
51941 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51942
51943 INIT_LIST_HEAD(&cmd->eh_entry);
51944
51945 - atomic_inc(&cmd->device->iodone_cnt);
51946 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51947 if (cmd->result)
51948 - atomic_inc(&cmd->device->ioerr_cnt);
51949 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51950
51951 disposition = scsi_decide_disposition(cmd);
51952 if (disposition != SUCCESS &&
51953 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51954 index f4cb7b3..dfa79c4 100644
51955 --- a/drivers/scsi/scsi_sysfs.c
51956 +++ b/drivers/scsi/scsi_sysfs.c
51957 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51958 char *buf) \
51959 { \
51960 struct scsi_device *sdev = to_scsi_device(dev); \
51961 - unsigned long long count = atomic_read(&sdev->field); \
51962 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51963 return snprintf(buf, 20, "0x%llx\n", count); \
51964 } \
51965 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51966 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51967 index 5d6f348..18778a6b 100644
51968 --- a/drivers/scsi/scsi_transport_fc.c
51969 +++ b/drivers/scsi/scsi_transport_fc.c
51970 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51971 * Netlink Infrastructure
51972 */
51973
51974 -static atomic_t fc_event_seq;
51975 +static atomic_unchecked_t fc_event_seq;
51976
51977 /**
51978 * fc_get_event_number - Obtain the next sequential FC event number
51979 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51980 u32
51981 fc_get_event_number(void)
51982 {
51983 - return atomic_add_return(1, &fc_event_seq);
51984 + return atomic_add_return_unchecked(1, &fc_event_seq);
51985 }
51986 EXPORT_SYMBOL(fc_get_event_number);
51987
51988 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51989 {
51990 int error;
51991
51992 - atomic_set(&fc_event_seq, 0);
51993 + atomic_set_unchecked(&fc_event_seq, 0);
51994
51995 error = transport_class_register(&fc_host_class);
51996 if (error)
51997 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51998 char *cp;
51999
52000 *val = simple_strtoul(buf, &cp, 0);
52001 - if ((*cp && (*cp != '\n')) || (*val < 0))
52002 + if (*cp && (*cp != '\n'))
52003 return -EINVAL;
52004 /*
52005 * Check for overflow; dev_loss_tmo is u32
52006 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52007 index 67d43e3..8cee73c 100644
52008 --- a/drivers/scsi/scsi_transport_iscsi.c
52009 +++ b/drivers/scsi/scsi_transport_iscsi.c
52010 @@ -79,7 +79,7 @@ struct iscsi_internal {
52011 struct transport_container session_cont;
52012 };
52013
52014 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52015 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52016 static struct workqueue_struct *iscsi_eh_timer_workq;
52017
52018 static DEFINE_IDA(iscsi_sess_ida);
52019 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52020 int err;
52021
52022 ihost = shost->shost_data;
52023 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52024 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52025
52026 if (target_id == ISCSI_MAX_TARGET) {
52027 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52028 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52029 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52030 ISCSI_TRANSPORT_VERSION);
52031
52032 - atomic_set(&iscsi_session_nr, 0);
52033 + atomic_set_unchecked(&iscsi_session_nr, 0);
52034
52035 err = class_register(&iscsi_transport_class);
52036 if (err)
52037 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52038 index ae45bd9..c32a586 100644
52039 --- a/drivers/scsi/scsi_transport_srp.c
52040 +++ b/drivers/scsi/scsi_transport_srp.c
52041 @@ -35,7 +35,7 @@
52042 #include "scsi_priv.h"
52043
52044 struct srp_host_attrs {
52045 - atomic_t next_port_id;
52046 + atomic_unchecked_t next_port_id;
52047 };
52048 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52049
52050 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52051 struct Scsi_Host *shost = dev_to_shost(dev);
52052 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52053
52054 - atomic_set(&srp_host->next_port_id, 0);
52055 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52056 return 0;
52057 }
52058
52059 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52060 rport_fast_io_fail_timedout);
52061 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52062
52063 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52064 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52065 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52066
52067 transport_setup_device(&rport->dev);
52068 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52069 index dd8c8d6..4cdf6a1 100644
52070 --- a/drivers/scsi/sd.c
52071 +++ b/drivers/scsi/sd.c
52072 @@ -3024,7 +3024,7 @@ static int sd_probe(struct device *dev)
52073 sdkp->disk = gd;
52074 sdkp->index = index;
52075 atomic_set(&sdkp->openers, 0);
52076 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52077 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52078
52079 if (!sdp->request_queue->rq_timeout) {
52080 if (sdp->type != TYPE_MOD)
52081 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52082 index 6035444..c82edd4 100644
52083 --- a/drivers/scsi/sg.c
52084 +++ b/drivers/scsi/sg.c
52085 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52086 sdp->disk->disk_name,
52087 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52088 NULL,
52089 - (char *)arg);
52090 + (char __user *)arg);
52091 case BLKTRACESTART:
52092 return blk_trace_startstop(sdp->device->request_queue, 1);
52093 case BLKTRACESTOP:
52094 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52095 index 11a5043..e36f04c 100644
52096 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52097 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52098 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52099 return i;
52100 }
52101
52102 -static struct bin_attribute fuse_bin_attr = {
52103 +static bin_attribute_no_const fuse_bin_attr = {
52104 .attr = { .name = "fuse", .mode = S_IRUGO, },
52105 .read = fuse_read,
52106 };
52107 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52108 index 50f20f2..6bd81e0 100644
52109 --- a/drivers/spi/spi.c
52110 +++ b/drivers/spi/spi.c
52111 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
52112 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52113
52114 /* portable code must never pass more than 32 bytes */
52115 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52116 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52117
52118 static u8 *buf;
52119
52120 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52121 index b41429f..2de5373 100644
52122 --- a/drivers/staging/android/timed_output.c
52123 +++ b/drivers/staging/android/timed_output.c
52124 @@ -25,7 +25,7 @@
52125 #include "timed_output.h"
52126
52127 static struct class *timed_output_class;
52128 -static atomic_t device_count;
52129 +static atomic_unchecked_t device_count;
52130
52131 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52132 char *buf)
52133 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52134 timed_output_class = class_create(THIS_MODULE, "timed_output");
52135 if (IS_ERR(timed_output_class))
52136 return PTR_ERR(timed_output_class);
52137 - atomic_set(&device_count, 0);
52138 + atomic_set_unchecked(&device_count, 0);
52139 timed_output_class->dev_groups = timed_output_groups;
52140 }
52141
52142 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52143 if (ret < 0)
52144 return ret;
52145
52146 - tdev->index = atomic_inc_return(&device_count);
52147 + tdev->index = atomic_inc_return_unchecked(&device_count);
52148 tdev->dev = device_create(timed_output_class, NULL,
52149 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52150 if (IS_ERR(tdev->dev))
52151 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52152 index 001348c..cfaac8a 100644
52153 --- a/drivers/staging/gdm724x/gdm_tty.c
52154 +++ b/drivers/staging/gdm724x/gdm_tty.c
52155 @@ -44,7 +44,7 @@
52156 #define gdm_tty_send_control(n, r, v, d, l) (\
52157 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52158
52159 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52160 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52161
52162 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52163 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52164 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52165 index 9cb222e..8766f26 100644
52166 --- a/drivers/staging/imx-drm/imx-drm-core.c
52167 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52168 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52169 if (imxdrm->pipes >= MAX_CRTC)
52170 return -EINVAL;
52171
52172 - if (imxdrm->drm->open_count)
52173 + if (local_read(&imxdrm->drm->open_count))
52174 return -EBUSY;
52175
52176 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52177 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52178 index 503b2d7..c904931 100644
52179 --- a/drivers/staging/line6/driver.c
52180 +++ b/drivers/staging/line6/driver.c
52181 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52182 {
52183 struct usb_device *usbdev = line6->usbdev;
52184 int ret;
52185 - unsigned char len;
52186 + unsigned char *plen;
52187
52188 /* query the serial number: */
52189 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52190 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52191 return ret;
52192 }
52193
52194 + plen = kmalloc(1, GFP_KERNEL);
52195 + if (plen == NULL)
52196 + return -ENOMEM;
52197 +
52198 /* Wait for data length. We'll get 0xff until length arrives. */
52199 do {
52200 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52201 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52202 USB_DIR_IN,
52203 - 0x0012, 0x0000, &len, 1,
52204 + 0x0012, 0x0000, plen, 1,
52205 LINE6_TIMEOUT * HZ);
52206 if (ret < 0) {
52207 dev_err(line6->ifcdev,
52208 "receive length failed (error %d)\n", ret);
52209 + kfree(plen);
52210 return ret;
52211 }
52212 - } while (len == 0xff);
52213 + } while (*plen == 0xff);
52214
52215 - if (len != datalen) {
52216 + if (*plen != datalen) {
52217 /* should be equal or something went wrong */
52218 dev_err(line6->ifcdev,
52219 "length mismatch (expected %d, got %d)\n",
52220 - (int)datalen, (int)len);
52221 + (int)datalen, (int)*plen);
52222 + kfree(plen);
52223 return -EINVAL;
52224 }
52225 + kfree(plen);
52226
52227 /* receive the result: */
52228 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52229 @@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52230 {
52231 struct usb_device *usbdev = line6->usbdev;
52232 int ret;
52233 - unsigned char status;
52234 + unsigned char *status;
52235
52236 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52237 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52238 @@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52239 return ret;
52240 }
52241
52242 + status = kmalloc(1, GFP_KERNEL);
52243 + if (status == NULL)
52244 + return -ENOMEM;
52245 +
52246 do {
52247 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52248 0x67,
52249 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52250 USB_DIR_IN,
52251 0x0012, 0x0000,
52252 - &status, 1, LINE6_TIMEOUT * HZ);
52253 + status, 1, LINE6_TIMEOUT * HZ);
52254
52255 if (ret < 0) {
52256 dev_err(line6->ifcdev,
52257 "receiving status failed (error %d)\n", ret);
52258 + kfree(status);
52259 return ret;
52260 }
52261 - } while (status == 0xff);
52262 + } while (*status == 0xff);
52263
52264 - if (status != 0) {
52265 + if (*status != 0) {
52266 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52267 + kfree(status);
52268 return -EINVAL;
52269 }
52270
52271 + kfree(status);
52272 +
52273 return 0;
52274 }
52275
52276 diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52277 index 6943715..0a93632 100644
52278 --- a/drivers/staging/line6/toneport.c
52279 +++ b/drivers/staging/line6/toneport.c
52280 @@ -11,6 +11,7 @@
52281 */
52282
52283 #include <linux/wait.h>
52284 +#include <linux/slab.h>
52285 #include <sound/control.h>
52286
52287 #include "audio.h"
52288 @@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52289 */
52290 static void toneport_setup(struct usb_line6_toneport *toneport)
52291 {
52292 - int ticks;
52293 + int *ticks;
52294 struct usb_line6 *line6 = &toneport->line6;
52295 struct usb_device *usbdev = line6->usbdev;
52296 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52297
52298 + ticks = kmalloc(sizeof(int), GFP_KERNEL);
52299 + if (ticks == NULL)
52300 + return;
52301 +
52302 /* sync time on device with host: */
52303 - ticks = (int)get_seconds();
52304 - line6_write_data(line6, 0x80c6, &ticks, 4);
52305 + *ticks = (int)get_seconds();
52306 + line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52307 +
52308 + kfree(ticks);
52309
52310 /* enable device: */
52311 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52312 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52313 index a94f336..6a1924d 100644
52314 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52315 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52316 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52317 return 0;
52318 }
52319
52320 -sfw_test_client_ops_t brw_test_client;
52321 -void brw_init_test_client(void)
52322 -{
52323 - brw_test_client.tso_init = brw_client_init;
52324 - brw_test_client.tso_fini = brw_client_fini;
52325 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52326 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52327 +sfw_test_client_ops_t brw_test_client = {
52328 + .tso_init = brw_client_init,
52329 + .tso_fini = brw_client_fini,
52330 + .tso_prep_rpc = brw_client_prep_rpc,
52331 + .tso_done_rpc = brw_client_done_rpc,
52332 };
52333
52334 srpc_service_t brw_test_service;
52335 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52336 index df04ab7..1deb1ac 100644
52337 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52338 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52339 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52340
52341 extern sfw_test_client_ops_t ping_test_client;
52342 extern srpc_service_t ping_test_service;
52343 -extern void ping_init_test_client(void);
52344 extern void ping_init_test_service(void);
52345
52346 extern sfw_test_client_ops_t brw_test_client;
52347 extern srpc_service_t brw_test_service;
52348 -extern void brw_init_test_client(void);
52349 extern void brw_init_test_service(void);
52350
52351
52352 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52353 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52354 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52355
52356 - brw_init_test_client();
52357 brw_init_test_service();
52358 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52359 LASSERT (rc == 0);
52360
52361 - ping_init_test_client();
52362 ping_init_test_service();
52363 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52364 LASSERT (rc == 0);
52365 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52366 index 750cac4..e4d751f 100644
52367 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52368 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52369 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52370 return 0;
52371 }
52372
52373 -sfw_test_client_ops_t ping_test_client;
52374 -void ping_init_test_client(void)
52375 -{
52376 - ping_test_client.tso_init = ping_client_init;
52377 - ping_test_client.tso_fini = ping_client_fini;
52378 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52379 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52380 -}
52381 +sfw_test_client_ops_t ping_test_client = {
52382 + .tso_init = ping_client_init,
52383 + .tso_fini = ping_client_fini,
52384 + .tso_prep_rpc = ping_client_prep_rpc,
52385 + .tso_done_rpc = ping_client_done_rpc,
52386 +};
52387
52388 srpc_service_t ping_test_service;
52389 void ping_init_test_service(void)
52390 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52391 index 14ac46f..eca2c16 100644
52392 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52393 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52394 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52395 ldlm_completion_callback lcs_completion;
52396 ldlm_blocking_callback lcs_blocking;
52397 ldlm_glimpse_callback lcs_glimpse;
52398 -};
52399 +} __no_const;
52400
52401 /* ldlm_lockd.c */
52402 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52403 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52404 index 2a88b80..62e7e5f 100644
52405 --- a/drivers/staging/lustre/lustre/include/obd.h
52406 +++ b/drivers/staging/lustre/lustre/include/obd.h
52407 @@ -1362,7 +1362,7 @@ struct md_ops {
52408 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52409 * wrapper function in include/linux/obd_class.h.
52410 */
52411 -};
52412 +} __no_const;
52413
52414 struct lsm_operations {
52415 void (*lsm_free)(struct lov_stripe_md *);
52416 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52417 index b798daa..b28ca8f 100644
52418 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52419 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52420 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52421 int added = (mode == LCK_NL);
52422 int overlaps = 0;
52423 int splitted = 0;
52424 - const struct ldlm_callback_suite null_cbs = { NULL };
52425 + const struct ldlm_callback_suite null_cbs = { };
52426
52427 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52428 *flags, new->l_policy_data.l_flock.owner,
52429 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52430 index bbe2c68..c6b4275 100644
52431 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52432 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52433 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52434 void __user *buffer, size_t *lenp, loff_t *ppos)
52435 {
52436 int rc, max_delay_cs;
52437 - struct ctl_table dummy = *table;
52438 + ctl_table_no_const dummy = *table;
52439 long d;
52440
52441 dummy.data = &max_delay_cs;
52442 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52443 void __user *buffer, size_t *lenp, loff_t *ppos)
52444 {
52445 int rc, min_delay_cs;
52446 - struct ctl_table dummy = *table;
52447 + ctl_table_no_const dummy = *table;
52448 long d;
52449
52450 dummy.data = &min_delay_cs;
52451 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52452 void __user *buffer, size_t *lenp, loff_t *ppos)
52453 {
52454 int rc, backoff;
52455 - struct ctl_table dummy = *table;
52456 + ctl_table_no_const dummy = *table;
52457
52458 dummy.data = &backoff;
52459 dummy.proc_handler = &proc_dointvec;
52460 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52461 index 2c4fc74..b04ca79 100644
52462 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52463 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52464 @@ -315,11 +315,11 @@ out:
52465
52466
52467 struct cfs_psdev_ops libcfs_psdev_ops = {
52468 - libcfs_psdev_open,
52469 - libcfs_psdev_release,
52470 - NULL,
52471 - NULL,
52472 - libcfs_ioctl
52473 + .p_open = libcfs_psdev_open,
52474 + .p_close = libcfs_psdev_release,
52475 + .p_read = NULL,
52476 + .p_write = NULL,
52477 + .p_ioctl = libcfs_ioctl
52478 };
52479
52480 extern int insert_proc(void);
52481 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52482 index b0bb709..0117c96 100644
52483 --- a/drivers/staging/lustre/lustre/llite/dir.c
52484 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52485 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52486 int mode;
52487 int err;
52488
52489 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52490 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52491 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52492 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52493 lump);
52494 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52495 index b2b6c3c..302e4e4 100644
52496 --- a/drivers/staging/octeon/ethernet-rx.c
52497 +++ b/drivers/staging/octeon/ethernet-rx.c
52498 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52499 /* Increment RX stats for virtual ports */
52500 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52501 #ifdef CONFIG_64BIT
52502 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52503 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52504 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52505 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52506 #else
52507 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52508 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52509 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52510 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52511 #endif
52512 }
52513 netif_receive_skb(skb);
52514 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52515 dev->name);
52516 */
52517 #ifdef CONFIG_64BIT
52518 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52519 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52520 #else
52521 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52522 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52523 #endif
52524 dev_kfree_skb_irq(skb);
52525 }
52526 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52527 index 8f9e3fb..d283fb9 100644
52528 --- a/drivers/staging/octeon/ethernet.c
52529 +++ b/drivers/staging/octeon/ethernet.c
52530 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52531 * since the RX tasklet also increments it.
52532 */
52533 #ifdef CONFIG_64BIT
52534 - atomic64_add(rx_status.dropped_packets,
52535 - (atomic64_t *)&priv->stats.rx_dropped);
52536 + atomic64_add_unchecked(rx_status.dropped_packets,
52537 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52538 #else
52539 - atomic_add(rx_status.dropped_packets,
52540 - (atomic_t *)&priv->stats.rx_dropped);
52541 + atomic_add_unchecked(rx_status.dropped_packets,
52542 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52543 #endif
52544 }
52545
52546 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52547 index 9191993..30e9817 100644
52548 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52549 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52550 @@ -225,7 +225,7 @@ struct hal_ops {
52551
52552 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52553 void (*hal_reset_security_engine)(struct adapter *adapter);
52554 -};
52555 +} __no_const;
52556
52557 enum rt_eeprom_type {
52558 EEPROM_93C46,
52559 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52560 index 070cc03..6806e37 100644
52561 --- a/drivers/staging/rtl8712/rtl871x_io.h
52562 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52563 @@ -108,7 +108,7 @@ struct _io_ops {
52564 u8 *pmem);
52565 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52566 u8 *pmem);
52567 -};
52568 +} __no_const;
52569
52570 struct io_req {
52571 struct list_head list;
52572 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52573 index 2bf2e2f..84421c9 100644
52574 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52575 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52576 @@ -228,7 +228,7 @@ typedef struct {
52577 void (*device_resume)(ulong busNo, ulong devNo);
52578 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52579 ulong *maxSize);
52580 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52581 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52582
52583 /* These functions live inside visorchipset, and will be called to indicate
52584 * responses to specific events (by code outside of visorchipset).
52585 @@ -243,7 +243,7 @@ typedef struct {
52586 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52587 void (*device_pause)(ulong busNo, ulong devNo, int response);
52588 void (*device_resume)(ulong busNo, ulong devNo, int response);
52589 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52590 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52591
52592 /** Register functions (in the bus driver) to get called by visorchipset
52593 * whenever a bus or device appears for which this service partition is
52594 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52595 index ae0dade..803d53a 100644
52596 --- a/drivers/staging/vt6655/hostap.c
52597 +++ b/drivers/staging/vt6655/hostap.c
52598 @@ -65,14 +65,13 @@
52599 *
52600 */
52601
52602 +static net_device_ops_no_const apdev_netdev_ops;
52603 +
52604 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52605 {
52606 struct vnt_private *apdev_priv;
52607 struct net_device *dev = pDevice->dev;
52608 int ret;
52609 - const struct net_device_ops apdev_netdev_ops = {
52610 - .ndo_start_xmit = pDevice->tx_80211,
52611 - };
52612
52613 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52614
52615 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52616 *apdev_priv = *pDevice;
52617 eth_hw_addr_inherit(pDevice->apdev, dev);
52618
52619 + /* only half broken now */
52620 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52621 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52622
52623 pDevice->apdev->type = ARPHRD_IEEE80211;
52624 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52625 index e7e9372..161f530 100644
52626 --- a/drivers/target/sbp/sbp_target.c
52627 +++ b/drivers/target/sbp/sbp_target.c
52628 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52629
52630 #define SESSION_MAINTENANCE_INTERVAL HZ
52631
52632 -static atomic_t login_id = ATOMIC_INIT(0);
52633 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52634
52635 static void session_maintenance_work(struct work_struct *);
52636 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52637 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52638 login->lun = se_lun;
52639 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52640 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52641 - login->login_id = atomic_inc_return(&login_id);
52642 + login->login_id = atomic_inc_return_unchecked(&login_id);
52643
52644 login->tgt_agt = sbp_target_agent_register(login);
52645 if (IS_ERR(login->tgt_agt)) {
52646 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52647 index 24fa5d1..fae56f1 100644
52648 --- a/drivers/target/target_core_device.c
52649 +++ b/drivers/target/target_core_device.c
52650 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52651 spin_lock_init(&dev->se_tmr_lock);
52652 spin_lock_init(&dev->qf_cmd_lock);
52653 sema_init(&dev->caw_sem, 1);
52654 - atomic_set(&dev->dev_ordered_id, 0);
52655 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52656 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52657 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52658 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52659 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52660 index be877bf..7be9cd4 100644
52661 --- a/drivers/target/target_core_transport.c
52662 +++ b/drivers/target/target_core_transport.c
52663 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52664 * Used to determine when ORDERED commands should go from
52665 * Dormant to Active status.
52666 */
52667 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52668 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52669 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52670 cmd->se_ordered_id, cmd->sam_task_attr,
52671 dev->transport->name);
52672 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52673 index edc1cce..769e4cb 100644
52674 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52675 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52676 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52677 platform_set_drvdata(pdev, priv);
52678
52679 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52680 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52681 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52682 + pax_open_kernel();
52683 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52684 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52685 + pax_close_kernel();
52686 }
52687 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52688 priv, &int3400_thermal_ops,
52689 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52690 index 62143ba..ae21165 100644
52691 --- a/drivers/thermal/of-thermal.c
52692 +++ b/drivers/thermal/of-thermal.c
52693 @@ -30,6 +30,7 @@
52694 #include <linux/err.h>
52695 #include <linux/export.h>
52696 #include <linux/string.h>
52697 +#include <linux/mm.h>
52698
52699 #include "thermal_core.h"
52700
52701 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52702 tz->get_trend = get_trend;
52703 tz->sensor_data = data;
52704
52705 - tzd->ops->get_temp = of_thermal_get_temp;
52706 - tzd->ops->get_trend = of_thermal_get_trend;
52707 + pax_open_kernel();
52708 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52709 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52710 + pax_close_kernel();
52711 mutex_unlock(&tzd->lock);
52712
52713 return tzd;
52714 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52715 return;
52716
52717 mutex_lock(&tzd->lock);
52718 - tzd->ops->get_temp = NULL;
52719 - tzd->ops->get_trend = NULL;
52720 + pax_open_kernel();
52721 + *(void **)&tzd->ops->get_temp = NULL;
52722 + *(void **)&tzd->ops->get_trend = NULL;
52723 + pax_close_kernel();
52724
52725 tz->get_temp = NULL;
52726 tz->get_trend = NULL;
52727 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52728 index fd66f57..48e6376 100644
52729 --- a/drivers/tty/cyclades.c
52730 +++ b/drivers/tty/cyclades.c
52731 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52732 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52733 info->port.count);
52734 #endif
52735 - info->port.count++;
52736 + atomic_inc(&info->port.count);
52737 #ifdef CY_DEBUG_COUNT
52738 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52739 - current->pid, info->port.count);
52740 + current->pid, atomic_read(&info->port.count));
52741 #endif
52742
52743 /*
52744 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52745 for (j = 0; j < cy_card[i].nports; j++) {
52746 info = &cy_card[i].ports[j];
52747
52748 - if (info->port.count) {
52749 + if (atomic_read(&info->port.count)) {
52750 /* XXX is the ldisc num worth this? */
52751 struct tty_struct *tty;
52752 struct tty_ldisc *ld;
52753 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52754 index 4fcec1d..5a036f7 100644
52755 --- a/drivers/tty/hvc/hvc_console.c
52756 +++ b/drivers/tty/hvc/hvc_console.c
52757 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52758
52759 spin_lock_irqsave(&hp->port.lock, flags);
52760 /* Check and then increment for fast path open. */
52761 - if (hp->port.count++ > 0) {
52762 + if (atomic_inc_return(&hp->port.count) > 1) {
52763 spin_unlock_irqrestore(&hp->port.lock, flags);
52764 hvc_kick();
52765 return 0;
52766 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52767
52768 spin_lock_irqsave(&hp->port.lock, flags);
52769
52770 - if (--hp->port.count == 0) {
52771 + if (atomic_dec_return(&hp->port.count) == 0) {
52772 spin_unlock_irqrestore(&hp->port.lock, flags);
52773 /* We are done with the tty pointer now. */
52774 tty_port_tty_set(&hp->port, NULL);
52775 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52776 */
52777 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52778 } else {
52779 - if (hp->port.count < 0)
52780 + if (atomic_read(&hp->port.count) < 0)
52781 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52782 - hp->vtermno, hp->port.count);
52783 + hp->vtermno, atomic_read(&hp->port.count));
52784 spin_unlock_irqrestore(&hp->port.lock, flags);
52785 }
52786 }
52787 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52788 * open->hangup case this can be called after the final close so prevent
52789 * that from happening for now.
52790 */
52791 - if (hp->port.count <= 0) {
52792 + if (atomic_read(&hp->port.count) <= 0) {
52793 spin_unlock_irqrestore(&hp->port.lock, flags);
52794 return;
52795 }
52796
52797 - hp->port.count = 0;
52798 + atomic_set(&hp->port.count, 0);
52799 spin_unlock_irqrestore(&hp->port.lock, flags);
52800 tty_port_tty_set(&hp->port, NULL);
52801
52802 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52803 return -EPIPE;
52804
52805 /* FIXME what's this (unprotected) check for? */
52806 - if (hp->port.count <= 0)
52807 + if (atomic_read(&hp->port.count) <= 0)
52808 return -EIO;
52809
52810 spin_lock_irqsave(&hp->lock, flags);
52811 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52812 index 81e939e..95ead10 100644
52813 --- a/drivers/tty/hvc/hvcs.c
52814 +++ b/drivers/tty/hvc/hvcs.c
52815 @@ -83,6 +83,7 @@
52816 #include <asm/hvcserver.h>
52817 #include <asm/uaccess.h>
52818 #include <asm/vio.h>
52819 +#include <asm/local.h>
52820
52821 /*
52822 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52823 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52824
52825 spin_lock_irqsave(&hvcsd->lock, flags);
52826
52827 - if (hvcsd->port.count > 0) {
52828 + if (atomic_read(&hvcsd->port.count) > 0) {
52829 spin_unlock_irqrestore(&hvcsd->lock, flags);
52830 printk(KERN_INFO "HVCS: vterm state unchanged. "
52831 "The hvcs device node is still in use.\n");
52832 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52833 }
52834 }
52835
52836 - hvcsd->port.count = 0;
52837 + atomic_set(&hvcsd->port.count, 0);
52838 hvcsd->port.tty = tty;
52839 tty->driver_data = hvcsd;
52840
52841 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52842 unsigned long flags;
52843
52844 spin_lock_irqsave(&hvcsd->lock, flags);
52845 - hvcsd->port.count++;
52846 + atomic_inc(&hvcsd->port.count);
52847 hvcsd->todo_mask |= HVCS_SCHED_READ;
52848 spin_unlock_irqrestore(&hvcsd->lock, flags);
52849
52850 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52851 hvcsd = tty->driver_data;
52852
52853 spin_lock_irqsave(&hvcsd->lock, flags);
52854 - if (--hvcsd->port.count == 0) {
52855 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52856
52857 vio_disable_interrupts(hvcsd->vdev);
52858
52859 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52860
52861 free_irq(irq, hvcsd);
52862 return;
52863 - } else if (hvcsd->port.count < 0) {
52864 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52865 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52866 " is missmanaged.\n",
52867 - hvcsd->vdev->unit_address, hvcsd->port.count);
52868 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52869 }
52870
52871 spin_unlock_irqrestore(&hvcsd->lock, flags);
52872 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52873
52874 spin_lock_irqsave(&hvcsd->lock, flags);
52875 /* Preserve this so that we know how many kref refs to put */
52876 - temp_open_count = hvcsd->port.count;
52877 + temp_open_count = atomic_read(&hvcsd->port.count);
52878
52879 /*
52880 * Don't kref put inside the spinlock because the destruction
52881 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52882 tty->driver_data = NULL;
52883 hvcsd->port.tty = NULL;
52884
52885 - hvcsd->port.count = 0;
52886 + atomic_set(&hvcsd->port.count, 0);
52887
52888 /* This will drop any buffered data on the floor which is OK in a hangup
52889 * scenario. */
52890 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52891 * the middle of a write operation? This is a crummy place to do this
52892 * but we want to keep it all in the spinlock.
52893 */
52894 - if (hvcsd->port.count <= 0) {
52895 + if (atomic_read(&hvcsd->port.count) <= 0) {
52896 spin_unlock_irqrestore(&hvcsd->lock, flags);
52897 return -ENODEV;
52898 }
52899 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52900 {
52901 struct hvcs_struct *hvcsd = tty->driver_data;
52902
52903 - if (!hvcsd || hvcsd->port.count <= 0)
52904 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52905 return 0;
52906
52907 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52908 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52909 index 4190199..06d5bfa 100644
52910 --- a/drivers/tty/hvc/hvsi.c
52911 +++ b/drivers/tty/hvc/hvsi.c
52912 @@ -85,7 +85,7 @@ struct hvsi_struct {
52913 int n_outbuf;
52914 uint32_t vtermno;
52915 uint32_t virq;
52916 - atomic_t seqno; /* HVSI packet sequence number */
52917 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52918 uint16_t mctrl;
52919 uint8_t state; /* HVSI protocol state */
52920 uint8_t flags;
52921 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52922
52923 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52924 packet.hdr.len = sizeof(struct hvsi_query_response);
52925 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52926 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52927 packet.verb = VSV_SEND_VERSION_NUMBER;
52928 packet.u.version = HVSI_VERSION;
52929 packet.query_seqno = query_seqno+1;
52930 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52931
52932 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52933 packet.hdr.len = sizeof(struct hvsi_query);
52934 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52935 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52936 packet.verb = verb;
52937
52938 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52939 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52940 int wrote;
52941
52942 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52943 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52944 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52945 packet.hdr.len = sizeof(struct hvsi_control);
52946 packet.verb = VSV_SET_MODEM_CTL;
52947 packet.mask = HVSI_TSDTR;
52948 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52949 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52950
52951 packet.hdr.type = VS_DATA_PACKET_HEADER;
52952 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52953 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52954 packet.hdr.len = count + sizeof(struct hvsi_header);
52955 memcpy(&packet.data, buf, count);
52956
52957 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52958 struct hvsi_control packet __ALIGNED__;
52959
52960 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52961 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52962 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52963 packet.hdr.len = 6;
52964 packet.verb = VSV_CLOSE_PROTOCOL;
52965
52966 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52967
52968 tty_port_tty_set(&hp->port, tty);
52969 spin_lock_irqsave(&hp->lock, flags);
52970 - hp->port.count++;
52971 + atomic_inc(&hp->port.count);
52972 atomic_set(&hp->seqno, 0);
52973 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52974 spin_unlock_irqrestore(&hp->lock, flags);
52975 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52976
52977 spin_lock_irqsave(&hp->lock, flags);
52978
52979 - if (--hp->port.count == 0) {
52980 + if (atomic_dec_return(&hp->port.count) == 0) {
52981 tty_port_tty_set(&hp->port, NULL);
52982 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52983
52984 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52985
52986 spin_lock_irqsave(&hp->lock, flags);
52987 }
52988 - } else if (hp->port.count < 0)
52989 + } else if (atomic_read(&hp->port.count) < 0)
52990 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52991 - hp - hvsi_ports, hp->port.count);
52992 + hp - hvsi_ports, atomic_read(&hp->port.count));
52993
52994 spin_unlock_irqrestore(&hp->lock, flags);
52995 }
52996 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52997 tty_port_tty_set(&hp->port, NULL);
52998
52999 spin_lock_irqsave(&hp->lock, flags);
53000 - hp->port.count = 0;
53001 + atomic_set(&hp->port.count, 0);
53002 hp->n_outbuf = 0;
53003 spin_unlock_irqrestore(&hp->lock, flags);
53004 }
53005 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53006 index 7ae6c29..05c6dba 100644
53007 --- a/drivers/tty/hvc/hvsi_lib.c
53008 +++ b/drivers/tty/hvc/hvsi_lib.c
53009 @@ -8,7 +8,7 @@
53010
53011 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53012 {
53013 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53014 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53015
53016 /* Assumes that always succeeds, works in practice */
53017 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53018 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53019
53020 /* Reset state */
53021 pv->established = 0;
53022 - atomic_set(&pv->seqno, 0);
53023 + atomic_set_unchecked(&pv->seqno, 0);
53024
53025 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53026
53027 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53028 index 345cebb..d5a1e9e 100644
53029 --- a/drivers/tty/ipwireless/tty.c
53030 +++ b/drivers/tty/ipwireless/tty.c
53031 @@ -28,6 +28,7 @@
53032 #include <linux/tty_driver.h>
53033 #include <linux/tty_flip.h>
53034 #include <linux/uaccess.h>
53035 +#include <asm/local.h>
53036
53037 #include "tty.h"
53038 #include "network.h"
53039 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53040 return -ENODEV;
53041
53042 mutex_lock(&tty->ipw_tty_mutex);
53043 - if (tty->port.count == 0)
53044 + if (atomic_read(&tty->port.count) == 0)
53045 tty->tx_bytes_queued = 0;
53046
53047 - tty->port.count++;
53048 + atomic_inc(&tty->port.count);
53049
53050 tty->port.tty = linux_tty;
53051 linux_tty->driver_data = tty;
53052 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53053
53054 static void do_ipw_close(struct ipw_tty *tty)
53055 {
53056 - tty->port.count--;
53057 -
53058 - if (tty->port.count == 0) {
53059 + if (atomic_dec_return(&tty->port.count) == 0) {
53060 struct tty_struct *linux_tty = tty->port.tty;
53061
53062 if (linux_tty != NULL) {
53063 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53064 return;
53065
53066 mutex_lock(&tty->ipw_tty_mutex);
53067 - if (tty->port.count == 0) {
53068 + if (atomic_read(&tty->port.count) == 0) {
53069 mutex_unlock(&tty->ipw_tty_mutex);
53070 return;
53071 }
53072 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53073
53074 mutex_lock(&tty->ipw_tty_mutex);
53075
53076 - if (!tty->port.count) {
53077 + if (!atomic_read(&tty->port.count)) {
53078 mutex_unlock(&tty->ipw_tty_mutex);
53079 return;
53080 }
53081 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53082 return -ENODEV;
53083
53084 mutex_lock(&tty->ipw_tty_mutex);
53085 - if (!tty->port.count) {
53086 + if (!atomic_read(&tty->port.count)) {
53087 mutex_unlock(&tty->ipw_tty_mutex);
53088 return -EINVAL;
53089 }
53090 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53091 if (!tty)
53092 return -ENODEV;
53093
53094 - if (!tty->port.count)
53095 + if (!atomic_read(&tty->port.count))
53096 return -EINVAL;
53097
53098 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53099 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53100 if (!tty)
53101 return 0;
53102
53103 - if (!tty->port.count)
53104 + if (!atomic_read(&tty->port.count))
53105 return 0;
53106
53107 return tty->tx_bytes_queued;
53108 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53109 if (!tty)
53110 return -ENODEV;
53111
53112 - if (!tty->port.count)
53113 + if (!atomic_read(&tty->port.count))
53114 return -EINVAL;
53115
53116 return get_control_lines(tty);
53117 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53118 if (!tty)
53119 return -ENODEV;
53120
53121 - if (!tty->port.count)
53122 + if (!atomic_read(&tty->port.count))
53123 return -EINVAL;
53124
53125 return set_control_lines(tty, set, clear);
53126 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53127 if (!tty)
53128 return -ENODEV;
53129
53130 - if (!tty->port.count)
53131 + if (!atomic_read(&tty->port.count))
53132 return -EINVAL;
53133
53134 /* FIXME: Exactly how is the tty object locked here .. */
53135 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53136 * are gone */
53137 mutex_lock(&ttyj->ipw_tty_mutex);
53138 }
53139 - while (ttyj->port.count)
53140 + while (atomic_read(&ttyj->port.count))
53141 do_ipw_close(ttyj);
53142 ipwireless_disassociate_network_ttys(network,
53143 ttyj->channel_idx);
53144 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53145 index 14c54e0..1efd4f2 100644
53146 --- a/drivers/tty/moxa.c
53147 +++ b/drivers/tty/moxa.c
53148 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53149 }
53150
53151 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53152 - ch->port.count++;
53153 + atomic_inc(&ch->port.count);
53154 tty->driver_data = ch;
53155 tty_port_tty_set(&ch->port, tty);
53156 mutex_lock(&ch->port.mutex);
53157 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53158 index c434376..114ce13 100644
53159 --- a/drivers/tty/n_gsm.c
53160 +++ b/drivers/tty/n_gsm.c
53161 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53162 spin_lock_init(&dlci->lock);
53163 mutex_init(&dlci->mutex);
53164 dlci->fifo = &dlci->_fifo;
53165 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53166 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53167 kfree(dlci);
53168 return NULL;
53169 }
53170 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53171 struct gsm_dlci *dlci = tty->driver_data;
53172 struct tty_port *port = &dlci->port;
53173
53174 - port->count++;
53175 + atomic_inc(&port->count);
53176 tty_port_tty_set(port, tty);
53177
53178 dlci->modem_rx = 0;
53179 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53180 index 47ca0f3..3c0b803 100644
53181 --- a/drivers/tty/n_tty.c
53182 +++ b/drivers/tty/n_tty.c
53183 @@ -115,7 +115,7 @@ struct n_tty_data {
53184 int minimum_to_wake;
53185
53186 /* consumer-published */
53187 - size_t read_tail;
53188 + size_t read_tail __intentional_overflow(-1);
53189 size_t line_start;
53190
53191 /* protected by output lock */
53192 @@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53193 {
53194 *ops = tty_ldisc_N_TTY;
53195 ops->owner = NULL;
53196 - ops->refcount = ops->flags = 0;
53197 + atomic_set(&ops->refcount, 0);
53198 + ops->flags = 0;
53199 }
53200 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53201 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53202 index 7c4447a..70fbc1e 100644
53203 --- a/drivers/tty/pty.c
53204 +++ b/drivers/tty/pty.c
53205 @@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
53206 panic("Couldn't register Unix98 pts driver");
53207
53208 /* Now create the /dev/ptmx special device */
53209 + pax_open_kernel();
53210 tty_default_fops(&ptmx_fops);
53211 - ptmx_fops.open = ptmx_open;
53212 + *(void **)&ptmx_fops.open = ptmx_open;
53213 + pax_close_kernel();
53214
53215 cdev_init(&ptmx_cdev, &ptmx_fops);
53216 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53217 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53218 index 383c4c7..d408e21 100644
53219 --- a/drivers/tty/rocket.c
53220 +++ b/drivers/tty/rocket.c
53221 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53222 tty->driver_data = info;
53223 tty_port_tty_set(port, tty);
53224
53225 - if (port->count++ == 0) {
53226 + if (atomic_inc_return(&port->count) == 1) {
53227 atomic_inc(&rp_num_ports_open);
53228
53229 #ifdef ROCKET_DEBUG_OPEN
53230 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53231 #endif
53232 }
53233 #ifdef ROCKET_DEBUG_OPEN
53234 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53235 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53236 #endif
53237
53238 /*
53239 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53240 spin_unlock_irqrestore(&info->port.lock, flags);
53241 return;
53242 }
53243 - if (info->port.count)
53244 + if (atomic_read(&info->port.count))
53245 atomic_dec(&rp_num_ports_open);
53246 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53247 spin_unlock_irqrestore(&info->port.lock, flags);
53248 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53249 index aa28209..e08fb85 100644
53250 --- a/drivers/tty/serial/ioc4_serial.c
53251 +++ b/drivers/tty/serial/ioc4_serial.c
53252 @@ -437,7 +437,7 @@ struct ioc4_soft {
53253 } is_intr_info[MAX_IOC4_INTR_ENTS];
53254
53255 /* Number of entries active in the above array */
53256 - atomic_t is_num_intrs;
53257 + atomic_unchecked_t is_num_intrs;
53258 } is_intr_type[IOC4_NUM_INTR_TYPES];
53259
53260 /* is_ir_lock must be held while
53261 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53262 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53263 || (type == IOC4_OTHER_INTR_TYPE)));
53264
53265 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53266 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53267 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53268
53269 /* Save off the lower level interrupt handler */
53270 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53271
53272 soft = arg;
53273 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53274 - num_intrs = (int)atomic_read(
53275 + num_intrs = (int)atomic_read_unchecked(
53276 &soft->is_intr_type[intr_type].is_num_intrs);
53277
53278 this_mir = this_ir = pending_intrs(soft, intr_type);
53279 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53280 index 129dc5b..1da5bb8 100644
53281 --- a/drivers/tty/serial/kgdb_nmi.c
53282 +++ b/drivers/tty/serial/kgdb_nmi.c
53283 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53284 * I/O utilities that messages sent to the console will automatically
53285 * be displayed on the dbg_io.
53286 */
53287 - dbg_io_ops->is_console = true;
53288 + pax_open_kernel();
53289 + *(int *)&dbg_io_ops->is_console = true;
53290 + pax_close_kernel();
53291
53292 return 0;
53293 }
53294 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53295 index a260cde..6b2b5ce 100644
53296 --- a/drivers/tty/serial/kgdboc.c
53297 +++ b/drivers/tty/serial/kgdboc.c
53298 @@ -24,8 +24,9 @@
53299 #define MAX_CONFIG_LEN 40
53300
53301 static struct kgdb_io kgdboc_io_ops;
53302 +static struct kgdb_io kgdboc_io_ops_console;
53303
53304 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53305 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53306 static int configured = -1;
53307
53308 static char config[MAX_CONFIG_LEN];
53309 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53310 kgdboc_unregister_kbd();
53311 if (configured == 1)
53312 kgdb_unregister_io_module(&kgdboc_io_ops);
53313 + else if (configured == 2)
53314 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53315 }
53316
53317 static int configure_kgdboc(void)
53318 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53319 int err;
53320 char *cptr = config;
53321 struct console *cons;
53322 + int is_console = 0;
53323
53324 err = kgdboc_option_setup(config);
53325 if (err || !strlen(config) || isspace(config[0]))
53326 goto noconfig;
53327
53328 err = -ENODEV;
53329 - kgdboc_io_ops.is_console = 0;
53330 kgdb_tty_driver = NULL;
53331
53332 kgdboc_use_kms = 0;
53333 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53334 int idx;
53335 if (cons->device && cons->device(cons, &idx) == p &&
53336 idx == tty_line) {
53337 - kgdboc_io_ops.is_console = 1;
53338 + is_console = 1;
53339 break;
53340 }
53341 cons = cons->next;
53342 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53343 kgdb_tty_line = tty_line;
53344
53345 do_register:
53346 - err = kgdb_register_io_module(&kgdboc_io_ops);
53347 + if (is_console) {
53348 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53349 + configured = 2;
53350 + } else {
53351 + err = kgdb_register_io_module(&kgdboc_io_ops);
53352 + configured = 1;
53353 + }
53354 if (err)
53355 goto noconfig;
53356
53357 @@ -205,8 +214,6 @@ do_register:
53358 if (err)
53359 goto nmi_con_failed;
53360
53361 - configured = 1;
53362 -
53363 return 0;
53364
53365 nmi_con_failed:
53366 @@ -223,7 +230,7 @@ noconfig:
53367 static int __init init_kgdboc(void)
53368 {
53369 /* Already configured? */
53370 - if (configured == 1)
53371 + if (configured >= 1)
53372 return 0;
53373
53374 return configure_kgdboc();
53375 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53376 if (config[len - 1] == '\n')
53377 config[len - 1] = '\0';
53378
53379 - if (configured == 1)
53380 + if (configured >= 1)
53381 cleanup_kgdboc();
53382
53383 /* Go and configure with the new params. */
53384 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53385 .post_exception = kgdboc_post_exp_handler,
53386 };
53387
53388 +static struct kgdb_io kgdboc_io_ops_console = {
53389 + .name = "kgdboc",
53390 + .read_char = kgdboc_get_char,
53391 + .write_char = kgdboc_put_char,
53392 + .pre_exception = kgdboc_pre_exp_handler,
53393 + .post_exception = kgdboc_post_exp_handler,
53394 + .is_console = 1
53395 +};
53396 +
53397 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53398 /* This is only available if kgdboc is a built in for early debugging */
53399 static int __init kgdboc_early_init(char *opt)
53400 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53401 index 4b6c783..9a19db3 100644
53402 --- a/drivers/tty/serial/msm_serial.c
53403 +++ b/drivers/tty/serial/msm_serial.c
53404 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53405 .cons = MSM_CONSOLE,
53406 };
53407
53408 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53409 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53410
53411 static const struct of_device_id msm_uartdm_table[] = {
53412 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53413 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53414 int irq;
53415
53416 if (pdev->id == -1)
53417 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53418 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53419
53420 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53421 return -ENXIO;
53422 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53423 index 587d63b..48423a6 100644
53424 --- a/drivers/tty/serial/samsung.c
53425 +++ b/drivers/tty/serial/samsung.c
53426 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53427 }
53428 }
53429
53430 +static int s3c64xx_serial_startup(struct uart_port *port);
53431 static int s3c24xx_serial_startup(struct uart_port *port)
53432 {
53433 struct s3c24xx_uart_port *ourport = to_ourport(port);
53434 int ret;
53435
53436 + /* Startup sequence is different for s3c64xx and higher SoC's */
53437 + if (s3c24xx_serial_has_interrupt_mask(port))
53438 + return s3c64xx_serial_startup(port);
53439 +
53440 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53441 port, (unsigned long long)port->mapbase, port->membase);
53442
53443 @@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53444 /* setup info for port */
53445 port->dev = &platdev->dev;
53446
53447 - /* Startup sequence is different for s3c64xx and higher SoC's */
53448 - if (s3c24xx_serial_has_interrupt_mask(port))
53449 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53450 -
53451 port->uartclk = 1;
53452
53453 if (cfg->uart_flags & UPF_CONS_FLOW) {
53454 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53455 index a28dee9..168ba47 100644
53456 --- a/drivers/tty/serial/serial_core.c
53457 +++ b/drivers/tty/serial/serial_core.c
53458 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53459
53460 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53461
53462 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53463 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53464 return;
53465
53466 /*
53467 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53468 uart_flush_buffer(tty);
53469 uart_shutdown(tty, state);
53470 spin_lock_irqsave(&port->lock, flags);
53471 - port->count = 0;
53472 + atomic_set(&port->count, 0);
53473 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53474 spin_unlock_irqrestore(&port->lock, flags);
53475 tty_port_tty_set(port, NULL);
53476 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53477 goto end;
53478 }
53479
53480 - port->count++;
53481 + atomic_inc(&port->count);
53482 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53483 retval = -ENXIO;
53484 goto err_dec_count;
53485 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53486 end:
53487 return retval;
53488 err_dec_count:
53489 - port->count--;
53490 + atomic_dec(&port->count);
53491 mutex_unlock(&port->mutex);
53492 goto end;
53493 }
53494 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53495 index b799170..87dafd5 100644
53496 --- a/drivers/tty/synclink.c
53497 +++ b/drivers/tty/synclink.c
53498 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53499
53500 if (debug_level >= DEBUG_LEVEL_INFO)
53501 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53502 - __FILE__,__LINE__, info->device_name, info->port.count);
53503 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53504
53505 if (tty_port_close_start(&info->port, tty, filp) == 0)
53506 goto cleanup;
53507 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53508 cleanup:
53509 if (debug_level >= DEBUG_LEVEL_INFO)
53510 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53511 - tty->driver->name, info->port.count);
53512 + tty->driver->name, atomic_read(&info->port.count));
53513
53514 } /* end of mgsl_close() */
53515
53516 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53517
53518 mgsl_flush_buffer(tty);
53519 shutdown(info);
53520 -
53521 - info->port.count = 0;
53522 +
53523 + atomic_set(&info->port.count, 0);
53524 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53525 info->port.tty = NULL;
53526
53527 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53528
53529 if (debug_level >= DEBUG_LEVEL_INFO)
53530 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53531 - __FILE__,__LINE__, tty->driver->name, port->count );
53532 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53533
53534 spin_lock_irqsave(&info->irq_spinlock, flags);
53535 - port->count--;
53536 + atomic_dec(&port->count);
53537 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53538 port->blocked_open++;
53539
53540 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53541
53542 if (debug_level >= DEBUG_LEVEL_INFO)
53543 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53544 - __FILE__,__LINE__, tty->driver->name, port->count );
53545 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53546
53547 tty_unlock(tty);
53548 schedule();
53549 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53550
53551 /* FIXME: Racy on hangup during close wait */
53552 if (!tty_hung_up_p(filp))
53553 - port->count++;
53554 + atomic_inc(&port->count);
53555 port->blocked_open--;
53556
53557 if (debug_level >= DEBUG_LEVEL_INFO)
53558 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53559 - __FILE__,__LINE__, tty->driver->name, port->count );
53560 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53561
53562 if (!retval)
53563 port->flags |= ASYNC_NORMAL_ACTIVE;
53564 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53565
53566 if (debug_level >= DEBUG_LEVEL_INFO)
53567 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53568 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53569 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53570
53571 /* If port is closing, signal caller to try again */
53572 if (info->port.flags & ASYNC_CLOSING){
53573 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53574 spin_unlock_irqrestore(&info->netlock, flags);
53575 goto cleanup;
53576 }
53577 - info->port.count++;
53578 + atomic_inc(&info->port.count);
53579 spin_unlock_irqrestore(&info->netlock, flags);
53580
53581 - if (info->port.count == 1) {
53582 + if (atomic_read(&info->port.count) == 1) {
53583 /* 1st open on this device, init hardware */
53584 retval = startup(info);
53585 if (retval < 0)
53586 @@ -3442,8 +3442,8 @@ cleanup:
53587 if (retval) {
53588 if (tty->count == 1)
53589 info->port.tty = NULL; /* tty layer will release tty struct */
53590 - if(info->port.count)
53591 - info->port.count--;
53592 + if (atomic_read(&info->port.count))
53593 + atomic_dec(&info->port.count);
53594 }
53595
53596 return retval;
53597 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53598 unsigned short new_crctype;
53599
53600 /* return error if TTY interface open */
53601 - if (info->port.count)
53602 + if (atomic_read(&info->port.count))
53603 return -EBUSY;
53604
53605 switch (encoding)
53606 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53607
53608 /* arbitrate between network and tty opens */
53609 spin_lock_irqsave(&info->netlock, flags);
53610 - if (info->port.count != 0 || info->netcount != 0) {
53611 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53612 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53613 spin_unlock_irqrestore(&info->netlock, flags);
53614 return -EBUSY;
53615 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53616 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53617
53618 /* return error if TTY interface open */
53619 - if (info->port.count)
53620 + if (atomic_read(&info->port.count))
53621 return -EBUSY;
53622
53623 if (cmd != SIOCWANDEV)
53624 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53625 index 0e8c39b..e0cb171 100644
53626 --- a/drivers/tty/synclink_gt.c
53627 +++ b/drivers/tty/synclink_gt.c
53628 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53629 tty->driver_data = info;
53630 info->port.tty = tty;
53631
53632 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53633 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53634
53635 /* If port is closing, signal caller to try again */
53636 if (info->port.flags & ASYNC_CLOSING){
53637 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53638 mutex_unlock(&info->port.mutex);
53639 goto cleanup;
53640 }
53641 - info->port.count++;
53642 + atomic_inc(&info->port.count);
53643 spin_unlock_irqrestore(&info->netlock, flags);
53644
53645 - if (info->port.count == 1) {
53646 + if (atomic_read(&info->port.count) == 1) {
53647 /* 1st open on this device, init hardware */
53648 retval = startup(info);
53649 if (retval < 0) {
53650 @@ -715,8 +715,8 @@ cleanup:
53651 if (retval) {
53652 if (tty->count == 1)
53653 info->port.tty = NULL; /* tty layer will release tty struct */
53654 - if(info->port.count)
53655 - info->port.count--;
53656 + if(atomic_read(&info->port.count))
53657 + atomic_dec(&info->port.count);
53658 }
53659
53660 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53661 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53662
53663 if (sanity_check(info, tty->name, "close"))
53664 return;
53665 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53666 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53667
53668 if (tty_port_close_start(&info->port, tty, filp) == 0)
53669 goto cleanup;
53670 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53671 tty_port_close_end(&info->port, tty);
53672 info->port.tty = NULL;
53673 cleanup:
53674 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53675 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53676 }
53677
53678 static void hangup(struct tty_struct *tty)
53679 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53680 shutdown(info);
53681
53682 spin_lock_irqsave(&info->port.lock, flags);
53683 - info->port.count = 0;
53684 + atomic_set(&info->port.count, 0);
53685 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53686 info->port.tty = NULL;
53687 spin_unlock_irqrestore(&info->port.lock, flags);
53688 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53689 unsigned short new_crctype;
53690
53691 /* return error if TTY interface open */
53692 - if (info->port.count)
53693 + if (atomic_read(&info->port.count))
53694 return -EBUSY;
53695
53696 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53697 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53698
53699 /* arbitrate between network and tty opens */
53700 spin_lock_irqsave(&info->netlock, flags);
53701 - if (info->port.count != 0 || info->netcount != 0) {
53702 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53703 DBGINFO(("%s hdlc_open busy\n", dev->name));
53704 spin_unlock_irqrestore(&info->netlock, flags);
53705 return -EBUSY;
53706 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53707 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53708
53709 /* return error if TTY interface open */
53710 - if (info->port.count)
53711 + if (atomic_read(&info->port.count))
53712 return -EBUSY;
53713
53714 if (cmd != SIOCWANDEV)
53715 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53716 if (port == NULL)
53717 continue;
53718 spin_lock(&port->lock);
53719 - if ((port->port.count || port->netcount) &&
53720 + if ((atomic_read(&port->port.count) || port->netcount) &&
53721 port->pending_bh && !port->bh_running &&
53722 !port->bh_requested) {
53723 DBGISR(("%s bh queued\n", port->device_name));
53724 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53725 add_wait_queue(&port->open_wait, &wait);
53726
53727 spin_lock_irqsave(&info->lock, flags);
53728 - port->count--;
53729 + atomic_dec(&port->count);
53730 spin_unlock_irqrestore(&info->lock, flags);
53731 port->blocked_open++;
53732
53733 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53734 remove_wait_queue(&port->open_wait, &wait);
53735
53736 if (!tty_hung_up_p(filp))
53737 - port->count++;
53738 + atomic_inc(&port->count);
53739 port->blocked_open--;
53740
53741 if (!retval)
53742 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53743 index c3f9091..abe4601 100644
53744 --- a/drivers/tty/synclinkmp.c
53745 +++ b/drivers/tty/synclinkmp.c
53746 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53747
53748 if (debug_level >= DEBUG_LEVEL_INFO)
53749 printk("%s(%d):%s open(), old ref count = %d\n",
53750 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53751 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53752
53753 /* If port is closing, signal caller to try again */
53754 if (info->port.flags & ASYNC_CLOSING){
53755 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53756 spin_unlock_irqrestore(&info->netlock, flags);
53757 goto cleanup;
53758 }
53759 - info->port.count++;
53760 + atomic_inc(&info->port.count);
53761 spin_unlock_irqrestore(&info->netlock, flags);
53762
53763 - if (info->port.count == 1) {
53764 + if (atomic_read(&info->port.count) == 1) {
53765 /* 1st open on this device, init hardware */
53766 retval = startup(info);
53767 if (retval < 0)
53768 @@ -796,8 +796,8 @@ cleanup:
53769 if (retval) {
53770 if (tty->count == 1)
53771 info->port.tty = NULL; /* tty layer will release tty struct */
53772 - if(info->port.count)
53773 - info->port.count--;
53774 + if(atomic_read(&info->port.count))
53775 + atomic_dec(&info->port.count);
53776 }
53777
53778 return retval;
53779 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53780
53781 if (debug_level >= DEBUG_LEVEL_INFO)
53782 printk("%s(%d):%s close() entry, count=%d\n",
53783 - __FILE__,__LINE__, info->device_name, info->port.count);
53784 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53785
53786 if (tty_port_close_start(&info->port, tty, filp) == 0)
53787 goto cleanup;
53788 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53789 cleanup:
53790 if (debug_level >= DEBUG_LEVEL_INFO)
53791 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53792 - tty->driver->name, info->port.count);
53793 + tty->driver->name, atomic_read(&info->port.count));
53794 }
53795
53796 /* Called by tty_hangup() when a hangup is signaled.
53797 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53798 shutdown(info);
53799
53800 spin_lock_irqsave(&info->port.lock, flags);
53801 - info->port.count = 0;
53802 + atomic_set(&info->port.count, 0);
53803 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53804 info->port.tty = NULL;
53805 spin_unlock_irqrestore(&info->port.lock, flags);
53806 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53807 unsigned short new_crctype;
53808
53809 /* return error if TTY interface open */
53810 - if (info->port.count)
53811 + if (atomic_read(&info->port.count))
53812 return -EBUSY;
53813
53814 switch (encoding)
53815 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53816
53817 /* arbitrate between network and tty opens */
53818 spin_lock_irqsave(&info->netlock, flags);
53819 - if (info->port.count != 0 || info->netcount != 0) {
53820 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53821 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53822 spin_unlock_irqrestore(&info->netlock, flags);
53823 return -EBUSY;
53824 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53825 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53826
53827 /* return error if TTY interface open */
53828 - if (info->port.count)
53829 + if (atomic_read(&info->port.count))
53830 return -EBUSY;
53831
53832 if (cmd != SIOCWANDEV)
53833 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53834 * do not request bottom half processing if the
53835 * device is not open in a normal mode.
53836 */
53837 - if ( port && (port->port.count || port->netcount) &&
53838 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53839 port->pending_bh && !port->bh_running &&
53840 !port->bh_requested ) {
53841 if ( debug_level >= DEBUG_LEVEL_ISR )
53842 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53843
53844 if (debug_level >= DEBUG_LEVEL_INFO)
53845 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53846 - __FILE__,__LINE__, tty->driver->name, port->count );
53847 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53848
53849 spin_lock_irqsave(&info->lock, flags);
53850 - port->count--;
53851 + atomic_dec(&port->count);
53852 spin_unlock_irqrestore(&info->lock, flags);
53853 port->blocked_open++;
53854
53855 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53856
53857 if (debug_level >= DEBUG_LEVEL_INFO)
53858 printk("%s(%d):%s block_til_ready() count=%d\n",
53859 - __FILE__,__LINE__, tty->driver->name, port->count );
53860 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53861
53862 tty_unlock(tty);
53863 schedule();
53864 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53865 set_current_state(TASK_RUNNING);
53866 remove_wait_queue(&port->open_wait, &wait);
53867 if (!tty_hung_up_p(filp))
53868 - port->count++;
53869 + atomic_inc(&port->count);
53870 port->blocked_open--;
53871
53872 if (debug_level >= DEBUG_LEVEL_INFO)
53873 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53874 - __FILE__,__LINE__, tty->driver->name, port->count );
53875 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53876
53877 if (!retval)
53878 port->flags |= ASYNC_NORMAL_ACTIVE;
53879 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53880 index 42bad18..447d7a2 100644
53881 --- a/drivers/tty/sysrq.c
53882 +++ b/drivers/tty/sysrq.c
53883 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53884 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53885 size_t count, loff_t *ppos)
53886 {
53887 - if (count) {
53888 + if (count && capable(CAP_SYS_ADMIN)) {
53889 char c;
53890
53891 if (get_user(c, buf))
53892 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53893 index 0508a1d..b610592 100644
53894 --- a/drivers/tty/tty_io.c
53895 +++ b/drivers/tty/tty_io.c
53896 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53897
53898 void tty_default_fops(struct file_operations *fops)
53899 {
53900 - *fops = tty_fops;
53901 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53902 }
53903
53904 /*
53905 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53906 index 2d822aa..a566234 100644
53907 --- a/drivers/tty/tty_ldisc.c
53908 +++ b/drivers/tty/tty_ldisc.c
53909 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53910 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53911 tty_ldiscs[disc] = new_ldisc;
53912 new_ldisc->num = disc;
53913 - new_ldisc->refcount = 0;
53914 + atomic_set(&new_ldisc->refcount, 0);
53915 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53916
53917 return ret;
53918 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53919 return -EINVAL;
53920
53921 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53922 - if (tty_ldiscs[disc]->refcount)
53923 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53924 ret = -EBUSY;
53925 else
53926 tty_ldiscs[disc] = NULL;
53927 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53928 if (ldops) {
53929 ret = ERR_PTR(-EAGAIN);
53930 if (try_module_get(ldops->owner)) {
53931 - ldops->refcount++;
53932 + atomic_inc(&ldops->refcount);
53933 ret = ldops;
53934 }
53935 }
53936 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53937 unsigned long flags;
53938
53939 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53940 - ldops->refcount--;
53941 + atomic_dec(&ldops->refcount);
53942 module_put(ldops->owner);
53943 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53944 }
53945 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53946 index 1b93357..ea9f82c 100644
53947 --- a/drivers/tty/tty_port.c
53948 +++ b/drivers/tty/tty_port.c
53949 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53950 unsigned long flags;
53951
53952 spin_lock_irqsave(&port->lock, flags);
53953 - port->count = 0;
53954 + atomic_set(&port->count, 0);
53955 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53956 tty = port->tty;
53957 if (tty)
53958 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53959
53960 /* The port lock protects the port counts */
53961 spin_lock_irqsave(&port->lock, flags);
53962 - port->count--;
53963 + atomic_dec(&port->count);
53964 port->blocked_open++;
53965 spin_unlock_irqrestore(&port->lock, flags);
53966
53967 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53968 we must not mess that up further */
53969 spin_lock_irqsave(&port->lock, flags);
53970 if (!tty_hung_up_p(filp))
53971 - port->count++;
53972 + atomic_inc(&port->count);
53973 port->blocked_open--;
53974 if (retval == 0)
53975 port->flags |= ASYNC_NORMAL_ACTIVE;
53976 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53977 return 0;
53978 }
53979
53980 - if (tty->count == 1 && port->count != 1) {
53981 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53982 printk(KERN_WARNING
53983 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53984 - port->count);
53985 - port->count = 1;
53986 + atomic_read(&port->count));
53987 + atomic_set(&port->count, 1);
53988 }
53989 - if (--port->count < 0) {
53990 + if (atomic_dec_return(&port->count) < 0) {
53991 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53992 - port->count);
53993 - port->count = 0;
53994 + atomic_read(&port->count));
53995 + atomic_set(&port->count, 0);
53996 }
53997
53998 - if (port->count) {
53999 + if (atomic_read(&port->count)) {
54000 spin_unlock_irqrestore(&port->lock, flags);
54001 return 0;
54002 }
54003 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54004 struct file *filp)
54005 {
54006 spin_lock_irq(&port->lock);
54007 - ++port->count;
54008 + atomic_inc(&port->count);
54009 spin_unlock_irq(&port->lock);
54010 tty_port_tty_set(port, tty);
54011
54012 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54013 index c039cfe..0b463b0 100644
54014 --- a/drivers/tty/vt/keyboard.c
54015 +++ b/drivers/tty/vt/keyboard.c
54016 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54017 kbd->kbdmode == VC_OFF) &&
54018 value != KVAL(K_SAK))
54019 return; /* SAK is allowed even in raw mode */
54020 +
54021 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54022 + {
54023 + void *func = fn_handler[value];
54024 + if (func == fn_show_state || func == fn_show_ptregs ||
54025 + func == fn_show_mem)
54026 + return;
54027 + }
54028 +#endif
54029 +
54030 fn_handler[value](vc);
54031 }
54032
54033 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54034 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54035 return -EFAULT;
54036
54037 - if (!capable(CAP_SYS_TTY_CONFIG))
54038 - perm = 0;
54039 -
54040 switch (cmd) {
54041 case KDGKBENT:
54042 /* Ensure another thread doesn't free it under us */
54043 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54044 spin_unlock_irqrestore(&kbd_event_lock, flags);
54045 return put_user(val, &user_kbe->kb_value);
54046 case KDSKBENT:
54047 + if (!capable(CAP_SYS_TTY_CONFIG))
54048 + perm = 0;
54049 +
54050 if (!perm)
54051 return -EPERM;
54052 if (!i && v == K_NOSUCHMAP) {
54053 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54054 int i, j, k;
54055 int ret;
54056
54057 - if (!capable(CAP_SYS_TTY_CONFIG))
54058 - perm = 0;
54059 -
54060 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54061 if (!kbs) {
54062 ret = -ENOMEM;
54063 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54064 kfree(kbs);
54065 return ((p && *p) ? -EOVERFLOW : 0);
54066 case KDSKBSENT:
54067 + if (!capable(CAP_SYS_TTY_CONFIG))
54068 + perm = 0;
54069 +
54070 if (!perm) {
54071 ret = -EPERM;
54072 goto reterr;
54073 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54074 index 60fa627..7214965 100644
54075 --- a/drivers/uio/uio.c
54076 +++ b/drivers/uio/uio.c
54077 @@ -25,6 +25,7 @@
54078 #include <linux/kobject.h>
54079 #include <linux/cdev.h>
54080 #include <linux/uio_driver.h>
54081 +#include <asm/local.h>
54082
54083 #define UIO_MAX_DEVICES (1U << MINORBITS)
54084
54085 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
54086 struct device_attribute *attr, char *buf)
54087 {
54088 struct uio_device *idev = dev_get_drvdata(dev);
54089 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54090 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54091 }
54092 static DEVICE_ATTR_RO(event);
54093
54094 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
54095 {
54096 struct uio_device *idev = info->uio_dev;
54097
54098 - atomic_inc(&idev->event);
54099 + atomic_inc_unchecked(&idev->event);
54100 wake_up_interruptible(&idev->wait);
54101 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54102 }
54103 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54104 }
54105
54106 listener->dev = idev;
54107 - listener->event_count = atomic_read(&idev->event);
54108 + listener->event_count = atomic_read_unchecked(&idev->event);
54109 filep->private_data = listener;
54110
54111 if (idev->info->open) {
54112 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54113 return -EIO;
54114
54115 poll_wait(filep, &idev->wait, wait);
54116 - if (listener->event_count != atomic_read(&idev->event))
54117 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54118 return POLLIN | POLLRDNORM;
54119 return 0;
54120 }
54121 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54122 do {
54123 set_current_state(TASK_INTERRUPTIBLE);
54124
54125 - event_count = atomic_read(&idev->event);
54126 + event_count = atomic_read_unchecked(&idev->event);
54127 if (event_count != listener->event_count) {
54128 if (copy_to_user(buf, &event_count, count))
54129 retval = -EFAULT;
54130 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54131 static int uio_find_mem_index(struct vm_area_struct *vma)
54132 {
54133 struct uio_device *idev = vma->vm_private_data;
54134 + unsigned long size;
54135
54136 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54137 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54138 + size = idev->info->mem[vma->vm_pgoff].size;
54139 + if (size == 0)
54140 + return -1;
54141 + if (vma->vm_end - vma->vm_start > size)
54142 return -1;
54143 return (int)vma->vm_pgoff;
54144 }
54145 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
54146 idev->owner = owner;
54147 idev->info = info;
54148 init_waitqueue_head(&idev->wait);
54149 - atomic_set(&idev->event, 0);
54150 + atomic_set_unchecked(&idev->event, 0);
54151
54152 ret = uio_get_minor(idev);
54153 if (ret)
54154 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54155 index 813d4d3..a71934f 100644
54156 --- a/drivers/usb/atm/cxacru.c
54157 +++ b/drivers/usb/atm/cxacru.c
54158 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54159 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54160 if (ret < 2)
54161 return -EINVAL;
54162 - if (index < 0 || index > 0x7f)
54163 + if (index > 0x7f)
54164 return -EINVAL;
54165 pos += tmp;
54166
54167 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54168 index dada014..1d0d517 100644
54169 --- a/drivers/usb/atm/usbatm.c
54170 +++ b/drivers/usb/atm/usbatm.c
54171 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54172 if (printk_ratelimit())
54173 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54174 __func__, vpi, vci);
54175 - atomic_inc(&vcc->stats->rx_err);
54176 + atomic_inc_unchecked(&vcc->stats->rx_err);
54177 return;
54178 }
54179
54180 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54181 if (length > ATM_MAX_AAL5_PDU) {
54182 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54183 __func__, length, vcc);
54184 - atomic_inc(&vcc->stats->rx_err);
54185 + atomic_inc_unchecked(&vcc->stats->rx_err);
54186 goto out;
54187 }
54188
54189 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54190 if (sarb->len < pdu_length) {
54191 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54192 __func__, pdu_length, sarb->len, vcc);
54193 - atomic_inc(&vcc->stats->rx_err);
54194 + atomic_inc_unchecked(&vcc->stats->rx_err);
54195 goto out;
54196 }
54197
54198 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54199 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54200 __func__, vcc);
54201 - atomic_inc(&vcc->stats->rx_err);
54202 + atomic_inc_unchecked(&vcc->stats->rx_err);
54203 goto out;
54204 }
54205
54206 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54207 if (printk_ratelimit())
54208 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54209 __func__, length);
54210 - atomic_inc(&vcc->stats->rx_drop);
54211 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54212 goto out;
54213 }
54214
54215 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54216
54217 vcc->push(vcc, skb);
54218
54219 - atomic_inc(&vcc->stats->rx);
54220 + atomic_inc_unchecked(&vcc->stats->rx);
54221 out:
54222 skb_trim(sarb, 0);
54223 }
54224 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54225 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54226
54227 usbatm_pop(vcc, skb);
54228 - atomic_inc(&vcc->stats->tx);
54229 + atomic_inc_unchecked(&vcc->stats->tx);
54230
54231 skb = skb_dequeue(&instance->sndqueue);
54232 }
54233 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54234 if (!left--)
54235 return sprintf(page,
54236 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54237 - atomic_read(&atm_dev->stats.aal5.tx),
54238 - atomic_read(&atm_dev->stats.aal5.tx_err),
54239 - atomic_read(&atm_dev->stats.aal5.rx),
54240 - atomic_read(&atm_dev->stats.aal5.rx_err),
54241 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54242 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54243 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54244 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54245 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54246 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54247
54248 if (!left--) {
54249 if (instance->disconnected)
54250 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54251 index 2a3bbdf..91d72cf 100644
54252 --- a/drivers/usb/core/devices.c
54253 +++ b/drivers/usb/core/devices.c
54254 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54255 * time it gets called.
54256 */
54257 static struct device_connect_event {
54258 - atomic_t count;
54259 + atomic_unchecked_t count;
54260 wait_queue_head_t wait;
54261 } device_event = {
54262 .count = ATOMIC_INIT(1),
54263 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54264
54265 void usbfs_conn_disc_event(void)
54266 {
54267 - atomic_add(2, &device_event.count);
54268 + atomic_add_unchecked(2, &device_event.count);
54269 wake_up(&device_event.wait);
54270 }
54271
54272 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54273
54274 poll_wait(file, &device_event.wait, wait);
54275
54276 - event_count = atomic_read(&device_event.count);
54277 + event_count = atomic_read_unchecked(&device_event.count);
54278 if (file->f_version != event_count) {
54279 file->f_version = event_count;
54280 return POLLIN | POLLRDNORM;
54281 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54282 index 0b59731..46ee7d1 100644
54283 --- a/drivers/usb/core/devio.c
54284 +++ b/drivers/usb/core/devio.c
54285 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54286 struct usb_dev_state *ps = file->private_data;
54287 struct usb_device *dev = ps->dev;
54288 ssize_t ret = 0;
54289 - unsigned len;
54290 + size_t len;
54291 loff_t pos;
54292 int i;
54293
54294 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54295 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54296 struct usb_config_descriptor *config =
54297 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54298 - unsigned int length = le16_to_cpu(config->wTotalLength);
54299 + size_t length = le16_to_cpu(config->wTotalLength);
54300
54301 if (*ppos < pos + length) {
54302
54303 /* The descriptor may claim to be longer than it
54304 * really is. Here is the actual allocated length. */
54305 - unsigned alloclen =
54306 + size_t alloclen =
54307 le16_to_cpu(dev->config[i].desc.wTotalLength);
54308
54309 - len = length - (*ppos - pos);
54310 + len = length + pos - *ppos;
54311 if (len > nbytes)
54312 len = nbytes;
54313
54314 /* Simply don't write (skip over) unallocated parts */
54315 if (alloclen > (*ppos - pos)) {
54316 - alloclen -= (*ppos - pos);
54317 + alloclen = alloclen + pos - *ppos;
54318 if (copy_to_user(buf,
54319 dev->rawdescriptors[i] + (*ppos - pos),
54320 min(len, alloclen))) {
54321 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54322 index a6efb41..6f72549b 100644
54323 --- a/drivers/usb/core/hcd.c
54324 +++ b/drivers/usb/core/hcd.c
54325 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54326 */
54327 usb_get_urb(urb);
54328 atomic_inc(&urb->use_count);
54329 - atomic_inc(&urb->dev->urbnum);
54330 + atomic_inc_unchecked(&urb->dev->urbnum);
54331 usbmon_urb_submit(&hcd->self, urb);
54332
54333 /* NOTE requirements on root-hub callers (usbfs and the hub
54334 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54335 urb->hcpriv = NULL;
54336 INIT_LIST_HEAD(&urb->urb_list);
54337 atomic_dec(&urb->use_count);
54338 - atomic_dec(&urb->dev->urbnum);
54339 + atomic_dec_unchecked(&urb->dev->urbnum);
54340 if (atomic_read(&urb->reject))
54341 wake_up(&usb_kill_urb_queue);
54342 usb_put_urb(urb);
54343 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54344 index b649fef..c7107a0 100644
54345 --- a/drivers/usb/core/hub.c
54346 +++ b/drivers/usb/core/hub.c
54347 @@ -26,6 +26,7 @@
54348 #include <linux/mutex.h>
54349 #include <linux/random.h>
54350 #include <linux/pm_qos.h>
54351 +#include <linux/grsecurity.h>
54352
54353 #include <asm/uaccess.h>
54354 #include <asm/byteorder.h>
54355 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54356 goto done;
54357 return;
54358 }
54359 +
54360 + if (gr_handle_new_usb())
54361 + goto done;
54362 +
54363 if (hub_is_superspeed(hub->hdev))
54364 unit_load = 150;
54365 else
54366 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54367 index f7b7713..23d07ec 100644
54368 --- a/drivers/usb/core/message.c
54369 +++ b/drivers/usb/core/message.c
54370 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54371 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54372 * error number.
54373 */
54374 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54375 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54376 __u8 requesttype, __u16 value, __u16 index, void *data,
54377 __u16 size, int timeout)
54378 {
54379 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54380 * If successful, 0. Otherwise a negative error number. The number of actual
54381 * bytes transferred will be stored in the @actual_length parameter.
54382 */
54383 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54384 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54385 void *data, int len, int *actual_length, int timeout)
54386 {
54387 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54388 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54389 * bytes transferred will be stored in the @actual_length parameter.
54390 *
54391 */
54392 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54393 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54394 void *data, int len, int *actual_length, int timeout)
54395 {
54396 struct urb *urb;
54397 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54398 index 1236c60..d47a51c 100644
54399 --- a/drivers/usb/core/sysfs.c
54400 +++ b/drivers/usb/core/sysfs.c
54401 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54402 struct usb_device *udev;
54403
54404 udev = to_usb_device(dev);
54405 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54406 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54407 }
54408 static DEVICE_ATTR_RO(urbnum);
54409
54410 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54411 index 2dd2362..1135437 100644
54412 --- a/drivers/usb/core/usb.c
54413 +++ b/drivers/usb/core/usb.c
54414 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54415 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54416 dev->state = USB_STATE_ATTACHED;
54417 dev->lpm_disable_count = 1;
54418 - atomic_set(&dev->urbnum, 0);
54419 + atomic_set_unchecked(&dev->urbnum, 0);
54420
54421 INIT_LIST_HEAD(&dev->ep0.urb_list);
54422 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54423 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54424 index 8cfc319..4868255 100644
54425 --- a/drivers/usb/early/ehci-dbgp.c
54426 +++ b/drivers/usb/early/ehci-dbgp.c
54427 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54428
54429 #ifdef CONFIG_KGDB
54430 static struct kgdb_io kgdbdbgp_io_ops;
54431 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54432 +static struct kgdb_io kgdbdbgp_io_ops_console;
54433 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54434 #else
54435 #define dbgp_kgdb_mode (0)
54436 #endif
54437 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54438 .write_char = kgdbdbgp_write_char,
54439 };
54440
54441 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54442 + .name = "kgdbdbgp",
54443 + .read_char = kgdbdbgp_read_char,
54444 + .write_char = kgdbdbgp_write_char,
54445 + .is_console = 1
54446 +};
54447 +
54448 static int kgdbdbgp_wait_time;
54449
54450 static int __init kgdbdbgp_parse_config(char *str)
54451 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54452 ptr++;
54453 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54454 }
54455 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54456 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54457 + if (early_dbgp_console.index != -1)
54458 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54459 + else
54460 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54461
54462 return 0;
54463 }
54464 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54465 index f7b2032..fbb340c 100644
54466 --- a/drivers/usb/gadget/function/f_uac1.c
54467 +++ b/drivers/usb/gadget/function/f_uac1.c
54468 @@ -14,6 +14,7 @@
54469 #include <linux/module.h>
54470 #include <linux/device.h>
54471 #include <linux/atomic.h>
54472 +#include <linux/module.h>
54473
54474 #include "u_uac1.h"
54475
54476 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54477 index 491082a..dfd7d17 100644
54478 --- a/drivers/usb/gadget/function/u_serial.c
54479 +++ b/drivers/usb/gadget/function/u_serial.c
54480 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54481 spin_lock_irq(&port->port_lock);
54482
54483 /* already open? Great. */
54484 - if (port->port.count) {
54485 + if (atomic_read(&port->port.count)) {
54486 status = 0;
54487 - port->port.count++;
54488 + atomic_inc(&port->port.count);
54489
54490 /* currently opening/closing? wait ... */
54491 } else if (port->openclose) {
54492 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54493 tty->driver_data = port;
54494 port->port.tty = tty;
54495
54496 - port->port.count = 1;
54497 + atomic_set(&port->port.count, 1);
54498 port->openclose = false;
54499
54500 /* if connected, start the I/O stream */
54501 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54502
54503 spin_lock_irq(&port->port_lock);
54504
54505 - if (port->port.count != 1) {
54506 - if (port->port.count == 0)
54507 + if (atomic_read(&port->port.count) != 1) {
54508 + if (atomic_read(&port->port.count) == 0)
54509 WARN_ON(1);
54510 else
54511 - --port->port.count;
54512 + atomic_dec(&port->port.count);
54513 goto exit;
54514 }
54515
54516 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54517 * and sleep if necessary
54518 */
54519 port->openclose = true;
54520 - port->port.count = 0;
54521 + atomic_set(&port->port.count, 0);
54522
54523 gser = port->port_usb;
54524 if (gser && gser->disconnect)
54525 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54526 int cond;
54527
54528 spin_lock_irq(&port->port_lock);
54529 - cond = (port->port.count == 0) && !port->openclose;
54530 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54531 spin_unlock_irq(&port->port_lock);
54532 return cond;
54533 }
54534 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54535 /* if it's already open, start I/O ... and notify the serial
54536 * protocol about open/close status (connect/disconnect).
54537 */
54538 - if (port->port.count) {
54539 + if (atomic_read(&port->port.count)) {
54540 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54541 gs_start_io(port);
54542 if (gser->connect)
54543 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54544
54545 port->port_usb = NULL;
54546 gser->ioport = NULL;
54547 - if (port->port.count > 0 || port->openclose) {
54548 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54549 wake_up_interruptible(&port->drain_wait);
54550 if (port->port.tty)
54551 tty_hangup(port->port.tty);
54552 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54553
54554 /* finally, free any unused/unusable I/O buffers */
54555 spin_lock_irqsave(&port->port_lock, flags);
54556 - if (port->port.count == 0 && !port->openclose)
54557 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54558 gs_buf_free(&port->port_write_buf);
54559 gs_free_requests(gser->out, &port->read_pool, NULL);
54560 gs_free_requests(gser->out, &port->read_queue, NULL);
54561 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54562 index a44a07f..ecea924 100644
54563 --- a/drivers/usb/gadget/function/u_uac1.c
54564 +++ b/drivers/usb/gadget/function/u_uac1.c
54565 @@ -17,6 +17,7 @@
54566 #include <linux/ctype.h>
54567 #include <linux/random.h>
54568 #include <linux/syscalls.h>
54569 +#include <linux/module.h>
54570
54571 #include "u_uac1.h"
54572
54573 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54574 index 5728829..fefc6bf 100644
54575 --- a/drivers/usb/host/ehci-hub.c
54576 +++ b/drivers/usb/host/ehci-hub.c
54577 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54578 urb->transfer_flags = URB_DIR_IN;
54579 usb_get_urb(urb);
54580 atomic_inc(&urb->use_count);
54581 - atomic_inc(&urb->dev->urbnum);
54582 + atomic_inc_unchecked(&urb->dev->urbnum);
54583 urb->setup_dma = dma_map_single(
54584 hcd->self.controller,
54585 urb->setup_packet,
54586 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54587 urb->status = -EINPROGRESS;
54588 usb_get_urb(urb);
54589 atomic_inc(&urb->use_count);
54590 - atomic_inc(&urb->dev->urbnum);
54591 + atomic_inc_unchecked(&urb->dev->urbnum);
54592 retval = submit_single_step_set_feature(hcd, urb, 0);
54593 if (!retval && !wait_for_completion_timeout(&done,
54594 msecs_to_jiffies(2000))) {
54595 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54596 index 1db0626..4948782 100644
54597 --- a/drivers/usb/host/hwa-hc.c
54598 +++ b/drivers/usb/host/hwa-hc.c
54599 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54600 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54601 struct wahc *wa = &hwahc->wa;
54602 struct device *dev = &wa->usb_iface->dev;
54603 - u8 mas_le[UWB_NUM_MAS/8];
54604 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54605 +
54606 + if (mas_le == NULL)
54607 + return -ENOMEM;
54608
54609 /* Set the stream index */
54610 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54611 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54612 WUSB_REQ_SET_WUSB_MAS,
54613 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54614 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54615 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54616 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54617 if (result < 0)
54618 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54619 out:
54620 + kfree(mas_le);
54621 +
54622 return result;
54623 }
54624
54625 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54626 index b3d245e..99549ed 100644
54627 --- a/drivers/usb/misc/appledisplay.c
54628 +++ b/drivers/usb/misc/appledisplay.c
54629 @@ -84,7 +84,7 @@ struct appledisplay {
54630 struct mutex sysfslock; /* concurrent read and write */
54631 };
54632
54633 -static atomic_t count_displays = ATOMIC_INIT(0);
54634 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54635 static struct workqueue_struct *wq;
54636
54637 static void appledisplay_complete(struct urb *urb)
54638 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54639
54640 /* Register backlight device */
54641 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54642 - atomic_inc_return(&count_displays) - 1);
54643 + atomic_inc_return_unchecked(&count_displays) - 1);
54644 memset(&props, 0, sizeof(struct backlight_properties));
54645 props.type = BACKLIGHT_RAW;
54646 props.max_brightness = 0xff;
54647 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54648 index 29fa1c3..a57b08e 100644
54649 --- a/drivers/usb/serial/console.c
54650 +++ b/drivers/usb/serial/console.c
54651 @@ -125,7 +125,7 @@ static int usb_console_setup(struct console *co, char *options)
54652
54653 info->port = port;
54654
54655 - ++port->port.count;
54656 + atomic_inc(&port->port.count);
54657 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54658 if (serial->type->set_termios) {
54659 /*
54660 @@ -173,7 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
54661 }
54662 /* Now that any required fake tty operations are completed restore
54663 * the tty port count */
54664 - --port->port.count;
54665 + atomic_dec(&port->port.count);
54666 /* The console is special in terms of closing the device so
54667 * indicate this port is now acting as a system console. */
54668 port->port.console = 1;
54669 @@ -186,7 +186,7 @@ static int usb_console_setup(struct console *co, char *options)
54670 put_tty:
54671 tty_kref_put(tty);
54672 reset_open_count:
54673 - port->port.count = 0;
54674 + atomic_set(&port->port.count, 0);
54675 usb_autopm_put_interface(serial->interface);
54676 error_get_interface:
54677 usb_serial_put(serial);
54678 @@ -197,7 +197,7 @@ static int usb_console_setup(struct console *co, char *options)
54679 static void usb_console_write(struct console *co,
54680 const char *buf, unsigned count)
54681 {
54682 - static struct usbcons_info *info = &usbcons_info;
54683 + struct usbcons_info *info = &usbcons_info;
54684 struct usb_serial_port *port = info->port;
54685 struct usb_serial *serial;
54686 int retval = -ENODEV;
54687 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54688 index 307e339..6aa97cb 100644
54689 --- a/drivers/usb/storage/usb.h
54690 +++ b/drivers/usb/storage/usb.h
54691 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54692 __u8 useProtocol;
54693 __u8 useTransport;
54694 int (*initFunction)(struct us_data *);
54695 -};
54696 +} __do_const;
54697
54698
54699 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54700 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54701 index a863a98..d272795 100644
54702 --- a/drivers/usb/usbip/vhci.h
54703 +++ b/drivers/usb/usbip/vhci.h
54704 @@ -83,7 +83,7 @@ struct vhci_hcd {
54705 unsigned resuming:1;
54706 unsigned long re_timeout;
54707
54708 - atomic_t seqnum;
54709 + atomic_unchecked_t seqnum;
54710
54711 /*
54712 * NOTE:
54713 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54714 index c02374b..32d47a9 100644
54715 --- a/drivers/usb/usbip/vhci_hcd.c
54716 +++ b/drivers/usb/usbip/vhci_hcd.c
54717 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54718
54719 spin_lock(&vdev->priv_lock);
54720
54721 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54722 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54723 if (priv->seqnum == 0xffff)
54724 dev_info(&urb->dev->dev, "seqnum max\n");
54725
54726 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54727 return -ENOMEM;
54728 }
54729
54730 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54731 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54732 if (unlink->seqnum == 0xffff)
54733 pr_info("seqnum max\n");
54734
54735 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54736 vdev->rhport = rhport;
54737 }
54738
54739 - atomic_set(&vhci->seqnum, 0);
54740 + atomic_set_unchecked(&vhci->seqnum, 0);
54741 spin_lock_init(&vhci->lock);
54742
54743 hcd->power_budget = 0; /* no limit */
54744 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54745 index 00e4a54..d676f85 100644
54746 --- a/drivers/usb/usbip/vhci_rx.c
54747 +++ b/drivers/usb/usbip/vhci_rx.c
54748 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54749 if (!urb) {
54750 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54751 pr_info("max seqnum %d\n",
54752 - atomic_read(&the_controller->seqnum));
54753 + atomic_read_unchecked(&the_controller->seqnum));
54754 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54755 return;
54756 }
54757 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54758 index edc7267..9f65ce2 100644
54759 --- a/drivers/usb/wusbcore/wa-hc.h
54760 +++ b/drivers/usb/wusbcore/wa-hc.h
54761 @@ -240,7 +240,7 @@ struct wahc {
54762 spinlock_t xfer_list_lock;
54763 struct work_struct xfer_enqueue_work;
54764 struct work_struct xfer_error_work;
54765 - atomic_t xfer_id_count;
54766 + atomic_unchecked_t xfer_id_count;
54767
54768 kernel_ulong_t quirks;
54769 };
54770 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54771 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54772 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54773 wa->dto_in_use = 0;
54774 - atomic_set(&wa->xfer_id_count, 1);
54775 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54776 /* init the buf in URBs */
54777 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54778 usb_init_urb(&(wa->buf_in_urbs[index]));
54779 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54780 index 69af4fd..da390d7 100644
54781 --- a/drivers/usb/wusbcore/wa-xfer.c
54782 +++ b/drivers/usb/wusbcore/wa-xfer.c
54783 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54784 */
54785 static void wa_xfer_id_init(struct wa_xfer *xfer)
54786 {
54787 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54788 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54789 }
54790
54791 /* Return the xfer's ID. */
54792 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54793 index f018d8d..ccab63f 100644
54794 --- a/drivers/vfio/vfio.c
54795 +++ b/drivers/vfio/vfio.c
54796 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54797 return 0;
54798
54799 /* TODO Prevent device auto probing */
54800 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54801 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54802 iommu_group_id(group->iommu_group));
54803
54804 return 0;
54805 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54806 index 5174eba..451e6bc 100644
54807 --- a/drivers/vhost/vringh.c
54808 +++ b/drivers/vhost/vringh.c
54809 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54810 /* Userspace access helpers: in this case, addresses are really userspace. */
54811 static inline int getu16_user(u16 *val, const u16 *p)
54812 {
54813 - return get_user(*val, (__force u16 __user *)p);
54814 + return get_user(*val, (u16 __force_user *)p);
54815 }
54816
54817 static inline int putu16_user(u16 *p, u16 val)
54818 {
54819 - return put_user(val, (__force u16 __user *)p);
54820 + return put_user(val, (u16 __force_user *)p);
54821 }
54822
54823 static inline int copydesc_user(void *dst, const void *src, size_t len)
54824 {
54825 - return copy_from_user(dst, (__force void __user *)src, len) ?
54826 + return copy_from_user(dst, (void __force_user *)src, len) ?
54827 -EFAULT : 0;
54828 }
54829
54830 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54831 const struct vring_used_elem *src,
54832 unsigned int num)
54833 {
54834 - return copy_to_user((__force void __user *)dst, src,
54835 + return copy_to_user((void __force_user *)dst, src,
54836 sizeof(*dst) * num) ? -EFAULT : 0;
54837 }
54838
54839 static inline int xfer_from_user(void *src, void *dst, size_t len)
54840 {
54841 - return copy_from_user(dst, (__force void __user *)src, len) ?
54842 + return copy_from_user(dst, (void __force_user *)src, len) ?
54843 -EFAULT : 0;
54844 }
54845
54846 static inline int xfer_to_user(void *dst, void *src, size_t len)
54847 {
54848 - return copy_to_user((__force void __user *)dst, src, len) ?
54849 + return copy_to_user((void __force_user *)dst, src, len) ?
54850 -EFAULT : 0;
54851 }
54852
54853 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54854 vrh->last_used_idx = 0;
54855 vrh->vring.num = num;
54856 /* vring expects kernel addresses, but only used via accessors. */
54857 - vrh->vring.desc = (__force struct vring_desc *)desc;
54858 - vrh->vring.avail = (__force struct vring_avail *)avail;
54859 - vrh->vring.used = (__force struct vring_used *)used;
54860 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54861 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54862 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54863 return 0;
54864 }
54865 EXPORT_SYMBOL(vringh_init_user);
54866 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54867
54868 static inline int putu16_kern(u16 *p, u16 val)
54869 {
54870 - ACCESS_ONCE(*p) = val;
54871 + ACCESS_ONCE_RW(*p) = val;
54872 return 0;
54873 }
54874
54875 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54876 index 84a110a..96312c3 100644
54877 --- a/drivers/video/backlight/kb3886_bl.c
54878 +++ b/drivers/video/backlight/kb3886_bl.c
54879 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54880 static unsigned long kb3886bl_flags;
54881 #define KB3886BL_SUSPENDED 0x01
54882
54883 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54884 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54885 {
54886 .ident = "Sahara Touch-iT",
54887 .matches = {
54888 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54889 index 1b0b233..6f34c2c 100644
54890 --- a/drivers/video/fbdev/arcfb.c
54891 +++ b/drivers/video/fbdev/arcfb.c
54892 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54893 return -ENOSPC;
54894
54895 err = 0;
54896 - if ((count + p) > fbmemlength) {
54897 + if (count > (fbmemlength - p)) {
54898 count = fbmemlength - p;
54899 err = -ENOSPC;
54900 }
54901 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54902 index aedf2fb..47c9aca 100644
54903 --- a/drivers/video/fbdev/aty/aty128fb.c
54904 +++ b/drivers/video/fbdev/aty/aty128fb.c
54905 @@ -149,7 +149,7 @@ enum {
54906 };
54907
54908 /* Must match above enum */
54909 -static char * const r128_family[] = {
54910 +static const char * const r128_family[] = {
54911 "AGP",
54912 "PCI",
54913 "PRO AGP",
54914 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54915 index 37ec09b..98f8862 100644
54916 --- a/drivers/video/fbdev/aty/atyfb_base.c
54917 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54918 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54919 par->accel_flags = var->accel_flags; /* hack */
54920
54921 if (var->accel_flags) {
54922 - info->fbops->fb_sync = atyfb_sync;
54923 + pax_open_kernel();
54924 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54925 + pax_close_kernel();
54926 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54927 } else {
54928 - info->fbops->fb_sync = NULL;
54929 + pax_open_kernel();
54930 + *(void **)&info->fbops->fb_sync = NULL;
54931 + pax_close_kernel();
54932 info->flags |= FBINFO_HWACCEL_DISABLED;
54933 }
54934
54935 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54936 index 2fa0317..4983f2a 100644
54937 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54938 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54939 @@ -8,6 +8,7 @@
54940 #include "../core/fb_draw.h"
54941
54942 #include <asm/io.h>
54943 +#include <asm/pgtable.h>
54944
54945 #ifdef __sparc__
54946 #include <asm/fbio.h>
54947 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54948 info->sprite.buf_align = 16; /* and 64 lines tall. */
54949 info->sprite.flags = FB_PIXMAP_IO;
54950
54951 - info->fbops->fb_cursor = atyfb_cursor;
54952 + pax_open_kernel();
54953 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54954 + pax_close_kernel();
54955
54956 return 0;
54957 }
54958 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54959 index d6cab1f..112f680 100644
54960 --- a/drivers/video/fbdev/core/fb_defio.c
54961 +++ b/drivers/video/fbdev/core/fb_defio.c
54962 @@ -207,7 +207,9 @@ void fb_deferred_io_init(struct fb_info *info)
54963
54964 BUG_ON(!fbdefio);
54965 mutex_init(&fbdefio->lock);
54966 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54967 + pax_open_kernel();
54968 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54969 + pax_close_kernel();
54970 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54971 INIT_LIST_HEAD(&fbdefio->pagelist);
54972 if (fbdefio->delay == 0) /* set a default of 1 s */
54973 @@ -238,7 +240,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54974 page->mapping = NULL;
54975 }
54976
54977 - info->fbops->fb_mmap = NULL;
54978 + *(void **)&info->fbops->fb_mmap = NULL;
54979 mutex_destroy(&fbdefio->lock);
54980 }
54981 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54982 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54983 index 0705d88..d9429bf 100644
54984 --- a/drivers/video/fbdev/core/fbmem.c
54985 +++ b/drivers/video/fbdev/core/fbmem.c
54986 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54987 __u32 data;
54988 int err;
54989
54990 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54991 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54992
54993 data = (__u32) (unsigned long) fix->smem_start;
54994 err |= put_user(data, &fix32->smem_start);
54995 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54996 index 4254336..282567e 100644
54997 --- a/drivers/video/fbdev/hyperv_fb.c
54998 +++ b/drivers/video/fbdev/hyperv_fb.c
54999 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55000 static inline int synthvid_send(struct hv_device *hdev,
55001 struct synthvid_msg *msg)
55002 {
55003 - static atomic64_t request_id = ATOMIC64_INIT(0);
55004 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55005 int ret;
55006
55007 msg->pipe_hdr.type = PIPE_MSG_DATA;
55008 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55009
55010 ret = vmbus_sendpacket(hdev->channel, msg,
55011 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55012 - atomic64_inc_return(&request_id),
55013 + atomic64_inc_return_unchecked(&request_id),
55014 VM_PKT_DATA_INBAND, 0);
55015
55016 if (ret)
55017 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55018 index 7672d2e..b56437f 100644
55019 --- a/drivers/video/fbdev/i810/i810_accel.c
55020 +++ b/drivers/video/fbdev/i810/i810_accel.c
55021 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55022 }
55023 }
55024 printk("ringbuffer lockup!!!\n");
55025 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55026 i810_report_error(mmio);
55027 par->dev_flags |= LOCKUP;
55028 info->pixmap.scan_align = 1;
55029 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55030 index a01147f..5d896f8 100644
55031 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55032 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55033 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55034
55035 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55036 struct matrox_switch matrox_mystique = {
55037 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55038 + .preinit = MGA1064_preinit,
55039 + .reset = MGA1064_reset,
55040 + .init = MGA1064_init,
55041 + .restore = MGA1064_restore,
55042 };
55043 EXPORT_SYMBOL(matrox_mystique);
55044 #endif
55045
55046 #ifdef CONFIG_FB_MATROX_G
55047 struct matrox_switch matrox_G100 = {
55048 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55049 + .preinit = MGAG100_preinit,
55050 + .reset = MGAG100_reset,
55051 + .init = MGAG100_init,
55052 + .restore = MGAG100_restore,
55053 };
55054 EXPORT_SYMBOL(matrox_G100);
55055 #endif
55056 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55057 index 195ad7c..09743fc 100644
55058 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55059 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55060 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55061 }
55062
55063 struct matrox_switch matrox_millennium = {
55064 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55065 + .preinit = Ti3026_preinit,
55066 + .reset = Ti3026_reset,
55067 + .init = Ti3026_init,
55068 + .restore = Ti3026_restore
55069 };
55070 EXPORT_SYMBOL(matrox_millennium);
55071 #endif
55072 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55073 index fe92eed..106e085 100644
55074 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55075 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55076 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55077 struct mb862xxfb_par *par = info->par;
55078
55079 if (info->var.bits_per_pixel == 32) {
55080 - info->fbops->fb_fillrect = cfb_fillrect;
55081 - info->fbops->fb_copyarea = cfb_copyarea;
55082 - info->fbops->fb_imageblit = cfb_imageblit;
55083 + pax_open_kernel();
55084 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55085 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55086 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55087 + pax_close_kernel();
55088 } else {
55089 outreg(disp, GC_L0EM, 3);
55090 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55091 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55092 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55093 + pax_open_kernel();
55094 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55095 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55096 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55097 + pax_close_kernel();
55098 }
55099 outreg(draw, GDC_REG_DRAW_BASE, 0);
55100 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55101 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55102 index def0412..fed6529 100644
55103 --- a/drivers/video/fbdev/nvidia/nvidia.c
55104 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55105 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55106 info->fix.line_length = (info->var.xres_virtual *
55107 info->var.bits_per_pixel) >> 3;
55108 if (info->var.accel_flags) {
55109 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55110 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55111 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55112 - info->fbops->fb_sync = nvidiafb_sync;
55113 + pax_open_kernel();
55114 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55115 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55116 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55117 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55118 + pax_close_kernel();
55119 info->pixmap.scan_align = 4;
55120 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55121 info->flags |= FBINFO_READS_FAST;
55122 NVResetGraphics(info);
55123 } else {
55124 - info->fbops->fb_imageblit = cfb_imageblit;
55125 - info->fbops->fb_fillrect = cfb_fillrect;
55126 - info->fbops->fb_copyarea = cfb_copyarea;
55127 - info->fbops->fb_sync = NULL;
55128 + pax_open_kernel();
55129 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55130 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55131 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55132 + *(void **)&info->fbops->fb_sync = NULL;
55133 + pax_close_kernel();
55134 info->pixmap.scan_align = 1;
55135 info->flags |= FBINFO_HWACCEL_DISABLED;
55136 info->flags &= ~FBINFO_READS_FAST;
55137 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55138 info->pixmap.size = 8 * 1024;
55139 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55140
55141 - if (!hwcur)
55142 - info->fbops->fb_cursor = NULL;
55143 + if (!hwcur) {
55144 + pax_open_kernel();
55145 + *(void **)&info->fbops->fb_cursor = NULL;
55146 + pax_close_kernel();
55147 + }
55148
55149 info->var.accel_flags = (!noaccel);
55150
55151 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55152 index 2412a0d..294215b 100644
55153 --- a/drivers/video/fbdev/omap2/dss/display.c
55154 +++ b/drivers/video/fbdev/omap2/dss/display.c
55155 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55156 if (dssdev->name == NULL)
55157 dssdev->name = dssdev->alias;
55158
55159 + pax_open_kernel();
55160 if (drv && drv->get_resolution == NULL)
55161 - drv->get_resolution = omapdss_default_get_resolution;
55162 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55163 if (drv && drv->get_recommended_bpp == NULL)
55164 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55165 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55166 if (drv && drv->get_timings == NULL)
55167 - drv->get_timings = omapdss_default_get_timings;
55168 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55169 + pax_close_kernel();
55170
55171 mutex_lock(&panel_list_mutex);
55172 list_add_tail(&dssdev->panel_list, &panel_list);
55173 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55174 index 83433cb..71e9b98 100644
55175 --- a/drivers/video/fbdev/s1d13xxxfb.c
55176 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55177 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55178
55179 switch(prod_id) {
55180 case S1D13506_PROD_ID: /* activate acceleration */
55181 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55182 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55183 + pax_open_kernel();
55184 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55185 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55186 + pax_close_kernel();
55187 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55188 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55189 break;
55190 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55191 index 2bcc84a..29dd1ea 100644
55192 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55193 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55194 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55195 }
55196
55197 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55198 - lcdc_sys_write_index,
55199 - lcdc_sys_write_data,
55200 - lcdc_sys_read_data,
55201 + .write_index = lcdc_sys_write_index,
55202 + .write_data = lcdc_sys_write_data,
55203 + .read_data = lcdc_sys_read_data,
55204 };
55205
55206 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55207 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55208 index d513ed6..90b0de9 100644
55209 --- a/drivers/video/fbdev/smscufx.c
55210 +++ b/drivers/video/fbdev/smscufx.c
55211 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55212 fb_deferred_io_cleanup(info);
55213 kfree(info->fbdefio);
55214 info->fbdefio = NULL;
55215 - info->fbops->fb_mmap = ufx_ops_mmap;
55216 + pax_open_kernel();
55217 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55218 + pax_close_kernel();
55219 }
55220
55221 pr_debug("released /dev/fb%d user=%d count=%d",
55222 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55223 index 046d51d..be564da 100644
55224 --- a/drivers/video/fbdev/udlfb.c
55225 +++ b/drivers/video/fbdev/udlfb.c
55226 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55227 dlfb_urb_completion(urb);
55228
55229 error:
55230 - atomic_add(bytes_sent, &dev->bytes_sent);
55231 - atomic_add(bytes_identical, &dev->bytes_identical);
55232 - atomic_add(width*height*2, &dev->bytes_rendered);
55233 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55234 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55235 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55236 end_cycles = get_cycles();
55237 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55238 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55239 >> 10)), /* Kcycles */
55240 &dev->cpu_kcycles_used);
55241
55242 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55243 dlfb_urb_completion(urb);
55244
55245 error:
55246 - atomic_add(bytes_sent, &dev->bytes_sent);
55247 - atomic_add(bytes_identical, &dev->bytes_identical);
55248 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55249 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55250 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55251 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55252 end_cycles = get_cycles();
55253 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55254 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55255 >> 10)), /* Kcycles */
55256 &dev->cpu_kcycles_used);
55257 }
55258 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55259 fb_deferred_io_cleanup(info);
55260 kfree(info->fbdefio);
55261 info->fbdefio = NULL;
55262 - info->fbops->fb_mmap = dlfb_ops_mmap;
55263 + pax_open_kernel();
55264 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55265 + pax_close_kernel();
55266 }
55267
55268 pr_warn("released /dev/fb%d user=%d count=%d\n",
55269 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55270 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55271 struct dlfb_data *dev = fb_info->par;
55272 return snprintf(buf, PAGE_SIZE, "%u\n",
55273 - atomic_read(&dev->bytes_rendered));
55274 + atomic_read_unchecked(&dev->bytes_rendered));
55275 }
55276
55277 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55278 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55279 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55280 struct dlfb_data *dev = fb_info->par;
55281 return snprintf(buf, PAGE_SIZE, "%u\n",
55282 - atomic_read(&dev->bytes_identical));
55283 + atomic_read_unchecked(&dev->bytes_identical));
55284 }
55285
55286 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55287 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55288 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55289 struct dlfb_data *dev = fb_info->par;
55290 return snprintf(buf, PAGE_SIZE, "%u\n",
55291 - atomic_read(&dev->bytes_sent));
55292 + atomic_read_unchecked(&dev->bytes_sent));
55293 }
55294
55295 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55296 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55297 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55298 struct dlfb_data *dev = fb_info->par;
55299 return snprintf(buf, PAGE_SIZE, "%u\n",
55300 - atomic_read(&dev->cpu_kcycles_used));
55301 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55302 }
55303
55304 static ssize_t edid_show(
55305 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55306 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55307 struct dlfb_data *dev = fb_info->par;
55308
55309 - atomic_set(&dev->bytes_rendered, 0);
55310 - atomic_set(&dev->bytes_identical, 0);
55311 - atomic_set(&dev->bytes_sent, 0);
55312 - atomic_set(&dev->cpu_kcycles_used, 0);
55313 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55314 + atomic_set_unchecked(&dev->bytes_identical, 0);
55315 + atomic_set_unchecked(&dev->bytes_sent, 0);
55316 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55317
55318 return count;
55319 }
55320 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55321 index 509d452..7c9d2de 100644
55322 --- a/drivers/video/fbdev/uvesafb.c
55323 +++ b/drivers/video/fbdev/uvesafb.c
55324 @@ -19,6 +19,7 @@
55325 #include <linux/io.h>
55326 #include <linux/mutex.h>
55327 #include <linux/slab.h>
55328 +#include <linux/moduleloader.h>
55329 #include <video/edid.h>
55330 #include <video/uvesafb.h>
55331 #ifdef CONFIG_X86
55332 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55333 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55334 par->pmi_setpal = par->ypan = 0;
55335 } else {
55336 +
55337 +#ifdef CONFIG_PAX_KERNEXEC
55338 +#ifdef CONFIG_MODULES
55339 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55340 +#endif
55341 + if (!par->pmi_code) {
55342 + par->pmi_setpal = par->ypan = 0;
55343 + return 0;
55344 + }
55345 +#endif
55346 +
55347 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55348 + task->t.regs.edi);
55349 +
55350 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55351 + pax_open_kernel();
55352 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55353 + pax_close_kernel();
55354 +
55355 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55356 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55357 +#else
55358 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55359 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55360 +#endif
55361 +
55362 printk(KERN_INFO "uvesafb: protected mode interface info at "
55363 "%04x:%04x\n",
55364 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55365 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55366 par->ypan = ypan;
55367
55368 if (par->pmi_setpal || par->ypan) {
55369 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55370 if (__supported_pte_mask & _PAGE_NX) {
55371 par->pmi_setpal = par->ypan = 0;
55372 printk(KERN_WARNING "uvesafb: NX protection is active, "
55373 "better not use the PMI.\n");
55374 - } else {
55375 + } else
55376 +#endif
55377 uvesafb_vbe_getpmi(task, par);
55378 - }
55379 }
55380 #else
55381 /* The protected mode interface is not available on non-x86. */
55382 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55383 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55384
55385 /* Disable blanking if the user requested so. */
55386 - if (!blank)
55387 - info->fbops->fb_blank = NULL;
55388 + if (!blank) {
55389 + pax_open_kernel();
55390 + *(void **)&info->fbops->fb_blank = NULL;
55391 + pax_close_kernel();
55392 + }
55393
55394 /*
55395 * Find out how much IO memory is required for the mode with
55396 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55397 info->flags = FBINFO_FLAG_DEFAULT |
55398 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55399
55400 - if (!par->ypan)
55401 - info->fbops->fb_pan_display = NULL;
55402 + if (!par->ypan) {
55403 + pax_open_kernel();
55404 + *(void **)&info->fbops->fb_pan_display = NULL;
55405 + pax_close_kernel();
55406 + }
55407 }
55408
55409 static void uvesafb_init_mtrr(struct fb_info *info)
55410 @@ -1787,6 +1817,11 @@ out_mode:
55411 out:
55412 kfree(par->vbe_modes);
55413
55414 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55415 + if (par->pmi_code)
55416 + module_free_exec(NULL, par->pmi_code);
55417 +#endif
55418 +
55419 framebuffer_release(info);
55420 return err;
55421 }
55422 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55423 kfree(par->vbe_state_orig);
55424 kfree(par->vbe_state_saved);
55425
55426 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55427 + if (par->pmi_code)
55428 + module_free_exec(NULL, par->pmi_code);
55429 +#endif
55430 +
55431 framebuffer_release(info);
55432 }
55433 return 0;
55434 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55435 index 6170e7f..dd63031 100644
55436 --- a/drivers/video/fbdev/vesafb.c
55437 +++ b/drivers/video/fbdev/vesafb.c
55438 @@ -9,6 +9,7 @@
55439 */
55440
55441 #include <linux/module.h>
55442 +#include <linux/moduleloader.h>
55443 #include <linux/kernel.h>
55444 #include <linux/errno.h>
55445 #include <linux/string.h>
55446 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55447 static int vram_total; /* Set total amount of memory */
55448 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55449 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55450 -static void (*pmi_start)(void) __read_mostly;
55451 -static void (*pmi_pal) (void) __read_mostly;
55452 +static void (*pmi_start)(void) __read_only;
55453 +static void (*pmi_pal) (void) __read_only;
55454 static int depth __read_mostly;
55455 static int vga_compat __read_mostly;
55456 /* --------------------------------------------------------------------- */
55457 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55458 unsigned int size_remap;
55459 unsigned int size_total;
55460 char *option = NULL;
55461 + void *pmi_code = NULL;
55462
55463 /* ignore error return of fb_get_options */
55464 fb_get_options("vesafb", &option);
55465 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55466 size_remap = size_total;
55467 vesafb_fix.smem_len = size_remap;
55468
55469 -#ifndef __i386__
55470 - screen_info.vesapm_seg = 0;
55471 -#endif
55472 -
55473 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55474 printk(KERN_WARNING
55475 "vesafb: cannot reserve video memory at 0x%lx\n",
55476 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55477 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55478 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55479
55480 +#ifdef __i386__
55481 +
55482 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55483 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55484 + if (!pmi_code)
55485 +#elif !defined(CONFIG_PAX_KERNEXEC)
55486 + if (0)
55487 +#endif
55488 +
55489 +#endif
55490 + screen_info.vesapm_seg = 0;
55491 +
55492 if (screen_info.vesapm_seg) {
55493 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55494 - screen_info.vesapm_seg,screen_info.vesapm_off);
55495 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55496 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55497 }
55498
55499 if (screen_info.vesapm_seg < 0xc000)
55500 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55501
55502 if (ypan || pmi_setpal) {
55503 unsigned short *pmi_base;
55504 +
55505 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55506 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55507 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55508 +
55509 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55510 + pax_open_kernel();
55511 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55512 +#else
55513 + pmi_code = pmi_base;
55514 +#endif
55515 +
55516 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55517 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55518 +
55519 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55520 + pmi_start = ktva_ktla(pmi_start);
55521 + pmi_pal = ktva_ktla(pmi_pal);
55522 + pax_close_kernel();
55523 +#endif
55524 +
55525 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55526 if (pmi_base[3]) {
55527 printk(KERN_INFO "vesafb: pmi: ports = ");
55528 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55529 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55530 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55531
55532 - if (!ypan)
55533 - info->fbops->fb_pan_display = NULL;
55534 + if (!ypan) {
55535 + pax_open_kernel();
55536 + *(void **)&info->fbops->fb_pan_display = NULL;
55537 + pax_close_kernel();
55538 + }
55539
55540 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55541 err = -ENOMEM;
55542 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55543 fb_info(info, "%s frame buffer device\n", info->fix.id);
55544 return 0;
55545 err:
55546 +
55547 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55548 + module_free_exec(NULL, pmi_code);
55549 +#endif
55550 +
55551 if (info->screen_base)
55552 iounmap(info->screen_base);
55553 framebuffer_release(info);
55554 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55555 index 88714ae..16c2e11 100644
55556 --- a/drivers/video/fbdev/via/via_clock.h
55557 +++ b/drivers/video/fbdev/via/via_clock.h
55558 @@ -56,7 +56,7 @@ struct via_clock {
55559
55560 void (*set_engine_pll_state)(u8 state);
55561 void (*set_engine_pll)(struct via_pll_config config);
55562 -};
55563 +} __no_const;
55564
55565
55566 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55567 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55568 index 3c14e43..2630570 100644
55569 --- a/drivers/video/logo/logo_linux_clut224.ppm
55570 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55571 @@ -2,1603 +2,1123 @@ P3
55572 # Standard 224-color Linux logo
55573 80 80
55574 255
55575 - 0 0 0 0 0 0 0 0 0 0 0 0
55576 - 0 0 0 0 0 0 0 0 0 0 0 0
55577 - 0 0 0 0 0 0 0 0 0 0 0 0
55578 - 0 0 0 0 0 0 0 0 0 0 0 0
55579 - 0 0 0 0 0 0 0 0 0 0 0 0
55580 - 0 0 0 0 0 0 0 0 0 0 0 0
55581 - 0 0 0 0 0 0 0 0 0 0 0 0
55582 - 0 0 0 0 0 0 0 0 0 0 0 0
55583 - 0 0 0 0 0 0 0 0 0 0 0 0
55584 - 6 6 6 6 6 6 10 10 10 10 10 10
55585 - 10 10 10 6 6 6 6 6 6 6 6 6
55586 - 0 0 0 0 0 0 0 0 0 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 0 0 0 0 0 0 0 0 0 0 0 0
55591 - 0 0 0 0 0 0 0 0 0 0 0 0
55592 - 0 0 0 0 0 0 0 0 0 0 0 0
55593 - 0 0 0 0 0 0 0 0 0 0 0 0
55594 - 0 0 0 0 0 0 0 0 0 0 0 0
55595 - 0 0 0 0 0 0 0 0 0 0 0 0
55596 - 0 0 0 0 0 0 0 0 0 0 0 0
55597 - 0 0 0 0 0 0 0 0 0 0 0 0
55598 - 0 0 0 0 0 0 0 0 0 0 0 0
55599 - 0 0 0 0 0 0 0 0 0 0 0 0
55600 - 0 0 0 0 0 0 0 0 0 0 0 0
55601 - 0 0 0 0 0 0 0 0 0 0 0 0
55602 - 0 0 0 0 0 0 0 0 0 0 0 0
55603 - 0 0 0 6 6 6 10 10 10 14 14 14
55604 - 22 22 22 26 26 26 30 30 30 34 34 34
55605 - 30 30 30 30 30 30 26 26 26 18 18 18
55606 - 14 14 14 10 10 10 6 6 6 0 0 0
55607 - 0 0 0 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 0 0 0 0 0 0 0 0 0
55610 - 0 0 0 0 0 0 0 0 0 0 0 0
55611 - 0 0 0 0 0 0 0 0 0 0 0 0
55612 - 0 0 0 0 0 0 0 0 0 0 0 0
55613 - 0 0 0 0 0 0 0 0 0 0 0 0
55614 - 0 0 0 0 0 0 0 0 0 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 0 0 0 1 0 0 1 0 0 0
55617 - 0 0 0 0 0 0 0 0 0 0 0 0
55618 - 0 0 0 0 0 0 0 0 0 0 0 0
55619 - 0 0 0 0 0 0 0 0 0 0 0 0
55620 - 0 0 0 0 0 0 0 0 0 0 0 0
55621 - 0 0 0 0 0 0 0 0 0 0 0 0
55622 - 0 0 0 0 0 0 0 0 0 0 0 0
55623 - 6 6 6 14 14 14 26 26 26 42 42 42
55624 - 54 54 54 66 66 66 78 78 78 78 78 78
55625 - 78 78 78 74 74 74 66 66 66 54 54 54
55626 - 42 42 42 26 26 26 18 18 18 10 10 10
55627 - 6 6 6 0 0 0 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 0 0 0 0 0 0 0 0 0 0 0 0
55630 - 0 0 0 0 0 0 0 0 0 0 0 0
55631 - 0 0 0 0 0 0 0 0 0 0 0 0
55632 - 0 0 0 0 0 0 0 0 0 0 0 0
55633 - 0 0 0 0 0 0 0 0 0 0 0 0
55634 - 0 0 0 0 0 0 0 0 0 0 0 0
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 1 0 0 0 0 0 0 0 0 0
55637 - 0 0 0 0 0 0 0 0 0 0 0 0
55638 - 0 0 0 0 0 0 0 0 0 0 0 0
55639 - 0 0 0 0 0 0 0 0 0 0 0 0
55640 - 0 0 0 0 0 0 0 0 0 0 0 0
55641 - 0 0 0 0 0 0 0 0 0 0 0 0
55642 - 0 0 0 0 0 0 0 0 0 10 10 10
55643 - 22 22 22 42 42 42 66 66 66 86 86 86
55644 - 66 66 66 38 38 38 38 38 38 22 22 22
55645 - 26 26 26 34 34 34 54 54 54 66 66 66
55646 - 86 86 86 70 70 70 46 46 46 26 26 26
55647 - 14 14 14 6 6 6 0 0 0 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 0 0 0
55649 - 0 0 0 0 0 0 0 0 0 0 0 0
55650 - 0 0 0 0 0 0 0 0 0 0 0 0
55651 - 0 0 0 0 0 0 0 0 0 0 0 0
55652 - 0 0 0 0 0 0 0 0 0 0 0 0
55653 - 0 0 0 0 0 0 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 1 0 0 1 0 0 1 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 0 0 0 0 0 0 10 10 10 26 26 26
55663 - 50 50 50 82 82 82 58 58 58 6 6 6
55664 - 2 2 6 2 2 6 2 2 6 2 2 6
55665 - 2 2 6 2 2 6 2 2 6 2 2 6
55666 - 6 6 6 54 54 54 86 86 86 66 66 66
55667 - 38 38 38 18 18 18 6 6 6 0 0 0
55668 - 0 0 0 0 0 0 0 0 0 0 0 0
55669 - 0 0 0 0 0 0 0 0 0 0 0 0
55670 - 0 0 0 0 0 0 0 0 0 0 0 0
55671 - 0 0 0 0 0 0 0 0 0 0 0 0
55672 - 0 0 0 0 0 0 0 0 0 0 0 0
55673 - 0 0 0 0 0 0 0 0 0 0 0 0
55674 - 0 0 0 0 0 0 0 0 0 0 0 0
55675 - 0 0 0 0 0 0 0 0 0 0 0 0
55676 - 0 0 0 0 0 0 0 0 0 0 0 0
55677 - 0 0 0 0 0 0 0 0 0 0 0 0
55678 - 0 0 0 0 0 0 0 0 0 0 0 0
55679 - 0 0 0 0 0 0 0 0 0 0 0 0
55680 - 0 0 0 0 0 0 0 0 0 0 0 0
55681 - 0 0 0 0 0 0 0 0 0 0 0 0
55682 - 0 0 0 6 6 6 22 22 22 50 50 50
55683 - 78 78 78 34 34 34 2 2 6 2 2 6
55684 - 2 2 6 2 2 6 2 2 6 2 2 6
55685 - 2 2 6 2 2 6 2 2 6 2 2 6
55686 - 2 2 6 2 2 6 6 6 6 70 70 70
55687 - 78 78 78 46 46 46 22 22 22 6 6 6
55688 - 0 0 0 0 0 0 0 0 0 0 0 0
55689 - 0 0 0 0 0 0 0 0 0 0 0 0
55690 - 0 0 0 0 0 0 0 0 0 0 0 0
55691 - 0 0 0 0 0 0 0 0 0 0 0 0
55692 - 0 0 0 0 0 0 0 0 0 0 0 0
55693 - 0 0 0 0 0 0 0 0 0 0 0 0
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 1 0 0 1 0 0 1 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 6 6 6 18 18 18 42 42 42 82 82 82
55703 - 26 26 26 2 2 6 2 2 6 2 2 6
55704 - 2 2 6 2 2 6 2 2 6 2 2 6
55705 - 2 2 6 2 2 6 2 2 6 14 14 14
55706 - 46 46 46 34 34 34 6 6 6 2 2 6
55707 - 42 42 42 78 78 78 42 42 42 18 18 18
55708 - 6 6 6 0 0 0 0 0 0 0 0 0
55709 - 0 0 0 0 0 0 0 0 0 0 0 0
55710 - 0 0 0 0 0 0 0 0 0 0 0 0
55711 - 0 0 0 0 0 0 0 0 0 0 0 0
55712 - 0 0 0 0 0 0 0 0 0 0 0 0
55713 - 0 0 0 0 0 0 0 0 0 0 0 0
55714 - 0 0 0 0 0 0 0 0 0 0 0 0
55715 - 0 0 0 0 0 0 0 0 0 0 0 0
55716 - 0 0 1 0 0 0 0 0 1 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 10 10 10 30 30 30 66 66 66 58 58 58
55723 - 2 2 6 2 2 6 2 2 6 2 2 6
55724 - 2 2 6 2 2 6 2 2 6 2 2 6
55725 - 2 2 6 2 2 6 2 2 6 26 26 26
55726 - 86 86 86 101 101 101 46 46 46 10 10 10
55727 - 2 2 6 58 58 58 70 70 70 34 34 34
55728 - 10 10 10 0 0 0 0 0 0 0 0 0
55729 - 0 0 0 0 0 0 0 0 0 0 0 0
55730 - 0 0 0 0 0 0 0 0 0 0 0 0
55731 - 0 0 0 0 0 0 0 0 0 0 0 0
55732 - 0 0 0 0 0 0 0 0 0 0 0 0
55733 - 0 0 0 0 0 0 0 0 0 0 0 0
55734 - 0 0 0 0 0 0 0 0 0 0 0 0
55735 - 0 0 0 0 0 0 0 0 0 0 0 0
55736 - 0 0 1 0 0 1 0 0 1 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 0 0 0
55742 - 14 14 14 42 42 42 86 86 86 10 10 10
55743 - 2 2 6 2 2 6 2 2 6 2 2 6
55744 - 2 2 6 2 2 6 2 2 6 2 2 6
55745 - 2 2 6 2 2 6 2 2 6 30 30 30
55746 - 94 94 94 94 94 94 58 58 58 26 26 26
55747 - 2 2 6 6 6 6 78 78 78 54 54 54
55748 - 22 22 22 6 6 6 0 0 0 0 0 0
55749 - 0 0 0 0 0 0 0 0 0 0 0 0
55750 - 0 0 0 0 0 0 0 0 0 0 0 0
55751 - 0 0 0 0 0 0 0 0 0 0 0 0
55752 - 0 0 0 0 0 0 0 0 0 0 0 0
55753 - 0 0 0 0 0 0 0 0 0 0 0 0
55754 - 0 0 0 0 0 0 0 0 0 0 0 0
55755 - 0 0 0 0 0 0 0 0 0 0 0 0
55756 - 0 0 0 0 0 0 0 0 0 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 6 6 6
55762 - 22 22 22 62 62 62 62 62 62 2 2 6
55763 - 2 2 6 2 2 6 2 2 6 2 2 6
55764 - 2 2 6 2 2 6 2 2 6 2 2 6
55765 - 2 2 6 2 2 6 2 2 6 26 26 26
55766 - 54 54 54 38 38 38 18 18 18 10 10 10
55767 - 2 2 6 2 2 6 34 34 34 82 82 82
55768 - 38 38 38 14 14 14 0 0 0 0 0 0
55769 - 0 0 0 0 0 0 0 0 0 0 0 0
55770 - 0 0 0 0 0 0 0 0 0 0 0 0
55771 - 0 0 0 0 0 0 0 0 0 0 0 0
55772 - 0 0 0 0 0 0 0 0 0 0 0 0
55773 - 0 0 0 0 0 0 0 0 0 0 0 0
55774 - 0 0 0 0 0 0 0 0 0 0 0 0
55775 - 0 0 0 0 0 0 0 0 0 0 0 0
55776 - 0 0 0 0 0 1 0 0 1 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 6 6 6
55782 - 30 30 30 78 78 78 30 30 30 2 2 6
55783 - 2 2 6 2 2 6 2 2 6 2 2 6
55784 - 2 2 6 2 2 6 2 2 6 2 2 6
55785 - 2 2 6 2 2 6 2 2 6 10 10 10
55786 - 10 10 10 2 2 6 2 2 6 2 2 6
55787 - 2 2 6 2 2 6 2 2 6 78 78 78
55788 - 50 50 50 18 18 18 6 6 6 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 0 0 0
55790 - 0 0 0 0 0 0 0 0 0 0 0 0
55791 - 0 0 0 0 0 0 0 0 0 0 0 0
55792 - 0 0 0 0 0 0 0 0 0 0 0 0
55793 - 0 0 0 0 0 0 0 0 0 0 0 0
55794 - 0 0 0 0 0 0 0 0 0 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 1 0 0 0 0 0 0 0 0 0
55797 - 0 0 0 0 0 0 0 0 0 0 0 0
55798 - 0 0 0 0 0 0 0 0 0 0 0 0
55799 - 0 0 0 0 0 0 0 0 0 0 0 0
55800 - 0 0 0 0 0 0 0 0 0 0 0 0
55801 - 0 0 0 0 0 0 0 0 0 10 10 10
55802 - 38 38 38 86 86 86 14 14 14 2 2 6
55803 - 2 2 6 2 2 6 2 2 6 2 2 6
55804 - 2 2 6 2 2 6 2 2 6 2 2 6
55805 - 2 2 6 2 2 6 2 2 6 2 2 6
55806 - 2 2 6 2 2 6 2 2 6 2 2 6
55807 - 2 2 6 2 2 6 2 2 6 54 54 54
55808 - 66 66 66 26 26 26 6 6 6 0 0 0
55809 - 0 0 0 0 0 0 0 0 0 0 0 0
55810 - 0 0 0 0 0 0 0 0 0 0 0 0
55811 - 0 0 0 0 0 0 0 0 0 0 0 0
55812 - 0 0 0 0 0 0 0 0 0 0 0 0
55813 - 0 0 0 0 0 0 0 0 0 0 0 0
55814 - 0 0 0 0 0 0 0 0 0 0 0 0
55815 - 0 0 0 0 0 0 0 0 0 0 0 0
55816 - 0 0 0 0 0 1 0 0 1 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 14 14 14
55822 - 42 42 42 82 82 82 2 2 6 2 2 6
55823 - 2 2 6 6 6 6 10 10 10 2 2 6
55824 - 2 2 6 2 2 6 2 2 6 2 2 6
55825 - 2 2 6 2 2 6 2 2 6 6 6 6
55826 - 14 14 14 10 10 10 2 2 6 2 2 6
55827 - 2 2 6 2 2 6 2 2 6 18 18 18
55828 - 82 82 82 34 34 34 10 10 10 0 0 0
55829 - 0 0 0 0 0 0 0 0 0 0 0 0
55830 - 0 0 0 0 0 0 0 0 0 0 0 0
55831 - 0 0 0 0 0 0 0 0 0 0 0 0
55832 - 0 0 0 0 0 0 0 0 0 0 0 0
55833 - 0 0 0 0 0 0 0 0 0 0 0 0
55834 - 0 0 0 0 0 0 0 0 0 0 0 0
55835 - 0 0 0 0 0 0 0 0 0 0 0 0
55836 - 0 0 1 0 0 0 0 0 0 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 14 14 14
55842 - 46 46 46 86 86 86 2 2 6 2 2 6
55843 - 6 6 6 6 6 6 22 22 22 34 34 34
55844 - 6 6 6 2 2 6 2 2 6 2 2 6
55845 - 2 2 6 2 2 6 18 18 18 34 34 34
55846 - 10 10 10 50 50 50 22 22 22 2 2 6
55847 - 2 2 6 2 2 6 2 2 6 10 10 10
55848 - 86 86 86 42 42 42 14 14 14 0 0 0
55849 - 0 0 0 0 0 0 0 0 0 0 0 0
55850 - 0 0 0 0 0 0 0 0 0 0 0 0
55851 - 0 0 0 0 0 0 0 0 0 0 0 0
55852 - 0 0 0 0 0 0 0 0 0 0 0 0
55853 - 0 0 0 0 0 0 0 0 0 0 0 0
55854 - 0 0 0 0 0 0 0 0 0 0 0 0
55855 - 0 0 0 0 0 0 0 0 0 0 0 0
55856 - 0 0 1 0 0 1 0 0 1 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 14 14 14
55862 - 46 46 46 86 86 86 2 2 6 2 2 6
55863 - 38 38 38 116 116 116 94 94 94 22 22 22
55864 - 22 22 22 2 2 6 2 2 6 2 2 6
55865 - 14 14 14 86 86 86 138 138 138 162 162 162
55866 -154 154 154 38 38 38 26 26 26 6 6 6
55867 - 2 2 6 2 2 6 2 2 6 2 2 6
55868 - 86 86 86 46 46 46 14 14 14 0 0 0
55869 - 0 0 0 0 0 0 0 0 0 0 0 0
55870 - 0 0 0 0 0 0 0 0 0 0 0 0
55871 - 0 0 0 0 0 0 0 0 0 0 0 0
55872 - 0 0 0 0 0 0 0 0 0 0 0 0
55873 - 0 0 0 0 0 0 0 0 0 0 0 0
55874 - 0 0 0 0 0 0 0 0 0 0 0 0
55875 - 0 0 0 0 0 0 0 0 0 0 0 0
55876 - 0 0 0 0 0 0 0 0 0 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 14 14 14
55882 - 46 46 46 86 86 86 2 2 6 14 14 14
55883 -134 134 134 198 198 198 195 195 195 116 116 116
55884 - 10 10 10 2 2 6 2 2 6 6 6 6
55885 -101 98 89 187 187 187 210 210 210 218 218 218
55886 -214 214 214 134 134 134 14 14 14 6 6 6
55887 - 2 2 6 2 2 6 2 2 6 2 2 6
55888 - 86 86 86 50 50 50 18 18 18 6 6 6
55889 - 0 0 0 0 0 0 0 0 0 0 0 0
55890 - 0 0 0 0 0 0 0 0 0 0 0 0
55891 - 0 0 0 0 0 0 0 0 0 0 0 0
55892 - 0 0 0 0 0 0 0 0 0 0 0 0
55893 - 0 0 0 0 0 0 0 0 0 0 0 0
55894 - 0 0 0 0 0 0 0 0 0 0 0 0
55895 - 0 0 0 0 0 0 0 0 1 0 0 0
55896 - 0 0 1 0 0 1 0 0 1 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 0 14 14 14
55902 - 46 46 46 86 86 86 2 2 6 54 54 54
55903 -218 218 218 195 195 195 226 226 226 246 246 246
55904 - 58 58 58 2 2 6 2 2 6 30 30 30
55905 -210 210 210 253 253 253 174 174 174 123 123 123
55906 -221 221 221 234 234 234 74 74 74 2 2 6
55907 - 2 2 6 2 2 6 2 2 6 2 2 6
55908 - 70 70 70 58 58 58 22 22 22 6 6 6
55909 - 0 0 0 0 0 0 0 0 0 0 0 0
55910 - 0 0 0 0 0 0 0 0 0 0 0 0
55911 - 0 0 0 0 0 0 0 0 0 0 0 0
55912 - 0 0 0 0 0 0 0 0 0 0 0 0
55913 - 0 0 0 0 0 0 0 0 0 0 0 0
55914 - 0 0 0 0 0 0 0 0 0 0 0 0
55915 - 0 0 0 0 0 0 0 0 0 0 0 0
55916 - 0 0 0 0 0 0 0 0 0 0 0 0
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 0 0 0 0 0 0 0 0 0
55921 - 0 0 0 0 0 0 0 0 0 14 14 14
55922 - 46 46 46 82 82 82 2 2 6 106 106 106
55923 -170 170 170 26 26 26 86 86 86 226 226 226
55924 -123 123 123 10 10 10 14 14 14 46 46 46
55925 -231 231 231 190 190 190 6 6 6 70 70 70
55926 - 90 90 90 238 238 238 158 158 158 2 2 6
55927 - 2 2 6 2 2 6 2 2 6 2 2 6
55928 - 70 70 70 58 58 58 22 22 22 6 6 6
55929 - 0 0 0 0 0 0 0 0 0 0 0 0
55930 - 0 0 0 0 0 0 0 0 0 0 0 0
55931 - 0 0 0 0 0 0 0 0 0 0 0 0
55932 - 0 0 0 0 0 0 0 0 0 0 0 0
55933 - 0 0 0 0 0 0 0 0 0 0 0 0
55934 - 0 0 0 0 0 0 0 0 0 0 0 0
55935 - 0 0 0 0 0 0 0 0 1 0 0 0
55936 - 0 0 1 0 0 1 0 0 1 0 0 0
55937 - 0 0 0 0 0 0 0 0 0 0 0 0
55938 - 0 0 0 0 0 0 0 0 0 0 0 0
55939 - 0 0 0 0 0 0 0 0 0 0 0 0
55940 - 0 0 0 0 0 0 0 0 0 0 0 0
55941 - 0 0 0 0 0 0 0 0 0 14 14 14
55942 - 42 42 42 86 86 86 6 6 6 116 116 116
55943 -106 106 106 6 6 6 70 70 70 149 149 149
55944 -128 128 128 18 18 18 38 38 38 54 54 54
55945 -221 221 221 106 106 106 2 2 6 14 14 14
55946 - 46 46 46 190 190 190 198 198 198 2 2 6
55947 - 2 2 6 2 2 6 2 2 6 2 2 6
55948 - 74 74 74 62 62 62 22 22 22 6 6 6
55949 - 0 0 0 0 0 0 0 0 0 0 0 0
55950 - 0 0 0 0 0 0 0 0 0 0 0 0
55951 - 0 0 0 0 0 0 0 0 0 0 0 0
55952 - 0 0 0 0 0 0 0 0 0 0 0 0
55953 - 0 0 0 0 0 0 0 0 0 0 0 0
55954 - 0 0 0 0 0 0 0 0 0 0 0 0
55955 - 0 0 0 0 0 0 0 0 1 0 0 0
55956 - 0 0 1 0 0 0 0 0 1 0 0 0
55957 - 0 0 0 0 0 0 0 0 0 0 0 0
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 14 14 14
55962 - 42 42 42 94 94 94 14 14 14 101 101 101
55963 -128 128 128 2 2 6 18 18 18 116 116 116
55964 -118 98 46 121 92 8 121 92 8 98 78 10
55965 -162 162 162 106 106 106 2 2 6 2 2 6
55966 - 2 2 6 195 195 195 195 195 195 6 6 6
55967 - 2 2 6 2 2 6 2 2 6 2 2 6
55968 - 74 74 74 62 62 62 22 22 22 6 6 6
55969 - 0 0 0 0 0 0 0 0 0 0 0 0
55970 - 0 0 0 0 0 0 0 0 0 0 0 0
55971 - 0 0 0 0 0 0 0 0 0 0 0 0
55972 - 0 0 0 0 0 0 0 0 0 0 0 0
55973 - 0 0 0 0 0 0 0 0 0 0 0 0
55974 - 0 0 0 0 0 0 0 0 0 0 0 0
55975 - 0 0 0 0 0 0 0 0 1 0 0 1
55976 - 0 0 1 0 0 0 0 0 1 0 0 0
55977 - 0 0 0 0 0 0 0 0 0 0 0 0
55978 - 0 0 0 0 0 0 0 0 0 0 0 0
55979 - 0 0 0 0 0 0 0 0 0 0 0 0
55980 - 0 0 0 0 0 0 0 0 0 0 0 0
55981 - 0 0 0 0 0 0 0 0 0 10 10 10
55982 - 38 38 38 90 90 90 14 14 14 58 58 58
55983 -210 210 210 26 26 26 54 38 6 154 114 10
55984 -226 170 11 236 186 11 225 175 15 184 144 12
55985 -215 174 15 175 146 61 37 26 9 2 2 6
55986 - 70 70 70 246 246 246 138 138 138 2 2 6
55987 - 2 2 6 2 2 6 2 2 6 2 2 6
55988 - 70 70 70 66 66 66 26 26 26 6 6 6
55989 - 0 0 0 0 0 0 0 0 0 0 0 0
55990 - 0 0 0 0 0 0 0 0 0 0 0 0
55991 - 0 0 0 0 0 0 0 0 0 0 0 0
55992 - 0 0 0 0 0 0 0 0 0 0 0 0
55993 - 0 0 0 0 0 0 0 0 0 0 0 0
55994 - 0 0 0 0 0 0 0 0 0 0 0 0
55995 - 0 0 0 0 0 0 0 0 0 0 0 0
55996 - 0 0 0 0 0 0 0 0 0 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 10 10 10
56002 - 38 38 38 86 86 86 14 14 14 10 10 10
56003 -195 195 195 188 164 115 192 133 9 225 175 15
56004 -239 182 13 234 190 10 232 195 16 232 200 30
56005 -245 207 45 241 208 19 232 195 16 184 144 12
56006 -218 194 134 211 206 186 42 42 42 2 2 6
56007 - 2 2 6 2 2 6 2 2 6 2 2 6
56008 - 50 50 50 74 74 74 30 30 30 6 6 6
56009 - 0 0 0 0 0 0 0 0 0 0 0 0
56010 - 0 0 0 0 0 0 0 0 0 0 0 0
56011 - 0 0 0 0 0 0 0 0 0 0 0 0
56012 - 0 0 0 0 0 0 0 0 0 0 0 0
56013 - 0 0 0 0 0 0 0 0 0 0 0 0
56014 - 0 0 0 0 0 0 0 0 0 0 0 0
56015 - 0 0 0 0 0 0 0 0 0 0 0 0
56016 - 0 0 0 0 0 0 0 0 0 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 10 10 10
56022 - 34 34 34 86 86 86 14 14 14 2 2 6
56023 -121 87 25 192 133 9 219 162 10 239 182 13
56024 -236 186 11 232 195 16 241 208 19 244 214 54
56025 -246 218 60 246 218 38 246 215 20 241 208 19
56026 -241 208 19 226 184 13 121 87 25 2 2 6
56027 - 2 2 6 2 2 6 2 2 6 2 2 6
56028 - 50 50 50 82 82 82 34 34 34 10 10 10
56029 - 0 0 0 0 0 0 0 0 0 0 0 0
56030 - 0 0 0 0 0 0 0 0 0 0 0 0
56031 - 0 0 0 0 0 0 0 0 0 0 0 0
56032 - 0 0 0 0 0 0 0 0 0 0 0 0
56033 - 0 0 0 0 0 0 0 0 0 0 0 0
56034 - 0 0 0 0 0 0 0 0 0 0 0 0
56035 - 0 0 0 0 0 0 0 0 0 0 0 0
56036 - 0 0 0 0 0 0 0 0 0 0 0 0
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 0 0 0 0 0 0 0 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 10 10 10
56042 - 34 34 34 82 82 82 30 30 30 61 42 6
56043 -180 123 7 206 145 10 230 174 11 239 182 13
56044 -234 190 10 238 202 15 241 208 19 246 218 74
56045 -246 218 38 246 215 20 246 215 20 246 215 20
56046 -226 184 13 215 174 15 184 144 12 6 6 6
56047 - 2 2 6 2 2 6 2 2 6 2 2 6
56048 - 26 26 26 94 94 94 42 42 42 14 14 14
56049 - 0 0 0 0 0 0 0 0 0 0 0 0
56050 - 0 0 0 0 0 0 0 0 0 0 0 0
56051 - 0 0 0 0 0 0 0 0 0 0 0 0
56052 - 0 0 0 0 0 0 0 0 0 0 0 0
56053 - 0 0 0 0 0 0 0 0 0 0 0 0
56054 - 0 0 0 0 0 0 0 0 0 0 0 0
56055 - 0 0 0 0 0 0 0 0 0 0 0 0
56056 - 0 0 0 0 0 0 0 0 0 0 0 0
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 10 10 10
56062 - 30 30 30 78 78 78 50 50 50 104 69 6
56063 -192 133 9 216 158 10 236 178 12 236 186 11
56064 -232 195 16 241 208 19 244 214 54 245 215 43
56065 -246 215 20 246 215 20 241 208 19 198 155 10
56066 -200 144 11 216 158 10 156 118 10 2 2 6
56067 - 2 2 6 2 2 6 2 2 6 2 2 6
56068 - 6 6 6 90 90 90 54 54 54 18 18 18
56069 - 6 6 6 0 0 0 0 0 0 0 0 0
56070 - 0 0 0 0 0 0 0 0 0 0 0 0
56071 - 0 0 0 0 0 0 0 0 0 0 0 0
56072 - 0 0 0 0 0 0 0 0 0 0 0 0
56073 - 0 0 0 0 0 0 0 0 0 0 0 0
56074 - 0 0 0 0 0 0 0 0 0 0 0 0
56075 - 0 0 0 0 0 0 0 0 0 0 0 0
56076 - 0 0 0 0 0 0 0 0 0 0 0 0
56077 - 0 0 0 0 0 0 0 0 0 0 0 0
56078 - 0 0 0 0 0 0 0 0 0 0 0 0
56079 - 0 0 0 0 0 0 0 0 0 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 10 10 10
56082 - 30 30 30 78 78 78 46 46 46 22 22 22
56083 -137 92 6 210 162 10 239 182 13 238 190 10
56084 -238 202 15 241 208 19 246 215 20 246 215 20
56085 -241 208 19 203 166 17 185 133 11 210 150 10
56086 -216 158 10 210 150 10 102 78 10 2 2 6
56087 - 6 6 6 54 54 54 14 14 14 2 2 6
56088 - 2 2 6 62 62 62 74 74 74 30 30 30
56089 - 10 10 10 0 0 0 0 0 0 0 0 0
56090 - 0 0 0 0 0 0 0 0 0 0 0 0
56091 - 0 0 0 0 0 0 0 0 0 0 0 0
56092 - 0 0 0 0 0 0 0 0 0 0 0 0
56093 - 0 0 0 0 0 0 0 0 0 0 0 0
56094 - 0 0 0 0 0 0 0 0 0 0 0 0
56095 - 0 0 0 0 0 0 0 0 0 0 0 0
56096 - 0 0 0 0 0 0 0 0 0 0 0 0
56097 - 0 0 0 0 0 0 0 0 0 0 0 0
56098 - 0 0 0 0 0 0 0 0 0 0 0 0
56099 - 0 0 0 0 0 0 0 0 0 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 10 10 10
56102 - 34 34 34 78 78 78 50 50 50 6 6 6
56103 - 94 70 30 139 102 15 190 146 13 226 184 13
56104 -232 200 30 232 195 16 215 174 15 190 146 13
56105 -168 122 10 192 133 9 210 150 10 213 154 11
56106 -202 150 34 182 157 106 101 98 89 2 2 6
56107 - 2 2 6 78 78 78 116 116 116 58 58 58
56108 - 2 2 6 22 22 22 90 90 90 46 46 46
56109 - 18 18 18 6 6 6 0 0 0 0 0 0
56110 - 0 0 0 0 0 0 0 0 0 0 0 0
56111 - 0 0 0 0 0 0 0 0 0 0 0 0
56112 - 0 0 0 0 0 0 0 0 0 0 0 0
56113 - 0 0 0 0 0 0 0 0 0 0 0 0
56114 - 0 0 0 0 0 0 0 0 0 0 0 0
56115 - 0 0 0 0 0 0 0 0 0 0 0 0
56116 - 0 0 0 0 0 0 0 0 0 0 0 0
56117 - 0 0 0 0 0 0 0 0 0 0 0 0
56118 - 0 0 0 0 0 0 0 0 0 0 0 0
56119 - 0 0 0 0 0 0 0 0 0 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 0 0 0 10 10 10
56122 - 38 38 38 86 86 86 50 50 50 6 6 6
56123 -128 128 128 174 154 114 156 107 11 168 122 10
56124 -198 155 10 184 144 12 197 138 11 200 144 11
56125 -206 145 10 206 145 10 197 138 11 188 164 115
56126 -195 195 195 198 198 198 174 174 174 14 14 14
56127 - 2 2 6 22 22 22 116 116 116 116 116 116
56128 - 22 22 22 2 2 6 74 74 74 70 70 70
56129 - 30 30 30 10 10 10 0 0 0 0 0 0
56130 - 0 0 0 0 0 0 0 0 0 0 0 0
56131 - 0 0 0 0 0 0 0 0 0 0 0 0
56132 - 0 0 0 0 0 0 0 0 0 0 0 0
56133 - 0 0 0 0 0 0 0 0 0 0 0 0
56134 - 0 0 0 0 0 0 0 0 0 0 0 0
56135 - 0 0 0 0 0 0 0 0 0 0 0 0
56136 - 0 0 0 0 0 0 0 0 0 0 0 0
56137 - 0 0 0 0 0 0 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 6 6 6 18 18 18
56142 - 50 50 50 101 101 101 26 26 26 10 10 10
56143 -138 138 138 190 190 190 174 154 114 156 107 11
56144 -197 138 11 200 144 11 197 138 11 192 133 9
56145 -180 123 7 190 142 34 190 178 144 187 187 187
56146 -202 202 202 221 221 221 214 214 214 66 66 66
56147 - 2 2 6 2 2 6 50 50 50 62 62 62
56148 - 6 6 6 2 2 6 10 10 10 90 90 90
56149 - 50 50 50 18 18 18 6 6 6 0 0 0
56150 - 0 0 0 0 0 0 0 0 0 0 0 0
56151 - 0 0 0 0 0 0 0 0 0 0 0 0
56152 - 0 0 0 0 0 0 0 0 0 0 0 0
56153 - 0 0 0 0 0 0 0 0 0 0 0 0
56154 - 0 0 0 0 0 0 0 0 0 0 0 0
56155 - 0 0 0 0 0 0 0 0 0 0 0 0
56156 - 0 0 0 0 0 0 0 0 0 0 0 0
56157 - 0 0 0 0 0 0 0 0 0 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 10 10 10 34 34 34
56162 - 74 74 74 74 74 74 2 2 6 6 6 6
56163 -144 144 144 198 198 198 190 190 190 178 166 146
56164 -154 121 60 156 107 11 156 107 11 168 124 44
56165 -174 154 114 187 187 187 190 190 190 210 210 210
56166 -246 246 246 253 253 253 253 253 253 182 182 182
56167 - 6 6 6 2 2 6 2 2 6 2 2 6
56168 - 2 2 6 2 2 6 2 2 6 62 62 62
56169 - 74 74 74 34 34 34 14 14 14 0 0 0
56170 - 0 0 0 0 0 0 0 0 0 0 0 0
56171 - 0 0 0 0 0 0 0 0 0 0 0 0
56172 - 0 0 0 0 0 0 0 0 0 0 0 0
56173 - 0 0 0 0 0 0 0 0 0 0 0 0
56174 - 0 0 0 0 0 0 0 0 0 0 0 0
56175 - 0 0 0 0 0 0 0 0 0 0 0 0
56176 - 0 0 0 0 0 0 0 0 0 0 0 0
56177 - 0 0 0 0 0 0 0 0 0 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 10 10 10 22 22 22 54 54 54
56182 - 94 94 94 18 18 18 2 2 6 46 46 46
56183 -234 234 234 221 221 221 190 190 190 190 190 190
56184 -190 190 190 187 187 187 187 187 187 190 190 190
56185 -190 190 190 195 195 195 214 214 214 242 242 242
56186 -253 253 253 253 253 253 253 253 253 253 253 253
56187 - 82 82 82 2 2 6 2 2 6 2 2 6
56188 - 2 2 6 2 2 6 2 2 6 14 14 14
56189 - 86 86 86 54 54 54 22 22 22 6 6 6
56190 - 0 0 0 0 0 0 0 0 0 0 0 0
56191 - 0 0 0 0 0 0 0 0 0 0 0 0
56192 - 0 0 0 0 0 0 0 0 0 0 0 0
56193 - 0 0 0 0 0 0 0 0 0 0 0 0
56194 - 0 0 0 0 0 0 0 0 0 0 0 0
56195 - 0 0 0 0 0 0 0 0 0 0 0 0
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 6 6 6 18 18 18 46 46 46 90 90 90
56202 - 46 46 46 18 18 18 6 6 6 182 182 182
56203 -253 253 253 246 246 246 206 206 206 190 190 190
56204 -190 190 190 190 190 190 190 190 190 190 190 190
56205 -206 206 206 231 231 231 250 250 250 253 253 253
56206 -253 253 253 253 253 253 253 253 253 253 253 253
56207 -202 202 202 14 14 14 2 2 6 2 2 6
56208 - 2 2 6 2 2 6 2 2 6 2 2 6
56209 - 42 42 42 86 86 86 42 42 42 18 18 18
56210 - 6 6 6 0 0 0 0 0 0 0 0 0
56211 - 0 0 0 0 0 0 0 0 0 0 0 0
56212 - 0 0 0 0 0 0 0 0 0 0 0 0
56213 - 0 0 0 0 0 0 0 0 0 0 0 0
56214 - 0 0 0 0 0 0 0 0 0 0 0 0
56215 - 0 0 0 0 0 0 0 0 0 0 0 0
56216 - 0 0 0 0 0 0 0 0 0 0 0 0
56217 - 0 0 0 0 0 0 0 0 0 0 0 0
56218 - 0 0 0 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 6 6 6
56221 - 14 14 14 38 38 38 74 74 74 66 66 66
56222 - 2 2 6 6 6 6 90 90 90 250 250 250
56223 -253 253 253 253 253 253 238 238 238 198 198 198
56224 -190 190 190 190 190 190 195 195 195 221 221 221
56225 -246 246 246 253 253 253 253 253 253 253 253 253
56226 -253 253 253 253 253 253 253 253 253 253 253 253
56227 -253 253 253 82 82 82 2 2 6 2 2 6
56228 - 2 2 6 2 2 6 2 2 6 2 2 6
56229 - 2 2 6 78 78 78 70 70 70 34 34 34
56230 - 14 14 14 6 6 6 0 0 0 0 0 0
56231 - 0 0 0 0 0 0 0 0 0 0 0 0
56232 - 0 0 0 0 0 0 0 0 0 0 0 0
56233 - 0 0 0 0 0 0 0 0 0 0 0 0
56234 - 0 0 0 0 0 0 0 0 0 0 0 0
56235 - 0 0 0 0 0 0 0 0 0 0 0 0
56236 - 0 0 0 0 0 0 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 14 14 14
56241 - 34 34 34 66 66 66 78 78 78 6 6 6
56242 - 2 2 6 18 18 18 218 218 218 253 253 253
56243 -253 253 253 253 253 253 253 253 253 246 246 246
56244 -226 226 226 231 231 231 246 246 246 253 253 253
56245 -253 253 253 253 253 253 253 253 253 253 253 253
56246 -253 253 253 253 253 253 253 253 253 253 253 253
56247 -253 253 253 178 178 178 2 2 6 2 2 6
56248 - 2 2 6 2 2 6 2 2 6 2 2 6
56249 - 2 2 6 18 18 18 90 90 90 62 62 62
56250 - 30 30 30 10 10 10 0 0 0 0 0 0
56251 - 0 0 0 0 0 0 0 0 0 0 0 0
56252 - 0 0 0 0 0 0 0 0 0 0 0 0
56253 - 0 0 0 0 0 0 0 0 0 0 0 0
56254 - 0 0 0 0 0 0 0 0 0 0 0 0
56255 - 0 0 0 0 0 0 0 0 0 0 0 0
56256 - 0 0 0 0 0 0 0 0 0 0 0 0
56257 - 0 0 0 0 0 0 0 0 0 0 0 0
56258 - 0 0 0 0 0 0 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 0 0 0 10 10 10 26 26 26
56261 - 58 58 58 90 90 90 18 18 18 2 2 6
56262 - 2 2 6 110 110 110 253 253 253 253 253 253
56263 -253 253 253 253 253 253 253 253 253 253 253 253
56264 -250 250 250 253 253 253 253 253 253 253 253 253
56265 -253 253 253 253 253 253 253 253 253 253 253 253
56266 -253 253 253 253 253 253 253 253 253 253 253 253
56267 -253 253 253 231 231 231 18 18 18 2 2 6
56268 - 2 2 6 2 2 6 2 2 6 2 2 6
56269 - 2 2 6 2 2 6 18 18 18 94 94 94
56270 - 54 54 54 26 26 26 10 10 10 0 0 0
56271 - 0 0 0 0 0 0 0 0 0 0 0 0
56272 - 0 0 0 0 0 0 0 0 0 0 0 0
56273 - 0 0 0 0 0 0 0 0 0 0 0 0
56274 - 0 0 0 0 0 0 0 0 0 0 0 0
56275 - 0 0 0 0 0 0 0 0 0 0 0 0
56276 - 0 0 0 0 0 0 0 0 0 0 0 0
56277 - 0 0 0 0 0 0 0 0 0 0 0 0
56278 - 0 0 0 0 0 0 0 0 0 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 0 0 0 6 6 6 22 22 22 50 50 50
56281 - 90 90 90 26 26 26 2 2 6 2 2 6
56282 - 14 14 14 195 195 195 250 250 250 253 253 253
56283 -253 253 253 253 253 253 253 253 253 253 253 253
56284 -253 253 253 253 253 253 253 253 253 253 253 253
56285 -253 253 253 253 253 253 253 253 253 253 253 253
56286 -253 253 253 253 253 253 253 253 253 253 253 253
56287 -250 250 250 242 242 242 54 54 54 2 2 6
56288 - 2 2 6 2 2 6 2 2 6 2 2 6
56289 - 2 2 6 2 2 6 2 2 6 38 38 38
56290 - 86 86 86 50 50 50 22 22 22 6 6 6
56291 - 0 0 0 0 0 0 0 0 0 0 0 0
56292 - 0 0 0 0 0 0 0 0 0 0 0 0
56293 - 0 0 0 0 0 0 0 0 0 0 0 0
56294 - 0 0 0 0 0 0 0 0 0 0 0 0
56295 - 0 0 0 0 0 0 0 0 0 0 0 0
56296 - 0 0 0 0 0 0 0 0 0 0 0 0
56297 - 0 0 0 0 0 0 0 0 0 0 0 0
56298 - 0 0 0 0 0 0 0 0 0 0 0 0
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 6 6 6 14 14 14 38 38 38 82 82 82
56301 - 34 34 34 2 2 6 2 2 6 2 2 6
56302 - 42 42 42 195 195 195 246 246 246 253 253 253
56303 -253 253 253 253 253 253 253 253 253 250 250 250
56304 -242 242 242 242 242 242 250 250 250 253 253 253
56305 -253 253 253 253 253 253 253 253 253 253 253 253
56306 -253 253 253 250 250 250 246 246 246 238 238 238
56307 -226 226 226 231 231 231 101 101 101 6 6 6
56308 - 2 2 6 2 2 6 2 2 6 2 2 6
56309 - 2 2 6 2 2 6 2 2 6 2 2 6
56310 - 38 38 38 82 82 82 42 42 42 14 14 14
56311 - 6 6 6 0 0 0 0 0 0 0 0 0
56312 - 0 0 0 0 0 0 0 0 0 0 0 0
56313 - 0 0 0 0 0 0 0 0 0 0 0 0
56314 - 0 0 0 0 0 0 0 0 0 0 0 0
56315 - 0 0 0 0 0 0 0 0 0 0 0 0
56316 - 0 0 0 0 0 0 0 0 0 0 0 0
56317 - 0 0 0 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 0 0 0
56319 - 0 0 0 0 0 0 0 0 0 0 0 0
56320 - 10 10 10 26 26 26 62 62 62 66 66 66
56321 - 2 2 6 2 2 6 2 2 6 6 6 6
56322 - 70 70 70 170 170 170 206 206 206 234 234 234
56323 -246 246 246 250 250 250 250 250 250 238 238 238
56324 -226 226 226 231 231 231 238 238 238 250 250 250
56325 -250 250 250 250 250 250 246 246 246 231 231 231
56326 -214 214 214 206 206 206 202 202 202 202 202 202
56327 -198 198 198 202 202 202 182 182 182 18 18 18
56328 - 2 2 6 2 2 6 2 2 6 2 2 6
56329 - 2 2 6 2 2 6 2 2 6 2 2 6
56330 - 2 2 6 62 62 62 66 66 66 30 30 30
56331 - 10 10 10 0 0 0 0 0 0 0 0 0
56332 - 0 0 0 0 0 0 0 0 0 0 0 0
56333 - 0 0 0 0 0 0 0 0 0 0 0 0
56334 - 0 0 0 0 0 0 0 0 0 0 0 0
56335 - 0 0 0 0 0 0 0 0 0 0 0 0
56336 - 0 0 0 0 0 0 0 0 0 0 0 0
56337 - 0 0 0 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 0 0 0
56339 - 0 0 0 0 0 0 0 0 0 0 0 0
56340 - 14 14 14 42 42 42 82 82 82 18 18 18
56341 - 2 2 6 2 2 6 2 2 6 10 10 10
56342 - 94 94 94 182 182 182 218 218 218 242 242 242
56343 -250 250 250 253 253 253 253 253 253 250 250 250
56344 -234 234 234 253 253 253 253 253 253 253 253 253
56345 -253 253 253 253 253 253 253 253 253 246 246 246
56346 -238 238 238 226 226 226 210 210 210 202 202 202
56347 -195 195 195 195 195 195 210 210 210 158 158 158
56348 - 6 6 6 14 14 14 50 50 50 14 14 14
56349 - 2 2 6 2 2 6 2 2 6 2 2 6
56350 - 2 2 6 6 6 6 86 86 86 46 46 46
56351 - 18 18 18 6 6 6 0 0 0 0 0 0
56352 - 0 0 0 0 0 0 0 0 0 0 0 0
56353 - 0 0 0 0 0 0 0 0 0 0 0 0
56354 - 0 0 0 0 0 0 0 0 0 0 0 0
56355 - 0 0 0 0 0 0 0 0 0 0 0 0
56356 - 0 0 0 0 0 0 0 0 0 0 0 0
56357 - 0 0 0 0 0 0 0 0 0 0 0 0
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 6 6 6
56360 - 22 22 22 54 54 54 70 70 70 2 2 6
56361 - 2 2 6 10 10 10 2 2 6 22 22 22
56362 -166 166 166 231 231 231 250 250 250 253 253 253
56363 -253 253 253 253 253 253 253 253 253 250 250 250
56364 -242 242 242 253 253 253 253 253 253 253 253 253
56365 -253 253 253 253 253 253 253 253 253 253 253 253
56366 -253 253 253 253 253 253 253 253 253 246 246 246
56367 -231 231 231 206 206 206 198 198 198 226 226 226
56368 - 94 94 94 2 2 6 6 6 6 38 38 38
56369 - 30 30 30 2 2 6 2 2 6 2 2 6
56370 - 2 2 6 2 2 6 62 62 62 66 66 66
56371 - 26 26 26 10 10 10 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 0 0 0 0 0 0 0 0 0
56376 - 0 0 0 0 0 0 0 0 0 0 0 0
56377 - 0 0 0 0 0 0 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 10 10 10
56380 - 30 30 30 74 74 74 50 50 50 2 2 6
56381 - 26 26 26 26 26 26 2 2 6 106 106 106
56382 -238 238 238 253 253 253 253 253 253 253 253 253
56383 -253 253 253 253 253 253 253 253 253 253 253 253
56384 -253 253 253 253 253 253 253 253 253 253 253 253
56385 -253 253 253 253 253 253 253 253 253 253 253 253
56386 -253 253 253 253 253 253 253 253 253 253 253 253
56387 -253 253 253 246 246 246 218 218 218 202 202 202
56388 -210 210 210 14 14 14 2 2 6 2 2 6
56389 - 30 30 30 22 22 22 2 2 6 2 2 6
56390 - 2 2 6 2 2 6 18 18 18 86 86 86
56391 - 42 42 42 14 14 14 0 0 0 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 0 0 0 0 0 0 0 0 0 0 0 0
56396 - 0 0 0 0 0 0 0 0 0 0 0 0
56397 - 0 0 0 0 0 0 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 0 0 0
56399 - 0 0 0 0 0 0 0 0 0 14 14 14
56400 - 42 42 42 90 90 90 22 22 22 2 2 6
56401 - 42 42 42 2 2 6 18 18 18 218 218 218
56402 -253 253 253 253 253 253 253 253 253 253 253 253
56403 -253 253 253 253 253 253 253 253 253 253 253 253
56404 -253 253 253 253 253 253 253 253 253 253 253 253
56405 -253 253 253 253 253 253 253 253 253 253 253 253
56406 -253 253 253 253 253 253 253 253 253 253 253 253
56407 -253 253 253 253 253 253 250 250 250 221 221 221
56408 -218 218 218 101 101 101 2 2 6 14 14 14
56409 - 18 18 18 38 38 38 10 10 10 2 2 6
56410 - 2 2 6 2 2 6 2 2 6 78 78 78
56411 - 58 58 58 22 22 22 6 6 6 0 0 0
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 0 0 0
56415 - 0 0 0 0 0 0 0 0 0 0 0 0
56416 - 0 0 0 0 0 0 0 0 0 0 0 0
56417 - 0 0 0 0 0 0 0 0 0 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 6 6 6 18 18 18
56420 - 54 54 54 82 82 82 2 2 6 26 26 26
56421 - 22 22 22 2 2 6 123 123 123 253 253 253
56422 -253 253 253 253 253 253 253 253 253 253 253 253
56423 -253 253 253 253 253 253 253 253 253 253 253 253
56424 -253 253 253 253 253 253 253 253 253 253 253 253
56425 -253 253 253 253 253 253 253 253 253 253 253 253
56426 -253 253 253 253 253 253 253 253 253 253 253 253
56427 -253 253 253 253 253 253 253 253 253 250 250 250
56428 -238 238 238 198 198 198 6 6 6 38 38 38
56429 - 58 58 58 26 26 26 38 38 38 2 2 6
56430 - 2 2 6 2 2 6 2 2 6 46 46 46
56431 - 78 78 78 30 30 30 10 10 10 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 0 0 0 10 10 10 30 30 30
56440 - 74 74 74 58 58 58 2 2 6 42 42 42
56441 - 2 2 6 22 22 22 231 231 231 253 253 253
56442 -253 253 253 253 253 253 253 253 253 253 253 253
56443 -253 253 253 253 253 253 253 253 253 250 250 250
56444 -253 253 253 253 253 253 253 253 253 253 253 253
56445 -253 253 253 253 253 253 253 253 253 253 253 253
56446 -253 253 253 253 253 253 253 253 253 253 253 253
56447 -253 253 253 253 253 253 253 253 253 253 253 253
56448 -253 253 253 246 246 246 46 46 46 38 38 38
56449 - 42 42 42 14 14 14 38 38 38 14 14 14
56450 - 2 2 6 2 2 6 2 2 6 6 6 6
56451 - 86 86 86 46 46 46 14 14 14 0 0 0
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 6 6 6 14 14 14 42 42 42
56460 - 90 90 90 18 18 18 18 18 18 26 26 26
56461 - 2 2 6 116 116 116 253 253 253 253 253 253
56462 -253 253 253 253 253 253 253 253 253 253 253 253
56463 -253 253 253 253 253 253 250 250 250 238 238 238
56464 -253 253 253 253 253 253 253 253 253 253 253 253
56465 -253 253 253 253 253 253 253 253 253 253 253 253
56466 -253 253 253 253 253 253 253 253 253 253 253 253
56467 -253 253 253 253 253 253 253 253 253 253 253 253
56468 -253 253 253 253 253 253 94 94 94 6 6 6
56469 - 2 2 6 2 2 6 10 10 10 34 34 34
56470 - 2 2 6 2 2 6 2 2 6 2 2 6
56471 - 74 74 74 58 58 58 22 22 22 6 6 6
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 10 10 10 26 26 26 66 66 66
56480 - 82 82 82 2 2 6 38 38 38 6 6 6
56481 - 14 14 14 210 210 210 253 253 253 253 253 253
56482 -253 253 253 253 253 253 253 253 253 253 253 253
56483 -253 253 253 253 253 253 246 246 246 242 242 242
56484 -253 253 253 253 253 253 253 253 253 253 253 253
56485 -253 253 253 253 253 253 253 253 253 253 253 253
56486 -253 253 253 253 253 253 253 253 253 253 253 253
56487 -253 253 253 253 253 253 253 253 253 253 253 253
56488 -253 253 253 253 253 253 144 144 144 2 2 6
56489 - 2 2 6 2 2 6 2 2 6 46 46 46
56490 - 2 2 6 2 2 6 2 2 6 2 2 6
56491 - 42 42 42 74 74 74 30 30 30 10 10 10
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 0 0 0 0 0 0 0 0 0
56497 - 0 0 0 0 0 0 0 0 0 0 0 0
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 6 6 6 14 14 14 42 42 42 90 90 90
56500 - 26 26 26 6 6 6 42 42 42 2 2 6
56501 - 74 74 74 250 250 250 253 253 253 253 253 253
56502 -253 253 253 253 253 253 253 253 253 253 253 253
56503 -253 253 253 253 253 253 242 242 242 242 242 242
56504 -253 253 253 253 253 253 253 253 253 253 253 253
56505 -253 253 253 253 253 253 253 253 253 253 253 253
56506 -253 253 253 253 253 253 253 253 253 253 253 253
56507 -253 253 253 253 253 253 253 253 253 253 253 253
56508 -253 253 253 253 253 253 182 182 182 2 2 6
56509 - 2 2 6 2 2 6 2 2 6 46 46 46
56510 - 2 2 6 2 2 6 2 2 6 2 2 6
56511 - 10 10 10 86 86 86 38 38 38 10 10 10
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 0 0 0 0 0 0 0 0 0 0 0 0
56517 - 0 0 0 0 0 0 0 0 0 0 0 0
56518 - 0 0 0 0 0 0 0 0 0 0 0 0
56519 - 10 10 10 26 26 26 66 66 66 82 82 82
56520 - 2 2 6 22 22 22 18 18 18 2 2 6
56521 -149 149 149 253 253 253 253 253 253 253 253 253
56522 -253 253 253 253 253 253 253 253 253 253 253 253
56523 -253 253 253 253 253 253 234 234 234 242 242 242
56524 -253 253 253 253 253 253 253 253 253 253 253 253
56525 -253 253 253 253 253 253 253 253 253 253 253 253
56526 -253 253 253 253 253 253 253 253 253 253 253 253
56527 -253 253 253 253 253 253 253 253 253 253 253 253
56528 -253 253 253 253 253 253 206 206 206 2 2 6
56529 - 2 2 6 2 2 6 2 2 6 38 38 38
56530 - 2 2 6 2 2 6 2 2 6 2 2 6
56531 - 6 6 6 86 86 86 46 46 46 14 14 14
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 0 0 0
56536 - 0 0 0 0 0 0 0 0 0 0 0 0
56537 - 0 0 0 0 0 0 0 0 0 0 0 0
56538 - 0 0 0 0 0 0 0 0 0 6 6 6
56539 - 18 18 18 46 46 46 86 86 86 18 18 18
56540 - 2 2 6 34 34 34 10 10 10 6 6 6
56541 -210 210 210 253 253 253 253 253 253 253 253 253
56542 -253 253 253 253 253 253 253 253 253 253 253 253
56543 -253 253 253 253 253 253 234 234 234 242 242 242
56544 -253 253 253 253 253 253 253 253 253 253 253 253
56545 -253 253 253 253 253 253 253 253 253 253 253 253
56546 -253 253 253 253 253 253 253 253 253 253 253 253
56547 -253 253 253 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 221 221 221 6 6 6
56549 - 2 2 6 2 2 6 6 6 6 30 30 30
56550 - 2 2 6 2 2 6 2 2 6 2 2 6
56551 - 2 2 6 82 82 82 54 54 54 18 18 18
56552 - 6 6 6 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 0 0 0 0 0 0
56556 - 0 0 0 0 0 0 0 0 0 0 0 0
56557 - 0 0 0 0 0 0 0 0 0 0 0 0
56558 - 0 0 0 0 0 0 0 0 0 10 10 10
56559 - 26 26 26 66 66 66 62 62 62 2 2 6
56560 - 2 2 6 38 38 38 10 10 10 26 26 26
56561 -238 238 238 253 253 253 253 253 253 253 253 253
56562 -253 253 253 253 253 253 253 253 253 253 253 253
56563 -253 253 253 253 253 253 231 231 231 238 238 238
56564 -253 253 253 253 253 253 253 253 253 253 253 253
56565 -253 253 253 253 253 253 253 253 253 253 253 253
56566 -253 253 253 253 253 253 253 253 253 253 253 253
56567 -253 253 253 253 253 253 253 253 253 253 253 253
56568 -253 253 253 253 253 253 231 231 231 6 6 6
56569 - 2 2 6 2 2 6 10 10 10 30 30 30
56570 - 2 2 6 2 2 6 2 2 6 2 2 6
56571 - 2 2 6 66 66 66 58 58 58 22 22 22
56572 - 6 6 6 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 0 0 0 0 0 0 0 0 0
56576 - 0 0 0 0 0 0 0 0 0 0 0 0
56577 - 0 0 0 0 0 0 0 0 0 0 0 0
56578 - 0 0 0 0 0 0 0 0 0 10 10 10
56579 - 38 38 38 78 78 78 6 6 6 2 2 6
56580 - 2 2 6 46 46 46 14 14 14 42 42 42
56581 -246 246 246 253 253 253 253 253 253 253 253 253
56582 -253 253 253 253 253 253 253 253 253 253 253 253
56583 -253 253 253 253 253 253 231 231 231 242 242 242
56584 -253 253 253 253 253 253 253 253 253 253 253 253
56585 -253 253 253 253 253 253 253 253 253 253 253 253
56586 -253 253 253 253 253 253 253 253 253 253 253 253
56587 -253 253 253 253 253 253 253 253 253 253 253 253
56588 -253 253 253 253 253 253 234 234 234 10 10 10
56589 - 2 2 6 2 2 6 22 22 22 14 14 14
56590 - 2 2 6 2 2 6 2 2 6 2 2 6
56591 - 2 2 6 66 66 66 62 62 62 22 22 22
56592 - 6 6 6 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 0 0 0 0 0 0 0 0 0 0 0 0
56596 - 0 0 0 0 0 0 0 0 0 0 0 0
56597 - 0 0 0 0 0 0 0 0 0 0 0 0
56598 - 0 0 0 0 0 0 6 6 6 18 18 18
56599 - 50 50 50 74 74 74 2 2 6 2 2 6
56600 - 14 14 14 70 70 70 34 34 34 62 62 62
56601 -250 250 250 253 253 253 253 253 253 253 253 253
56602 -253 253 253 253 253 253 253 253 253 253 253 253
56603 -253 253 253 253 253 253 231 231 231 246 246 246
56604 -253 253 253 253 253 253 253 253 253 253 253 253
56605 -253 253 253 253 253 253 253 253 253 253 253 253
56606 -253 253 253 253 253 253 253 253 253 253 253 253
56607 -253 253 253 253 253 253 253 253 253 253 253 253
56608 -253 253 253 253 253 253 234 234 234 14 14 14
56609 - 2 2 6 2 2 6 30 30 30 2 2 6
56610 - 2 2 6 2 2 6 2 2 6 2 2 6
56611 - 2 2 6 66 66 66 62 62 62 22 22 22
56612 - 6 6 6 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 0 0 0 0 0 0 0 0 0 0 0 0
56616 - 0 0 0 0 0 0 0 0 0 0 0 0
56617 - 0 0 0 0 0 0 0 0 0 0 0 0
56618 - 0 0 0 0 0 0 6 6 6 18 18 18
56619 - 54 54 54 62 62 62 2 2 6 2 2 6
56620 - 2 2 6 30 30 30 46 46 46 70 70 70
56621 -250 250 250 253 253 253 253 253 253 253 253 253
56622 -253 253 253 253 253 253 253 253 253 253 253 253
56623 -253 253 253 253 253 253 231 231 231 246 246 246
56624 -253 253 253 253 253 253 253 253 253 253 253 253
56625 -253 253 253 253 253 253 253 253 253 253 253 253
56626 -253 253 253 253 253 253 253 253 253 253 253 253
56627 -253 253 253 253 253 253 253 253 253 253 253 253
56628 -253 253 253 253 253 253 226 226 226 10 10 10
56629 - 2 2 6 6 6 6 30 30 30 2 2 6
56630 - 2 2 6 2 2 6 2 2 6 2 2 6
56631 - 2 2 6 66 66 66 58 58 58 22 22 22
56632 - 6 6 6 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 0 0 0 0 0 0 0 0 0 0 0 0
56636 - 0 0 0 0 0 0 0 0 0 0 0 0
56637 - 0 0 0 0 0 0 0 0 0 0 0 0
56638 - 0 0 0 0 0 0 6 6 6 22 22 22
56639 - 58 58 58 62 62 62 2 2 6 2 2 6
56640 - 2 2 6 2 2 6 30 30 30 78 78 78
56641 -250 250 250 253 253 253 253 253 253 253 253 253
56642 -253 253 253 253 253 253 253 253 253 253 253 253
56643 -253 253 253 253 253 253 231 231 231 246 246 246
56644 -253 253 253 253 253 253 253 253 253 253 253 253
56645 -253 253 253 253 253 253 253 253 253 253 253 253
56646 -253 253 253 253 253 253 253 253 253 253 253 253
56647 -253 253 253 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 206 206 206 2 2 6
56649 - 22 22 22 34 34 34 18 14 6 22 22 22
56650 - 26 26 26 18 18 18 6 6 6 2 2 6
56651 - 2 2 6 82 82 82 54 54 54 18 18 18
56652 - 6 6 6 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 0 0 0 0 0 0 0 0 0
56658 - 0 0 0 0 0 0 6 6 6 26 26 26
56659 - 62 62 62 106 106 106 74 54 14 185 133 11
56660 -210 162 10 121 92 8 6 6 6 62 62 62
56661 -238 238 238 253 253 253 253 253 253 253 253 253
56662 -253 253 253 253 253 253 253 253 253 253 253 253
56663 -253 253 253 253 253 253 231 231 231 246 246 246
56664 -253 253 253 253 253 253 253 253 253 253 253 253
56665 -253 253 253 253 253 253 253 253 253 253 253 253
56666 -253 253 253 253 253 253 253 253 253 253 253 253
56667 -253 253 253 253 253 253 253 253 253 253 253 253
56668 -253 253 253 253 253 253 158 158 158 18 18 18
56669 - 14 14 14 2 2 6 2 2 6 2 2 6
56670 - 6 6 6 18 18 18 66 66 66 38 38 38
56671 - 6 6 6 94 94 94 50 50 50 18 18 18
56672 - 6 6 6 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 0 0 0
56675 - 0 0 0 0 0 0 0 0 0 0 0 0
56676 - 0 0 0 0 0 0 0 0 0 0 0 0
56677 - 0 0 0 0 0 0 0 0 0 6 6 6
56678 - 10 10 10 10 10 10 18 18 18 38 38 38
56679 - 78 78 78 142 134 106 216 158 10 242 186 14
56680 -246 190 14 246 190 14 156 118 10 10 10 10
56681 - 90 90 90 238 238 238 253 253 253 253 253 253
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 231 231 231 250 250 250
56684 -253 253 253 253 253 253 253 253 253 253 253 253
56685 -253 253 253 253 253 253 253 253 253 253 253 253
56686 -253 253 253 253 253 253 253 253 253 253 253 253
56687 -253 253 253 253 253 253 253 253 253 246 230 190
56688 -238 204 91 238 204 91 181 142 44 37 26 9
56689 - 2 2 6 2 2 6 2 2 6 2 2 6
56690 - 2 2 6 2 2 6 38 38 38 46 46 46
56691 - 26 26 26 106 106 106 54 54 54 18 18 18
56692 - 6 6 6 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 0 0 0
56695 - 0 0 0 0 0 0 0 0 0 0 0 0
56696 - 0 0 0 0 0 0 0 0 0 0 0 0
56697 - 0 0 0 6 6 6 14 14 14 22 22 22
56698 - 30 30 30 38 38 38 50 50 50 70 70 70
56699 -106 106 106 190 142 34 226 170 11 242 186 14
56700 -246 190 14 246 190 14 246 190 14 154 114 10
56701 - 6 6 6 74 74 74 226 226 226 253 253 253
56702 -253 253 253 253 253 253 253 253 253 253 253 253
56703 -253 253 253 253 253 253 231 231 231 250 250 250
56704 -253 253 253 253 253 253 253 253 253 253 253 253
56705 -253 253 253 253 253 253 253 253 253 253 253 253
56706 -253 253 253 253 253 253 253 253 253 253 253 253
56707 -253 253 253 253 253 253 253 253 253 228 184 62
56708 -241 196 14 241 208 19 232 195 16 38 30 10
56709 - 2 2 6 2 2 6 2 2 6 2 2 6
56710 - 2 2 6 6 6 6 30 30 30 26 26 26
56711 -203 166 17 154 142 90 66 66 66 26 26 26
56712 - 6 6 6 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 0 0 0
56715 - 0 0 0 0 0 0 0 0 0 0 0 0
56716 - 0 0 0 0 0 0 0 0 0 0 0 0
56717 - 6 6 6 18 18 18 38 38 38 58 58 58
56718 - 78 78 78 86 86 86 101 101 101 123 123 123
56719 -175 146 61 210 150 10 234 174 13 246 186 14
56720 -246 190 14 246 190 14 246 190 14 238 190 10
56721 -102 78 10 2 2 6 46 46 46 198 198 198
56722 -253 253 253 253 253 253 253 253 253 253 253 253
56723 -253 253 253 253 253 253 234 234 234 242 242 242
56724 -253 253 253 253 253 253 253 253 253 253 253 253
56725 -253 253 253 253 253 253 253 253 253 253 253 253
56726 -253 253 253 253 253 253 253 253 253 253 253 253
56727 -253 253 253 253 253 253 253 253 253 224 178 62
56728 -242 186 14 241 196 14 210 166 10 22 18 6
56729 - 2 2 6 2 2 6 2 2 6 2 2 6
56730 - 2 2 6 2 2 6 6 6 6 121 92 8
56731 -238 202 15 232 195 16 82 82 82 34 34 34
56732 - 10 10 10 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 0 0 0 0 0 0
56737 - 14 14 14 38 38 38 70 70 70 154 122 46
56738 -190 142 34 200 144 11 197 138 11 197 138 11
56739 -213 154 11 226 170 11 242 186 14 246 190 14
56740 -246 190 14 246 190 14 246 190 14 246 190 14
56741 -225 175 15 46 32 6 2 2 6 22 22 22
56742 -158 158 158 250 250 250 253 253 253 253 253 253
56743 -253 253 253 253 253 253 253 253 253 253 253 253
56744 -253 253 253 253 253 253 253 253 253 253 253 253
56745 -253 253 253 253 253 253 253 253 253 253 253 253
56746 -253 253 253 253 253 253 253 253 253 253 253 253
56747 -253 253 253 250 250 250 242 242 242 224 178 62
56748 -239 182 13 236 186 11 213 154 11 46 32 6
56749 - 2 2 6 2 2 6 2 2 6 2 2 6
56750 - 2 2 6 2 2 6 61 42 6 225 175 15
56751 -238 190 10 236 186 11 112 100 78 42 42 42
56752 - 14 14 14 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 6 6 6
56757 - 22 22 22 54 54 54 154 122 46 213 154 11
56758 -226 170 11 230 174 11 226 170 11 226 170 11
56759 -236 178 12 242 186 14 246 190 14 246 190 14
56760 -246 190 14 246 190 14 246 190 14 246 190 14
56761 -241 196 14 184 144 12 10 10 10 2 2 6
56762 - 6 6 6 116 116 116 242 242 242 253 253 253
56763 -253 253 253 253 253 253 253 253 253 253 253 253
56764 -253 253 253 253 253 253 253 253 253 253 253 253
56765 -253 253 253 253 253 253 253 253 253 253 253 253
56766 -253 253 253 253 253 253 253 253 253 253 253 253
56767 -253 253 253 231 231 231 198 198 198 214 170 54
56768 -236 178 12 236 178 12 210 150 10 137 92 6
56769 - 18 14 6 2 2 6 2 2 6 2 2 6
56770 - 6 6 6 70 47 6 200 144 11 236 178 12
56771 -239 182 13 239 182 13 124 112 88 58 58 58
56772 - 22 22 22 6 6 6 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 10 10 10
56777 - 30 30 30 70 70 70 180 133 36 226 170 11
56778 -239 182 13 242 186 14 242 186 14 246 186 14
56779 -246 190 14 246 190 14 246 190 14 246 190 14
56780 -246 190 14 246 190 14 246 190 14 246 190 14
56781 -246 190 14 232 195 16 98 70 6 2 2 6
56782 - 2 2 6 2 2 6 66 66 66 221 221 221
56783 -253 253 253 253 253 253 253 253 253 253 253 253
56784 -253 253 253 253 253 253 253 253 253 253 253 253
56785 -253 253 253 253 253 253 253 253 253 253 253 253
56786 -253 253 253 253 253 253 253 253 253 253 253 253
56787 -253 253 253 206 206 206 198 198 198 214 166 58
56788 -230 174 11 230 174 11 216 158 10 192 133 9
56789 -163 110 8 116 81 8 102 78 10 116 81 8
56790 -167 114 7 197 138 11 226 170 11 239 182 13
56791 -242 186 14 242 186 14 162 146 94 78 78 78
56792 - 34 34 34 14 14 14 6 6 6 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 0 0 0 0 0 0 6 6 6
56797 - 30 30 30 78 78 78 190 142 34 226 170 11
56798 -239 182 13 246 190 14 246 190 14 246 190 14
56799 -246 190 14 246 190 14 246 190 14 246 190 14
56800 -246 190 14 246 190 14 246 190 14 246 190 14
56801 -246 190 14 241 196 14 203 166 17 22 18 6
56802 - 2 2 6 2 2 6 2 2 6 38 38 38
56803 -218 218 218 253 253 253 253 253 253 253 253 253
56804 -253 253 253 253 253 253 253 253 253 253 253 253
56805 -253 253 253 253 253 253 253 253 253 253 253 253
56806 -253 253 253 253 253 253 253 253 253 253 253 253
56807 -250 250 250 206 206 206 198 198 198 202 162 69
56808 -226 170 11 236 178 12 224 166 10 210 150 10
56809 -200 144 11 197 138 11 192 133 9 197 138 11
56810 -210 150 10 226 170 11 242 186 14 246 190 14
56811 -246 190 14 246 186 14 225 175 15 124 112 88
56812 - 62 62 62 30 30 30 14 14 14 6 6 6
56813 - 0 0 0 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 0 0 0 0 0 0 0 0 0 10 10 10
56817 - 30 30 30 78 78 78 174 135 50 224 166 10
56818 -239 182 13 246 190 14 246 190 14 246 190 14
56819 -246 190 14 246 190 14 246 190 14 246 190 14
56820 -246 190 14 246 190 14 246 190 14 246 190 14
56821 -246 190 14 246 190 14 241 196 14 139 102 15
56822 - 2 2 6 2 2 6 2 2 6 2 2 6
56823 - 78 78 78 250 250 250 253 253 253 253 253 253
56824 -253 253 253 253 253 253 253 253 253 253 253 253
56825 -253 253 253 253 253 253 253 253 253 253 253 253
56826 -253 253 253 253 253 253 253 253 253 253 253 253
56827 -250 250 250 214 214 214 198 198 198 190 150 46
56828 -219 162 10 236 178 12 234 174 13 224 166 10
56829 -216 158 10 213 154 11 213 154 11 216 158 10
56830 -226 170 11 239 182 13 246 190 14 246 190 14
56831 -246 190 14 246 190 14 242 186 14 206 162 42
56832 -101 101 101 58 58 58 30 30 30 14 14 14
56833 - 6 6 6 0 0 0 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 10 10 10
56837 - 30 30 30 74 74 74 174 135 50 216 158 10
56838 -236 178 12 246 190 14 246 190 14 246 190 14
56839 -246 190 14 246 190 14 246 190 14 246 190 14
56840 -246 190 14 246 190 14 246 190 14 246 190 14
56841 -246 190 14 246 190 14 241 196 14 226 184 13
56842 - 61 42 6 2 2 6 2 2 6 2 2 6
56843 - 22 22 22 238 238 238 253 253 253 253 253 253
56844 -253 253 253 253 253 253 253 253 253 253 253 253
56845 -253 253 253 253 253 253 253 253 253 253 253 253
56846 -253 253 253 253 253 253 253 253 253 253 253 253
56847 -253 253 253 226 226 226 187 187 187 180 133 36
56848 -216 158 10 236 178 12 239 182 13 236 178 12
56849 -230 174 11 226 170 11 226 170 11 230 174 11
56850 -236 178 12 242 186 14 246 190 14 246 190 14
56851 -246 190 14 246 190 14 246 186 14 239 182 13
56852 -206 162 42 106 106 106 66 66 66 34 34 34
56853 - 14 14 14 6 6 6 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 6 6 6
56857 - 26 26 26 70 70 70 163 133 67 213 154 11
56858 -236 178 12 246 190 14 246 190 14 246 190 14
56859 -246 190 14 246 190 14 246 190 14 246 190 14
56860 -246 190 14 246 190 14 246 190 14 246 190 14
56861 -246 190 14 246 190 14 246 190 14 241 196 14
56862 -190 146 13 18 14 6 2 2 6 2 2 6
56863 - 46 46 46 246 246 246 253 253 253 253 253 253
56864 -253 253 253 253 253 253 253 253 253 253 253 253
56865 -253 253 253 253 253 253 253 253 253 253 253 253
56866 -253 253 253 253 253 253 253 253 253 253 253 253
56867 -253 253 253 221 221 221 86 86 86 156 107 11
56868 -216 158 10 236 178 12 242 186 14 246 186 14
56869 -242 186 14 239 182 13 239 182 13 242 186 14
56870 -242 186 14 246 186 14 246 190 14 246 190 14
56871 -246 190 14 246 190 14 246 190 14 246 190 14
56872 -242 186 14 225 175 15 142 122 72 66 66 66
56873 - 30 30 30 10 10 10 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 0 0 0 0 6 6 6
56877 - 26 26 26 70 70 70 163 133 67 210 150 10
56878 -236 178 12 246 190 14 246 190 14 246 190 14
56879 -246 190 14 246 190 14 246 190 14 246 190 14
56880 -246 190 14 246 190 14 246 190 14 246 190 14
56881 -246 190 14 246 190 14 246 190 14 246 190 14
56882 -232 195 16 121 92 8 34 34 34 106 106 106
56883 -221 221 221 253 253 253 253 253 253 253 253 253
56884 -253 253 253 253 253 253 253 253 253 253 253 253
56885 -253 253 253 253 253 253 253 253 253 253 253 253
56886 -253 253 253 253 253 253 253 253 253 253 253 253
56887 -242 242 242 82 82 82 18 14 6 163 110 8
56888 -216 158 10 236 178 12 242 186 14 246 190 14
56889 -246 190 14 246 190 14 246 190 14 246 190 14
56890 -246 190 14 246 190 14 246 190 14 246 190 14
56891 -246 190 14 246 190 14 246 190 14 246 190 14
56892 -246 190 14 246 190 14 242 186 14 163 133 67
56893 - 46 46 46 18 18 18 6 6 6 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 0 0 0 10 10 10
56897 - 30 30 30 78 78 78 163 133 67 210 150 10
56898 -236 178 12 246 186 14 246 190 14 246 190 14
56899 -246 190 14 246 190 14 246 190 14 246 190 14
56900 -246 190 14 246 190 14 246 190 14 246 190 14
56901 -246 190 14 246 190 14 246 190 14 246 190 14
56902 -241 196 14 215 174 15 190 178 144 253 253 253
56903 -253 253 253 253 253 253 253 253 253 253 253 253
56904 -253 253 253 253 253 253 253 253 253 253 253 253
56905 -253 253 253 253 253 253 253 253 253 253 253 253
56906 -253 253 253 253 253 253 253 253 253 218 218 218
56907 - 58 58 58 2 2 6 22 18 6 167 114 7
56908 -216 158 10 236 178 12 246 186 14 246 190 14
56909 -246 190 14 246 190 14 246 190 14 246 190 14
56910 -246 190 14 246 190 14 246 190 14 246 190 14
56911 -246 190 14 246 190 14 246 190 14 246 190 14
56912 -246 190 14 246 186 14 242 186 14 190 150 46
56913 - 54 54 54 22 22 22 6 6 6 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 0 0 0 0 0 0 0 14 14 14
56917 - 38 38 38 86 86 86 180 133 36 213 154 11
56918 -236 178 12 246 186 14 246 190 14 246 190 14
56919 -246 190 14 246 190 14 246 190 14 246 190 14
56920 -246 190 14 246 190 14 246 190 14 246 190 14
56921 -246 190 14 246 190 14 246 190 14 246 190 14
56922 -246 190 14 232 195 16 190 146 13 214 214 214
56923 -253 253 253 253 253 253 253 253 253 253 253 253
56924 -253 253 253 253 253 253 253 253 253 253 253 253
56925 -253 253 253 253 253 253 253 253 253 253 253 253
56926 -253 253 253 250 250 250 170 170 170 26 26 26
56927 - 2 2 6 2 2 6 37 26 9 163 110 8
56928 -219 162 10 239 182 13 246 186 14 246 190 14
56929 -246 190 14 246 190 14 246 190 14 246 190 14
56930 -246 190 14 246 190 14 246 190 14 246 190 14
56931 -246 190 14 246 190 14 246 190 14 246 190 14
56932 -246 186 14 236 178 12 224 166 10 142 122 72
56933 - 46 46 46 18 18 18 6 6 6 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 6 6 6 18 18 18
56937 - 50 50 50 109 106 95 192 133 9 224 166 10
56938 -242 186 14 246 190 14 246 190 14 246 190 14
56939 -246 190 14 246 190 14 246 190 14 246 190 14
56940 -246 190 14 246 190 14 246 190 14 246 190 14
56941 -246 190 14 246 190 14 246 190 14 246 190 14
56942 -242 186 14 226 184 13 210 162 10 142 110 46
56943 -226 226 226 253 253 253 253 253 253 253 253 253
56944 -253 253 253 253 253 253 253 253 253 253 253 253
56945 -253 253 253 253 253 253 253 253 253 253 253 253
56946 -198 198 198 66 66 66 2 2 6 2 2 6
56947 - 2 2 6 2 2 6 50 34 6 156 107 11
56948 -219 162 10 239 182 13 246 186 14 246 190 14
56949 -246 190 14 246 190 14 246 190 14 246 190 14
56950 -246 190 14 246 190 14 246 190 14 246 190 14
56951 -246 190 14 246 190 14 246 190 14 242 186 14
56952 -234 174 13 213 154 11 154 122 46 66 66 66
56953 - 30 30 30 10 10 10 0 0 0 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 0 0 0 0 0 0
56956 - 0 0 0 0 0 0 6 6 6 22 22 22
56957 - 58 58 58 154 121 60 206 145 10 234 174 13
56958 -242 186 14 246 186 14 246 190 14 246 190 14
56959 -246 190 14 246 190 14 246 190 14 246 190 14
56960 -246 190 14 246 190 14 246 190 14 246 190 14
56961 -246 190 14 246 190 14 246 190 14 246 190 14
56962 -246 186 14 236 178 12 210 162 10 163 110 8
56963 - 61 42 6 138 138 138 218 218 218 250 250 250
56964 -253 253 253 253 253 253 253 253 253 250 250 250
56965 -242 242 242 210 210 210 144 144 144 66 66 66
56966 - 6 6 6 2 2 6 2 2 6 2 2 6
56967 - 2 2 6 2 2 6 61 42 6 163 110 8
56968 -216 158 10 236 178 12 246 190 14 246 190 14
56969 -246 190 14 246 190 14 246 190 14 246 190 14
56970 -246 190 14 246 190 14 246 190 14 246 190 14
56971 -246 190 14 239 182 13 230 174 11 216 158 10
56972 -190 142 34 124 112 88 70 70 70 38 38 38
56973 - 18 18 18 6 6 6 0 0 0 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 0 0 0 0 0 0
56976 - 0 0 0 0 0 0 6 6 6 22 22 22
56977 - 62 62 62 168 124 44 206 145 10 224 166 10
56978 -236 178 12 239 182 13 242 186 14 242 186 14
56979 -246 186 14 246 190 14 246 190 14 246 190 14
56980 -246 190 14 246 190 14 246 190 14 246 190 14
56981 -246 190 14 246 190 14 246 190 14 246 190 14
56982 -246 190 14 236 178 12 216 158 10 175 118 6
56983 - 80 54 7 2 2 6 6 6 6 30 30 30
56984 - 54 54 54 62 62 62 50 50 50 38 38 38
56985 - 14 14 14 2 2 6 2 2 6 2 2 6
56986 - 2 2 6 2 2 6 2 2 6 2 2 6
56987 - 2 2 6 6 6 6 80 54 7 167 114 7
56988 -213 154 11 236 178 12 246 190 14 246 190 14
56989 -246 190 14 246 190 14 246 190 14 246 190 14
56990 -246 190 14 242 186 14 239 182 13 239 182 13
56991 -230 174 11 210 150 10 174 135 50 124 112 88
56992 - 82 82 82 54 54 54 34 34 34 18 18 18
56993 - 6 6 6 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 0 0 0
56995 - 0 0 0 0 0 0 0 0 0 0 0 0
56996 - 0 0 0 0 0 0 6 6 6 18 18 18
56997 - 50 50 50 158 118 36 192 133 9 200 144 11
56998 -216 158 10 219 162 10 224 166 10 226 170 11
56999 -230 174 11 236 178 12 239 182 13 239 182 13
57000 -242 186 14 246 186 14 246 190 14 246 190 14
57001 -246 190 14 246 190 14 246 190 14 246 190 14
57002 -246 186 14 230 174 11 210 150 10 163 110 8
57003 -104 69 6 10 10 10 2 2 6 2 2 6
57004 - 2 2 6 2 2 6 2 2 6 2 2 6
57005 - 2 2 6 2 2 6 2 2 6 2 2 6
57006 - 2 2 6 2 2 6 2 2 6 2 2 6
57007 - 2 2 6 6 6 6 91 60 6 167 114 7
57008 -206 145 10 230 174 11 242 186 14 246 190 14
57009 -246 190 14 246 190 14 246 186 14 242 186 14
57010 -239 182 13 230 174 11 224 166 10 213 154 11
57011 -180 133 36 124 112 88 86 86 86 58 58 58
57012 - 38 38 38 22 22 22 10 10 10 6 6 6
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 0 0 0
57015 - 0 0 0 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 0 0 0 14 14 14
57017 - 34 34 34 70 70 70 138 110 50 158 118 36
57018 -167 114 7 180 123 7 192 133 9 197 138 11
57019 -200 144 11 206 145 10 213 154 11 219 162 10
57020 -224 166 10 230 174 11 239 182 13 242 186 14
57021 -246 186 14 246 186 14 246 186 14 246 186 14
57022 -239 182 13 216 158 10 185 133 11 152 99 6
57023 -104 69 6 18 14 6 2 2 6 2 2 6
57024 - 2 2 6 2 2 6 2 2 6 2 2 6
57025 - 2 2 6 2 2 6 2 2 6 2 2 6
57026 - 2 2 6 2 2 6 2 2 6 2 2 6
57027 - 2 2 6 6 6 6 80 54 7 152 99 6
57028 -192 133 9 219 162 10 236 178 12 239 182 13
57029 -246 186 14 242 186 14 239 182 13 236 178 12
57030 -224 166 10 206 145 10 192 133 9 154 121 60
57031 - 94 94 94 62 62 62 42 42 42 22 22 22
57032 - 14 14 14 6 6 6 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 0 0 0 0 0 0
57035 - 0 0 0 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 0 0 0 0 6 6 6
57037 - 18 18 18 34 34 34 58 58 58 78 78 78
57038 -101 98 89 124 112 88 142 110 46 156 107 11
57039 -163 110 8 167 114 7 175 118 6 180 123 7
57040 -185 133 11 197 138 11 210 150 10 219 162 10
57041 -226 170 11 236 178 12 236 178 12 234 174 13
57042 -219 162 10 197 138 11 163 110 8 130 83 6
57043 - 91 60 6 10 10 10 2 2 6 2 2 6
57044 - 18 18 18 38 38 38 38 38 38 38 38 38
57045 - 38 38 38 38 38 38 38 38 38 38 38 38
57046 - 38 38 38 38 38 38 26 26 26 2 2 6
57047 - 2 2 6 6 6 6 70 47 6 137 92 6
57048 -175 118 6 200 144 11 219 162 10 230 174 11
57049 -234 174 13 230 174 11 219 162 10 210 150 10
57050 -192 133 9 163 110 8 124 112 88 82 82 82
57051 - 50 50 50 30 30 30 14 14 14 6 6 6
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 0 0 0 0 0 0
57055 - 0 0 0 0 0 0 0 0 0 0 0 0
57056 - 0 0 0 0 0 0 0 0 0 0 0 0
57057 - 6 6 6 14 14 14 22 22 22 34 34 34
57058 - 42 42 42 58 58 58 74 74 74 86 86 86
57059 -101 98 89 122 102 70 130 98 46 121 87 25
57060 -137 92 6 152 99 6 163 110 8 180 123 7
57061 -185 133 11 197 138 11 206 145 10 200 144 11
57062 -180 123 7 156 107 11 130 83 6 104 69 6
57063 - 50 34 6 54 54 54 110 110 110 101 98 89
57064 - 86 86 86 82 82 82 78 78 78 78 78 78
57065 - 78 78 78 78 78 78 78 78 78 78 78 78
57066 - 78 78 78 82 82 82 86 86 86 94 94 94
57067 -106 106 106 101 101 101 86 66 34 124 80 6
57068 -156 107 11 180 123 7 192 133 9 200 144 11
57069 -206 145 10 200 144 11 192 133 9 175 118 6
57070 -139 102 15 109 106 95 70 70 70 42 42 42
57071 - 22 22 22 10 10 10 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 0 0 0 0 0 0 0 0 0
57075 - 0 0 0 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 0 0 0 0 0 0 0
57077 - 0 0 0 0 0 0 6 6 6 10 10 10
57078 - 14 14 14 22 22 22 30 30 30 38 38 38
57079 - 50 50 50 62 62 62 74 74 74 90 90 90
57080 -101 98 89 112 100 78 121 87 25 124 80 6
57081 -137 92 6 152 99 6 152 99 6 152 99 6
57082 -138 86 6 124 80 6 98 70 6 86 66 30
57083 -101 98 89 82 82 82 58 58 58 46 46 46
57084 - 38 38 38 34 34 34 34 34 34 34 34 34
57085 - 34 34 34 34 34 34 34 34 34 34 34 34
57086 - 34 34 34 34 34 34 38 38 38 42 42 42
57087 - 54 54 54 82 82 82 94 86 76 91 60 6
57088 -134 86 6 156 107 11 167 114 7 175 118 6
57089 -175 118 6 167 114 7 152 99 6 121 87 25
57090 -101 98 89 62 62 62 34 34 34 18 18 18
57091 - 6 6 6 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 0 0 0 0 0 0 0 0 0 0 0 0
57095 - 0 0 0 0 0 0 0 0 0 0 0 0
57096 - 0 0 0 0 0 0 0 0 0 0 0 0
57097 - 0 0 0 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 6 6 6 6 6 6 10 10 10
57099 - 18 18 18 22 22 22 30 30 30 42 42 42
57100 - 50 50 50 66 66 66 86 86 86 101 98 89
57101 -106 86 58 98 70 6 104 69 6 104 69 6
57102 -104 69 6 91 60 6 82 62 34 90 90 90
57103 - 62 62 62 38 38 38 22 22 22 14 14 14
57104 - 10 10 10 10 10 10 10 10 10 10 10 10
57105 - 10 10 10 10 10 10 6 6 6 10 10 10
57106 - 10 10 10 10 10 10 10 10 10 14 14 14
57107 - 22 22 22 42 42 42 70 70 70 89 81 66
57108 - 80 54 7 104 69 6 124 80 6 137 92 6
57109 -134 86 6 116 81 8 100 82 52 86 86 86
57110 - 58 58 58 30 30 30 14 14 14 6 6 6
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 0 0 0
57114 - 0 0 0 0 0 0 0 0 0 0 0 0
57115 - 0 0 0 0 0 0 0 0 0 0 0 0
57116 - 0 0 0 0 0 0 0 0 0 0 0 0
57117 - 0 0 0 0 0 0 0 0 0 0 0 0
57118 - 0 0 0 0 0 0 0 0 0 0 0 0
57119 - 0 0 0 6 6 6 10 10 10 14 14 14
57120 - 18 18 18 26 26 26 38 38 38 54 54 54
57121 - 70 70 70 86 86 86 94 86 76 89 81 66
57122 - 89 81 66 86 86 86 74 74 74 50 50 50
57123 - 30 30 30 14 14 14 6 6 6 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 6 6 6 18 18 18 34 34 34 58 58 58
57128 - 82 82 82 89 81 66 89 81 66 89 81 66
57129 - 94 86 66 94 86 76 74 74 74 50 50 50
57130 - 26 26 26 14 14 14 6 6 6 0 0 0
57131 - 0 0 0 0 0 0 0 0 0 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 - 0 0 0 0 0 0 0 0 0 0 0 0
57136 - 0 0 0 0 0 0 0 0 0 0 0 0
57137 - 0 0 0 0 0 0 0 0 0 0 0 0
57138 - 0 0 0 0 0 0 0 0 0 0 0 0
57139 - 0 0 0 0 0 0 0 0 0 0 0 0
57140 - 6 6 6 6 6 6 14 14 14 18 18 18
57141 - 30 30 30 38 38 38 46 46 46 54 54 54
57142 - 50 50 50 42 42 42 30 30 30 18 18 18
57143 - 10 10 10 0 0 0 0 0 0 0 0 0
57144 - 0 0 0 0 0 0 0 0 0 0 0 0
57145 - 0 0 0 0 0 0 0 0 0 0 0 0
57146 - 0 0 0 0 0 0 0 0 0 0 0 0
57147 - 0 0 0 6 6 6 14 14 14 26 26 26
57148 - 38 38 38 50 50 50 58 58 58 58 58 58
57149 - 54 54 54 42 42 42 30 30 30 18 18 18
57150 - 10 10 10 0 0 0 0 0 0 0 0 0
57151 - 0 0 0 0 0 0 0 0 0 0 0 0
57152 - 0 0 0 0 0 0 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 0 0 0
57154 - 0 0 0 0 0 0 0 0 0 0 0 0
57155 - 0 0 0 0 0 0 0 0 0 0 0 0
57156 - 0 0 0 0 0 0 0 0 0 0 0 0
57157 - 0 0 0 0 0 0 0 0 0 0 0 0
57158 - 0 0 0 0 0 0 0 0 0 0 0 0
57159 - 0 0 0 0 0 0 0 0 0 0 0 0
57160 - 0 0 0 0 0 0 0 0 0 6 6 6
57161 - 6 6 6 10 10 10 14 14 14 18 18 18
57162 - 18 18 18 14 14 14 10 10 10 6 6 6
57163 - 0 0 0 0 0 0 0 0 0 0 0 0
57164 - 0 0 0 0 0 0 0 0 0 0 0 0
57165 - 0 0 0 0 0 0 0 0 0 0 0 0
57166 - 0 0 0 0 0 0 0 0 0 0 0 0
57167 - 0 0 0 0 0 0 0 0 0 6 6 6
57168 - 14 14 14 18 18 18 22 22 22 22 22 22
57169 - 18 18 18 14 14 14 10 10 10 6 6 6
57170 - 0 0 0 0 0 0 0 0 0 0 0 0
57171 - 0 0 0 0 0 0 0 0 0 0 0 0
57172 - 0 0 0 0 0 0 0 0 0 0 0 0
57173 - 0 0 0 0 0 0 0 0 0 0 0 0
57174 - 0 0 0 0 0 0 0 0 0 0 0 0
57175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57188 +4 4 4 4 4 4
57189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57202 +4 4 4 4 4 4
57203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57216 +4 4 4 4 4 4
57217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57230 +4 4 4 4 4 4
57231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57244 +4 4 4 4 4 4
57245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57258 +4 4 4 4 4 4
57259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57264 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57268 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57269 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57270 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57272 +4 4 4 4 4 4
57273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57277 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57278 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57279 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57283 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57284 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57285 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57286 +4 4 4 4 4 4
57287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57291 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57292 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57293 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57297 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57298 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57299 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57300 +4 4 4 4 4 4
57301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57305 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57306 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57307 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57309 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57310 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57311 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57312 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57313 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57314 +4 4 4 4 4 4
57315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57319 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57320 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57321 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57322 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57323 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57324 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57325 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57326 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57327 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57328 +4 4 4 4 4 4
57329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57332 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57333 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57334 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57335 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57336 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57337 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57338 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57339 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57340 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57341 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57342 +4 4 4 4 4 4
57343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57345 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57346 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57347 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57348 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57349 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57350 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57351 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57352 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57353 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57354 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57355 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57356 +4 4 4 4 4 4
57357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57359 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57360 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57361 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57362 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57363 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57364 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57365 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57366 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57367 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57368 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57369 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57370 +4 4 4 4 4 4
57371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57373 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57374 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57375 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57376 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57377 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57378 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57379 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57380 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57381 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57382 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57383 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57384 +4 4 4 4 4 4
57385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57387 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57388 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57389 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57390 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57391 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57392 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57393 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57394 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57395 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57396 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57397 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57398 +4 4 4 4 4 4
57399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57400 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57401 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57402 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57403 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57404 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57405 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57406 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57407 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57408 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57409 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57410 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57411 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57412 +4 4 4 4 4 4
57413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57414 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57415 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57416 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57417 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57418 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57419 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57420 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57421 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57422 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57423 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57424 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57425 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57426 +0 0 0 4 4 4
57427 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57428 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57429 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57430 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57431 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57432 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57433 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57434 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57435 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57436 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57437 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57438 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57439 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57440 +2 0 0 0 0 0
57441 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57442 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57443 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57444 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57445 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57446 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57447 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57448 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57449 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57450 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57451 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57452 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57453 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57454 +37 38 37 0 0 0
57455 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57456 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57457 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57458 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57459 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57460 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57461 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57462 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57463 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57464 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57465 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57466 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57467 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57468 +85 115 134 4 0 0
57469 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57470 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57471 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57472 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57473 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57474 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57475 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57476 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57477 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57478 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57479 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57480 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57481 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57482 +60 73 81 4 0 0
57483 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57484 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57485 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57486 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57487 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57488 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57489 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57490 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57491 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57492 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57493 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57494 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57495 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57496 +16 19 21 4 0 0
57497 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57498 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57499 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57500 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57501 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57502 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57503 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57504 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57505 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57506 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57507 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57508 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57509 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57510 +4 0 0 4 3 3
57511 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57512 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57513 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57515 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57516 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57517 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57518 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57519 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57520 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57521 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57522 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57523 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57524 +3 2 2 4 4 4
57525 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57526 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57527 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57528 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57529 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57530 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57531 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57532 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57533 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57534 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57535 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57536 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57537 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57538 +4 4 4 4 4 4
57539 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57540 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57541 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57542 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57543 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57544 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57545 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57546 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57547 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57548 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57549 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57550 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57551 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57552 +4 4 4 4 4 4
57553 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57554 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57555 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57556 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57557 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57558 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57559 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57560 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57561 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57562 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57563 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57564 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57565 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57566 +5 5 5 5 5 5
57567 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57568 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57569 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57570 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57571 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57572 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57573 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57574 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57575 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57576 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57577 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57578 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57579 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57580 +5 5 5 4 4 4
57581 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57582 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57583 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57584 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57585 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57586 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57587 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57588 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57589 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57590 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57591 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57592 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57594 +4 4 4 4 4 4
57595 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57596 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57597 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57598 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57599 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57600 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57601 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57602 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57603 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57604 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57605 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57606 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57608 +4 4 4 4 4 4
57609 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57610 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57611 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57612 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57613 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57614 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57615 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57616 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57617 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57618 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57619 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57622 +4 4 4 4 4 4
57623 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57624 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57625 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57626 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57627 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57628 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57629 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57630 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57631 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57632 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57633 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57636 +4 4 4 4 4 4
57637 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57638 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57639 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57640 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57641 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57642 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57643 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57644 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57645 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57646 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57647 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57650 +4 4 4 4 4 4
57651 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57652 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57653 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57654 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57655 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57656 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57657 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57658 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57659 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57660 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57661 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57664 +4 4 4 4 4 4
57665 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57666 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57667 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57668 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57669 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57670 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57671 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57672 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57673 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57674 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57675 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57678 +4 4 4 4 4 4
57679 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57680 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57681 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57682 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57683 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57684 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57685 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57686 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57687 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57688 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57689 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57692 +4 4 4 4 4 4
57693 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57694 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57695 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57696 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57697 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57698 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57699 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57700 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57701 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57702 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57703 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57706 +4 4 4 4 4 4
57707 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57708 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57709 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57710 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57711 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57712 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57713 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57714 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57715 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57716 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57717 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57720 +4 4 4 4 4 4
57721 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57722 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57723 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57724 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57725 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57726 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57727 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57728 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57729 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57730 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57731 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57734 +4 4 4 4 4 4
57735 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57736 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57737 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57738 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57739 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57740 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57741 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57742 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57743 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57744 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57745 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57748 +4 4 4 4 4 4
57749 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57750 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57751 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57752 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57753 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57754 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57755 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57756 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57757 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57758 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57759 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57762 +4 4 4 4 4 4
57763 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57764 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57765 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57766 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57767 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57768 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57769 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57770 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57771 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57772 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57773 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57776 +4 4 4 4 4 4
57777 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57778 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57779 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57780 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57781 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57782 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57783 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57784 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57785 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57786 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57787 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57790 +4 4 4 4 4 4
57791 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57792 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57793 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57794 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57795 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57796 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57797 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57798 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57799 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57800 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57801 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57804 +4 4 4 4 4 4
57805 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57806 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57807 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57808 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57809 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57810 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57811 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57812 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57813 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57814 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57815 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57818 +4 4 4 4 4 4
57819 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57820 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57821 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57822 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57823 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57824 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57825 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57826 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57827 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57828 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57829 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57832 +4 4 4 4 4 4
57833 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57834 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57835 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57836 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57837 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57838 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57839 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57840 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57841 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57842 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57843 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57846 +4 4 4 4 4 4
57847 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57848 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57849 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57850 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57851 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57852 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57853 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57854 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57855 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57856 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57857 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57860 +4 4 4 4 4 4
57861 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57862 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57863 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57864 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57865 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57866 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57867 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57868 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57869 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57870 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57871 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57874 +4 4 4 4 4 4
57875 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57876 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57877 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57878 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57879 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57880 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57881 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57882 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57883 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57884 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57885 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57888 +4 4 4 4 4 4
57889 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57890 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57891 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57892 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57893 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57894 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57895 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57896 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57897 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57898 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57899 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57902 +4 4 4 4 4 4
57903 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57904 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57905 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57906 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57907 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57908 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57909 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57910 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57911 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57912 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57913 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57916 +4 4 4 4 4 4
57917 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57918 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57919 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57920 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57921 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57922 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57923 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57924 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57925 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57926 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57927 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57930 +4 4 4 4 4 4
57931 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57932 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57933 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57934 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57935 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57936 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57937 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57938 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57939 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57940 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57941 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57944 +4 4 4 4 4 4
57945 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57946 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57947 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57948 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57949 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57950 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57951 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57952 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57953 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57954 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57955 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57958 +4 4 4 4 4 4
57959 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57960 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57961 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57962 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57963 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57964 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57965 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57967 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57968 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57969 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972 +4 4 4 4 4 4
57973 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57974 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57975 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57976 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57977 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57978 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57979 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57980 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57981 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57982 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57983 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57986 +4 4 4 4 4 4
57987 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57988 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57989 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57990 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57991 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57992 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57993 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57994 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57995 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57996 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000 +4 4 4 4 4 4
58001 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58002 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58003 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58004 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58005 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58006 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58007 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58008 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58009 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58010 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014 +4 4 4 4 4 4
58015 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58016 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58017 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58018 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58019 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58020 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58021 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58022 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58023 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58024 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028 +4 4 4 4 4 4
58029 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58030 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58031 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58032 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58033 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58034 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58035 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58036 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58037 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58038 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58042 +4 4 4 4 4 4
58043 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58044 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58045 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58046 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58047 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58048 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58049 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58050 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58051 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58056 +4 4 4 4 4 4
58057 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58058 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58059 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58060 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58061 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58062 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58063 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58064 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58065 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070 +4 4 4 4 4 4
58071 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58072 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58073 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58074 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58075 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58076 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58077 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58078 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58079 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084 +4 4 4 4 4 4
58085 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58086 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58087 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58088 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58089 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58090 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58091 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58092 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098 +4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58100 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58101 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58102 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58103 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58104 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58105 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58106 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112 +4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58114 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58115 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58116 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58117 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58118 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58119 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58120 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126 +4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58129 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58130 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58131 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58132 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58133 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58134 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58143 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58144 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58145 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58146 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58147 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58148 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58158 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58159 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58160 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58161 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58162 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4
58169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58172 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58173 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58174 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58175 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4
58183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58187 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58188 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58189 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4
58197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58201 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58202 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58203 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 4 4 4
58211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58215 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58216 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58217 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58224 +4 4 4 4 4 4
58225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58229 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58230 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58231 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4
58239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58244 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58245 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58258 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58259 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58266 +4 4 4 4 4 4
58267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58272 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58280 +4 4 4 4 4 4
58281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58285 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58286 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58294 +4 4 4 4 4 4
58295 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58296 index fef20db..d28b1ab 100644
58297 --- a/drivers/xen/xenfs/xenstored.c
58298 +++ b/drivers/xen/xenfs/xenstored.c
58299 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58300 static int xsd_kva_open(struct inode *inode, struct file *file)
58301 {
58302 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58304 + NULL);
58305 +#else
58306 xen_store_interface);
58307 +#endif
58308 +
58309 if (!file->private_data)
58310 return -ENOMEM;
58311 return 0;
58312 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58313 index eb14e05..5156de7 100644
58314 --- a/fs/9p/vfs_addr.c
58315 +++ b/fs/9p/vfs_addr.c
58316 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58317
58318 retval = v9fs_file_write_internal(inode,
58319 v9inode->writeback_fid,
58320 - (__force const char __user *)buffer,
58321 + (const char __force_user *)buffer,
58322 len, &offset, 0);
58323 if (retval > 0)
58324 retval = 0;
58325 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58326 index 296482f..183ddc3 100644
58327 --- a/fs/9p/vfs_inode.c
58328 +++ b/fs/9p/vfs_inode.c
58329 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58330 void
58331 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58332 {
58333 - char *s = nd_get_link(nd);
58334 + const char *s = nd_get_link(nd);
58335
58336 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58337 dentry, IS_ERR(s) ? "<error>" : s);
58338 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58339 index 370b24c..ff0be7b 100644
58340 --- a/fs/Kconfig.binfmt
58341 +++ b/fs/Kconfig.binfmt
58342 @@ -103,7 +103,7 @@ config HAVE_AOUT
58343
58344 config BINFMT_AOUT
58345 tristate "Kernel support for a.out and ECOFF binaries"
58346 - depends on HAVE_AOUT
58347 + depends on HAVE_AOUT && BROKEN
58348 ---help---
58349 A.out (Assembler.OUTput) is a set of formats for libraries and
58350 executables used in the earliest versions of UNIX. Linux used
58351 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58352 index 2946712..f737435 100644
58353 --- a/fs/afs/inode.c
58354 +++ b/fs/afs/inode.c
58355 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58356 struct afs_vnode *vnode;
58357 struct super_block *sb;
58358 struct inode *inode;
58359 - static atomic_t afs_autocell_ino;
58360 + static atomic_unchecked_t afs_autocell_ino;
58361
58362 _enter("{%x:%u},%*.*s,",
58363 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58364 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58365 data.fid.unique = 0;
58366 data.fid.vnode = 0;
58367
58368 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58369 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58370 afs_iget5_autocell_test, afs_iget5_set,
58371 &data);
58372 if (!inode) {
58373 diff --git a/fs/aio.c b/fs/aio.c
58374 index 14b9315..365980f 100644
58375 --- a/fs/aio.c
58376 +++ b/fs/aio.c
58377 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58378 size += sizeof(struct io_event) * nr_events;
58379
58380 nr_pages = PFN_UP(size);
58381 - if (nr_pages < 0)
58382 + if (nr_pages <= 0)
58383 return -EINVAL;
58384
58385 file = aio_private_file(ctx, nr_pages);
58386 diff --git a/fs/attr.c b/fs/attr.c
58387 index 6530ced..4a827e2 100644
58388 --- a/fs/attr.c
58389 +++ b/fs/attr.c
58390 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58391 unsigned long limit;
58392
58393 limit = rlimit(RLIMIT_FSIZE);
58394 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58395 if (limit != RLIM_INFINITY && offset > limit)
58396 goto out_sig;
58397 if (offset > inode->i_sb->s_maxbytes)
58398 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58399 index 116fd38..c04182da 100644
58400 --- a/fs/autofs4/waitq.c
58401 +++ b/fs/autofs4/waitq.c
58402 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58403 {
58404 unsigned long sigpipe, flags;
58405 mm_segment_t fs;
58406 - const char *data = (const char *)addr;
58407 + const char __user *data = (const char __force_user *)addr;
58408 ssize_t wr = 0;
58409
58410 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58411 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58412 return 1;
58413 }
58414
58415 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58416 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58417 +#endif
58418 +
58419 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58420 enum autofs_notify notify)
58421 {
58422 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58423
58424 /* If this is a direct mount request create a dummy name */
58425 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58426 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58427 + /* this name does get written to userland via autofs4_write() */
58428 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58429 +#else
58430 qstr.len = sprintf(name, "%p", dentry);
58431 +#endif
58432 else {
58433 qstr.len = autofs4_getpath(sbi, dentry, &name);
58434 if (!qstr.len) {
58435 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58436 index 2722387..56059b5 100644
58437 --- a/fs/befs/endian.h
58438 +++ b/fs/befs/endian.h
58439 @@ -11,7 +11,7 @@
58440
58441 #include <asm/byteorder.h>
58442
58443 -static inline u64
58444 +static inline u64 __intentional_overflow(-1)
58445 fs64_to_cpu(const struct super_block *sb, fs64 n)
58446 {
58447 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58448 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58449 return (__force fs64)cpu_to_be64(n);
58450 }
58451
58452 -static inline u32
58453 +static inline u32 __intentional_overflow(-1)
58454 fs32_to_cpu(const struct super_block *sb, fs32 n)
58455 {
58456 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58457 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58458 return (__force fs32)cpu_to_be32(n);
58459 }
58460
58461 -static inline u16
58462 +static inline u16 __intentional_overflow(-1)
58463 fs16_to_cpu(const struct super_block *sb, fs16 n)
58464 {
58465 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58466 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58467 index 929dec0..84bd914 100644
58468 --- a/fs/binfmt_aout.c
58469 +++ b/fs/binfmt_aout.c
58470 @@ -16,6 +16,7 @@
58471 #include <linux/string.h>
58472 #include <linux/fs.h>
58473 #include <linux/file.h>
58474 +#include <linux/security.h>
58475 #include <linux/stat.h>
58476 #include <linux/fcntl.h>
58477 #include <linux/ptrace.h>
58478 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58479 #endif
58480 # define START_STACK(u) ((void __user *)u.start_stack)
58481
58482 + memset(&dump, 0, sizeof(dump));
58483 +
58484 fs = get_fs();
58485 set_fs(KERNEL_DS);
58486 has_dumped = 1;
58487 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58488
58489 /* If the size of the dump file exceeds the rlimit, then see what would happen
58490 if we wrote the stack, but not the data area. */
58491 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58492 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58493 dump.u_dsize = 0;
58494
58495 /* Make sure we have enough room to write the stack and data areas. */
58496 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58497 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58498 dump.u_ssize = 0;
58499
58500 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58501 rlim = rlimit(RLIMIT_DATA);
58502 if (rlim >= RLIM_INFINITY)
58503 rlim = ~0;
58504 +
58505 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58506 if (ex.a_data + ex.a_bss > rlim)
58507 return -ENOMEM;
58508
58509 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58510
58511 install_exec_creds(bprm);
58512
58513 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58514 + current->mm->pax_flags = 0UL;
58515 +#endif
58516 +
58517 +#ifdef CONFIG_PAX_PAGEEXEC
58518 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58519 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58520 +
58521 +#ifdef CONFIG_PAX_EMUTRAMP
58522 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58523 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58524 +#endif
58525 +
58526 +#ifdef CONFIG_PAX_MPROTECT
58527 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58528 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58529 +#endif
58530 +
58531 + }
58532 +#endif
58533 +
58534 if (N_MAGIC(ex) == OMAGIC) {
58535 unsigned long text_addr, map_size;
58536 loff_t pos;
58537 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58538 return error;
58539
58540 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58541 - PROT_READ | PROT_WRITE | PROT_EXEC,
58542 + PROT_READ | PROT_WRITE,
58543 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58544 fd_offset + ex.a_text);
58545 if (error != N_DATADDR(ex))
58546 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58547 index d8fc060..cbd44d5 100644
58548 --- a/fs/binfmt_elf.c
58549 +++ b/fs/binfmt_elf.c
58550 @@ -34,6 +34,7 @@
58551 #include <linux/utsname.h>
58552 #include <linux/coredump.h>
58553 #include <linux/sched.h>
58554 +#include <linux/xattr.h>
58555 #include <asm/uaccess.h>
58556 #include <asm/param.h>
58557 #include <asm/page.h>
58558 @@ -47,7 +48,7 @@
58559
58560 static int load_elf_binary(struct linux_binprm *bprm);
58561 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58562 - int, int, unsigned long);
58563 + int, int, unsigned long) __intentional_overflow(-1);
58564
58565 #ifdef CONFIG_USELIB
58566 static int load_elf_library(struct file *);
58567 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58568 #define elf_core_dump NULL
58569 #endif
58570
58571 +#ifdef CONFIG_PAX_MPROTECT
58572 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58573 +#endif
58574 +
58575 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58576 +static void elf_handle_mmap(struct file *file);
58577 +#endif
58578 +
58579 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58580 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58581 #else
58582 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58583 .load_binary = load_elf_binary,
58584 .load_shlib = load_elf_library,
58585 .core_dump = elf_core_dump,
58586 +
58587 +#ifdef CONFIG_PAX_MPROTECT
58588 + .handle_mprotect= elf_handle_mprotect,
58589 +#endif
58590 +
58591 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58592 + .handle_mmap = elf_handle_mmap,
58593 +#endif
58594 +
58595 .min_coredump = ELF_EXEC_PAGESIZE,
58596 };
58597
58598 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58599
58600 static int set_brk(unsigned long start, unsigned long end)
58601 {
58602 + unsigned long e = end;
58603 +
58604 start = ELF_PAGEALIGN(start);
58605 end = ELF_PAGEALIGN(end);
58606 if (end > start) {
58607 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58608 if (BAD_ADDR(addr))
58609 return addr;
58610 }
58611 - current->mm->start_brk = current->mm->brk = end;
58612 + current->mm->start_brk = current->mm->brk = e;
58613 return 0;
58614 }
58615
58616 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58617 elf_addr_t __user *u_rand_bytes;
58618 const char *k_platform = ELF_PLATFORM;
58619 const char *k_base_platform = ELF_BASE_PLATFORM;
58620 - unsigned char k_rand_bytes[16];
58621 + u32 k_rand_bytes[4];
58622 int items;
58623 elf_addr_t *elf_info;
58624 int ei_index = 0;
58625 const struct cred *cred = current_cred();
58626 struct vm_area_struct *vma;
58627 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58628
58629 /*
58630 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58631 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58632 * Generate 16 random bytes for userspace PRNG seeding.
58633 */
58634 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58635 - u_rand_bytes = (elf_addr_t __user *)
58636 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58637 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58638 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58639 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58640 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58641 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58642 + u_rand_bytes = (elf_addr_t __user *) p;
58643 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58644 return -EFAULT;
58645
58646 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58647 return -EFAULT;
58648 current->mm->env_end = p;
58649
58650 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58651 +
58652 /* Put the elf_info on the stack in the right place. */
58653 sp = (elf_addr_t __user *)envp + 1;
58654 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58655 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58656 return -EFAULT;
58657 return 0;
58658 }
58659 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58660 an ELF header */
58661
58662 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58663 - struct file *interpreter, unsigned long *interp_map_addr,
58664 - unsigned long no_base)
58665 + struct file *interpreter, unsigned long no_base)
58666 {
58667 struct elf_phdr *elf_phdata;
58668 struct elf_phdr *eppnt;
58669 - unsigned long load_addr = 0;
58670 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58671 int load_addr_set = 0;
58672 unsigned long last_bss = 0, elf_bss = 0;
58673 - unsigned long error = ~0UL;
58674 + unsigned long error = -EINVAL;
58675 unsigned long total_size;
58676 int retval, i, size;
58677
58678 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58679 goto out_close;
58680 }
58681
58682 +#ifdef CONFIG_PAX_SEGMEXEC
58683 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58684 + pax_task_size = SEGMEXEC_TASK_SIZE;
58685 +#endif
58686 +
58687 eppnt = elf_phdata;
58688 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58689 if (eppnt->p_type == PT_LOAD) {
58690 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58691 map_addr = elf_map(interpreter, load_addr + vaddr,
58692 eppnt, elf_prot, elf_type, total_size);
58693 total_size = 0;
58694 - if (!*interp_map_addr)
58695 - *interp_map_addr = map_addr;
58696 error = map_addr;
58697 if (BAD_ADDR(map_addr))
58698 goto out_close;
58699 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58700 k = load_addr + eppnt->p_vaddr;
58701 if (BAD_ADDR(k) ||
58702 eppnt->p_filesz > eppnt->p_memsz ||
58703 - eppnt->p_memsz > TASK_SIZE ||
58704 - TASK_SIZE - eppnt->p_memsz < k) {
58705 + eppnt->p_memsz > pax_task_size ||
58706 + pax_task_size - eppnt->p_memsz < k) {
58707 error = -ENOMEM;
58708 goto out_close;
58709 }
58710 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58711 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58712
58713 /* Map the last of the bss segment */
58714 - error = vm_brk(elf_bss, last_bss - elf_bss);
58715 - if (BAD_ADDR(error))
58716 - goto out_close;
58717 + if (last_bss > elf_bss) {
58718 + error = vm_brk(elf_bss, last_bss - elf_bss);
58719 + if (BAD_ADDR(error))
58720 + goto out_close;
58721 + }
58722 }
58723
58724 error = load_addr;
58725 @@ -543,6 +574,336 @@ out:
58726 return error;
58727 }
58728
58729 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58730 +#ifdef CONFIG_PAX_SOFTMODE
58731 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58732 +{
58733 + unsigned long pax_flags = 0UL;
58734 +
58735 +#ifdef CONFIG_PAX_PAGEEXEC
58736 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58737 + pax_flags |= MF_PAX_PAGEEXEC;
58738 +#endif
58739 +
58740 +#ifdef CONFIG_PAX_SEGMEXEC
58741 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58742 + pax_flags |= MF_PAX_SEGMEXEC;
58743 +#endif
58744 +
58745 +#ifdef CONFIG_PAX_EMUTRAMP
58746 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58747 + pax_flags |= MF_PAX_EMUTRAMP;
58748 +#endif
58749 +
58750 +#ifdef CONFIG_PAX_MPROTECT
58751 + if (elf_phdata->p_flags & PF_MPROTECT)
58752 + pax_flags |= MF_PAX_MPROTECT;
58753 +#endif
58754 +
58755 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58756 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58757 + pax_flags |= MF_PAX_RANDMMAP;
58758 +#endif
58759 +
58760 + return pax_flags;
58761 +}
58762 +#endif
58763 +
58764 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58765 +{
58766 + unsigned long pax_flags = 0UL;
58767 +
58768 +#ifdef CONFIG_PAX_PAGEEXEC
58769 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58770 + pax_flags |= MF_PAX_PAGEEXEC;
58771 +#endif
58772 +
58773 +#ifdef CONFIG_PAX_SEGMEXEC
58774 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58775 + pax_flags |= MF_PAX_SEGMEXEC;
58776 +#endif
58777 +
58778 +#ifdef CONFIG_PAX_EMUTRAMP
58779 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58780 + pax_flags |= MF_PAX_EMUTRAMP;
58781 +#endif
58782 +
58783 +#ifdef CONFIG_PAX_MPROTECT
58784 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58785 + pax_flags |= MF_PAX_MPROTECT;
58786 +#endif
58787 +
58788 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58789 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58790 + pax_flags |= MF_PAX_RANDMMAP;
58791 +#endif
58792 +
58793 + return pax_flags;
58794 +}
58795 +#endif
58796 +
58797 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58798 +#ifdef CONFIG_PAX_SOFTMODE
58799 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58800 +{
58801 + unsigned long pax_flags = 0UL;
58802 +
58803 +#ifdef CONFIG_PAX_PAGEEXEC
58804 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58805 + pax_flags |= MF_PAX_PAGEEXEC;
58806 +#endif
58807 +
58808 +#ifdef CONFIG_PAX_SEGMEXEC
58809 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58810 + pax_flags |= MF_PAX_SEGMEXEC;
58811 +#endif
58812 +
58813 +#ifdef CONFIG_PAX_EMUTRAMP
58814 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58815 + pax_flags |= MF_PAX_EMUTRAMP;
58816 +#endif
58817 +
58818 +#ifdef CONFIG_PAX_MPROTECT
58819 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58820 + pax_flags |= MF_PAX_MPROTECT;
58821 +#endif
58822 +
58823 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58824 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58825 + pax_flags |= MF_PAX_RANDMMAP;
58826 +#endif
58827 +
58828 + return pax_flags;
58829 +}
58830 +#endif
58831 +
58832 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58833 +{
58834 + unsigned long pax_flags = 0UL;
58835 +
58836 +#ifdef CONFIG_PAX_PAGEEXEC
58837 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58838 + pax_flags |= MF_PAX_PAGEEXEC;
58839 +#endif
58840 +
58841 +#ifdef CONFIG_PAX_SEGMEXEC
58842 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58843 + pax_flags |= MF_PAX_SEGMEXEC;
58844 +#endif
58845 +
58846 +#ifdef CONFIG_PAX_EMUTRAMP
58847 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58848 + pax_flags |= MF_PAX_EMUTRAMP;
58849 +#endif
58850 +
58851 +#ifdef CONFIG_PAX_MPROTECT
58852 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58853 + pax_flags |= MF_PAX_MPROTECT;
58854 +#endif
58855 +
58856 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58857 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58858 + pax_flags |= MF_PAX_RANDMMAP;
58859 +#endif
58860 +
58861 + return pax_flags;
58862 +}
58863 +#endif
58864 +
58865 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58866 +static unsigned long pax_parse_defaults(void)
58867 +{
58868 + unsigned long pax_flags = 0UL;
58869 +
58870 +#ifdef CONFIG_PAX_SOFTMODE
58871 + if (pax_softmode)
58872 + return pax_flags;
58873 +#endif
58874 +
58875 +#ifdef CONFIG_PAX_PAGEEXEC
58876 + pax_flags |= MF_PAX_PAGEEXEC;
58877 +#endif
58878 +
58879 +#ifdef CONFIG_PAX_SEGMEXEC
58880 + pax_flags |= MF_PAX_SEGMEXEC;
58881 +#endif
58882 +
58883 +#ifdef CONFIG_PAX_MPROTECT
58884 + pax_flags |= MF_PAX_MPROTECT;
58885 +#endif
58886 +
58887 +#ifdef CONFIG_PAX_RANDMMAP
58888 + if (randomize_va_space)
58889 + pax_flags |= MF_PAX_RANDMMAP;
58890 +#endif
58891 +
58892 + return pax_flags;
58893 +}
58894 +
58895 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58896 +{
58897 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58898 +
58899 +#ifdef CONFIG_PAX_EI_PAX
58900 +
58901 +#ifdef CONFIG_PAX_SOFTMODE
58902 + if (pax_softmode)
58903 + return pax_flags;
58904 +#endif
58905 +
58906 + pax_flags = 0UL;
58907 +
58908 +#ifdef CONFIG_PAX_PAGEEXEC
58909 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58910 + pax_flags |= MF_PAX_PAGEEXEC;
58911 +#endif
58912 +
58913 +#ifdef CONFIG_PAX_SEGMEXEC
58914 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58915 + pax_flags |= MF_PAX_SEGMEXEC;
58916 +#endif
58917 +
58918 +#ifdef CONFIG_PAX_EMUTRAMP
58919 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58920 + pax_flags |= MF_PAX_EMUTRAMP;
58921 +#endif
58922 +
58923 +#ifdef CONFIG_PAX_MPROTECT
58924 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58925 + pax_flags |= MF_PAX_MPROTECT;
58926 +#endif
58927 +
58928 +#ifdef CONFIG_PAX_ASLR
58929 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58930 + pax_flags |= MF_PAX_RANDMMAP;
58931 +#endif
58932 +
58933 +#endif
58934 +
58935 + return pax_flags;
58936 +
58937 +}
58938 +
58939 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58940 +{
58941 +
58942 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58943 + unsigned long i;
58944 +
58945 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58946 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58947 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58948 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58949 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58950 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58951 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58952 + return PAX_PARSE_FLAGS_FALLBACK;
58953 +
58954 +#ifdef CONFIG_PAX_SOFTMODE
58955 + if (pax_softmode)
58956 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58957 + else
58958 +#endif
58959 +
58960 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58961 + break;
58962 + }
58963 +#endif
58964 +
58965 + return PAX_PARSE_FLAGS_FALLBACK;
58966 +}
58967 +
58968 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58969 +{
58970 +
58971 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58972 + ssize_t xattr_size, i;
58973 + unsigned char xattr_value[sizeof("pemrs") - 1];
58974 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58975 +
58976 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58977 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58978 + return PAX_PARSE_FLAGS_FALLBACK;
58979 +
58980 + for (i = 0; i < xattr_size; i++)
58981 + switch (xattr_value[i]) {
58982 + default:
58983 + return PAX_PARSE_FLAGS_FALLBACK;
58984 +
58985 +#define parse_flag(option1, option2, flag) \
58986 + case option1: \
58987 + if (pax_flags_hardmode & MF_PAX_##flag) \
58988 + return PAX_PARSE_FLAGS_FALLBACK;\
58989 + pax_flags_hardmode |= MF_PAX_##flag; \
58990 + break; \
58991 + case option2: \
58992 + if (pax_flags_softmode & MF_PAX_##flag) \
58993 + return PAX_PARSE_FLAGS_FALLBACK;\
58994 + pax_flags_softmode |= MF_PAX_##flag; \
58995 + break;
58996 +
58997 + parse_flag('p', 'P', PAGEEXEC);
58998 + parse_flag('e', 'E', EMUTRAMP);
58999 + parse_flag('m', 'M', MPROTECT);
59000 + parse_flag('r', 'R', RANDMMAP);
59001 + parse_flag('s', 'S', SEGMEXEC);
59002 +
59003 +#undef parse_flag
59004 + }
59005 +
59006 + if (pax_flags_hardmode & pax_flags_softmode)
59007 + return PAX_PARSE_FLAGS_FALLBACK;
59008 +
59009 +#ifdef CONFIG_PAX_SOFTMODE
59010 + if (pax_softmode)
59011 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59012 + else
59013 +#endif
59014 +
59015 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59016 +#else
59017 + return PAX_PARSE_FLAGS_FALLBACK;
59018 +#endif
59019 +
59020 +}
59021 +
59022 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59023 +{
59024 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59025 +
59026 + pax_flags = pax_parse_defaults();
59027 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59028 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59029 + xattr_pax_flags = pax_parse_xattr_pax(file);
59030 +
59031 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59032 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59033 + pt_pax_flags != xattr_pax_flags)
59034 + return -EINVAL;
59035 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59036 + pax_flags = xattr_pax_flags;
59037 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59038 + pax_flags = pt_pax_flags;
59039 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59040 + pax_flags = ei_pax_flags;
59041 +
59042 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59043 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59044 + if ((__supported_pte_mask & _PAGE_NX))
59045 + pax_flags &= ~MF_PAX_SEGMEXEC;
59046 + else
59047 + pax_flags &= ~MF_PAX_PAGEEXEC;
59048 + }
59049 +#endif
59050 +
59051 + if (0 > pax_check_flags(&pax_flags))
59052 + return -EINVAL;
59053 +
59054 + current->mm->pax_flags = pax_flags;
59055 + return 0;
59056 +}
59057 +#endif
59058 +
59059 /*
59060 * These are the functions used to load ELF style executables and shared
59061 * libraries. There is no binary dependent code anywhere else.
59062 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59063 {
59064 unsigned int random_variable = 0;
59065
59066 +#ifdef CONFIG_PAX_RANDUSTACK
59067 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59068 + return stack_top - current->mm->delta_stack;
59069 +#endif
59070 +
59071 if ((current->flags & PF_RANDOMIZE) &&
59072 !(current->personality & ADDR_NO_RANDOMIZE)) {
59073 random_variable = get_random_int() & STACK_RND_MASK;
59074 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59075 unsigned long load_addr = 0, load_bias = 0;
59076 int load_addr_set = 0;
59077 char * elf_interpreter = NULL;
59078 - unsigned long error;
59079 + unsigned long error = 0;
59080 struct elf_phdr *elf_ppnt, *elf_phdata;
59081 unsigned long elf_bss, elf_brk;
59082 int retval, i;
59083 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59084 struct elfhdr elf_ex;
59085 struct elfhdr interp_elf_ex;
59086 } *loc;
59087 + unsigned long pax_task_size;
59088
59089 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59090 if (!loc) {
59091 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59092 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59093 may depend on the personality. */
59094 SET_PERSONALITY(loc->elf_ex);
59095 +
59096 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59097 + current->mm->pax_flags = 0UL;
59098 +#endif
59099 +
59100 +#ifdef CONFIG_PAX_DLRESOLVE
59101 + current->mm->call_dl_resolve = 0UL;
59102 +#endif
59103 +
59104 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59105 + current->mm->call_syscall = 0UL;
59106 +#endif
59107 +
59108 +#ifdef CONFIG_PAX_ASLR
59109 + current->mm->delta_mmap = 0UL;
59110 + current->mm->delta_stack = 0UL;
59111 +#endif
59112 +
59113 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59114 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59115 + send_sig(SIGKILL, current, 0);
59116 + goto out_free_dentry;
59117 + }
59118 +#endif
59119 +
59120 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59121 + pax_set_initial_flags(bprm);
59122 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59123 + if (pax_set_initial_flags_func)
59124 + (pax_set_initial_flags_func)(bprm);
59125 +#endif
59126 +
59127 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59128 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59129 + current->mm->context.user_cs_limit = PAGE_SIZE;
59130 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59131 + }
59132 +#endif
59133 +
59134 +#ifdef CONFIG_PAX_SEGMEXEC
59135 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59136 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59137 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59138 + pax_task_size = SEGMEXEC_TASK_SIZE;
59139 + current->mm->def_flags |= VM_NOHUGEPAGE;
59140 + } else
59141 +#endif
59142 +
59143 + pax_task_size = TASK_SIZE;
59144 +
59145 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59146 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59147 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59148 + put_cpu();
59149 + }
59150 +#endif
59151 +
59152 +#ifdef CONFIG_PAX_ASLR
59153 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59154 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59155 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59156 + }
59157 +#endif
59158 +
59159 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59160 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59161 + executable_stack = EXSTACK_DISABLE_X;
59162 + current->personality &= ~READ_IMPLIES_EXEC;
59163 + } else
59164 +#endif
59165 +
59166 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59167 current->personality |= READ_IMPLIES_EXEC;
59168
59169 @@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59170 #else
59171 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59172 #endif
59173 +
59174 +#ifdef CONFIG_PAX_RANDMMAP
59175 + /* PaX: randomize base address at the default exe base if requested */
59176 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59177 +#ifdef CONFIG_SPARC64
59178 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59179 +#else
59180 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59181 +#endif
59182 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59183 + elf_flags |= MAP_FIXED;
59184 + }
59185 +#endif
59186 +
59187 }
59188
59189 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59190 @@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59191 * allowed task size. Note that p_filesz must always be
59192 * <= p_memsz so it is only necessary to check p_memsz.
59193 */
59194 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59195 - elf_ppnt->p_memsz > TASK_SIZE ||
59196 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59197 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59198 + elf_ppnt->p_memsz > pax_task_size ||
59199 + pax_task_size - elf_ppnt->p_memsz < k) {
59200 /* set_brk can never work. Avoid overflows. */
59201 retval = -EINVAL;
59202 goto out_free_dentry;
59203 @@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
59204 if (retval)
59205 goto out_free_dentry;
59206 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59207 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59208 - goto out_free_dentry;
59209 + /*
59210 + * This bss-zeroing can fail if the ELF
59211 + * file specifies odd protections. So
59212 + * we don't check the return value
59213 + */
59214 }
59215
59216 +#ifdef CONFIG_PAX_RANDMMAP
59217 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59218 + unsigned long start, size, flags;
59219 + vm_flags_t vm_flags;
59220 +
59221 + start = ELF_PAGEALIGN(elf_brk);
59222 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59223 + flags = MAP_FIXED | MAP_PRIVATE;
59224 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59225 +
59226 + down_write(&current->mm->mmap_sem);
59227 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59228 + retval = -ENOMEM;
59229 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59230 +// if (current->personality & ADDR_NO_RANDOMIZE)
59231 +// vm_flags |= VM_READ | VM_MAYREAD;
59232 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59233 + retval = IS_ERR_VALUE(start) ? start : 0;
59234 + }
59235 + up_write(&current->mm->mmap_sem);
59236 + if (retval == 0)
59237 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59238 + if (retval < 0)
59239 + goto out_free_dentry;
59240 + }
59241 +#endif
59242 +
59243 if (elf_interpreter) {
59244 - unsigned long interp_map_addr = 0;
59245 -
59246 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59247 interpreter,
59248 - &interp_map_addr,
59249 load_bias);
59250 if (!IS_ERR((void *)elf_entry)) {
59251 /*
59252 @@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59253 * Decide what to dump of a segment, part, all or none.
59254 */
59255 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59256 - unsigned long mm_flags)
59257 + unsigned long mm_flags, long signr)
59258 {
59259 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59260
59261 @@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59262 if (vma->vm_file == NULL)
59263 return 0;
59264
59265 - if (FILTER(MAPPED_PRIVATE))
59266 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59267 goto whole;
59268
59269 /*
59270 @@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59271 {
59272 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59273 int i = 0;
59274 - do
59275 + do {
59276 i += 2;
59277 - while (auxv[i - 2] != AT_NULL);
59278 + } while (auxv[i - 2] != AT_NULL);
59279 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59280 }
59281
59282 @@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59283 {
59284 mm_segment_t old_fs = get_fs();
59285 set_fs(KERNEL_DS);
59286 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59287 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59288 set_fs(old_fs);
59289 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59290 }
59291 @@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59292 }
59293
59294 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59295 - unsigned long mm_flags)
59296 + struct coredump_params *cprm)
59297 {
59298 struct vm_area_struct *vma;
59299 size_t size = 0;
59300
59301 for (vma = first_vma(current, gate_vma); vma != NULL;
59302 vma = next_vma(vma, gate_vma))
59303 - size += vma_dump_size(vma, mm_flags);
59304 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59305 return size;
59306 }
59307
59308 @@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59309
59310 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59311
59312 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59313 + offset += elf_core_vma_data_size(gate_vma, cprm);
59314 offset += elf_core_extra_data_size();
59315 e_shoff = offset;
59316
59317 @@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59318 phdr.p_offset = offset;
59319 phdr.p_vaddr = vma->vm_start;
59320 phdr.p_paddr = 0;
59321 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59322 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59323 phdr.p_memsz = vma->vm_end - vma->vm_start;
59324 offset += phdr.p_filesz;
59325 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59326 @@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59327 unsigned long addr;
59328 unsigned long end;
59329
59330 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59331 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59332
59333 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59334 struct page *page;
59335 @@ -2195,6 +2674,167 @@ out:
59336
59337 #endif /* CONFIG_ELF_CORE */
59338
59339 +#ifdef CONFIG_PAX_MPROTECT
59340 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59341 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59342 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59343 + *
59344 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59345 + * basis because we want to allow the common case and not the special ones.
59346 + */
59347 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59348 +{
59349 + struct elfhdr elf_h;
59350 + struct elf_phdr elf_p;
59351 + unsigned long i;
59352 + unsigned long oldflags;
59353 + bool is_textrel_rw, is_textrel_rx, is_relro;
59354 +
59355 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59356 + return;
59357 +
59358 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59359 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59360 +
59361 +#ifdef CONFIG_PAX_ELFRELOCS
59362 + /* possible TEXTREL */
59363 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59364 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59365 +#else
59366 + is_textrel_rw = false;
59367 + is_textrel_rx = false;
59368 +#endif
59369 +
59370 + /* possible RELRO */
59371 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59372 +
59373 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59374 + return;
59375 +
59376 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59377 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59378 +
59379 +#ifdef CONFIG_PAX_ETEXECRELOCS
59380 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59381 +#else
59382 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59383 +#endif
59384 +
59385 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59386 + !elf_check_arch(&elf_h) ||
59387 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59388 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59389 + return;
59390 +
59391 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59392 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59393 + return;
59394 + switch (elf_p.p_type) {
59395 + case PT_DYNAMIC:
59396 + if (!is_textrel_rw && !is_textrel_rx)
59397 + continue;
59398 + i = 0UL;
59399 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59400 + elf_dyn dyn;
59401 +
59402 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59403 + break;
59404 + if (dyn.d_tag == DT_NULL)
59405 + break;
59406 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59407 + gr_log_textrel(vma);
59408 + if (is_textrel_rw)
59409 + vma->vm_flags |= VM_MAYWRITE;
59410 + else
59411 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59412 + vma->vm_flags &= ~VM_MAYWRITE;
59413 + break;
59414 + }
59415 + i++;
59416 + }
59417 + is_textrel_rw = false;
59418 + is_textrel_rx = false;
59419 + continue;
59420 +
59421 + case PT_GNU_RELRO:
59422 + if (!is_relro)
59423 + continue;
59424 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59425 + vma->vm_flags &= ~VM_MAYWRITE;
59426 + is_relro = false;
59427 + continue;
59428 +
59429 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59430 + case PT_PAX_FLAGS: {
59431 + const char *msg_mprotect = "", *msg_emutramp = "";
59432 + char *buffer_lib, *buffer_exe;
59433 +
59434 + if (elf_p.p_flags & PF_NOMPROTECT)
59435 + msg_mprotect = "MPROTECT disabled";
59436 +
59437 +#ifdef CONFIG_PAX_EMUTRAMP
59438 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59439 + msg_emutramp = "EMUTRAMP enabled";
59440 +#endif
59441 +
59442 + if (!msg_mprotect[0] && !msg_emutramp[0])
59443 + continue;
59444 +
59445 + if (!printk_ratelimit())
59446 + continue;
59447 +
59448 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59449 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59450 + if (buffer_lib && buffer_exe) {
59451 + char *path_lib, *path_exe;
59452 +
59453 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59454 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59455 +
59456 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59457 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59458 +
59459 + }
59460 + free_page((unsigned long)buffer_exe);
59461 + free_page((unsigned long)buffer_lib);
59462 + continue;
59463 + }
59464 +#endif
59465 +
59466 + }
59467 + }
59468 +}
59469 +#endif
59470 +
59471 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59472 +
59473 +extern int grsec_enable_log_rwxmaps;
59474 +
59475 +static void elf_handle_mmap(struct file *file)
59476 +{
59477 + struct elfhdr elf_h;
59478 + struct elf_phdr elf_p;
59479 + unsigned long i;
59480 +
59481 + if (!grsec_enable_log_rwxmaps)
59482 + return;
59483 +
59484 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59485 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59486 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59487 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59488 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59489 + return;
59490 +
59491 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59492 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59493 + return;
59494 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59495 + gr_log_ptgnustack(file);
59496 + }
59497 +}
59498 +#endif
59499 +
59500 static int __init init_elf_binfmt(void)
59501 {
59502 register_binfmt(&elf_format);
59503 diff --git a/fs/block_dev.c b/fs/block_dev.c
59504 index 1d9c9f3..2905786 100644
59505 --- a/fs/block_dev.c
59506 +++ b/fs/block_dev.c
59507 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59508 else if (bdev->bd_contains == bdev)
59509 return true; /* is a whole device which isn't held */
59510
59511 - else if (whole->bd_holder == bd_may_claim)
59512 + else if (whole->bd_holder == (void *)bd_may_claim)
59513 return true; /* is a partition of a device that is being partitioned */
59514 else if (whole->bd_holder != NULL)
59515 return false; /* is a partition of a held device */
59516 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59517 index 150822e..75bb326 100644
59518 --- a/fs/btrfs/ctree.c
59519 +++ b/fs/btrfs/ctree.c
59520 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59521 free_extent_buffer(buf);
59522 add_root_to_dirty_list(root);
59523 } else {
59524 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59525 - parent_start = parent->start;
59526 - else
59527 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59528 + if (parent)
59529 + parent_start = parent->start;
59530 + else
59531 + parent_start = 0;
59532 + } else
59533 parent_start = 0;
59534
59535 WARN_ON(trans->transid != btrfs_header_generation(parent));
59536 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59537 index de4e70f..b41dc45 100644
59538 --- a/fs/btrfs/delayed-inode.c
59539 +++ b/fs/btrfs/delayed-inode.c
59540 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59541
59542 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59543 {
59544 - int seq = atomic_inc_return(&delayed_root->items_seq);
59545 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59546 if ((atomic_dec_return(&delayed_root->items) <
59547 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59548 waitqueue_active(&delayed_root->wait))
59549 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59550
59551 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59552 {
59553 - int val = atomic_read(&delayed_root->items_seq);
59554 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59555
59556 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59557 return 1;
59558 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59559 int seq;
59560 int ret;
59561
59562 - seq = atomic_read(&delayed_root->items_seq);
59563 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59564
59565 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59566 if (ret)
59567 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59568 index f70119f..ab5894d 100644
59569 --- a/fs/btrfs/delayed-inode.h
59570 +++ b/fs/btrfs/delayed-inode.h
59571 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59572 */
59573 struct list_head prepare_list;
59574 atomic_t items; /* for delayed items */
59575 - atomic_t items_seq; /* for delayed items */
59576 + atomic_unchecked_t items_seq; /* for delayed items */
59577 int nodes; /* for delayed nodes */
59578 wait_queue_head_t wait;
59579 };
59580 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59581 struct btrfs_delayed_root *delayed_root)
59582 {
59583 atomic_set(&delayed_root->items, 0);
59584 - atomic_set(&delayed_root->items_seq, 0);
59585 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59586 delayed_root->nodes = 0;
59587 spin_lock_init(&delayed_root->lock);
59588 init_waitqueue_head(&delayed_root->wait);
59589 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59590 index 4399f0c..a34d8b4 100644
59591 --- a/fs/btrfs/ioctl.c
59592 +++ b/fs/btrfs/ioctl.c
59593 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59594 for (i = 0; i < num_types; i++) {
59595 struct btrfs_space_info *tmp;
59596
59597 + /* Don't copy in more than we allocated */
59598 if (!slot_count)
59599 break;
59600
59601 + slot_count--;
59602 +
59603 info = NULL;
59604 rcu_read_lock();
59605 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59606 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59607 memcpy(dest, &space, sizeof(space));
59608 dest++;
59609 space_args.total_spaces++;
59610 - slot_count--;
59611 }
59612 - if (!slot_count)
59613 - break;
59614 }
59615 up_read(&info->groups_sem);
59616 }
59617 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59618 index cde9c03..ad4d4db 100644
59619 --- a/fs/btrfs/super.c
59620 +++ b/fs/btrfs/super.c
59621 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59622 function, line, errstr);
59623 return;
59624 }
59625 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59626 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59627 /* Wake up anybody who may be waiting on this transaction */
59628 wake_up(&root->fs_info->transaction_wait);
59629 wake_up(&root->fs_info->transaction_blocked_wait);
59630 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59631 index b2e7bb4..3719201 100644
59632 --- a/fs/btrfs/sysfs.c
59633 +++ b/fs/btrfs/sysfs.c
59634 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59635 for (set = 0; set < FEAT_MAX; set++) {
59636 int i;
59637 struct attribute *attrs[2];
59638 - struct attribute_group agroup = {
59639 + attribute_group_no_const agroup = {
59640 .name = "features",
59641 .attrs = attrs,
59642 };
59643 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59644 index 2299bfd..4098e72 100644
59645 --- a/fs/btrfs/tests/free-space-tests.c
59646 +++ b/fs/btrfs/tests/free-space-tests.c
59647 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59648 * extent entry.
59649 */
59650 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59651 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59652 + pax_open_kernel();
59653 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59654 + pax_close_kernel();
59655
59656 /*
59657 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59658 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59659 if (ret)
59660 return ret;
59661
59662 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59663 + pax_open_kernel();
59664 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59665 + pax_close_kernel();
59666 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59667
59668 return 0;
59669 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59670 index 154990c..d0cf699 100644
59671 --- a/fs/btrfs/tree-log.h
59672 +++ b/fs/btrfs/tree-log.h
59673 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59674 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59675 struct btrfs_trans_handle *trans)
59676 {
59677 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59678 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59679 }
59680
59681 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59682 diff --git a/fs/buffer.c b/fs/buffer.c
59683 index 20805db..2e8fc69 100644
59684 --- a/fs/buffer.c
59685 +++ b/fs/buffer.c
59686 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59687 bh_cachep = kmem_cache_create("buffer_head",
59688 sizeof(struct buffer_head), 0,
59689 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59690 - SLAB_MEM_SPREAD),
59691 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59692 NULL);
59693
59694 /*
59695 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59696 index fbb08e9..0fda764 100644
59697 --- a/fs/cachefiles/bind.c
59698 +++ b/fs/cachefiles/bind.c
59699 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59700 args);
59701
59702 /* start by checking things over */
59703 - ASSERT(cache->fstop_percent >= 0 &&
59704 - cache->fstop_percent < cache->fcull_percent &&
59705 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59706 cache->fcull_percent < cache->frun_percent &&
59707 cache->frun_percent < 100);
59708
59709 - ASSERT(cache->bstop_percent >= 0 &&
59710 - cache->bstop_percent < cache->bcull_percent &&
59711 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59712 cache->bcull_percent < cache->brun_percent &&
59713 cache->brun_percent < 100);
59714
59715 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59716 index ce1b115..4a6852c 100644
59717 --- a/fs/cachefiles/daemon.c
59718 +++ b/fs/cachefiles/daemon.c
59719 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59720 if (n > buflen)
59721 return -EMSGSIZE;
59722
59723 - if (copy_to_user(_buffer, buffer, n) != 0)
59724 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59725 return -EFAULT;
59726
59727 return n;
59728 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59729 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59730 return -EIO;
59731
59732 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59733 + if (datalen > PAGE_SIZE - 1)
59734 return -EOPNOTSUPP;
59735
59736 /* drag the command string into the kernel so we can parse it */
59737 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59738 if (args[0] != '%' || args[1] != '\0')
59739 return -EINVAL;
59740
59741 - if (fstop < 0 || fstop >= cache->fcull_percent)
59742 + if (fstop >= cache->fcull_percent)
59743 return cachefiles_daemon_range_error(cache, args);
59744
59745 cache->fstop_percent = fstop;
59746 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59747 if (args[0] != '%' || args[1] != '\0')
59748 return -EINVAL;
59749
59750 - if (bstop < 0 || bstop >= cache->bcull_percent)
59751 + if (bstop >= cache->bcull_percent)
59752 return cachefiles_daemon_range_error(cache, args);
59753
59754 cache->bstop_percent = bstop;
59755 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59756 index 8c52472..c4e3a69 100644
59757 --- a/fs/cachefiles/internal.h
59758 +++ b/fs/cachefiles/internal.h
59759 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59760 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59761 struct rb_root active_nodes; /* active nodes (can't be culled) */
59762 rwlock_t active_lock; /* lock for active_nodes */
59763 - atomic_t gravecounter; /* graveyard uniquifier */
59764 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59765 unsigned frun_percent; /* when to stop culling (% files) */
59766 unsigned fcull_percent; /* when to start culling (% files) */
59767 unsigned fstop_percent; /* when to stop allocating (% files) */
59768 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59769 * proc.c
59770 */
59771 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59772 -extern atomic_t cachefiles_lookup_histogram[HZ];
59773 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59774 -extern atomic_t cachefiles_create_histogram[HZ];
59775 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59776 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59777 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59778
59779 extern int __init cachefiles_proc_init(void);
59780 extern void cachefiles_proc_cleanup(void);
59781 static inline
59782 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59783 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59784 {
59785 unsigned long jif = jiffies - start_jif;
59786 if (jif >= HZ)
59787 jif = HZ - 1;
59788 - atomic_inc(&histogram[jif]);
59789 + atomic_inc_unchecked(&histogram[jif]);
59790 }
59791
59792 #else
59793 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59794 index e12f189..ed17244 100644
59795 --- a/fs/cachefiles/namei.c
59796 +++ b/fs/cachefiles/namei.c
59797 @@ -312,7 +312,7 @@ try_again:
59798 /* first step is to make up a grave dentry in the graveyard */
59799 sprintf(nbuffer, "%08x%08x",
59800 (uint32_t) get_seconds(),
59801 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59802 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59803
59804 /* do the multiway lock magic */
59805 trap = lock_rename(cache->graveyard, dir);
59806 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59807 index eccd339..4c1d995 100644
59808 --- a/fs/cachefiles/proc.c
59809 +++ b/fs/cachefiles/proc.c
59810 @@ -14,9 +14,9 @@
59811 #include <linux/seq_file.h>
59812 #include "internal.h"
59813
59814 -atomic_t cachefiles_lookup_histogram[HZ];
59815 -atomic_t cachefiles_mkdir_histogram[HZ];
59816 -atomic_t cachefiles_create_histogram[HZ];
59817 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59818 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59819 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59820
59821 /*
59822 * display the latency histogram
59823 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59824 return 0;
59825 default:
59826 index = (unsigned long) v - 3;
59827 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59828 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59829 - z = atomic_read(&cachefiles_create_histogram[index]);
59830 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59831 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59832 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59833 if (x == 0 && y == 0 && z == 0)
59834 return 0;
59835
59836 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59837 index 695e788..f4a9d4d 100644
59838 --- a/fs/ceph/dir.c
59839 +++ b/fs/ceph/dir.c
59840 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59841 struct dentry *dentry, *last;
59842 struct ceph_dentry_info *di;
59843 int err = 0;
59844 + char d_name[DNAME_INLINE_LEN];
59845 + const unsigned char *name;
59846
59847 /* claim ref on last dentry we returned */
59848 last = fi->dentry;
59849 @@ -192,7 +194,12 @@ more:
59850
59851 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59852 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59853 - if (!dir_emit(ctx, dentry->d_name.name,
59854 + name = dentry->d_name.name;
59855 + if (name == dentry->d_iname) {
59856 + memcpy(d_name, name, dentry->d_name.len);
59857 + name = d_name;
59858 + }
59859 + if (!dir_emit(ctx, name,
59860 dentry->d_name.len,
59861 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59862 dentry->d_inode->i_mode >> 12)) {
59863 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59864 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59865 struct ceph_mds_client *mdsc = fsc->mdsc;
59866 unsigned frag = fpos_frag(ctx->pos);
59867 - int off = fpos_off(ctx->pos);
59868 + unsigned int off = fpos_off(ctx->pos);
59869 int err;
59870 u32 ftype;
59871 struct ceph_mds_reply_info_parsed *rinfo;
59872 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59873 index f6e1237..796ffd1 100644
59874 --- a/fs/ceph/super.c
59875 +++ b/fs/ceph/super.c
59876 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59877 /*
59878 * construct our own bdi so we can control readahead, etc.
59879 */
59880 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59881 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59882
59883 static int ceph_register_bdi(struct super_block *sb,
59884 struct ceph_fs_client *fsc)
59885 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59886 default_backing_dev_info.ra_pages;
59887
59888 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59889 - atomic_long_inc_return(&bdi_seq));
59890 + atomic_long_inc_return_unchecked(&bdi_seq));
59891 if (!err)
59892 sb->s_bdi = &fsc->backing_dev_info;
59893 return err;
59894 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59895 index 44ec726..11a056f 100644
59896 --- a/fs/cifs/cifs_debug.c
59897 +++ b/fs/cifs/cifs_debug.c
59898 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59899
59900 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59901 #ifdef CONFIG_CIFS_STATS2
59902 - atomic_set(&totBufAllocCount, 0);
59903 - atomic_set(&totSmBufAllocCount, 0);
59904 + atomic_set_unchecked(&totBufAllocCount, 0);
59905 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59906 #endif /* CONFIG_CIFS_STATS2 */
59907 spin_lock(&cifs_tcp_ses_lock);
59908 list_for_each(tmp1, &cifs_tcp_ses_list) {
59909 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59910 tcon = list_entry(tmp3,
59911 struct cifs_tcon,
59912 tcon_list);
59913 - atomic_set(&tcon->num_smbs_sent, 0);
59914 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59915 if (server->ops->clear_stats)
59916 server->ops->clear_stats(tcon);
59917 }
59918 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59919 smBufAllocCount.counter, cifs_min_small);
59920 #ifdef CONFIG_CIFS_STATS2
59921 seq_printf(m, "Total Large %d Small %d Allocations\n",
59922 - atomic_read(&totBufAllocCount),
59923 - atomic_read(&totSmBufAllocCount));
59924 + atomic_read_unchecked(&totBufAllocCount),
59925 + atomic_read_unchecked(&totSmBufAllocCount));
59926 #endif /* CONFIG_CIFS_STATS2 */
59927
59928 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59929 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59930 if (tcon->need_reconnect)
59931 seq_puts(m, "\tDISCONNECTED ");
59932 seq_printf(m, "\nSMBs: %d",
59933 - atomic_read(&tcon->num_smbs_sent));
59934 + atomic_read_unchecked(&tcon->num_smbs_sent));
59935 if (server->ops->print_stats)
59936 server->ops->print_stats(m, tcon);
59937 }
59938 @@ -615,9 +615,11 @@ cifs_security_flags_handle_must_flags(unsigned int *flags)
59939 *flags = CIFSSEC_MUST_NTLMV2;
59940 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
59941 *flags = CIFSSEC_MUST_NTLM;
59942 - else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59943 + else if (CIFSSEC_MUST_LANMAN &&
59944 + (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59945 *flags = CIFSSEC_MUST_LANMAN;
59946 - else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59947 + else if (CIFSSEC_MUST_PLNTXT &&
59948 + (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59949 *flags = CIFSSEC_MUST_PLNTXT;
59950
59951 *flags |= signflags;
59952 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59953 index 9d7996e..35ad5cf4 100644
59954 --- a/fs/cifs/cifsfs.c
59955 +++ b/fs/cifs/cifsfs.c
59956 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59957 */
59958 cifs_req_cachep = kmem_cache_create("cifs_request",
59959 CIFSMaxBufSize + max_hdr_size, 0,
59960 - SLAB_HWCACHE_ALIGN, NULL);
59961 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59962 if (cifs_req_cachep == NULL)
59963 return -ENOMEM;
59964
59965 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59966 efficient to alloc 1 per page off the slab compared to 17K (5page)
59967 alloc of large cifs buffers even when page debugging is on */
59968 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59969 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59970 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59971 NULL);
59972 if (cifs_sm_req_cachep == NULL) {
59973 mempool_destroy(cifs_req_poolp);
59974 @@ -1205,8 +1205,8 @@ init_cifs(void)
59975 atomic_set(&bufAllocCount, 0);
59976 atomic_set(&smBufAllocCount, 0);
59977 #ifdef CONFIG_CIFS_STATS2
59978 - atomic_set(&totBufAllocCount, 0);
59979 - atomic_set(&totSmBufAllocCount, 0);
59980 + atomic_set_unchecked(&totBufAllocCount, 0);
59981 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59982 #endif /* CONFIG_CIFS_STATS2 */
59983
59984 atomic_set(&midCount, 0);
59985 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59986 index 02a33e5..3a28b5a 100644
59987 --- a/fs/cifs/cifsglob.h
59988 +++ b/fs/cifs/cifsglob.h
59989 @@ -823,35 +823,35 @@ struct cifs_tcon {
59990 __u16 Flags; /* optional support bits */
59991 enum statusEnum tidStatus;
59992 #ifdef CONFIG_CIFS_STATS
59993 - atomic_t num_smbs_sent;
59994 + atomic_unchecked_t num_smbs_sent;
59995 union {
59996 struct {
59997 - atomic_t num_writes;
59998 - atomic_t num_reads;
59999 - atomic_t num_flushes;
60000 - atomic_t num_oplock_brks;
60001 - atomic_t num_opens;
60002 - atomic_t num_closes;
60003 - atomic_t num_deletes;
60004 - atomic_t num_mkdirs;
60005 - atomic_t num_posixopens;
60006 - atomic_t num_posixmkdirs;
60007 - atomic_t num_rmdirs;
60008 - atomic_t num_renames;
60009 - atomic_t num_t2renames;
60010 - atomic_t num_ffirst;
60011 - atomic_t num_fnext;
60012 - atomic_t num_fclose;
60013 - atomic_t num_hardlinks;
60014 - atomic_t num_symlinks;
60015 - atomic_t num_locks;
60016 - atomic_t num_acl_get;
60017 - atomic_t num_acl_set;
60018 + atomic_unchecked_t num_writes;
60019 + atomic_unchecked_t num_reads;
60020 + atomic_unchecked_t num_flushes;
60021 + atomic_unchecked_t num_oplock_brks;
60022 + atomic_unchecked_t num_opens;
60023 + atomic_unchecked_t num_closes;
60024 + atomic_unchecked_t num_deletes;
60025 + atomic_unchecked_t num_mkdirs;
60026 + atomic_unchecked_t num_posixopens;
60027 + atomic_unchecked_t num_posixmkdirs;
60028 + atomic_unchecked_t num_rmdirs;
60029 + atomic_unchecked_t num_renames;
60030 + atomic_unchecked_t num_t2renames;
60031 + atomic_unchecked_t num_ffirst;
60032 + atomic_unchecked_t num_fnext;
60033 + atomic_unchecked_t num_fclose;
60034 + atomic_unchecked_t num_hardlinks;
60035 + atomic_unchecked_t num_symlinks;
60036 + atomic_unchecked_t num_locks;
60037 + atomic_unchecked_t num_acl_get;
60038 + atomic_unchecked_t num_acl_set;
60039 } cifs_stats;
60040 #ifdef CONFIG_CIFS_SMB2
60041 struct {
60042 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60043 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60044 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60045 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60046 } smb2_stats;
60047 #endif /* CONFIG_CIFS_SMB2 */
60048 } stats;
60049 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
60050 }
60051
60052 #ifdef CONFIG_CIFS_STATS
60053 -#define cifs_stats_inc atomic_inc
60054 +#define cifs_stats_inc atomic_inc_unchecked
60055
60056 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60057 unsigned int bytes)
60058 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60059 /* Various Debug counters */
60060 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60061 #ifdef CONFIG_CIFS_STATS2
60062 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60063 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60064 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60065 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60066 #endif
60067 GLOBAL_EXTERN atomic_t smBufAllocCount;
60068 GLOBAL_EXTERN atomic_t midCount;
60069 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60070 index 9a7b6947..4132187 100644
60071 --- a/fs/cifs/file.c
60072 +++ b/fs/cifs/file.c
60073 @@ -2060,10 +2060,14 @@ static int cifs_writepages(struct address_space *mapping,
60074 index = mapping->writeback_index; /* Start from prev offset */
60075 end = -1;
60076 } else {
60077 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60078 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60079 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60080 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60081 range_whole = true;
60082 + index = 0;
60083 + end = ULONG_MAX;
60084 + } else {
60085 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60086 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60087 + }
60088 scanned = true;
60089 }
60090 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60091 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60092 index b7415d5..3984ec0 100644
60093 --- a/fs/cifs/misc.c
60094 +++ b/fs/cifs/misc.c
60095 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60096 memset(ret_buf, 0, buf_size + 3);
60097 atomic_inc(&bufAllocCount);
60098 #ifdef CONFIG_CIFS_STATS2
60099 - atomic_inc(&totBufAllocCount);
60100 + atomic_inc_unchecked(&totBufAllocCount);
60101 #endif /* CONFIG_CIFS_STATS2 */
60102 }
60103
60104 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60105 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60106 atomic_inc(&smBufAllocCount);
60107 #ifdef CONFIG_CIFS_STATS2
60108 - atomic_inc(&totSmBufAllocCount);
60109 + atomic_inc_unchecked(&totSmBufAllocCount);
60110 #endif /* CONFIG_CIFS_STATS2 */
60111
60112 }
60113 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60114 index d297903..1cb7516 100644
60115 --- a/fs/cifs/smb1ops.c
60116 +++ b/fs/cifs/smb1ops.c
60117 @@ -622,27 +622,27 @@ static void
60118 cifs_clear_stats(struct cifs_tcon *tcon)
60119 {
60120 #ifdef CONFIG_CIFS_STATS
60121 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60122 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60123 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60124 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60125 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60126 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60127 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60128 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60129 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60130 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60131 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60132 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60133 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60134 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60135 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60136 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60137 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60138 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60139 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60140 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60141 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60142 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60143 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60144 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60145 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60146 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60147 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60148 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60149 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60150 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60151 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60152 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60153 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60154 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60155 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60156 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60157 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60158 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60159 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60160 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60161 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60162 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60163 #endif
60164 }
60165
60166 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60167 {
60168 #ifdef CONFIG_CIFS_STATS
60169 seq_printf(m, " Oplocks breaks: %d",
60170 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60171 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60172 seq_printf(m, "\nReads: %d Bytes: %llu",
60173 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60174 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60175 (long long)(tcon->bytes_read));
60176 seq_printf(m, "\nWrites: %d Bytes: %llu",
60177 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60178 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60179 (long long)(tcon->bytes_written));
60180 seq_printf(m, "\nFlushes: %d",
60181 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60182 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60183 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60184 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60185 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60186 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60187 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60188 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60189 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60190 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60191 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60192 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60193 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60194 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60195 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60196 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60197 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60198 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60199 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60200 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60201 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60202 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60203 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60204 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60205 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60206 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60207 seq_printf(m, "\nRenames: %d T2 Renames %d",
60208 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60209 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60210 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60211 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60212 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60213 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60214 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60215 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60216 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60217 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60218 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60219 #endif
60220 }
60221
60222 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60223 index c5f521b..1a40865 100644
60224 --- a/fs/cifs/smb2ops.c
60225 +++ b/fs/cifs/smb2ops.c
60226 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60227 #ifdef CONFIG_CIFS_STATS
60228 int i;
60229 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60230 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60231 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60232 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60233 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60234 }
60235 #endif
60236 }
60237 @@ -458,65 +458,65 @@ static void
60238 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60239 {
60240 #ifdef CONFIG_CIFS_STATS
60241 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60242 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60243 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60244 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60245 seq_printf(m, "\nNegotiates: %d sent %d failed",
60246 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60247 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60248 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60249 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60250 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60251 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60252 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60253 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60254 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60255 seq_printf(m, "\nLogoffs: %d sent %d failed",
60256 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60257 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60258 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60259 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60260 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60261 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60262 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60263 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60264 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60265 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60266 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60267 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60268 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60269 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60270 seq_printf(m, "\nCreates: %d sent %d failed",
60271 - atomic_read(&sent[SMB2_CREATE_HE]),
60272 - atomic_read(&failed[SMB2_CREATE_HE]));
60273 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60274 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60275 seq_printf(m, "\nCloses: %d sent %d failed",
60276 - atomic_read(&sent[SMB2_CLOSE_HE]),
60277 - atomic_read(&failed[SMB2_CLOSE_HE]));
60278 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60279 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60280 seq_printf(m, "\nFlushes: %d sent %d failed",
60281 - atomic_read(&sent[SMB2_FLUSH_HE]),
60282 - atomic_read(&failed[SMB2_FLUSH_HE]));
60283 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60284 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60285 seq_printf(m, "\nReads: %d sent %d failed",
60286 - atomic_read(&sent[SMB2_READ_HE]),
60287 - atomic_read(&failed[SMB2_READ_HE]));
60288 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60289 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60290 seq_printf(m, "\nWrites: %d sent %d failed",
60291 - atomic_read(&sent[SMB2_WRITE_HE]),
60292 - atomic_read(&failed[SMB2_WRITE_HE]));
60293 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60294 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60295 seq_printf(m, "\nLocks: %d sent %d failed",
60296 - atomic_read(&sent[SMB2_LOCK_HE]),
60297 - atomic_read(&failed[SMB2_LOCK_HE]));
60298 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60299 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60300 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60301 - atomic_read(&sent[SMB2_IOCTL_HE]),
60302 - atomic_read(&failed[SMB2_IOCTL_HE]));
60303 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60304 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60305 seq_printf(m, "\nCancels: %d sent %d failed",
60306 - atomic_read(&sent[SMB2_CANCEL_HE]),
60307 - atomic_read(&failed[SMB2_CANCEL_HE]));
60308 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60309 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60310 seq_printf(m, "\nEchos: %d sent %d failed",
60311 - atomic_read(&sent[SMB2_ECHO_HE]),
60312 - atomic_read(&failed[SMB2_ECHO_HE]));
60313 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60314 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60315 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60316 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60317 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60318 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60319 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60320 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60321 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60322 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60323 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60324 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60325 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60326 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60327 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60328 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60329 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60330 seq_printf(m, "\nSetInfos: %d sent %d failed",
60331 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60332 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60333 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60334 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60335 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60336 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60337 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60338 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60339 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60340 #endif
60341 }
60342
60343 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60344 index 8f1672b..af339c07 100644
60345 --- a/fs/cifs/smb2pdu.c
60346 +++ b/fs/cifs/smb2pdu.c
60347 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60348 default:
60349 cifs_dbg(VFS, "info level %u isn't supported\n",
60350 srch_inf->info_level);
60351 - rc = -EINVAL;
60352 - goto qdir_exit;
60353 + return -EINVAL;
60354 }
60355
60356 req->FileIndex = cpu_to_le32(index);
60357 diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
60358 index 6c15663..a4232ec 100644
60359 --- a/fs/cifs/smbencrypt.c
60360 +++ b/fs/cifs/smbencrypt.c
60361 @@ -221,7 +221,7 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16,
60362 }
60363
60364 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16));
60365 - memset(wpwd, 0, 129 * sizeof(__le16));
60366 + memzero_explicit(wpwd, sizeof(wpwd));
60367
60368 return rc;
60369 }
60370 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60371 index 46ee6f2..89a9e7f 100644
60372 --- a/fs/coda/cache.c
60373 +++ b/fs/coda/cache.c
60374 @@ -24,7 +24,7 @@
60375 #include "coda_linux.h"
60376 #include "coda_cache.h"
60377
60378 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60379 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60380
60381 /* replace or extend an acl cache hit */
60382 void coda_cache_enter(struct inode *inode, int mask)
60383 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60384 struct coda_inode_info *cii = ITOC(inode);
60385
60386 spin_lock(&cii->c_lock);
60387 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60388 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60389 if (!uid_eq(cii->c_uid, current_fsuid())) {
60390 cii->c_uid = current_fsuid();
60391 cii->c_cached_perm = mask;
60392 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60393 {
60394 struct coda_inode_info *cii = ITOC(inode);
60395 spin_lock(&cii->c_lock);
60396 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60397 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60398 spin_unlock(&cii->c_lock);
60399 }
60400
60401 /* remove all acl caches */
60402 void coda_cache_clear_all(struct super_block *sb)
60403 {
60404 - atomic_inc(&permission_epoch);
60405 + atomic_inc_unchecked(&permission_epoch);
60406 }
60407
60408
60409 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60410 spin_lock(&cii->c_lock);
60411 hit = (mask & cii->c_cached_perm) == mask &&
60412 uid_eq(cii->c_uid, current_fsuid()) &&
60413 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60414 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60415 spin_unlock(&cii->c_lock);
60416
60417 return hit;
60418 diff --git a/fs/compat.c b/fs/compat.c
60419 index b13df99..6f6f4a3 100644
60420 --- a/fs/compat.c
60421 +++ b/fs/compat.c
60422 @@ -54,7 +54,7 @@
60423 #include <asm/ioctls.h>
60424 #include "internal.h"
60425
60426 -int compat_log = 1;
60427 +int compat_log = 0;
60428
60429 int compat_printk(const char *fmt, ...)
60430 {
60431 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60432
60433 set_fs(KERNEL_DS);
60434 /* The __user pointer cast is valid because of the set_fs() */
60435 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60436 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60437 set_fs(oldfs);
60438 /* truncating is ok because it's a user address */
60439 if (!ret)
60440 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60441 goto out;
60442
60443 ret = -EINVAL;
60444 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60445 + if (nr_segs > UIO_MAXIOV)
60446 goto out;
60447 if (nr_segs > fast_segs) {
60448 ret = -ENOMEM;
60449 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60450 struct compat_readdir_callback {
60451 struct dir_context ctx;
60452 struct compat_old_linux_dirent __user *dirent;
60453 + struct file * file;
60454 int result;
60455 };
60456
60457 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60458 buf->result = -EOVERFLOW;
60459 return -EOVERFLOW;
60460 }
60461 +
60462 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60463 + return 0;
60464 +
60465 buf->result++;
60466 dirent = buf->dirent;
60467 if (!access_ok(VERIFY_WRITE, dirent,
60468 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60469 if (!f.file)
60470 return -EBADF;
60471
60472 + buf.file = f.file;
60473 error = iterate_dir(f.file, &buf.ctx);
60474 if (buf.result)
60475 error = buf.result;
60476 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60477 struct dir_context ctx;
60478 struct compat_linux_dirent __user *current_dir;
60479 struct compat_linux_dirent __user *previous;
60480 + struct file * file;
60481 int count;
60482 int error;
60483 };
60484 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60485 buf->error = -EOVERFLOW;
60486 return -EOVERFLOW;
60487 }
60488 +
60489 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60490 + return 0;
60491 +
60492 dirent = buf->previous;
60493 if (dirent) {
60494 if (__put_user(offset, &dirent->d_off))
60495 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60496 if (!f.file)
60497 return -EBADF;
60498
60499 + buf.file = f.file;
60500 error = iterate_dir(f.file, &buf.ctx);
60501 if (error >= 0)
60502 error = buf.error;
60503 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60504 struct dir_context ctx;
60505 struct linux_dirent64 __user *current_dir;
60506 struct linux_dirent64 __user *previous;
60507 + struct file * file;
60508 int count;
60509 int error;
60510 };
60511 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60512 buf->error = -EINVAL; /* only used if we fail.. */
60513 if (reclen > buf->count)
60514 return -EINVAL;
60515 +
60516 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60517 + return 0;
60518 +
60519 dirent = buf->previous;
60520
60521 if (dirent) {
60522 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60523 if (!f.file)
60524 return -EBADF;
60525
60526 + buf.file = f.file;
60527 error = iterate_dir(f.file, &buf.ctx);
60528 if (error >= 0)
60529 error = buf.error;
60530 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60531 index 4d24d17..4f8c09e 100644
60532 --- a/fs/compat_binfmt_elf.c
60533 +++ b/fs/compat_binfmt_elf.c
60534 @@ -30,11 +30,13 @@
60535 #undef elf_phdr
60536 #undef elf_shdr
60537 #undef elf_note
60538 +#undef elf_dyn
60539 #undef elf_addr_t
60540 #define elfhdr elf32_hdr
60541 #define elf_phdr elf32_phdr
60542 #define elf_shdr elf32_shdr
60543 #define elf_note elf32_note
60544 +#define elf_dyn Elf32_Dyn
60545 #define elf_addr_t Elf32_Addr
60546
60547 /*
60548 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60549 index afec645..9c65620 100644
60550 --- a/fs/compat_ioctl.c
60551 +++ b/fs/compat_ioctl.c
60552 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60553 return -EFAULT;
60554 if (__get_user(udata, &ss32->iomem_base))
60555 return -EFAULT;
60556 - ss.iomem_base = compat_ptr(udata);
60557 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60558 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60559 __get_user(ss.port_high, &ss32->port_high))
60560 return -EFAULT;
60561 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60562 for (i = 0; i < nmsgs; i++) {
60563 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60564 return -EFAULT;
60565 - if (get_user(datap, &umsgs[i].buf) ||
60566 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60567 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60568 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60569 return -EFAULT;
60570 }
60571 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60572 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60573 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60574 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60575 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60576 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60577 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60578 return -EFAULT;
60579
60580 return ioctl_preallocate(file, p);
60581 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60582 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60583 {
60584 unsigned int a, b;
60585 - a = *(unsigned int *)p;
60586 - b = *(unsigned int *)q;
60587 + a = *(const unsigned int *)p;
60588 + b = *(const unsigned int *)q;
60589 if (a > b)
60590 return 1;
60591 if (a < b)
60592 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60593 index 668dcab..daebcd6 100644
60594 --- a/fs/configfs/dir.c
60595 +++ b/fs/configfs/dir.c
60596 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60597 }
60598 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60599 struct configfs_dirent *next;
60600 - const char *name;
60601 + const unsigned char * name;
60602 + char d_name[sizeof(next->s_dentry->d_iname)];
60603 int len;
60604 struct inode *inode = NULL;
60605
60606 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60607 continue;
60608
60609 name = configfs_get_name(next);
60610 - len = strlen(name);
60611 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60612 + len = next->s_dentry->d_name.len;
60613 + memcpy(d_name, name, len);
60614 + name = d_name;
60615 + } else
60616 + len = strlen(name);
60617
60618 /*
60619 * We'll have a dentry and an inode for
60620 diff --git a/fs/coredump.c b/fs/coredump.c
60621 index b5c86ff..0dac262 100644
60622 --- a/fs/coredump.c
60623 +++ b/fs/coredump.c
60624 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60625 struct pipe_inode_info *pipe = file->private_data;
60626
60627 pipe_lock(pipe);
60628 - pipe->readers++;
60629 - pipe->writers--;
60630 + atomic_inc(&pipe->readers);
60631 + atomic_dec(&pipe->writers);
60632 wake_up_interruptible_sync(&pipe->wait);
60633 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60634 pipe_unlock(pipe);
60635 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60636 * We actually want wait_event_freezable() but then we need
60637 * to clear TIF_SIGPENDING and improve dump_interrupted().
60638 */
60639 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60640 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60641
60642 pipe_lock(pipe);
60643 - pipe->readers--;
60644 - pipe->writers++;
60645 + atomic_dec(&pipe->readers);
60646 + atomic_inc(&pipe->writers);
60647 pipe_unlock(pipe);
60648 }
60649
60650 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60651 struct files_struct *displaced;
60652 bool need_nonrelative = false;
60653 bool core_dumped = false;
60654 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60655 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60656 + long signr = siginfo->si_signo;
60657 + int dumpable;
60658 struct coredump_params cprm = {
60659 .siginfo = siginfo,
60660 .regs = signal_pt_regs(),
60661 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60662 .mm_flags = mm->flags,
60663 };
60664
60665 - audit_core_dumps(siginfo->si_signo);
60666 + audit_core_dumps(signr);
60667 +
60668 + dumpable = __get_dumpable(cprm.mm_flags);
60669 +
60670 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60671 + gr_handle_brute_attach(dumpable);
60672
60673 binfmt = mm->binfmt;
60674 if (!binfmt || !binfmt->core_dump)
60675 goto fail;
60676 - if (!__get_dumpable(cprm.mm_flags))
60677 + if (!dumpable)
60678 goto fail;
60679
60680 cred = prepare_creds();
60681 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60682 need_nonrelative = true;
60683 }
60684
60685 - retval = coredump_wait(siginfo->si_signo, &core_state);
60686 + retval = coredump_wait(signr, &core_state);
60687 if (retval < 0)
60688 goto fail_creds;
60689
60690 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60691 }
60692 cprm.limit = RLIM_INFINITY;
60693
60694 - dump_count = atomic_inc_return(&core_dump_count);
60695 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60696 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60697 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60698 task_tgid_vnr(current), current->comm);
60699 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60700 } else {
60701 struct inode *inode;
60702
60703 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60704 +
60705 if (cprm.limit < binfmt->min_coredump)
60706 goto fail_unlock;
60707
60708 @@ -681,7 +690,7 @@ close_fail:
60709 filp_close(cprm.file, NULL);
60710 fail_dropcount:
60711 if (ispipe)
60712 - atomic_dec(&core_dump_count);
60713 + atomic_dec_unchecked(&core_dump_count);
60714 fail_unlock:
60715 kfree(cn.corename);
60716 coredump_finish(mm, core_dumped);
60717 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60718 struct file *file = cprm->file;
60719 loff_t pos = file->f_pos;
60720 ssize_t n;
60721 +
60722 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60723 if (cprm->written + nr > cprm->limit)
60724 return 0;
60725 while (nr) {
60726 diff --git a/fs/dcache.c b/fs/dcache.c
60727 index 03dca3c..15f326d 100644
60728 --- a/fs/dcache.c
60729 +++ b/fs/dcache.c
60730 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60731 * dentry_iput drops the locks, at which point nobody (except
60732 * transient RCU lookups) can reach this dentry.
60733 */
60734 - BUG_ON((int)dentry->d_lockref.count > 0);
60735 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60736 this_cpu_dec(nr_dentry);
60737 if (dentry->d_op && dentry->d_op->d_release)
60738 dentry->d_op->d_release(dentry);
60739 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60740 struct dentry *parent = dentry->d_parent;
60741 if (IS_ROOT(dentry))
60742 return NULL;
60743 - if (unlikely((int)dentry->d_lockref.count < 0))
60744 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60745 return NULL;
60746 if (likely(spin_trylock(&parent->d_lock)))
60747 return parent;
60748 @@ -638,7 +638,7 @@ repeat:
60749 dentry->d_flags |= DCACHE_REFERENCED;
60750 dentry_lru_add(dentry);
60751
60752 - dentry->d_lockref.count--;
60753 + __lockref_dec(&dentry->d_lockref);
60754 spin_unlock(&dentry->d_lock);
60755 return;
60756
60757 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60758 /* This must be called with d_lock held */
60759 static inline void __dget_dlock(struct dentry *dentry)
60760 {
60761 - dentry->d_lockref.count++;
60762 + __lockref_inc(&dentry->d_lockref);
60763 }
60764
60765 static inline void __dget(struct dentry *dentry)
60766 @@ -694,8 +694,8 @@ repeat:
60767 goto repeat;
60768 }
60769 rcu_read_unlock();
60770 - BUG_ON(!ret->d_lockref.count);
60771 - ret->d_lockref.count++;
60772 + BUG_ON(!__lockref_read(&ret->d_lockref));
60773 + __lockref_inc(&ret->d_lockref);
60774 spin_unlock(&ret->d_lock);
60775 return ret;
60776 }
60777 @@ -773,9 +773,9 @@ restart:
60778 spin_lock(&inode->i_lock);
60779 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60780 spin_lock(&dentry->d_lock);
60781 - if (!dentry->d_lockref.count) {
60782 + if (!__lockref_read(&dentry->d_lockref)) {
60783 struct dentry *parent = lock_parent(dentry);
60784 - if (likely(!dentry->d_lockref.count)) {
60785 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60786 __dentry_kill(dentry);
60787 dput(parent);
60788 goto restart;
60789 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60790 * We found an inuse dentry which was not removed from
60791 * the LRU because of laziness during lookup. Do not free it.
60792 */
60793 - if ((int)dentry->d_lockref.count > 0) {
60794 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60795 spin_unlock(&dentry->d_lock);
60796 if (parent)
60797 spin_unlock(&parent->d_lock);
60798 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60799 dentry = parent;
60800 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60801 parent = lock_parent(dentry);
60802 - if (dentry->d_lockref.count != 1) {
60803 - dentry->d_lockref.count--;
60804 + if (__lockref_read(&dentry->d_lockref) != 1) {
60805 + __lockref_inc(&dentry->d_lockref);
60806 spin_unlock(&dentry->d_lock);
60807 if (parent)
60808 spin_unlock(&parent->d_lock);
60809 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60810 * counts, just remove them from the LRU. Otherwise give them
60811 * another pass through the LRU.
60812 */
60813 - if (dentry->d_lockref.count) {
60814 + if (__lockref_read(&dentry->d_lockref) > 0) {
60815 d_lru_isolate(dentry);
60816 spin_unlock(&dentry->d_lock);
60817 return LRU_REMOVED;
60818 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60819 } else {
60820 if (dentry->d_flags & DCACHE_LRU_LIST)
60821 d_lru_del(dentry);
60822 - if (!dentry->d_lockref.count) {
60823 + if (!__lockref_read(&dentry->d_lockref)) {
60824 d_shrink_add(dentry, &data->dispose);
60825 data->found++;
60826 }
60827 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60828 return D_WALK_CONTINUE;
60829
60830 /* root with refcount 1 is fine */
60831 - if (dentry == _data && dentry->d_lockref.count == 1)
60832 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60833 return D_WALK_CONTINUE;
60834
60835 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60836 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60837 dentry->d_inode ?
60838 dentry->d_inode->i_ino : 0UL,
60839 dentry,
60840 - dentry->d_lockref.count,
60841 + __lockref_read(&dentry->d_lockref),
60842 dentry->d_sb->s_type->name,
60843 dentry->d_sb->s_id);
60844 WARN_ON(1);
60845 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60846 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60847 if (name->len > DNAME_INLINE_LEN-1) {
60848 size_t size = offsetof(struct external_name, name[1]);
60849 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60850 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60851 if (!p) {
60852 kmem_cache_free(dentry_cache, dentry);
60853 return NULL;
60854 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60855 smp_wmb();
60856 dentry->d_name.name = dname;
60857
60858 - dentry->d_lockref.count = 1;
60859 + __lockref_set(&dentry->d_lockref, 1);
60860 dentry->d_flags = 0;
60861 spin_lock_init(&dentry->d_lock);
60862 seqcount_init(&dentry->d_seq);
60863 @@ -1452,6 +1452,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60864 dentry->d_sb = sb;
60865 dentry->d_op = NULL;
60866 dentry->d_fsdata = NULL;
60867 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
60868 + atomic_set(&dentry->chroot_refcnt, 0);
60869 +#endif
60870 INIT_HLIST_BL_NODE(&dentry->d_hash);
60871 INIT_LIST_HEAD(&dentry->d_lru);
60872 INIT_LIST_HEAD(&dentry->d_subdirs);
60873 @@ -2183,7 +2186,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60874 goto next;
60875 }
60876
60877 - dentry->d_lockref.count++;
60878 + __lockref_inc(&dentry->d_lockref);
60879 found = dentry;
60880 spin_unlock(&dentry->d_lock);
60881 break;
60882 @@ -2282,7 +2285,7 @@ again:
60883 spin_lock(&dentry->d_lock);
60884 inode = dentry->d_inode;
60885 isdir = S_ISDIR(inode->i_mode);
60886 - if (dentry->d_lockref.count == 1) {
60887 + if (__lockref_read(&dentry->d_lockref) == 1) {
60888 if (!spin_trylock(&inode->i_lock)) {
60889 spin_unlock(&dentry->d_lock);
60890 cpu_relax();
60891 @@ -3308,7 +3311,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60892
60893 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60894 dentry->d_flags |= DCACHE_GENOCIDE;
60895 - dentry->d_lockref.count--;
60896 + __lockref_dec(&dentry->d_lockref);
60897 }
60898 }
60899 return D_WALK_CONTINUE;
60900 @@ -3424,7 +3427,8 @@ void __init vfs_caches_init(unsigned long mempages)
60901 mempages -= reserve;
60902
60903 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60904 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60905 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60906 + SLAB_NO_SANITIZE, NULL);
60907
60908 dcache_init();
60909 inode_init();
60910 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60911 index 05f2960..b012481 100644
60912 --- a/fs/debugfs/inode.c
60913 +++ b/fs/debugfs/inode.c
60914 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60915 */
60916 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60917 {
60918 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60919 + return __create_file(name, S_IFDIR | S_IRWXU,
60920 +#else
60921 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60922 +#endif
60923 parent, NULL, NULL);
60924 }
60925 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60926 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60927 index 1686dc2..9611c50 100644
60928 --- a/fs/ecryptfs/inode.c
60929 +++ b/fs/ecryptfs/inode.c
60930 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60931 old_fs = get_fs();
60932 set_fs(get_ds());
60933 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60934 - (char __user *)lower_buf,
60935 + (char __force_user *)lower_buf,
60936 PATH_MAX);
60937 set_fs(old_fs);
60938 if (rc < 0)
60939 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60940 index e4141f2..d8263e8 100644
60941 --- a/fs/ecryptfs/miscdev.c
60942 +++ b/fs/ecryptfs/miscdev.c
60943 @@ -304,7 +304,7 @@ check_list:
60944 goto out_unlock_msg_ctx;
60945 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60946 if (msg_ctx->msg) {
60947 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60948 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60949 goto out_unlock_msg_ctx;
60950 i += packet_length_size;
60951 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60952 diff --git a/fs/exec.c b/fs/exec.c
60953 index 7302b75..b917171 100644
60954 --- a/fs/exec.c
60955 +++ b/fs/exec.c
60956 @@ -56,8 +56,20 @@
60957 #include <linux/pipe_fs_i.h>
60958 #include <linux/oom.h>
60959 #include <linux/compat.h>
60960 +#include <linux/random.h>
60961 +#include <linux/seq_file.h>
60962 +#include <linux/coredump.h>
60963 +#include <linux/mman.h>
60964 +
60965 +#ifdef CONFIG_PAX_REFCOUNT
60966 +#include <linux/kallsyms.h>
60967 +#include <linux/kdebug.h>
60968 +#endif
60969 +
60970 +#include <trace/events/fs.h>
60971
60972 #include <asm/uaccess.h>
60973 +#include <asm/sections.h>
60974 #include <asm/mmu_context.h>
60975 #include <asm/tlb.h>
60976
60977 @@ -66,19 +78,34 @@
60978
60979 #include <trace/events/sched.h>
60980
60981 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60982 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60983 +{
60984 + 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");
60985 +}
60986 +#endif
60987 +
60988 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60989 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60990 +EXPORT_SYMBOL(pax_set_initial_flags_func);
60991 +#endif
60992 +
60993 int suid_dumpable = 0;
60994
60995 static LIST_HEAD(formats);
60996 static DEFINE_RWLOCK(binfmt_lock);
60997
60998 +extern int gr_process_kernel_exec_ban(void);
60999 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61000 +
61001 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61002 {
61003 BUG_ON(!fmt);
61004 if (WARN_ON(!fmt->load_binary))
61005 return;
61006 write_lock(&binfmt_lock);
61007 - insert ? list_add(&fmt->lh, &formats) :
61008 - list_add_tail(&fmt->lh, &formats);
61009 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61010 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61011 write_unlock(&binfmt_lock);
61012 }
61013
61014 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61015 void unregister_binfmt(struct linux_binfmt * fmt)
61016 {
61017 write_lock(&binfmt_lock);
61018 - list_del(&fmt->lh);
61019 + pax_list_del((struct list_head *)&fmt->lh);
61020 write_unlock(&binfmt_lock);
61021 }
61022
61023 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61024 int write)
61025 {
61026 struct page *page;
61027 - int ret;
61028
61029 -#ifdef CONFIG_STACK_GROWSUP
61030 - if (write) {
61031 - ret = expand_downwards(bprm->vma, pos);
61032 - if (ret < 0)
61033 - return NULL;
61034 - }
61035 -#endif
61036 - ret = get_user_pages(current, bprm->mm, pos,
61037 - 1, write, 1, &page, NULL);
61038 - if (ret <= 0)
61039 + if (0 > expand_downwards(bprm->vma, pos))
61040 + return NULL;
61041 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61042 return NULL;
61043
61044 if (write) {
61045 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61046 if (size <= ARG_MAX)
61047 return page;
61048
61049 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61050 + // only allow 512KB for argv+env on suid/sgid binaries
61051 + // to prevent easy ASLR exhaustion
61052 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61053 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61054 + (size > (512 * 1024))) {
61055 + put_page(page);
61056 + return NULL;
61057 + }
61058 +#endif
61059 +
61060 /*
61061 * Limit to 1/4-th the stack size for the argv+env strings.
61062 * This ensures that:
61063 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61064 vma->vm_end = STACK_TOP_MAX;
61065 vma->vm_start = vma->vm_end - PAGE_SIZE;
61066 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61067 +
61068 +#ifdef CONFIG_PAX_SEGMEXEC
61069 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61070 +#endif
61071 +
61072 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61073 INIT_LIST_HEAD(&vma->anon_vma_chain);
61074
61075 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61076 mm->stack_vm = mm->total_vm = 1;
61077 up_write(&mm->mmap_sem);
61078 bprm->p = vma->vm_end - sizeof(void *);
61079 +
61080 +#ifdef CONFIG_PAX_RANDUSTACK
61081 + if (randomize_va_space)
61082 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61083 +#endif
61084 +
61085 return 0;
61086 err:
61087 up_write(&mm->mmap_sem);
61088 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61089 } ptr;
61090 };
61091
61092 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61093 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61094 {
61095 const char __user *native;
61096
61097 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61098 compat_uptr_t compat;
61099
61100 if (get_user(compat, argv.ptr.compat + nr))
61101 - return ERR_PTR(-EFAULT);
61102 + return (const char __force_user *)ERR_PTR(-EFAULT);
61103
61104 return compat_ptr(compat);
61105 }
61106 #endif
61107
61108 if (get_user(native, argv.ptr.native + nr))
61109 - return ERR_PTR(-EFAULT);
61110 + return (const char __force_user *)ERR_PTR(-EFAULT);
61111
61112 return native;
61113 }
61114 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61115 if (!p)
61116 break;
61117
61118 - if (IS_ERR(p))
61119 + if (IS_ERR((const char __force_kernel *)p))
61120 return -EFAULT;
61121
61122 if (i >= max)
61123 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61124
61125 ret = -EFAULT;
61126 str = get_user_arg_ptr(argv, argc);
61127 - if (IS_ERR(str))
61128 + if (IS_ERR((const char __force_kernel *)str))
61129 goto out;
61130
61131 len = strnlen_user(str, MAX_ARG_STRLEN);
61132 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61133 int r;
61134 mm_segment_t oldfs = get_fs();
61135 struct user_arg_ptr argv = {
61136 - .ptr.native = (const char __user *const __user *)__argv,
61137 + .ptr.native = (const char __user * const __force_user *)__argv,
61138 };
61139
61140 set_fs(KERNEL_DS);
61141 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61142 unsigned long new_end = old_end - shift;
61143 struct mmu_gather tlb;
61144
61145 - BUG_ON(new_start > new_end);
61146 + if (new_start >= new_end || new_start < mmap_min_addr)
61147 + return -ENOMEM;
61148
61149 /*
61150 * ensure there are no vmas between where we want to go
61151 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61152 if (vma != find_vma(mm, new_start))
61153 return -EFAULT;
61154
61155 +#ifdef CONFIG_PAX_SEGMEXEC
61156 + BUG_ON(pax_find_mirror_vma(vma));
61157 +#endif
61158 +
61159 /*
61160 * cover the whole range: [new_start, old_end)
61161 */
61162 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61163 stack_top = arch_align_stack(stack_top);
61164 stack_top = PAGE_ALIGN(stack_top);
61165
61166 - if (unlikely(stack_top < mmap_min_addr) ||
61167 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61168 - return -ENOMEM;
61169 -
61170 stack_shift = vma->vm_end - stack_top;
61171
61172 bprm->p -= stack_shift;
61173 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61174 bprm->exec -= stack_shift;
61175
61176 down_write(&mm->mmap_sem);
61177 +
61178 + /* Move stack pages down in memory. */
61179 + if (stack_shift) {
61180 + ret = shift_arg_pages(vma, stack_shift);
61181 + if (ret)
61182 + goto out_unlock;
61183 + }
61184 +
61185 vm_flags = VM_STACK_FLAGS;
61186
61187 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61188 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61189 + vm_flags &= ~VM_EXEC;
61190 +
61191 +#ifdef CONFIG_PAX_MPROTECT
61192 + if (mm->pax_flags & MF_PAX_MPROTECT)
61193 + vm_flags &= ~VM_MAYEXEC;
61194 +#endif
61195 +
61196 + }
61197 +#endif
61198 +
61199 /*
61200 * Adjust stack execute permissions; explicitly enable for
61201 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61202 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61203 goto out_unlock;
61204 BUG_ON(prev != vma);
61205
61206 - /* Move stack pages down in memory. */
61207 - if (stack_shift) {
61208 - ret = shift_arg_pages(vma, stack_shift);
61209 - if (ret)
61210 - goto out_unlock;
61211 - }
61212 -
61213 /* mprotect_fixup is overkill to remove the temporary stack flags */
61214 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61215
61216 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61217 #endif
61218 current->mm->start_stack = bprm->p;
61219 ret = expand_stack(vma, stack_base);
61220 +
61221 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61222 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61223 + unsigned long size;
61224 + vm_flags_t vm_flags;
61225 +
61226 + size = STACK_TOP - vma->vm_end;
61227 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61228 +
61229 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61230 +
61231 +#ifdef CONFIG_X86
61232 + if (!ret) {
61233 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61234 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61235 + }
61236 +#endif
61237 +
61238 + }
61239 +#endif
61240 +
61241 if (ret)
61242 ret = -EFAULT;
61243
61244 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61245
61246 fsnotify_open(file);
61247
61248 + trace_open_exec(name->name);
61249 +
61250 err = deny_write_access(file);
61251 if (err)
61252 goto exit;
61253 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61254 old_fs = get_fs();
61255 set_fs(get_ds());
61256 /* The cast to a user pointer is valid due to the set_fs() */
61257 - result = vfs_read(file, (void __user *)addr, count, &pos);
61258 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61259 set_fs(old_fs);
61260 return result;
61261 }
61262 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61263 tsk->mm = mm;
61264 tsk->active_mm = mm;
61265 activate_mm(active_mm, mm);
61266 + populate_stack();
61267 tsk->mm->vmacache_seqnum = 0;
61268 vmacache_flush(tsk);
61269 task_unlock(tsk);
61270 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61271 }
61272 rcu_read_unlock();
61273
61274 - if (p->fs->users > n_fs)
61275 + if (atomic_read(&p->fs->users) > n_fs)
61276 bprm->unsafe |= LSM_UNSAFE_SHARE;
61277 else
61278 p->fs->in_exec = 1;
61279 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61280 return ret;
61281 }
61282
61283 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61284 +static DEFINE_PER_CPU(u64, exec_counter);
61285 +static int __init init_exec_counters(void)
61286 +{
61287 + unsigned int cpu;
61288 +
61289 + for_each_possible_cpu(cpu) {
61290 + per_cpu(exec_counter, cpu) = (u64)cpu;
61291 + }
61292 +
61293 + return 0;
61294 +}
61295 +early_initcall(init_exec_counters);
61296 +static inline void increment_exec_counter(void)
61297 +{
61298 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61299 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61300 +}
61301 +#else
61302 +static inline void increment_exec_counter(void) {}
61303 +#endif
61304 +
61305 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61306 + struct user_arg_ptr argv);
61307 +
61308 /*
61309 * sys_execve() executes a new program.
61310 */
61311 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61312 struct user_arg_ptr argv,
61313 struct user_arg_ptr envp)
61314 {
61315 +#ifdef CONFIG_GRKERNSEC
61316 + struct file *old_exec_file;
61317 + struct acl_subject_label *old_acl;
61318 + struct rlimit old_rlim[RLIM_NLIMITS];
61319 +#endif
61320 struct linux_binprm *bprm;
61321 struct file *file;
61322 struct files_struct *displaced;
61323 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61324 if (IS_ERR(filename))
61325 return PTR_ERR(filename);
61326
61327 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61328 +
61329 /*
61330 * We move the actual failure in case of RLIMIT_NPROC excess from
61331 * set*uid() to execve() because too many poorly written programs
61332 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61333 if (IS_ERR(file))
61334 goto out_unmark;
61335
61336 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61337 + retval = -EPERM;
61338 + goto out_unmark;
61339 + }
61340 +
61341 sched_exec();
61342
61343 bprm->file = file;
61344 bprm->filename = bprm->interp = filename->name;
61345
61346 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61347 + retval = -EACCES;
61348 + goto out_unmark;
61349 + }
61350 +
61351 retval = bprm_mm_init(bprm);
61352 if (retval)
61353 goto out_unmark;
61354 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61355 if (retval < 0)
61356 goto out;
61357
61358 +#ifdef CONFIG_GRKERNSEC
61359 + old_acl = current->acl;
61360 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61361 + old_exec_file = current->exec_file;
61362 + get_file(file);
61363 + current->exec_file = file;
61364 +#endif
61365 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61366 + /* limit suid stack to 8MB
61367 + * we saved the old limits above and will restore them if this exec fails
61368 + */
61369 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61370 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61371 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61372 +#endif
61373 +
61374 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61375 + retval = -EPERM;
61376 + goto out_fail;
61377 + }
61378 +
61379 + if (!gr_tpe_allow(file)) {
61380 + retval = -EACCES;
61381 + goto out_fail;
61382 + }
61383 +
61384 + if (gr_check_crash_exec(file)) {
61385 + retval = -EACCES;
61386 + goto out_fail;
61387 + }
61388 +
61389 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61390 + bprm->unsafe);
61391 + if (retval < 0)
61392 + goto out_fail;
61393 +
61394 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61395 if (retval < 0)
61396 - goto out;
61397 + goto out_fail;
61398
61399 bprm->exec = bprm->p;
61400 retval = copy_strings(bprm->envc, envp, bprm);
61401 if (retval < 0)
61402 - goto out;
61403 + goto out_fail;
61404
61405 retval = copy_strings(bprm->argc, argv, bprm);
61406 if (retval < 0)
61407 - goto out;
61408 + goto out_fail;
61409 +
61410 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61411 +
61412 + gr_handle_exec_args(bprm, argv);
61413
61414 retval = exec_binprm(bprm);
61415 if (retval < 0)
61416 - goto out;
61417 + goto out_fail;
61418 +#ifdef CONFIG_GRKERNSEC
61419 + if (old_exec_file)
61420 + fput(old_exec_file);
61421 +#endif
61422
61423 /* execve succeeded */
61424 +
61425 + increment_exec_counter();
61426 current->fs->in_exec = 0;
61427 current->in_execve = 0;
61428 acct_update_integrals(current);
61429 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61430 put_files_struct(displaced);
61431 return retval;
61432
61433 +out_fail:
61434 +#ifdef CONFIG_GRKERNSEC
61435 + current->acl = old_acl;
61436 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61437 + fput(current->exec_file);
61438 + current->exec_file = old_exec_file;
61439 +#endif
61440 +
61441 out:
61442 if (bprm->mm) {
61443 acct_arg_size(bprm, 0);
61444 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61445 return compat_do_execve(getname(filename), argv, envp);
61446 }
61447 #endif
61448 +
61449 +int pax_check_flags(unsigned long *flags)
61450 +{
61451 + int retval = 0;
61452 +
61453 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61454 + if (*flags & MF_PAX_SEGMEXEC)
61455 + {
61456 + *flags &= ~MF_PAX_SEGMEXEC;
61457 + retval = -EINVAL;
61458 + }
61459 +#endif
61460 +
61461 + if ((*flags & MF_PAX_PAGEEXEC)
61462 +
61463 +#ifdef CONFIG_PAX_PAGEEXEC
61464 + && (*flags & MF_PAX_SEGMEXEC)
61465 +#endif
61466 +
61467 + )
61468 + {
61469 + *flags &= ~MF_PAX_PAGEEXEC;
61470 + retval = -EINVAL;
61471 + }
61472 +
61473 + if ((*flags & MF_PAX_MPROTECT)
61474 +
61475 +#ifdef CONFIG_PAX_MPROTECT
61476 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61477 +#endif
61478 +
61479 + )
61480 + {
61481 + *flags &= ~MF_PAX_MPROTECT;
61482 + retval = -EINVAL;
61483 + }
61484 +
61485 + if ((*flags & MF_PAX_EMUTRAMP)
61486 +
61487 +#ifdef CONFIG_PAX_EMUTRAMP
61488 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61489 +#endif
61490 +
61491 + )
61492 + {
61493 + *flags &= ~MF_PAX_EMUTRAMP;
61494 + retval = -EINVAL;
61495 + }
61496 +
61497 + return retval;
61498 +}
61499 +
61500 +EXPORT_SYMBOL(pax_check_flags);
61501 +
61502 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61503 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61504 +{
61505 + char *pathname = d_path(path, buf, buflen);
61506 +
61507 + if (IS_ERR(pathname))
61508 + goto toolong;
61509 +
61510 + pathname = mangle_path(buf, pathname, "\t\n\\");
61511 + if (!pathname)
61512 + goto toolong;
61513 +
61514 + *pathname = 0;
61515 + return buf;
61516 +
61517 +toolong:
61518 + return "<path too long>";
61519 +}
61520 +EXPORT_SYMBOL(pax_get_path);
61521 +
61522 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61523 +{
61524 + struct task_struct *tsk = current;
61525 + struct mm_struct *mm = current->mm;
61526 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61527 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61528 + char *path_exec = NULL;
61529 + char *path_fault = NULL;
61530 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61531 + siginfo_t info = { };
61532 +
61533 + if (buffer_exec && buffer_fault) {
61534 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61535 +
61536 + down_read(&mm->mmap_sem);
61537 + vma = mm->mmap;
61538 + while (vma && (!vma_exec || !vma_fault)) {
61539 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61540 + vma_exec = vma;
61541 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61542 + vma_fault = vma;
61543 + vma = vma->vm_next;
61544 + }
61545 + if (vma_exec)
61546 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61547 + if (vma_fault) {
61548 + start = vma_fault->vm_start;
61549 + end = vma_fault->vm_end;
61550 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61551 + if (vma_fault->vm_file)
61552 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61553 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61554 + path_fault = "<heap>";
61555 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61556 + path_fault = "<stack>";
61557 + else
61558 + path_fault = "<anonymous mapping>";
61559 + }
61560 + up_read(&mm->mmap_sem);
61561 + }
61562 + if (tsk->signal->curr_ip)
61563 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61564 + else
61565 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61566 + 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),
61567 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61568 + free_page((unsigned long)buffer_exec);
61569 + free_page((unsigned long)buffer_fault);
61570 + pax_report_insns(regs, pc, sp);
61571 + info.si_signo = SIGKILL;
61572 + info.si_errno = 0;
61573 + info.si_code = SI_KERNEL;
61574 + info.si_pid = 0;
61575 + info.si_uid = 0;
61576 + do_coredump(&info);
61577 +}
61578 +#endif
61579 +
61580 +#ifdef CONFIG_PAX_REFCOUNT
61581 +void pax_report_refcount_overflow(struct pt_regs *regs)
61582 +{
61583 + if (current->signal->curr_ip)
61584 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61585 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61586 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61587 + else
61588 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61589 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61590 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61591 + preempt_disable();
61592 + show_regs(regs);
61593 + preempt_enable();
61594 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61595 +}
61596 +#endif
61597 +
61598 +#ifdef CONFIG_PAX_USERCOPY
61599 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61600 +static noinline int check_stack_object(const void *obj, unsigned long len)
61601 +{
61602 + const void * const stack = task_stack_page(current);
61603 + const void * const stackend = stack + THREAD_SIZE;
61604 +
61605 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61606 + const void *frame = NULL;
61607 + const void *oldframe;
61608 +#endif
61609 +
61610 + if (obj + len < obj)
61611 + return -1;
61612 +
61613 + if (obj + len <= stack || stackend <= obj)
61614 + return 0;
61615 +
61616 + if (obj < stack || stackend < obj + len)
61617 + return -1;
61618 +
61619 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61620 + oldframe = __builtin_frame_address(1);
61621 + if (oldframe)
61622 + frame = __builtin_frame_address(2);
61623 + /*
61624 + low ----------------------------------------------> high
61625 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61626 + ^----------------^
61627 + allow copies only within here
61628 + */
61629 + while (stack <= frame && frame < stackend) {
61630 + /* if obj + len extends past the last frame, this
61631 + check won't pass and the next frame will be 0,
61632 + causing us to bail out and correctly report
61633 + the copy as invalid
61634 + */
61635 + if (obj + len <= frame)
61636 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61637 + oldframe = frame;
61638 + frame = *(const void * const *)frame;
61639 + }
61640 + return -1;
61641 +#else
61642 + return 1;
61643 +#endif
61644 +}
61645 +
61646 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61647 +{
61648 + if (current->signal->curr_ip)
61649 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61650 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61651 + else
61652 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61653 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61654 + dump_stack();
61655 + gr_handle_kernel_exploit();
61656 + do_group_exit(SIGKILL);
61657 +}
61658 +#endif
61659 +
61660 +#ifdef CONFIG_PAX_USERCOPY
61661 +
61662 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61663 +{
61664 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61665 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61666 +#ifdef CONFIG_MODULES
61667 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61668 +#else
61669 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61670 +#endif
61671 +
61672 +#else
61673 + unsigned long textlow = (unsigned long)_stext;
61674 + unsigned long texthigh = (unsigned long)_etext;
61675 +
61676 +#ifdef CONFIG_X86_64
61677 + /* check against linear mapping as well */
61678 + if (high > (unsigned long)__va(__pa(textlow)) &&
61679 + low < (unsigned long)__va(__pa(texthigh)))
61680 + return true;
61681 +#endif
61682 +
61683 +#endif
61684 +
61685 + if (high <= textlow || low >= texthigh)
61686 + return false;
61687 + else
61688 + return true;
61689 +}
61690 +#endif
61691 +
61692 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61693 +{
61694 +#ifdef CONFIG_PAX_USERCOPY
61695 + const char *type;
61696 +#endif
61697 +
61698 +#ifndef CONFIG_STACK_GROWSUP
61699 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61700 + unsigned long currentsp = (unsigned long)&stackstart;
61701 + if (unlikely((currentsp < stackstart + 512 ||
61702 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61703 + BUG();
61704 +#endif
61705 +
61706 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61707 + if (const_size)
61708 + return;
61709 +#endif
61710 +
61711 +#ifdef CONFIG_PAX_USERCOPY
61712 + if (!n)
61713 + return;
61714 +
61715 + type = check_heap_object(ptr, n);
61716 + if (!type) {
61717 + int ret = check_stack_object(ptr, n);
61718 + if (ret == 1 || ret == 2)
61719 + return;
61720 + if (ret == 0) {
61721 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61722 + type = "<kernel text>";
61723 + else
61724 + return;
61725 + } else
61726 + type = "<process stack>";
61727 + }
61728 +
61729 + pax_report_usercopy(ptr, n, to_user, type);
61730 +#endif
61731 +
61732 +}
61733 +EXPORT_SYMBOL(__check_object_size);
61734 +
61735 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61736 +void pax_track_stack(void)
61737 +{
61738 + unsigned long sp = (unsigned long)&sp;
61739 + if (sp < current_thread_info()->lowest_stack &&
61740 + sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61741 + current_thread_info()->lowest_stack = sp;
61742 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61743 + BUG();
61744 +}
61745 +EXPORT_SYMBOL(pax_track_stack);
61746 +#endif
61747 +
61748 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61749 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61750 +{
61751 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61752 + dump_stack();
61753 + do_group_exit(SIGKILL);
61754 +}
61755 +EXPORT_SYMBOL(report_size_overflow);
61756 +#endif
61757 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61758 index 9f9992b..8b59411 100644
61759 --- a/fs/ext2/balloc.c
61760 +++ b/fs/ext2/balloc.c
61761 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61762
61763 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61764 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61765 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61766 + if (free_blocks < root_blocks + 1 &&
61767 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61768 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61769 - !in_group_p (sbi->s_resgid))) {
61770 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61771 return 0;
61772 }
61773 return 1;
61774 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61775 index 170dc41..62f6b18 100644
61776 --- a/fs/ext2/super.c
61777 +++ b/fs/ext2/super.c
61778 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61779 #ifdef CONFIG_EXT2_FS_XATTR
61780 if (test_opt(sb, XATTR_USER))
61781 seq_puts(seq, ",user_xattr");
61782 - if (!test_opt(sb, XATTR_USER) &&
61783 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61784 + if (!test_opt(sb, XATTR_USER))
61785 seq_puts(seq, ",nouser_xattr");
61786 - }
61787 #endif
61788
61789 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61790 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61791 if (def_mount_opts & EXT2_DEFM_UID16)
61792 set_opt(sbi->s_mount_opt, NO_UID32);
61793 #ifdef CONFIG_EXT2_FS_XATTR
61794 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61795 - set_opt(sbi->s_mount_opt, XATTR_USER);
61796 + /* always enable user xattrs */
61797 + set_opt(sbi->s_mount_opt, XATTR_USER);
61798 #endif
61799 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61800 if (def_mount_opts & EXT2_DEFM_ACL)
61801 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61802 index 9142614..97484fa 100644
61803 --- a/fs/ext2/xattr.c
61804 +++ b/fs/ext2/xattr.c
61805 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61806 struct buffer_head *bh = NULL;
61807 struct ext2_xattr_entry *entry;
61808 char *end;
61809 - size_t rest = buffer_size;
61810 + size_t rest = buffer_size, total_size = 0;
61811 int error;
61812
61813 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61814 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61815 buffer += size;
61816 }
61817 rest -= size;
61818 + total_size += size;
61819 }
61820 }
61821 - error = buffer_size - rest; /* total size */
61822 + error = total_size;
61823
61824 cleanup:
61825 brelse(bh);
61826 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61827 index 158b5d4..2432610 100644
61828 --- a/fs/ext3/balloc.c
61829 +++ b/fs/ext3/balloc.c
61830 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61831
61832 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61833 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61834 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61835 + if (free_blocks < root_blocks + 1 &&
61836 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61837 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61838 - !in_group_p (sbi->s_resgid))) {
61839 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61840 return 0;
61841 }
61842 return 1;
61843 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61844 index eb742d0..c19f705 100644
61845 --- a/fs/ext3/super.c
61846 +++ b/fs/ext3/super.c
61847 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61848 #ifdef CONFIG_EXT3_FS_XATTR
61849 if (test_opt(sb, XATTR_USER))
61850 seq_puts(seq, ",user_xattr");
61851 - if (!test_opt(sb, XATTR_USER) &&
61852 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61853 + if (!test_opt(sb, XATTR_USER))
61854 seq_puts(seq, ",nouser_xattr");
61855 - }
61856 #endif
61857 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61858 if (test_opt(sb, POSIX_ACL))
61859 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61860 if (def_mount_opts & EXT3_DEFM_UID16)
61861 set_opt(sbi->s_mount_opt, NO_UID32);
61862 #ifdef CONFIG_EXT3_FS_XATTR
61863 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61864 - set_opt(sbi->s_mount_opt, XATTR_USER);
61865 + /* always enable user xattrs */
61866 + set_opt(sbi->s_mount_opt, XATTR_USER);
61867 #endif
61868 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61869 if (def_mount_opts & EXT3_DEFM_ACL)
61870 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61871 index c6874be..f8a6ae8 100644
61872 --- a/fs/ext3/xattr.c
61873 +++ b/fs/ext3/xattr.c
61874 @@ -330,7 +330,7 @@ static int
61875 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61876 char *buffer, size_t buffer_size)
61877 {
61878 - size_t rest = buffer_size;
61879 + size_t rest = buffer_size, total_size = 0;
61880
61881 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61882 const struct xattr_handler *handler =
61883 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61884 buffer += size;
61885 }
61886 rest -= size;
61887 + total_size += size;
61888 }
61889 }
61890 - return buffer_size - rest;
61891 + return total_size;
61892 }
61893
61894 static int
61895 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61896 index 83a6f49..d4e4d03 100644
61897 --- a/fs/ext4/balloc.c
61898 +++ b/fs/ext4/balloc.c
61899 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61900 /* Hm, nope. Are (enough) root reserved clusters available? */
61901 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61902 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61903 - capable(CAP_SYS_RESOURCE) ||
61904 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61905 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61906 + capable_nolog(CAP_SYS_RESOURCE)) {
61907
61908 if (free_clusters >= (nclusters + dirty_clusters +
61909 resv_clusters))
61910 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61911 index c55a1fa..9904ebb 100644
61912 --- a/fs/ext4/ext4.h
61913 +++ b/fs/ext4/ext4.h
61914 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61915 unsigned long s_mb_last_start;
61916
61917 /* stats for buddy allocator */
61918 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61919 - atomic_t s_bal_success; /* we found long enough chunks */
61920 - atomic_t s_bal_allocated; /* in blocks */
61921 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61922 - atomic_t s_bal_goals; /* goal hits */
61923 - atomic_t s_bal_breaks; /* too long searches */
61924 - atomic_t s_bal_2orders; /* 2^order hits */
61925 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61926 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61927 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61928 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61929 + atomic_unchecked_t s_bal_goals; /* goal hits */
61930 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61931 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61932 spinlock_t s_bal_lock;
61933 unsigned long s_mb_buddies_generated;
61934 unsigned long long s_mb_generation_time;
61935 - atomic_t s_mb_lost_chunks;
61936 - atomic_t s_mb_preallocated;
61937 - atomic_t s_mb_discarded;
61938 + atomic_unchecked_t s_mb_lost_chunks;
61939 + atomic_unchecked_t s_mb_preallocated;
61940 + atomic_unchecked_t s_mb_discarded;
61941 atomic_t s_lock_busy;
61942
61943 /* locality groups */
61944 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61945 index dbfe15c..9a6ee8d 100644
61946 --- a/fs/ext4/mballoc.c
61947 +++ b/fs/ext4/mballoc.c
61948 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61949 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61950
61951 if (EXT4_SB(sb)->s_mb_stats)
61952 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61953 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61954
61955 break;
61956 }
61957 @@ -2211,7 +2211,7 @@ repeat:
61958 ac->ac_status = AC_STATUS_CONTINUE;
61959 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61960 cr = 3;
61961 - atomic_inc(&sbi->s_mb_lost_chunks);
61962 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61963 goto repeat;
61964 }
61965 }
61966 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61967 if (sbi->s_mb_stats) {
61968 ext4_msg(sb, KERN_INFO,
61969 "mballoc: %u blocks %u reqs (%u success)",
61970 - atomic_read(&sbi->s_bal_allocated),
61971 - atomic_read(&sbi->s_bal_reqs),
61972 - atomic_read(&sbi->s_bal_success));
61973 + atomic_read_unchecked(&sbi->s_bal_allocated),
61974 + atomic_read_unchecked(&sbi->s_bal_reqs),
61975 + atomic_read_unchecked(&sbi->s_bal_success));
61976 ext4_msg(sb, KERN_INFO,
61977 "mballoc: %u extents scanned, %u goal hits, "
61978 "%u 2^N hits, %u breaks, %u lost",
61979 - atomic_read(&sbi->s_bal_ex_scanned),
61980 - atomic_read(&sbi->s_bal_goals),
61981 - atomic_read(&sbi->s_bal_2orders),
61982 - atomic_read(&sbi->s_bal_breaks),
61983 - atomic_read(&sbi->s_mb_lost_chunks));
61984 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61985 + atomic_read_unchecked(&sbi->s_bal_goals),
61986 + atomic_read_unchecked(&sbi->s_bal_2orders),
61987 + atomic_read_unchecked(&sbi->s_bal_breaks),
61988 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61989 ext4_msg(sb, KERN_INFO,
61990 "mballoc: %lu generated and it took %Lu",
61991 sbi->s_mb_buddies_generated,
61992 sbi->s_mb_generation_time);
61993 ext4_msg(sb, KERN_INFO,
61994 "mballoc: %u preallocated, %u discarded",
61995 - atomic_read(&sbi->s_mb_preallocated),
61996 - atomic_read(&sbi->s_mb_discarded));
61997 + atomic_read_unchecked(&sbi->s_mb_preallocated),
61998 + atomic_read_unchecked(&sbi->s_mb_discarded));
61999 }
62000
62001 free_percpu(sbi->s_locality_groups);
62002 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62003 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62004
62005 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62006 - atomic_inc(&sbi->s_bal_reqs);
62007 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62008 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62009 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62010 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62011 - atomic_inc(&sbi->s_bal_success);
62012 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62013 + atomic_inc_unchecked(&sbi->s_bal_success);
62014 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62015 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62016 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62017 - atomic_inc(&sbi->s_bal_goals);
62018 + atomic_inc_unchecked(&sbi->s_bal_goals);
62019 if (ac->ac_found > sbi->s_mb_max_to_scan)
62020 - atomic_inc(&sbi->s_bal_breaks);
62021 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62022 }
62023
62024 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62025 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62026 trace_ext4_mb_new_inode_pa(ac, pa);
62027
62028 ext4_mb_use_inode_pa(ac, pa);
62029 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62030 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62031
62032 ei = EXT4_I(ac->ac_inode);
62033 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62034 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62035 trace_ext4_mb_new_group_pa(ac, pa);
62036
62037 ext4_mb_use_group_pa(ac, pa);
62038 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62039 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62040
62041 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62042 lg = ac->ac_lg;
62043 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62044 * from the bitmap and continue.
62045 */
62046 }
62047 - atomic_add(free, &sbi->s_mb_discarded);
62048 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62049
62050 return err;
62051 }
62052 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62053 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62054 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62055 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62056 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62057 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62058 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62059
62060 return 0;
62061 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62062 index 8313ca3..8a37d08 100644
62063 --- a/fs/ext4/mmp.c
62064 +++ b/fs/ext4/mmp.c
62065 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62066 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62067 const char *function, unsigned int line, const char *msg)
62068 {
62069 - __ext4_warning(sb, function, line, msg);
62070 + __ext4_warning(sb, function, line, "%s", msg);
62071 __ext4_warning(sb, function, line,
62072 "MMP failure info: last update time: %llu, last update "
62073 "node: %s, last update device: %s\n",
62074 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62075 index 2c9e686..6a40edc 100644
62076 --- a/fs/ext4/super.c
62077 +++ b/fs/ext4/super.c
62078 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62079 }
62080
62081 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62082 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62083 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62084 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62085
62086 #ifdef CONFIG_QUOTA
62087 @@ -2434,7 +2434,7 @@ struct ext4_attr {
62088 int offset;
62089 int deprecated_val;
62090 } u;
62091 -};
62092 +} __do_const;
62093
62094 static int parse_strtoull(const char *buf,
62095 unsigned long long max, unsigned long long *value)
62096 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62097 index 1e09fc7..0400dd4 100644
62098 --- a/fs/ext4/xattr.c
62099 +++ b/fs/ext4/xattr.c
62100 @@ -399,7 +399,7 @@ static int
62101 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62102 char *buffer, size_t buffer_size)
62103 {
62104 - size_t rest = buffer_size;
62105 + size_t rest = buffer_size, total_size = 0;
62106
62107 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62108 const struct xattr_handler *handler =
62109 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62110 buffer += size;
62111 }
62112 rest -= size;
62113 + total_size += size;
62114 }
62115 }
62116 - return buffer_size - rest;
62117 + return total_size;
62118 }
62119
62120 static int
62121 diff --git a/fs/fcntl.c b/fs/fcntl.c
62122 index 99d440a..eb979d1 100644
62123 --- a/fs/fcntl.c
62124 +++ b/fs/fcntl.c
62125 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62126 int force)
62127 {
62128 security_file_set_fowner(filp);
62129 + if (gr_handle_chroot_fowner(pid, type))
62130 + return;
62131 + if (gr_check_protected_task_fowner(pid, type))
62132 + return;
62133 f_modown(filp, pid, type, force);
62134 }
62135 EXPORT_SYMBOL(__f_setown);
62136 diff --git a/fs/fhandle.c b/fs/fhandle.c
62137 index 999ff5c..2281df9 100644
62138 --- a/fs/fhandle.c
62139 +++ b/fs/fhandle.c
62140 @@ -8,6 +8,7 @@
62141 #include <linux/fs_struct.h>
62142 #include <linux/fsnotify.h>
62143 #include <linux/personality.h>
62144 +#include <linux/grsecurity.h>
62145 #include <asm/uaccess.h>
62146 #include "internal.h"
62147 #include "mount.h"
62148 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62149 } else
62150 retval = 0;
62151 /* copy the mount id */
62152 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62153 - sizeof(*mnt_id)) ||
62154 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62155 copy_to_user(ufh, handle,
62156 sizeof(struct file_handle) + handle_bytes))
62157 retval = -EFAULT;
62158 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62159 * the directory. Ideally we would like CAP_DAC_SEARCH.
62160 * But we don't have that
62161 */
62162 - if (!capable(CAP_DAC_READ_SEARCH)) {
62163 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62164 retval = -EPERM;
62165 goto out_err;
62166 }
62167 @@ -195,8 +195,9 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62168 goto out_err;
62169 }
62170 /* copy the full handle */
62171 - if (copy_from_user(handle, ufh,
62172 - sizeof(struct file_handle) +
62173 + *handle = f_handle;
62174 + if (copy_from_user(&handle->f_handle,
62175 + &ufh->f_handle,
62176 f_handle.handle_bytes)) {
62177 retval = -EFAULT;
62178 goto out_handle;
62179 diff --git a/fs/file.c b/fs/file.c
62180 index ab3eb6a..8de2392 100644
62181 --- a/fs/file.c
62182 +++ b/fs/file.c
62183 @@ -16,6 +16,7 @@
62184 #include <linux/slab.h>
62185 #include <linux/vmalloc.h>
62186 #include <linux/file.h>
62187 +#include <linux/security.h>
62188 #include <linux/fdtable.h>
62189 #include <linux/bitops.h>
62190 #include <linux/interrupt.h>
62191 @@ -139,7 +140,7 @@ out:
62192 * Return <0 error code on error; 1 on successful completion.
62193 * The files->file_lock should be held on entry, and will be held on exit.
62194 */
62195 -static int expand_fdtable(struct files_struct *files, int nr)
62196 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62197 __releases(files->file_lock)
62198 __acquires(files->file_lock)
62199 {
62200 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62201 * expanded and execution may have blocked.
62202 * The files->file_lock should be held on entry, and will be held on exit.
62203 */
62204 -static int expand_files(struct files_struct *files, int nr)
62205 +static int expand_files(struct files_struct *files, unsigned int nr)
62206 {
62207 struct fdtable *fdt;
62208
62209 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62210 if (!file)
62211 return __close_fd(files, fd);
62212
62213 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62214 if (fd >= rlimit(RLIMIT_NOFILE))
62215 return -EBADF;
62216
62217 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62218 if (unlikely(oldfd == newfd))
62219 return -EINVAL;
62220
62221 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62222 if (newfd >= rlimit(RLIMIT_NOFILE))
62223 return -EBADF;
62224
62225 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62226 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62227 {
62228 int err;
62229 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62230 if (from >= rlimit(RLIMIT_NOFILE))
62231 return -EINVAL;
62232 err = alloc_fd(from, flags);
62233 diff --git a/fs/filesystems.c b/fs/filesystems.c
62234 index 5797d45..7d7d79a 100644
62235 --- a/fs/filesystems.c
62236 +++ b/fs/filesystems.c
62237 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62238 int len = dot ? dot - name : strlen(name);
62239
62240 fs = __get_fs_type(name, len);
62241 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62242 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62243 +#else
62244 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62245 +#endif
62246 fs = __get_fs_type(name, len);
62247
62248 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62249 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62250 index 7dca743..2f2786d 100644
62251 --- a/fs/fs_struct.c
62252 +++ b/fs/fs_struct.c
62253 @@ -4,6 +4,7 @@
62254 #include <linux/path.h>
62255 #include <linux/slab.h>
62256 #include <linux/fs_struct.h>
62257 +#include <linux/grsecurity.h>
62258 #include "internal.h"
62259
62260 /*
62261 @@ -15,14 +16,18 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62262 struct path old_root;
62263
62264 path_get(path);
62265 + gr_inc_chroot_refcnts(path->dentry, path->mnt);
62266 spin_lock(&fs->lock);
62267 write_seqcount_begin(&fs->seq);
62268 old_root = fs->root;
62269 fs->root = *path;
62270 + gr_set_chroot_entries(current, path);
62271 write_seqcount_end(&fs->seq);
62272 spin_unlock(&fs->lock);
62273 - if (old_root.dentry)
62274 + if (old_root.dentry) {
62275 + gr_dec_chroot_refcnts(old_root.dentry, old_root.mnt);
62276 path_put(&old_root);
62277 + }
62278 }
62279
62280 /*
62281 @@ -67,6 +72,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62282 int hits = 0;
62283 spin_lock(&fs->lock);
62284 write_seqcount_begin(&fs->seq);
62285 + /* this root replacement is only done by pivot_root,
62286 + leave grsec's chroot tagging alone for this task
62287 + so that a pivoted root isn't treated as a chroot
62288 + */
62289 hits += replace_path(&fs->root, old_root, new_root);
62290 hits += replace_path(&fs->pwd, old_root, new_root);
62291 write_seqcount_end(&fs->seq);
62292 @@ -85,6 +94,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62293
62294 void free_fs_struct(struct fs_struct *fs)
62295 {
62296 + gr_dec_chroot_refcnts(fs->root.dentry, fs->root.mnt);
62297 path_put(&fs->root);
62298 path_put(&fs->pwd);
62299 kmem_cache_free(fs_cachep, fs);
62300 @@ -99,7 +109,8 @@ void exit_fs(struct task_struct *tsk)
62301 task_lock(tsk);
62302 spin_lock(&fs->lock);
62303 tsk->fs = NULL;
62304 - kill = !--fs->users;
62305 + gr_clear_chroot_entries(tsk);
62306 + kill = !atomic_dec_return(&fs->users);
62307 spin_unlock(&fs->lock);
62308 task_unlock(tsk);
62309 if (kill)
62310 @@ -112,7 +123,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62311 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62312 /* We don't need to lock fs - think why ;-) */
62313 if (fs) {
62314 - fs->users = 1;
62315 + atomic_set(&fs->users, 1);
62316 fs->in_exec = 0;
62317 spin_lock_init(&fs->lock);
62318 seqcount_init(&fs->seq);
62319 @@ -121,6 +132,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62320 spin_lock(&old->lock);
62321 fs->root = old->root;
62322 path_get(&fs->root);
62323 + /* instead of calling gr_set_chroot_entries here,
62324 + we call it from every caller of this function
62325 + */
62326 fs->pwd = old->pwd;
62327 path_get(&fs->pwd);
62328 spin_unlock(&old->lock);
62329 @@ -139,8 +153,9 @@ int unshare_fs_struct(void)
62330
62331 task_lock(current);
62332 spin_lock(&fs->lock);
62333 - kill = !--fs->users;
62334 + kill = !atomic_dec_return(&fs->users);
62335 current->fs = new_fs;
62336 + gr_set_chroot_entries(current, &new_fs->root);
62337 spin_unlock(&fs->lock);
62338 task_unlock(current);
62339
62340 @@ -153,13 +168,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62341
62342 int current_umask(void)
62343 {
62344 - return current->fs->umask;
62345 + return current->fs->umask | gr_acl_umask();
62346 }
62347 EXPORT_SYMBOL(current_umask);
62348
62349 /* to be mentioned only in INIT_TASK */
62350 struct fs_struct init_fs = {
62351 - .users = 1,
62352 + .users = ATOMIC_INIT(1),
62353 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62354 .seq = SEQCNT_ZERO(init_fs.seq),
62355 .umask = 0022,
62356 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62357 index 89acec7..a575262 100644
62358 --- a/fs/fscache/cookie.c
62359 +++ b/fs/fscache/cookie.c
62360 @@ -19,7 +19,7 @@
62361
62362 struct kmem_cache *fscache_cookie_jar;
62363
62364 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62365 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62366
62367 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62368 static int fscache_alloc_object(struct fscache_cache *cache,
62369 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62370 parent ? (char *) parent->def->name : "<no-parent>",
62371 def->name, netfs_data, enable);
62372
62373 - fscache_stat(&fscache_n_acquires);
62374 + fscache_stat_unchecked(&fscache_n_acquires);
62375
62376 /* if there's no parent cookie, then we don't create one here either */
62377 if (!parent) {
62378 - fscache_stat(&fscache_n_acquires_null);
62379 + fscache_stat_unchecked(&fscache_n_acquires_null);
62380 _leave(" [no parent]");
62381 return NULL;
62382 }
62383 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62384 /* allocate and initialise a cookie */
62385 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62386 if (!cookie) {
62387 - fscache_stat(&fscache_n_acquires_oom);
62388 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62389 _leave(" [ENOMEM]");
62390 return NULL;
62391 }
62392 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62393
62394 switch (cookie->def->type) {
62395 case FSCACHE_COOKIE_TYPE_INDEX:
62396 - fscache_stat(&fscache_n_cookie_index);
62397 + fscache_stat_unchecked(&fscache_n_cookie_index);
62398 break;
62399 case FSCACHE_COOKIE_TYPE_DATAFILE:
62400 - fscache_stat(&fscache_n_cookie_data);
62401 + fscache_stat_unchecked(&fscache_n_cookie_data);
62402 break;
62403 default:
62404 - fscache_stat(&fscache_n_cookie_special);
62405 + fscache_stat_unchecked(&fscache_n_cookie_special);
62406 break;
62407 }
62408
62409 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62410 } else {
62411 atomic_dec(&parent->n_children);
62412 __fscache_cookie_put(cookie);
62413 - fscache_stat(&fscache_n_acquires_nobufs);
62414 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62415 _leave(" = NULL");
62416 return NULL;
62417 }
62418 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62419 }
62420 }
62421
62422 - fscache_stat(&fscache_n_acquires_ok);
62423 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62424 _leave(" = %p", cookie);
62425 return cookie;
62426 }
62427 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62428 cache = fscache_select_cache_for_object(cookie->parent);
62429 if (!cache) {
62430 up_read(&fscache_addremove_sem);
62431 - fscache_stat(&fscache_n_acquires_no_cache);
62432 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62433 _leave(" = -ENOMEDIUM [no cache]");
62434 return -ENOMEDIUM;
62435 }
62436 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62437 object = cache->ops->alloc_object(cache, cookie);
62438 fscache_stat_d(&fscache_n_cop_alloc_object);
62439 if (IS_ERR(object)) {
62440 - fscache_stat(&fscache_n_object_no_alloc);
62441 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62442 ret = PTR_ERR(object);
62443 goto error;
62444 }
62445
62446 - fscache_stat(&fscache_n_object_alloc);
62447 + fscache_stat_unchecked(&fscache_n_object_alloc);
62448
62449 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62450 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62451
62452 _debug("ALLOC OBJ%x: %s {%lx}",
62453 object->debug_id, cookie->def->name, object->events);
62454 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62455
62456 _enter("{%s}", cookie->def->name);
62457
62458 - fscache_stat(&fscache_n_invalidates);
62459 + fscache_stat_unchecked(&fscache_n_invalidates);
62460
62461 /* Only permit invalidation of data files. Invalidating an index will
62462 * require the caller to release all its attachments to the tree rooted
62463 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62464 {
62465 struct fscache_object *object;
62466
62467 - fscache_stat(&fscache_n_updates);
62468 + fscache_stat_unchecked(&fscache_n_updates);
62469
62470 if (!cookie) {
62471 - fscache_stat(&fscache_n_updates_null);
62472 + fscache_stat_unchecked(&fscache_n_updates_null);
62473 _leave(" [no cookie]");
62474 return;
62475 }
62476 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62477 */
62478 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62479 {
62480 - fscache_stat(&fscache_n_relinquishes);
62481 + fscache_stat_unchecked(&fscache_n_relinquishes);
62482 if (retire)
62483 - fscache_stat(&fscache_n_relinquishes_retire);
62484 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62485
62486 if (!cookie) {
62487 - fscache_stat(&fscache_n_relinquishes_null);
62488 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62489 _leave(" [no cookie]");
62490 return;
62491 }
62492 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62493 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62494 goto inconsistent;
62495
62496 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62497 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62498
62499 __fscache_use_cookie(cookie);
62500 if (fscache_submit_op(object, op) < 0)
62501 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62502 index 7872a62..d91b19f 100644
62503 --- a/fs/fscache/internal.h
62504 +++ b/fs/fscache/internal.h
62505 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62506 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62507 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62508 struct fscache_operation *,
62509 - atomic_t *,
62510 - atomic_t *,
62511 + atomic_unchecked_t *,
62512 + atomic_unchecked_t *,
62513 void (*)(struct fscache_operation *));
62514 extern void fscache_invalidate_writes(struct fscache_cookie *);
62515
62516 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62517 * stats.c
62518 */
62519 #ifdef CONFIG_FSCACHE_STATS
62520 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62521 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62522 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62523 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62524
62525 -extern atomic_t fscache_n_op_pend;
62526 -extern atomic_t fscache_n_op_run;
62527 -extern atomic_t fscache_n_op_enqueue;
62528 -extern atomic_t fscache_n_op_deferred_release;
62529 -extern atomic_t fscache_n_op_release;
62530 -extern atomic_t fscache_n_op_gc;
62531 -extern atomic_t fscache_n_op_cancelled;
62532 -extern atomic_t fscache_n_op_rejected;
62533 +extern atomic_unchecked_t fscache_n_op_pend;
62534 +extern atomic_unchecked_t fscache_n_op_run;
62535 +extern atomic_unchecked_t fscache_n_op_enqueue;
62536 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62537 +extern atomic_unchecked_t fscache_n_op_release;
62538 +extern atomic_unchecked_t fscache_n_op_gc;
62539 +extern atomic_unchecked_t fscache_n_op_cancelled;
62540 +extern atomic_unchecked_t fscache_n_op_rejected;
62541
62542 -extern atomic_t fscache_n_attr_changed;
62543 -extern atomic_t fscache_n_attr_changed_ok;
62544 -extern atomic_t fscache_n_attr_changed_nobufs;
62545 -extern atomic_t fscache_n_attr_changed_nomem;
62546 -extern atomic_t fscache_n_attr_changed_calls;
62547 +extern atomic_unchecked_t fscache_n_attr_changed;
62548 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62549 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62550 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62551 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62552
62553 -extern atomic_t fscache_n_allocs;
62554 -extern atomic_t fscache_n_allocs_ok;
62555 -extern atomic_t fscache_n_allocs_wait;
62556 -extern atomic_t fscache_n_allocs_nobufs;
62557 -extern atomic_t fscache_n_allocs_intr;
62558 -extern atomic_t fscache_n_allocs_object_dead;
62559 -extern atomic_t fscache_n_alloc_ops;
62560 -extern atomic_t fscache_n_alloc_op_waits;
62561 +extern atomic_unchecked_t fscache_n_allocs;
62562 +extern atomic_unchecked_t fscache_n_allocs_ok;
62563 +extern atomic_unchecked_t fscache_n_allocs_wait;
62564 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62565 +extern atomic_unchecked_t fscache_n_allocs_intr;
62566 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62567 +extern atomic_unchecked_t fscache_n_alloc_ops;
62568 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62569
62570 -extern atomic_t fscache_n_retrievals;
62571 -extern atomic_t fscache_n_retrievals_ok;
62572 -extern atomic_t fscache_n_retrievals_wait;
62573 -extern atomic_t fscache_n_retrievals_nodata;
62574 -extern atomic_t fscache_n_retrievals_nobufs;
62575 -extern atomic_t fscache_n_retrievals_intr;
62576 -extern atomic_t fscache_n_retrievals_nomem;
62577 -extern atomic_t fscache_n_retrievals_object_dead;
62578 -extern atomic_t fscache_n_retrieval_ops;
62579 -extern atomic_t fscache_n_retrieval_op_waits;
62580 +extern atomic_unchecked_t fscache_n_retrievals;
62581 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62582 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62583 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62584 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62585 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62586 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62587 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62588 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62589 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62590
62591 -extern atomic_t fscache_n_stores;
62592 -extern atomic_t fscache_n_stores_ok;
62593 -extern atomic_t fscache_n_stores_again;
62594 -extern atomic_t fscache_n_stores_nobufs;
62595 -extern atomic_t fscache_n_stores_oom;
62596 -extern atomic_t fscache_n_store_ops;
62597 -extern atomic_t fscache_n_store_calls;
62598 -extern atomic_t fscache_n_store_pages;
62599 -extern atomic_t fscache_n_store_radix_deletes;
62600 -extern atomic_t fscache_n_store_pages_over_limit;
62601 +extern atomic_unchecked_t fscache_n_stores;
62602 +extern atomic_unchecked_t fscache_n_stores_ok;
62603 +extern atomic_unchecked_t fscache_n_stores_again;
62604 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62605 +extern atomic_unchecked_t fscache_n_stores_oom;
62606 +extern atomic_unchecked_t fscache_n_store_ops;
62607 +extern atomic_unchecked_t fscache_n_store_calls;
62608 +extern atomic_unchecked_t fscache_n_store_pages;
62609 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62610 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62611
62612 -extern atomic_t fscache_n_store_vmscan_not_storing;
62613 -extern atomic_t fscache_n_store_vmscan_gone;
62614 -extern atomic_t fscache_n_store_vmscan_busy;
62615 -extern atomic_t fscache_n_store_vmscan_cancelled;
62616 -extern atomic_t fscache_n_store_vmscan_wait;
62617 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62618 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62619 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62620 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62621 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62622
62623 -extern atomic_t fscache_n_marks;
62624 -extern atomic_t fscache_n_uncaches;
62625 +extern atomic_unchecked_t fscache_n_marks;
62626 +extern atomic_unchecked_t fscache_n_uncaches;
62627
62628 -extern atomic_t fscache_n_acquires;
62629 -extern atomic_t fscache_n_acquires_null;
62630 -extern atomic_t fscache_n_acquires_no_cache;
62631 -extern atomic_t fscache_n_acquires_ok;
62632 -extern atomic_t fscache_n_acquires_nobufs;
62633 -extern atomic_t fscache_n_acquires_oom;
62634 +extern atomic_unchecked_t fscache_n_acquires;
62635 +extern atomic_unchecked_t fscache_n_acquires_null;
62636 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62637 +extern atomic_unchecked_t fscache_n_acquires_ok;
62638 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62639 +extern atomic_unchecked_t fscache_n_acquires_oom;
62640
62641 -extern atomic_t fscache_n_invalidates;
62642 -extern atomic_t fscache_n_invalidates_run;
62643 +extern atomic_unchecked_t fscache_n_invalidates;
62644 +extern atomic_unchecked_t fscache_n_invalidates_run;
62645
62646 -extern atomic_t fscache_n_updates;
62647 -extern atomic_t fscache_n_updates_null;
62648 -extern atomic_t fscache_n_updates_run;
62649 +extern atomic_unchecked_t fscache_n_updates;
62650 +extern atomic_unchecked_t fscache_n_updates_null;
62651 +extern atomic_unchecked_t fscache_n_updates_run;
62652
62653 -extern atomic_t fscache_n_relinquishes;
62654 -extern atomic_t fscache_n_relinquishes_null;
62655 -extern atomic_t fscache_n_relinquishes_waitcrt;
62656 -extern atomic_t fscache_n_relinquishes_retire;
62657 +extern atomic_unchecked_t fscache_n_relinquishes;
62658 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62659 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62660 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62661
62662 -extern atomic_t fscache_n_cookie_index;
62663 -extern atomic_t fscache_n_cookie_data;
62664 -extern atomic_t fscache_n_cookie_special;
62665 +extern atomic_unchecked_t fscache_n_cookie_index;
62666 +extern atomic_unchecked_t fscache_n_cookie_data;
62667 +extern atomic_unchecked_t fscache_n_cookie_special;
62668
62669 -extern atomic_t fscache_n_object_alloc;
62670 -extern atomic_t fscache_n_object_no_alloc;
62671 -extern atomic_t fscache_n_object_lookups;
62672 -extern atomic_t fscache_n_object_lookups_negative;
62673 -extern atomic_t fscache_n_object_lookups_positive;
62674 -extern atomic_t fscache_n_object_lookups_timed_out;
62675 -extern atomic_t fscache_n_object_created;
62676 -extern atomic_t fscache_n_object_avail;
62677 -extern atomic_t fscache_n_object_dead;
62678 +extern atomic_unchecked_t fscache_n_object_alloc;
62679 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62680 +extern atomic_unchecked_t fscache_n_object_lookups;
62681 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62682 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62683 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62684 +extern atomic_unchecked_t fscache_n_object_created;
62685 +extern atomic_unchecked_t fscache_n_object_avail;
62686 +extern atomic_unchecked_t fscache_n_object_dead;
62687
62688 -extern atomic_t fscache_n_checkaux_none;
62689 -extern atomic_t fscache_n_checkaux_okay;
62690 -extern atomic_t fscache_n_checkaux_update;
62691 -extern atomic_t fscache_n_checkaux_obsolete;
62692 +extern atomic_unchecked_t fscache_n_checkaux_none;
62693 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62694 +extern atomic_unchecked_t fscache_n_checkaux_update;
62695 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62696
62697 extern atomic_t fscache_n_cop_alloc_object;
62698 extern atomic_t fscache_n_cop_lookup_object;
62699 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62700 atomic_inc(stat);
62701 }
62702
62703 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62704 +{
62705 + atomic_inc_unchecked(stat);
62706 +}
62707 +
62708 static inline void fscache_stat_d(atomic_t *stat)
62709 {
62710 atomic_dec(stat);
62711 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62712
62713 #define __fscache_stat(stat) (NULL)
62714 #define fscache_stat(stat) do {} while (0)
62715 +#define fscache_stat_unchecked(stat) do {} while (0)
62716 #define fscache_stat_d(stat) do {} while (0)
62717 #endif
62718
62719 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62720 index da032da..0076ce7 100644
62721 --- a/fs/fscache/object.c
62722 +++ b/fs/fscache/object.c
62723 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62724 _debug("LOOKUP \"%s\" in \"%s\"",
62725 cookie->def->name, object->cache->tag->name);
62726
62727 - fscache_stat(&fscache_n_object_lookups);
62728 + fscache_stat_unchecked(&fscache_n_object_lookups);
62729 fscache_stat(&fscache_n_cop_lookup_object);
62730 ret = object->cache->ops->lookup_object(object);
62731 fscache_stat_d(&fscache_n_cop_lookup_object);
62732 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62733 if (ret == -ETIMEDOUT) {
62734 /* probably stuck behind another object, so move this one to
62735 * the back of the queue */
62736 - fscache_stat(&fscache_n_object_lookups_timed_out);
62737 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62738 _leave(" [timeout]");
62739 return NO_TRANSIT;
62740 }
62741 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62742 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62743
62744 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62745 - fscache_stat(&fscache_n_object_lookups_negative);
62746 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62747
62748 /* Allow write requests to begin stacking up and read requests to begin
62749 * returning ENODATA.
62750 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62751 /* if we were still looking up, then we must have a positive lookup
62752 * result, in which case there may be data available */
62753 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62754 - fscache_stat(&fscache_n_object_lookups_positive);
62755 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62756
62757 /* We do (presumably) have data */
62758 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62759 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62760 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62761 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62762 } else {
62763 - fscache_stat(&fscache_n_object_created);
62764 + fscache_stat_unchecked(&fscache_n_object_created);
62765 }
62766
62767 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62768 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62769 fscache_stat_d(&fscache_n_cop_lookup_complete);
62770
62771 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62772 - fscache_stat(&fscache_n_object_avail);
62773 + fscache_stat_unchecked(&fscache_n_object_avail);
62774
62775 _leave("");
62776 return transit_to(JUMPSTART_DEPS);
62777 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62778
62779 /* this just shifts the object release to the work processor */
62780 fscache_put_object(object);
62781 - fscache_stat(&fscache_n_object_dead);
62782 + fscache_stat_unchecked(&fscache_n_object_dead);
62783
62784 _leave("");
62785 return transit_to(OBJECT_DEAD);
62786 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62787 enum fscache_checkaux result;
62788
62789 if (!object->cookie->def->check_aux) {
62790 - fscache_stat(&fscache_n_checkaux_none);
62791 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62792 return FSCACHE_CHECKAUX_OKAY;
62793 }
62794
62795 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62796 switch (result) {
62797 /* entry okay as is */
62798 case FSCACHE_CHECKAUX_OKAY:
62799 - fscache_stat(&fscache_n_checkaux_okay);
62800 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62801 break;
62802
62803 /* entry requires update */
62804 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62805 - fscache_stat(&fscache_n_checkaux_update);
62806 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62807 break;
62808
62809 /* entry requires deletion */
62810 case FSCACHE_CHECKAUX_OBSOLETE:
62811 - fscache_stat(&fscache_n_checkaux_obsolete);
62812 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62813 break;
62814
62815 default:
62816 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62817 {
62818 const struct fscache_state *s;
62819
62820 - fscache_stat(&fscache_n_invalidates_run);
62821 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62822 fscache_stat(&fscache_n_cop_invalidate_object);
62823 s = _fscache_invalidate_object(object, event);
62824 fscache_stat_d(&fscache_n_cop_invalidate_object);
62825 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62826 {
62827 _enter("{OBJ%x},%d", object->debug_id, event);
62828
62829 - fscache_stat(&fscache_n_updates_run);
62830 + fscache_stat_unchecked(&fscache_n_updates_run);
62831 fscache_stat(&fscache_n_cop_update_object);
62832 object->cache->ops->update_object(object);
62833 fscache_stat_d(&fscache_n_cop_update_object);
62834 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62835 index e7b87a0..a85d47a 100644
62836 --- a/fs/fscache/operation.c
62837 +++ b/fs/fscache/operation.c
62838 @@ -17,7 +17,7 @@
62839 #include <linux/slab.h>
62840 #include "internal.h"
62841
62842 -atomic_t fscache_op_debug_id;
62843 +atomic_unchecked_t fscache_op_debug_id;
62844 EXPORT_SYMBOL(fscache_op_debug_id);
62845
62846 /**
62847 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62848 ASSERTCMP(atomic_read(&op->usage), >, 0);
62849 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62850
62851 - fscache_stat(&fscache_n_op_enqueue);
62852 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62853 switch (op->flags & FSCACHE_OP_TYPE) {
62854 case FSCACHE_OP_ASYNC:
62855 _debug("queue async");
62856 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62857 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62858 if (op->processor)
62859 fscache_enqueue_operation(op);
62860 - fscache_stat(&fscache_n_op_run);
62861 + fscache_stat_unchecked(&fscache_n_op_run);
62862 }
62863
62864 /*
62865 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62866 if (object->n_in_progress > 0) {
62867 atomic_inc(&op->usage);
62868 list_add_tail(&op->pend_link, &object->pending_ops);
62869 - fscache_stat(&fscache_n_op_pend);
62870 + fscache_stat_unchecked(&fscache_n_op_pend);
62871 } else if (!list_empty(&object->pending_ops)) {
62872 atomic_inc(&op->usage);
62873 list_add_tail(&op->pend_link, &object->pending_ops);
62874 - fscache_stat(&fscache_n_op_pend);
62875 + fscache_stat_unchecked(&fscache_n_op_pend);
62876 fscache_start_operations(object);
62877 } else {
62878 ASSERTCMP(object->n_in_progress, ==, 0);
62879 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62880 object->n_exclusive++; /* reads and writes must wait */
62881 atomic_inc(&op->usage);
62882 list_add_tail(&op->pend_link, &object->pending_ops);
62883 - fscache_stat(&fscache_n_op_pend);
62884 + fscache_stat_unchecked(&fscache_n_op_pend);
62885 ret = 0;
62886 } else {
62887 /* If we're in any other state, there must have been an I/O
62888 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62889 if (object->n_exclusive > 0) {
62890 atomic_inc(&op->usage);
62891 list_add_tail(&op->pend_link, &object->pending_ops);
62892 - fscache_stat(&fscache_n_op_pend);
62893 + fscache_stat_unchecked(&fscache_n_op_pend);
62894 } else if (!list_empty(&object->pending_ops)) {
62895 atomic_inc(&op->usage);
62896 list_add_tail(&op->pend_link, &object->pending_ops);
62897 - fscache_stat(&fscache_n_op_pend);
62898 + fscache_stat_unchecked(&fscache_n_op_pend);
62899 fscache_start_operations(object);
62900 } else {
62901 ASSERTCMP(object->n_exclusive, ==, 0);
62902 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62903 object->n_ops++;
62904 atomic_inc(&op->usage);
62905 list_add_tail(&op->pend_link, &object->pending_ops);
62906 - fscache_stat(&fscache_n_op_pend);
62907 + fscache_stat_unchecked(&fscache_n_op_pend);
62908 ret = 0;
62909 } else if (fscache_object_is_dying(object)) {
62910 - fscache_stat(&fscache_n_op_rejected);
62911 + fscache_stat_unchecked(&fscache_n_op_rejected);
62912 op->state = FSCACHE_OP_ST_CANCELLED;
62913 ret = -ENOBUFS;
62914 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62915 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62916 ret = -EBUSY;
62917 if (op->state == FSCACHE_OP_ST_PENDING) {
62918 ASSERT(!list_empty(&op->pend_link));
62919 - fscache_stat(&fscache_n_op_cancelled);
62920 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62921 list_del_init(&op->pend_link);
62922 if (do_cancel)
62923 do_cancel(op);
62924 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62925 while (!list_empty(&object->pending_ops)) {
62926 op = list_entry(object->pending_ops.next,
62927 struct fscache_operation, pend_link);
62928 - fscache_stat(&fscache_n_op_cancelled);
62929 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62930 list_del_init(&op->pend_link);
62931
62932 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62933 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62934 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62935 op->state = FSCACHE_OP_ST_DEAD;
62936
62937 - fscache_stat(&fscache_n_op_release);
62938 + fscache_stat_unchecked(&fscache_n_op_release);
62939
62940 if (op->release) {
62941 op->release(op);
62942 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62943 * lock, and defer it otherwise */
62944 if (!spin_trylock(&object->lock)) {
62945 _debug("defer put");
62946 - fscache_stat(&fscache_n_op_deferred_release);
62947 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62948
62949 cache = object->cache;
62950 spin_lock(&cache->op_gc_list_lock);
62951 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62952
62953 _debug("GC DEFERRED REL OBJ%x OP%x",
62954 object->debug_id, op->debug_id);
62955 - fscache_stat(&fscache_n_op_gc);
62956 + fscache_stat_unchecked(&fscache_n_op_gc);
62957
62958 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62959 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62960 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62961 index de33b3f..8be4d29 100644
62962 --- a/fs/fscache/page.c
62963 +++ b/fs/fscache/page.c
62964 @@ -74,7 +74,7 @@ try_again:
62965 val = radix_tree_lookup(&cookie->stores, page->index);
62966 if (!val) {
62967 rcu_read_unlock();
62968 - fscache_stat(&fscache_n_store_vmscan_not_storing);
62969 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62970 __fscache_uncache_page(cookie, page);
62971 return true;
62972 }
62973 @@ -104,11 +104,11 @@ try_again:
62974 spin_unlock(&cookie->stores_lock);
62975
62976 if (xpage) {
62977 - fscache_stat(&fscache_n_store_vmscan_cancelled);
62978 - fscache_stat(&fscache_n_store_radix_deletes);
62979 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62980 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62981 ASSERTCMP(xpage, ==, page);
62982 } else {
62983 - fscache_stat(&fscache_n_store_vmscan_gone);
62984 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62985 }
62986
62987 wake_up_bit(&cookie->flags, 0);
62988 @@ -123,11 +123,11 @@ page_busy:
62989 * sleeping on memory allocation, so we may need to impose a timeout
62990 * too. */
62991 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62992 - fscache_stat(&fscache_n_store_vmscan_busy);
62993 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62994 return false;
62995 }
62996
62997 - fscache_stat(&fscache_n_store_vmscan_wait);
62998 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62999 if (!release_page_wait_timeout(cookie, page))
63000 _debug("fscache writeout timeout page: %p{%lx}",
63001 page, page->index);
63002 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63003 FSCACHE_COOKIE_STORING_TAG);
63004 if (!radix_tree_tag_get(&cookie->stores, page->index,
63005 FSCACHE_COOKIE_PENDING_TAG)) {
63006 - fscache_stat(&fscache_n_store_radix_deletes);
63007 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63008 xpage = radix_tree_delete(&cookie->stores, page->index);
63009 }
63010 spin_unlock(&cookie->stores_lock);
63011 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63012
63013 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63014
63015 - fscache_stat(&fscache_n_attr_changed_calls);
63016 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63017
63018 if (fscache_object_is_active(object)) {
63019 fscache_stat(&fscache_n_cop_attr_changed);
63020 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63021
63022 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63023
63024 - fscache_stat(&fscache_n_attr_changed);
63025 + fscache_stat_unchecked(&fscache_n_attr_changed);
63026
63027 op = kzalloc(sizeof(*op), GFP_KERNEL);
63028 if (!op) {
63029 - fscache_stat(&fscache_n_attr_changed_nomem);
63030 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63031 _leave(" = -ENOMEM");
63032 return -ENOMEM;
63033 }
63034 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63035 if (fscache_submit_exclusive_op(object, op) < 0)
63036 goto nobufs_dec;
63037 spin_unlock(&cookie->lock);
63038 - fscache_stat(&fscache_n_attr_changed_ok);
63039 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63040 fscache_put_operation(op);
63041 _leave(" = 0");
63042 return 0;
63043 @@ -242,7 +242,7 @@ nobufs:
63044 kfree(op);
63045 if (wake_cookie)
63046 __fscache_wake_unused_cookie(cookie);
63047 - fscache_stat(&fscache_n_attr_changed_nobufs);
63048 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63049 _leave(" = %d", -ENOBUFS);
63050 return -ENOBUFS;
63051 }
63052 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63053 /* allocate a retrieval operation and attempt to submit it */
63054 op = kzalloc(sizeof(*op), GFP_NOIO);
63055 if (!op) {
63056 - fscache_stat(&fscache_n_retrievals_nomem);
63057 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63058 return NULL;
63059 }
63060
63061 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63062 return 0;
63063 }
63064
63065 - fscache_stat(&fscache_n_retrievals_wait);
63066 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63067
63068 jif = jiffies;
63069 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63070 TASK_INTERRUPTIBLE) != 0) {
63071 - fscache_stat(&fscache_n_retrievals_intr);
63072 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63073 _leave(" = -ERESTARTSYS");
63074 return -ERESTARTSYS;
63075 }
63076 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63077 */
63078 int fscache_wait_for_operation_activation(struct fscache_object *object,
63079 struct fscache_operation *op,
63080 - atomic_t *stat_op_waits,
63081 - atomic_t *stat_object_dead,
63082 + atomic_unchecked_t *stat_op_waits,
63083 + atomic_unchecked_t *stat_object_dead,
63084 void (*do_cancel)(struct fscache_operation *))
63085 {
63086 int ret;
63087 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63088
63089 _debug(">>> WT");
63090 if (stat_op_waits)
63091 - fscache_stat(stat_op_waits);
63092 + fscache_stat_unchecked(stat_op_waits);
63093 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63094 TASK_INTERRUPTIBLE) != 0) {
63095 ret = fscache_cancel_op(op, do_cancel);
63096 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63097 check_if_dead:
63098 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63099 if (stat_object_dead)
63100 - fscache_stat(stat_object_dead);
63101 + fscache_stat_unchecked(stat_object_dead);
63102 _leave(" = -ENOBUFS [cancelled]");
63103 return -ENOBUFS;
63104 }
63105 @@ -381,7 +381,7 @@ check_if_dead:
63106 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63107 fscache_cancel_op(op, do_cancel);
63108 if (stat_object_dead)
63109 - fscache_stat(stat_object_dead);
63110 + fscache_stat_unchecked(stat_object_dead);
63111 return -ENOBUFS;
63112 }
63113 return 0;
63114 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63115
63116 _enter("%p,%p,,,", cookie, page);
63117
63118 - fscache_stat(&fscache_n_retrievals);
63119 + fscache_stat_unchecked(&fscache_n_retrievals);
63120
63121 if (hlist_empty(&cookie->backing_objects))
63122 goto nobufs;
63123 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63124 goto nobufs_unlock_dec;
63125 spin_unlock(&cookie->lock);
63126
63127 - fscache_stat(&fscache_n_retrieval_ops);
63128 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63129
63130 /* pin the netfs read context in case we need to do the actual netfs
63131 * read because we've encountered a cache read failure */
63132 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63133
63134 error:
63135 if (ret == -ENOMEM)
63136 - fscache_stat(&fscache_n_retrievals_nomem);
63137 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63138 else if (ret == -ERESTARTSYS)
63139 - fscache_stat(&fscache_n_retrievals_intr);
63140 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63141 else if (ret == -ENODATA)
63142 - fscache_stat(&fscache_n_retrievals_nodata);
63143 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63144 else if (ret < 0)
63145 - fscache_stat(&fscache_n_retrievals_nobufs);
63146 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63147 else
63148 - fscache_stat(&fscache_n_retrievals_ok);
63149 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63150
63151 fscache_put_retrieval(op);
63152 _leave(" = %d", ret);
63153 @@ -505,7 +505,7 @@ nobufs_unlock:
63154 __fscache_wake_unused_cookie(cookie);
63155 kfree(op);
63156 nobufs:
63157 - fscache_stat(&fscache_n_retrievals_nobufs);
63158 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63159 _leave(" = -ENOBUFS");
63160 return -ENOBUFS;
63161 }
63162 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63163
63164 _enter("%p,,%d,,,", cookie, *nr_pages);
63165
63166 - fscache_stat(&fscache_n_retrievals);
63167 + fscache_stat_unchecked(&fscache_n_retrievals);
63168
63169 if (hlist_empty(&cookie->backing_objects))
63170 goto nobufs;
63171 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63172 goto nobufs_unlock_dec;
63173 spin_unlock(&cookie->lock);
63174
63175 - fscache_stat(&fscache_n_retrieval_ops);
63176 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63177
63178 /* pin the netfs read context in case we need to do the actual netfs
63179 * read because we've encountered a cache read failure */
63180 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63181
63182 error:
63183 if (ret == -ENOMEM)
63184 - fscache_stat(&fscache_n_retrievals_nomem);
63185 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63186 else if (ret == -ERESTARTSYS)
63187 - fscache_stat(&fscache_n_retrievals_intr);
63188 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63189 else if (ret == -ENODATA)
63190 - fscache_stat(&fscache_n_retrievals_nodata);
63191 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63192 else if (ret < 0)
63193 - fscache_stat(&fscache_n_retrievals_nobufs);
63194 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63195 else
63196 - fscache_stat(&fscache_n_retrievals_ok);
63197 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63198
63199 fscache_put_retrieval(op);
63200 _leave(" = %d", ret);
63201 @@ -636,7 +636,7 @@ nobufs_unlock:
63202 if (wake_cookie)
63203 __fscache_wake_unused_cookie(cookie);
63204 nobufs:
63205 - fscache_stat(&fscache_n_retrievals_nobufs);
63206 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63207 _leave(" = -ENOBUFS");
63208 return -ENOBUFS;
63209 }
63210 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63211
63212 _enter("%p,%p,,,", cookie, page);
63213
63214 - fscache_stat(&fscache_n_allocs);
63215 + fscache_stat_unchecked(&fscache_n_allocs);
63216
63217 if (hlist_empty(&cookie->backing_objects))
63218 goto nobufs;
63219 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63220 goto nobufs_unlock_dec;
63221 spin_unlock(&cookie->lock);
63222
63223 - fscache_stat(&fscache_n_alloc_ops);
63224 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63225
63226 ret = fscache_wait_for_operation_activation(
63227 object, &op->op,
63228 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63229
63230 error:
63231 if (ret == -ERESTARTSYS)
63232 - fscache_stat(&fscache_n_allocs_intr);
63233 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63234 else if (ret < 0)
63235 - fscache_stat(&fscache_n_allocs_nobufs);
63236 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63237 else
63238 - fscache_stat(&fscache_n_allocs_ok);
63239 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63240
63241 fscache_put_retrieval(op);
63242 _leave(" = %d", ret);
63243 @@ -730,7 +730,7 @@ nobufs_unlock:
63244 if (wake_cookie)
63245 __fscache_wake_unused_cookie(cookie);
63246 nobufs:
63247 - fscache_stat(&fscache_n_allocs_nobufs);
63248 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63249 _leave(" = -ENOBUFS");
63250 return -ENOBUFS;
63251 }
63252 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63253
63254 spin_lock(&cookie->stores_lock);
63255
63256 - fscache_stat(&fscache_n_store_calls);
63257 + fscache_stat_unchecked(&fscache_n_store_calls);
63258
63259 /* find a page to store */
63260 page = NULL;
63261 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63262 page = results[0];
63263 _debug("gang %d [%lx]", n, page->index);
63264 if (page->index > op->store_limit) {
63265 - fscache_stat(&fscache_n_store_pages_over_limit);
63266 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63267 goto superseded;
63268 }
63269
63270 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63271 spin_unlock(&cookie->stores_lock);
63272 spin_unlock(&object->lock);
63273
63274 - fscache_stat(&fscache_n_store_pages);
63275 + fscache_stat_unchecked(&fscache_n_store_pages);
63276 fscache_stat(&fscache_n_cop_write_page);
63277 ret = object->cache->ops->write_page(op, page);
63278 fscache_stat_d(&fscache_n_cop_write_page);
63279 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63280 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63281 ASSERT(PageFsCache(page));
63282
63283 - fscache_stat(&fscache_n_stores);
63284 + fscache_stat_unchecked(&fscache_n_stores);
63285
63286 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63287 _leave(" = -ENOBUFS [invalidating]");
63288 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63289 spin_unlock(&cookie->stores_lock);
63290 spin_unlock(&object->lock);
63291
63292 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63293 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63294 op->store_limit = object->store_limit;
63295
63296 __fscache_use_cookie(cookie);
63297 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63298
63299 spin_unlock(&cookie->lock);
63300 radix_tree_preload_end();
63301 - fscache_stat(&fscache_n_store_ops);
63302 - fscache_stat(&fscache_n_stores_ok);
63303 + fscache_stat_unchecked(&fscache_n_store_ops);
63304 + fscache_stat_unchecked(&fscache_n_stores_ok);
63305
63306 /* the work queue now carries its own ref on the object */
63307 fscache_put_operation(&op->op);
63308 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63309 return 0;
63310
63311 already_queued:
63312 - fscache_stat(&fscache_n_stores_again);
63313 + fscache_stat_unchecked(&fscache_n_stores_again);
63314 already_pending:
63315 spin_unlock(&cookie->stores_lock);
63316 spin_unlock(&object->lock);
63317 spin_unlock(&cookie->lock);
63318 radix_tree_preload_end();
63319 kfree(op);
63320 - fscache_stat(&fscache_n_stores_ok);
63321 + fscache_stat_unchecked(&fscache_n_stores_ok);
63322 _leave(" = 0");
63323 return 0;
63324
63325 @@ -1039,14 +1039,14 @@ nobufs:
63326 kfree(op);
63327 if (wake_cookie)
63328 __fscache_wake_unused_cookie(cookie);
63329 - fscache_stat(&fscache_n_stores_nobufs);
63330 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63331 _leave(" = -ENOBUFS");
63332 return -ENOBUFS;
63333
63334 nomem_free:
63335 kfree(op);
63336 nomem:
63337 - fscache_stat(&fscache_n_stores_oom);
63338 + fscache_stat_unchecked(&fscache_n_stores_oom);
63339 _leave(" = -ENOMEM");
63340 return -ENOMEM;
63341 }
63342 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63343 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63344 ASSERTCMP(page, !=, NULL);
63345
63346 - fscache_stat(&fscache_n_uncaches);
63347 + fscache_stat_unchecked(&fscache_n_uncaches);
63348
63349 /* cache withdrawal may beat us to it */
63350 if (!PageFsCache(page))
63351 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63352 struct fscache_cookie *cookie = op->op.object->cookie;
63353
63354 #ifdef CONFIG_FSCACHE_STATS
63355 - atomic_inc(&fscache_n_marks);
63356 + atomic_inc_unchecked(&fscache_n_marks);
63357 #endif
63358
63359 _debug("- mark %p{%lx}", page, page->index);
63360 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63361 index 40d13c7..ddf52b9 100644
63362 --- a/fs/fscache/stats.c
63363 +++ b/fs/fscache/stats.c
63364 @@ -18,99 +18,99 @@
63365 /*
63366 * operation counters
63367 */
63368 -atomic_t fscache_n_op_pend;
63369 -atomic_t fscache_n_op_run;
63370 -atomic_t fscache_n_op_enqueue;
63371 -atomic_t fscache_n_op_requeue;
63372 -atomic_t fscache_n_op_deferred_release;
63373 -atomic_t fscache_n_op_release;
63374 -atomic_t fscache_n_op_gc;
63375 -atomic_t fscache_n_op_cancelled;
63376 -atomic_t fscache_n_op_rejected;
63377 +atomic_unchecked_t fscache_n_op_pend;
63378 +atomic_unchecked_t fscache_n_op_run;
63379 +atomic_unchecked_t fscache_n_op_enqueue;
63380 +atomic_unchecked_t fscache_n_op_requeue;
63381 +atomic_unchecked_t fscache_n_op_deferred_release;
63382 +atomic_unchecked_t fscache_n_op_release;
63383 +atomic_unchecked_t fscache_n_op_gc;
63384 +atomic_unchecked_t fscache_n_op_cancelled;
63385 +atomic_unchecked_t fscache_n_op_rejected;
63386
63387 -atomic_t fscache_n_attr_changed;
63388 -atomic_t fscache_n_attr_changed_ok;
63389 -atomic_t fscache_n_attr_changed_nobufs;
63390 -atomic_t fscache_n_attr_changed_nomem;
63391 -atomic_t fscache_n_attr_changed_calls;
63392 +atomic_unchecked_t fscache_n_attr_changed;
63393 +atomic_unchecked_t fscache_n_attr_changed_ok;
63394 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63395 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63396 +atomic_unchecked_t fscache_n_attr_changed_calls;
63397
63398 -atomic_t fscache_n_allocs;
63399 -atomic_t fscache_n_allocs_ok;
63400 -atomic_t fscache_n_allocs_wait;
63401 -atomic_t fscache_n_allocs_nobufs;
63402 -atomic_t fscache_n_allocs_intr;
63403 -atomic_t fscache_n_allocs_object_dead;
63404 -atomic_t fscache_n_alloc_ops;
63405 -atomic_t fscache_n_alloc_op_waits;
63406 +atomic_unchecked_t fscache_n_allocs;
63407 +atomic_unchecked_t fscache_n_allocs_ok;
63408 +atomic_unchecked_t fscache_n_allocs_wait;
63409 +atomic_unchecked_t fscache_n_allocs_nobufs;
63410 +atomic_unchecked_t fscache_n_allocs_intr;
63411 +atomic_unchecked_t fscache_n_allocs_object_dead;
63412 +atomic_unchecked_t fscache_n_alloc_ops;
63413 +atomic_unchecked_t fscache_n_alloc_op_waits;
63414
63415 -atomic_t fscache_n_retrievals;
63416 -atomic_t fscache_n_retrievals_ok;
63417 -atomic_t fscache_n_retrievals_wait;
63418 -atomic_t fscache_n_retrievals_nodata;
63419 -atomic_t fscache_n_retrievals_nobufs;
63420 -atomic_t fscache_n_retrievals_intr;
63421 -atomic_t fscache_n_retrievals_nomem;
63422 -atomic_t fscache_n_retrievals_object_dead;
63423 -atomic_t fscache_n_retrieval_ops;
63424 -atomic_t fscache_n_retrieval_op_waits;
63425 +atomic_unchecked_t fscache_n_retrievals;
63426 +atomic_unchecked_t fscache_n_retrievals_ok;
63427 +atomic_unchecked_t fscache_n_retrievals_wait;
63428 +atomic_unchecked_t fscache_n_retrievals_nodata;
63429 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63430 +atomic_unchecked_t fscache_n_retrievals_intr;
63431 +atomic_unchecked_t fscache_n_retrievals_nomem;
63432 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63433 +atomic_unchecked_t fscache_n_retrieval_ops;
63434 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63435
63436 -atomic_t fscache_n_stores;
63437 -atomic_t fscache_n_stores_ok;
63438 -atomic_t fscache_n_stores_again;
63439 -atomic_t fscache_n_stores_nobufs;
63440 -atomic_t fscache_n_stores_oom;
63441 -atomic_t fscache_n_store_ops;
63442 -atomic_t fscache_n_store_calls;
63443 -atomic_t fscache_n_store_pages;
63444 -atomic_t fscache_n_store_radix_deletes;
63445 -atomic_t fscache_n_store_pages_over_limit;
63446 +atomic_unchecked_t fscache_n_stores;
63447 +atomic_unchecked_t fscache_n_stores_ok;
63448 +atomic_unchecked_t fscache_n_stores_again;
63449 +atomic_unchecked_t fscache_n_stores_nobufs;
63450 +atomic_unchecked_t fscache_n_stores_oom;
63451 +atomic_unchecked_t fscache_n_store_ops;
63452 +atomic_unchecked_t fscache_n_store_calls;
63453 +atomic_unchecked_t fscache_n_store_pages;
63454 +atomic_unchecked_t fscache_n_store_radix_deletes;
63455 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63456
63457 -atomic_t fscache_n_store_vmscan_not_storing;
63458 -atomic_t fscache_n_store_vmscan_gone;
63459 -atomic_t fscache_n_store_vmscan_busy;
63460 -atomic_t fscache_n_store_vmscan_cancelled;
63461 -atomic_t fscache_n_store_vmscan_wait;
63462 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63463 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63464 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63465 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63466 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63467
63468 -atomic_t fscache_n_marks;
63469 -atomic_t fscache_n_uncaches;
63470 +atomic_unchecked_t fscache_n_marks;
63471 +atomic_unchecked_t fscache_n_uncaches;
63472
63473 -atomic_t fscache_n_acquires;
63474 -atomic_t fscache_n_acquires_null;
63475 -atomic_t fscache_n_acquires_no_cache;
63476 -atomic_t fscache_n_acquires_ok;
63477 -atomic_t fscache_n_acquires_nobufs;
63478 -atomic_t fscache_n_acquires_oom;
63479 +atomic_unchecked_t fscache_n_acquires;
63480 +atomic_unchecked_t fscache_n_acquires_null;
63481 +atomic_unchecked_t fscache_n_acquires_no_cache;
63482 +atomic_unchecked_t fscache_n_acquires_ok;
63483 +atomic_unchecked_t fscache_n_acquires_nobufs;
63484 +atomic_unchecked_t fscache_n_acquires_oom;
63485
63486 -atomic_t fscache_n_invalidates;
63487 -atomic_t fscache_n_invalidates_run;
63488 +atomic_unchecked_t fscache_n_invalidates;
63489 +atomic_unchecked_t fscache_n_invalidates_run;
63490
63491 -atomic_t fscache_n_updates;
63492 -atomic_t fscache_n_updates_null;
63493 -atomic_t fscache_n_updates_run;
63494 +atomic_unchecked_t fscache_n_updates;
63495 +atomic_unchecked_t fscache_n_updates_null;
63496 +atomic_unchecked_t fscache_n_updates_run;
63497
63498 -atomic_t fscache_n_relinquishes;
63499 -atomic_t fscache_n_relinquishes_null;
63500 -atomic_t fscache_n_relinquishes_waitcrt;
63501 -atomic_t fscache_n_relinquishes_retire;
63502 +atomic_unchecked_t fscache_n_relinquishes;
63503 +atomic_unchecked_t fscache_n_relinquishes_null;
63504 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63505 +atomic_unchecked_t fscache_n_relinquishes_retire;
63506
63507 -atomic_t fscache_n_cookie_index;
63508 -atomic_t fscache_n_cookie_data;
63509 -atomic_t fscache_n_cookie_special;
63510 +atomic_unchecked_t fscache_n_cookie_index;
63511 +atomic_unchecked_t fscache_n_cookie_data;
63512 +atomic_unchecked_t fscache_n_cookie_special;
63513
63514 -atomic_t fscache_n_object_alloc;
63515 -atomic_t fscache_n_object_no_alloc;
63516 -atomic_t fscache_n_object_lookups;
63517 -atomic_t fscache_n_object_lookups_negative;
63518 -atomic_t fscache_n_object_lookups_positive;
63519 -atomic_t fscache_n_object_lookups_timed_out;
63520 -atomic_t fscache_n_object_created;
63521 -atomic_t fscache_n_object_avail;
63522 -atomic_t fscache_n_object_dead;
63523 +atomic_unchecked_t fscache_n_object_alloc;
63524 +atomic_unchecked_t fscache_n_object_no_alloc;
63525 +atomic_unchecked_t fscache_n_object_lookups;
63526 +atomic_unchecked_t fscache_n_object_lookups_negative;
63527 +atomic_unchecked_t fscache_n_object_lookups_positive;
63528 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63529 +atomic_unchecked_t fscache_n_object_created;
63530 +atomic_unchecked_t fscache_n_object_avail;
63531 +atomic_unchecked_t fscache_n_object_dead;
63532
63533 -atomic_t fscache_n_checkaux_none;
63534 -atomic_t fscache_n_checkaux_okay;
63535 -atomic_t fscache_n_checkaux_update;
63536 -atomic_t fscache_n_checkaux_obsolete;
63537 +atomic_unchecked_t fscache_n_checkaux_none;
63538 +atomic_unchecked_t fscache_n_checkaux_okay;
63539 +atomic_unchecked_t fscache_n_checkaux_update;
63540 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63541
63542 atomic_t fscache_n_cop_alloc_object;
63543 atomic_t fscache_n_cop_lookup_object;
63544 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63545 seq_puts(m, "FS-Cache statistics\n");
63546
63547 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63548 - atomic_read(&fscache_n_cookie_index),
63549 - atomic_read(&fscache_n_cookie_data),
63550 - atomic_read(&fscache_n_cookie_special));
63551 + atomic_read_unchecked(&fscache_n_cookie_index),
63552 + atomic_read_unchecked(&fscache_n_cookie_data),
63553 + atomic_read_unchecked(&fscache_n_cookie_special));
63554
63555 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63556 - atomic_read(&fscache_n_object_alloc),
63557 - atomic_read(&fscache_n_object_no_alloc),
63558 - atomic_read(&fscache_n_object_avail),
63559 - atomic_read(&fscache_n_object_dead));
63560 + atomic_read_unchecked(&fscache_n_object_alloc),
63561 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63562 + atomic_read_unchecked(&fscache_n_object_avail),
63563 + atomic_read_unchecked(&fscache_n_object_dead));
63564 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63565 - atomic_read(&fscache_n_checkaux_none),
63566 - atomic_read(&fscache_n_checkaux_okay),
63567 - atomic_read(&fscache_n_checkaux_update),
63568 - atomic_read(&fscache_n_checkaux_obsolete));
63569 + atomic_read_unchecked(&fscache_n_checkaux_none),
63570 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63571 + atomic_read_unchecked(&fscache_n_checkaux_update),
63572 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63573
63574 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63575 - atomic_read(&fscache_n_marks),
63576 - atomic_read(&fscache_n_uncaches));
63577 + atomic_read_unchecked(&fscache_n_marks),
63578 + atomic_read_unchecked(&fscache_n_uncaches));
63579
63580 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63581 " oom=%u\n",
63582 - atomic_read(&fscache_n_acquires),
63583 - atomic_read(&fscache_n_acquires_null),
63584 - atomic_read(&fscache_n_acquires_no_cache),
63585 - atomic_read(&fscache_n_acquires_ok),
63586 - atomic_read(&fscache_n_acquires_nobufs),
63587 - atomic_read(&fscache_n_acquires_oom));
63588 + atomic_read_unchecked(&fscache_n_acquires),
63589 + atomic_read_unchecked(&fscache_n_acquires_null),
63590 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63591 + atomic_read_unchecked(&fscache_n_acquires_ok),
63592 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63593 + atomic_read_unchecked(&fscache_n_acquires_oom));
63594
63595 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63596 - atomic_read(&fscache_n_object_lookups),
63597 - atomic_read(&fscache_n_object_lookups_negative),
63598 - atomic_read(&fscache_n_object_lookups_positive),
63599 - atomic_read(&fscache_n_object_created),
63600 - atomic_read(&fscache_n_object_lookups_timed_out));
63601 + atomic_read_unchecked(&fscache_n_object_lookups),
63602 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63603 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63604 + atomic_read_unchecked(&fscache_n_object_created),
63605 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63606
63607 seq_printf(m, "Invals : n=%u run=%u\n",
63608 - atomic_read(&fscache_n_invalidates),
63609 - atomic_read(&fscache_n_invalidates_run));
63610 + atomic_read_unchecked(&fscache_n_invalidates),
63611 + atomic_read_unchecked(&fscache_n_invalidates_run));
63612
63613 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63614 - atomic_read(&fscache_n_updates),
63615 - atomic_read(&fscache_n_updates_null),
63616 - atomic_read(&fscache_n_updates_run));
63617 + atomic_read_unchecked(&fscache_n_updates),
63618 + atomic_read_unchecked(&fscache_n_updates_null),
63619 + atomic_read_unchecked(&fscache_n_updates_run));
63620
63621 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63622 - atomic_read(&fscache_n_relinquishes),
63623 - atomic_read(&fscache_n_relinquishes_null),
63624 - atomic_read(&fscache_n_relinquishes_waitcrt),
63625 - atomic_read(&fscache_n_relinquishes_retire));
63626 + atomic_read_unchecked(&fscache_n_relinquishes),
63627 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63628 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63629 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63630
63631 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63632 - atomic_read(&fscache_n_attr_changed),
63633 - atomic_read(&fscache_n_attr_changed_ok),
63634 - atomic_read(&fscache_n_attr_changed_nobufs),
63635 - atomic_read(&fscache_n_attr_changed_nomem),
63636 - atomic_read(&fscache_n_attr_changed_calls));
63637 + atomic_read_unchecked(&fscache_n_attr_changed),
63638 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63639 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63640 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63641 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63642
63643 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63644 - atomic_read(&fscache_n_allocs),
63645 - atomic_read(&fscache_n_allocs_ok),
63646 - atomic_read(&fscache_n_allocs_wait),
63647 - atomic_read(&fscache_n_allocs_nobufs),
63648 - atomic_read(&fscache_n_allocs_intr));
63649 + atomic_read_unchecked(&fscache_n_allocs),
63650 + atomic_read_unchecked(&fscache_n_allocs_ok),
63651 + atomic_read_unchecked(&fscache_n_allocs_wait),
63652 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63653 + atomic_read_unchecked(&fscache_n_allocs_intr));
63654 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63655 - atomic_read(&fscache_n_alloc_ops),
63656 - atomic_read(&fscache_n_alloc_op_waits),
63657 - atomic_read(&fscache_n_allocs_object_dead));
63658 + atomic_read_unchecked(&fscache_n_alloc_ops),
63659 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63660 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63661
63662 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63663 " int=%u oom=%u\n",
63664 - atomic_read(&fscache_n_retrievals),
63665 - atomic_read(&fscache_n_retrievals_ok),
63666 - atomic_read(&fscache_n_retrievals_wait),
63667 - atomic_read(&fscache_n_retrievals_nodata),
63668 - atomic_read(&fscache_n_retrievals_nobufs),
63669 - atomic_read(&fscache_n_retrievals_intr),
63670 - atomic_read(&fscache_n_retrievals_nomem));
63671 + atomic_read_unchecked(&fscache_n_retrievals),
63672 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63673 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63674 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63675 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63676 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63677 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63678 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63679 - atomic_read(&fscache_n_retrieval_ops),
63680 - atomic_read(&fscache_n_retrieval_op_waits),
63681 - atomic_read(&fscache_n_retrievals_object_dead));
63682 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63683 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63684 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63685
63686 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63687 - atomic_read(&fscache_n_stores),
63688 - atomic_read(&fscache_n_stores_ok),
63689 - atomic_read(&fscache_n_stores_again),
63690 - atomic_read(&fscache_n_stores_nobufs),
63691 - atomic_read(&fscache_n_stores_oom));
63692 + atomic_read_unchecked(&fscache_n_stores),
63693 + atomic_read_unchecked(&fscache_n_stores_ok),
63694 + atomic_read_unchecked(&fscache_n_stores_again),
63695 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63696 + atomic_read_unchecked(&fscache_n_stores_oom));
63697 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63698 - atomic_read(&fscache_n_store_ops),
63699 - atomic_read(&fscache_n_store_calls),
63700 - atomic_read(&fscache_n_store_pages),
63701 - atomic_read(&fscache_n_store_radix_deletes),
63702 - atomic_read(&fscache_n_store_pages_over_limit));
63703 + atomic_read_unchecked(&fscache_n_store_ops),
63704 + atomic_read_unchecked(&fscache_n_store_calls),
63705 + atomic_read_unchecked(&fscache_n_store_pages),
63706 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63707 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63708
63709 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63710 - atomic_read(&fscache_n_store_vmscan_not_storing),
63711 - atomic_read(&fscache_n_store_vmscan_gone),
63712 - atomic_read(&fscache_n_store_vmscan_busy),
63713 - atomic_read(&fscache_n_store_vmscan_cancelled),
63714 - atomic_read(&fscache_n_store_vmscan_wait));
63715 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63716 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63717 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63718 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63719 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63720
63721 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63722 - atomic_read(&fscache_n_op_pend),
63723 - atomic_read(&fscache_n_op_run),
63724 - atomic_read(&fscache_n_op_enqueue),
63725 - atomic_read(&fscache_n_op_cancelled),
63726 - atomic_read(&fscache_n_op_rejected));
63727 + atomic_read_unchecked(&fscache_n_op_pend),
63728 + atomic_read_unchecked(&fscache_n_op_run),
63729 + atomic_read_unchecked(&fscache_n_op_enqueue),
63730 + atomic_read_unchecked(&fscache_n_op_cancelled),
63731 + atomic_read_unchecked(&fscache_n_op_rejected));
63732 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63733 - atomic_read(&fscache_n_op_deferred_release),
63734 - atomic_read(&fscache_n_op_release),
63735 - atomic_read(&fscache_n_op_gc));
63736 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63737 + atomic_read_unchecked(&fscache_n_op_release),
63738 + atomic_read_unchecked(&fscache_n_op_gc));
63739
63740 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63741 atomic_read(&fscache_n_cop_alloc_object),
63742 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63743 index 966ace8..030a03a 100644
63744 --- a/fs/fuse/cuse.c
63745 +++ b/fs/fuse/cuse.c
63746 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63747 INIT_LIST_HEAD(&cuse_conntbl[i]);
63748
63749 /* inherit and extend fuse_dev_operations */
63750 - cuse_channel_fops = fuse_dev_operations;
63751 - cuse_channel_fops.owner = THIS_MODULE;
63752 - cuse_channel_fops.open = cuse_channel_open;
63753 - cuse_channel_fops.release = cuse_channel_release;
63754 + pax_open_kernel();
63755 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63756 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63757 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63758 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63759 + pax_close_kernel();
63760
63761 cuse_class = class_create(THIS_MODULE, "cuse");
63762 if (IS_ERR(cuse_class))
63763 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63764 index ca88731..8e9c55d 100644
63765 --- a/fs/fuse/dev.c
63766 +++ b/fs/fuse/dev.c
63767 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63768 ret = 0;
63769 pipe_lock(pipe);
63770
63771 - if (!pipe->readers) {
63772 + if (!atomic_read(&pipe->readers)) {
63773 send_sig(SIGPIPE, current, 0);
63774 if (!ret)
63775 ret = -EPIPE;
63776 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63777 page_nr++;
63778 ret += buf->len;
63779
63780 - if (pipe->files)
63781 + if (atomic_read(&pipe->files))
63782 do_wakeup = 1;
63783 }
63784
63785 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63786 index dbab798..fefa22b 100644
63787 --- a/fs/fuse/dir.c
63788 +++ b/fs/fuse/dir.c
63789 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63790 return link;
63791 }
63792
63793 -static void free_link(char *link)
63794 +static void free_link(const char *link)
63795 {
63796 if (!IS_ERR(link))
63797 free_page((unsigned long) link);
63798 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63799 index fd62cae..3494dfa 100644
63800 --- a/fs/hostfs/hostfs_kern.c
63801 +++ b/fs/hostfs/hostfs_kern.c
63802 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63803
63804 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63805 {
63806 - char *s = nd_get_link(nd);
63807 + const char *s = nd_get_link(nd);
63808 if (!IS_ERR(s))
63809 __putname(s);
63810 }
63811 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63812 index 1e2872b..7aea000 100644
63813 --- a/fs/hugetlbfs/inode.c
63814 +++ b/fs/hugetlbfs/inode.c
63815 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63816 struct mm_struct *mm = current->mm;
63817 struct vm_area_struct *vma;
63818 struct hstate *h = hstate_file(file);
63819 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63820 struct vm_unmapped_area_info info;
63821
63822 if (len & ~huge_page_mask(h))
63823 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63824 return addr;
63825 }
63826
63827 +#ifdef CONFIG_PAX_RANDMMAP
63828 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63829 +#endif
63830 +
63831 if (addr) {
63832 addr = ALIGN(addr, huge_page_size(h));
63833 vma = find_vma(mm, addr);
63834 - if (TASK_SIZE - len >= addr &&
63835 - (!vma || addr + len <= vma->vm_start))
63836 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63837 return addr;
63838 }
63839
63840 info.flags = 0;
63841 info.length = len;
63842 info.low_limit = TASK_UNMAPPED_BASE;
63843 +
63844 +#ifdef CONFIG_PAX_RANDMMAP
63845 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63846 + info.low_limit += mm->delta_mmap;
63847 +#endif
63848 +
63849 info.high_limit = TASK_SIZE;
63850 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63851 info.align_offset = 0;
63852 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63853 };
63854 MODULE_ALIAS_FS("hugetlbfs");
63855
63856 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63857 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63858
63859 static int can_do_hugetlb_shm(void)
63860 {
63861 diff --git a/fs/inode.c b/fs/inode.c
63862 index 26753ba..d19eb34 100644
63863 --- a/fs/inode.c
63864 +++ b/fs/inode.c
63865 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63866 unsigned int *p = &get_cpu_var(last_ino);
63867 unsigned int res = *p;
63868
63869 +start:
63870 +
63871 #ifdef CONFIG_SMP
63872 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63873 - static atomic_t shared_last_ino;
63874 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63875 + static atomic_unchecked_t shared_last_ino;
63876 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63877
63878 res = next - LAST_INO_BATCH;
63879 }
63880 #endif
63881
63882 - *p = ++res;
63883 + if (unlikely(!++res))
63884 + goto start; /* never zero */
63885 + *p = res;
63886 put_cpu_var(last_ino);
63887 return res;
63888 }
63889 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63890 index 4a6cf28..d3a29d3 100644
63891 --- a/fs/jffs2/erase.c
63892 +++ b/fs/jffs2/erase.c
63893 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63894 struct jffs2_unknown_node marker = {
63895 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63896 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63897 - .totlen = cpu_to_je32(c->cleanmarker_size)
63898 + .totlen = cpu_to_je32(c->cleanmarker_size),
63899 + .hdr_crc = cpu_to_je32(0)
63900 };
63901
63902 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63903 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63904 index 09ed551..45684f8 100644
63905 --- a/fs/jffs2/wbuf.c
63906 +++ b/fs/jffs2/wbuf.c
63907 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63908 {
63909 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63910 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63911 - .totlen = constant_cpu_to_je32(8)
63912 + .totlen = constant_cpu_to_je32(8),
63913 + .hdr_crc = constant_cpu_to_je32(0)
63914 };
63915
63916 /*
63917 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63918 index 93e897e..a863de4 100644
63919 --- a/fs/jfs/super.c
63920 +++ b/fs/jfs/super.c
63921 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63922
63923 jfs_inode_cachep =
63924 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63925 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63926 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63927 init_once);
63928 if (jfs_inode_cachep == NULL)
63929 return -ENOMEM;
63930 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63931 index 1c77193..ba73e66 100644
63932 --- a/fs/kernfs/dir.c
63933 +++ b/fs/kernfs/dir.c
63934 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63935 *
63936 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63937 */
63938 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63939 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63940 {
63941 unsigned long hash = init_name_hash();
63942 unsigned int len = strlen(name);
63943 @@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63944 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63945
63946 kernfs_put_active(parent);
63947 +
63948 + if (!ret) {
63949 + struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
63950 + ret = PTR_ERR_OR_ZERO(dentry_ret);
63951 + }
63952 +
63953 return ret;
63954 }
63955
63956 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63957 index 4429d6d..9831f52 100644
63958 --- a/fs/kernfs/file.c
63959 +++ b/fs/kernfs/file.c
63960 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63961
63962 struct kernfs_open_node {
63963 atomic_t refcnt;
63964 - atomic_t event;
63965 + atomic_unchecked_t event;
63966 wait_queue_head_t poll;
63967 struct list_head files; /* goes through kernfs_open_file.list */
63968 };
63969 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63970 {
63971 struct kernfs_open_file *of = sf->private;
63972
63973 - of->event = atomic_read(&of->kn->attr.open->event);
63974 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63975
63976 return of->kn->attr.ops->seq_show(sf, v);
63977 }
63978 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63979 return ret;
63980 }
63981
63982 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63983 - void *buf, int len, int write)
63984 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63985 + void *buf, size_t len, int write)
63986 {
63987 struct file *file = vma->vm_file;
63988 struct kernfs_open_file *of = kernfs_of(file);
63989 - int ret;
63990 + ssize_t ret;
63991
63992 if (!of->vm_ops)
63993 return -EINVAL;
63994 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63995 return -ENOMEM;
63996
63997 atomic_set(&new_on->refcnt, 0);
63998 - atomic_set(&new_on->event, 1);
63999 + atomic_set_unchecked(&new_on->event, 1);
64000 init_waitqueue_head(&new_on->poll);
64001 INIT_LIST_HEAD(&new_on->files);
64002 goto retry;
64003 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64004
64005 kernfs_put_active(kn);
64006
64007 - if (of->event != atomic_read(&on->event))
64008 + if (of->event != atomic_read_unchecked(&on->event))
64009 goto trigger;
64010
64011 return DEFAULT_POLLMASK;
64012 @@ -818,7 +818,7 @@ repeat:
64013
64014 on = kn->attr.open;
64015 if (on) {
64016 - atomic_inc(&on->event);
64017 + atomic_inc_unchecked(&on->event);
64018 wake_up_interruptible(&on->poll);
64019 }
64020
64021 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64022 index 8a19889..4c3069a 100644
64023 --- a/fs/kernfs/symlink.c
64024 +++ b/fs/kernfs/symlink.c
64025 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64026 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64027 void *cookie)
64028 {
64029 - char *page = nd_get_link(nd);
64030 + const char *page = nd_get_link(nd);
64031 if (!IS_ERR(page))
64032 free_page((unsigned long)page);
64033 }
64034 diff --git a/fs/libfs.c b/fs/libfs.c
64035 index 005843c..06c4191 100644
64036 --- a/fs/libfs.c
64037 +++ b/fs/libfs.c
64038 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64039
64040 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64041 struct dentry *next = list_entry(p, struct dentry, d_child);
64042 + char d_name[sizeof(next->d_iname)];
64043 + const unsigned char *name;
64044 +
64045 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64046 if (!simple_positive(next)) {
64047 spin_unlock(&next->d_lock);
64048 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64049
64050 spin_unlock(&next->d_lock);
64051 spin_unlock(&dentry->d_lock);
64052 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64053 + name = next->d_name.name;
64054 + if (name == next->d_iname) {
64055 + memcpy(d_name, name, next->d_name.len);
64056 + name = d_name;
64057 + }
64058 + if (!dir_emit(ctx, name, next->d_name.len,
64059 next->d_inode->i_ino, dt_type(next->d_inode)))
64060 return 0;
64061 spin_lock(&dentry->d_lock);
64062 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64063 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64064 void *cookie)
64065 {
64066 - char *s = nd_get_link(nd);
64067 + const char *s = nd_get_link(nd);
64068 if (!IS_ERR(s))
64069 kfree(s);
64070 }
64071 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64072 index acd3947..1f896e2 100644
64073 --- a/fs/lockd/clntproc.c
64074 +++ b/fs/lockd/clntproc.c
64075 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64076 /*
64077 * Cookie counter for NLM requests
64078 */
64079 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64080 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64081
64082 void nlmclnt_next_cookie(struct nlm_cookie *c)
64083 {
64084 - u32 cookie = atomic_inc_return(&nlm_cookie);
64085 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64086
64087 memcpy(c->data, &cookie, 4);
64088 c->len=4;
64089 diff --git a/fs/locks.c b/fs/locks.c
64090 index 59e2f90..bd69071 100644
64091 --- a/fs/locks.c
64092 +++ b/fs/locks.c
64093 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
64094 locks_remove_posix(filp, filp);
64095
64096 if (filp->f_op->flock) {
64097 - struct file_lock fl = {
64098 + struct file_lock flock = {
64099 .fl_owner = filp,
64100 .fl_pid = current->tgid,
64101 .fl_file = filp,
64102 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
64103 .fl_type = F_UNLCK,
64104 .fl_end = OFFSET_MAX,
64105 };
64106 - filp->f_op->flock(filp, F_SETLKW, &fl);
64107 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64108 - fl.fl_ops->fl_release_private(&fl);
64109 + filp->f_op->flock(filp, F_SETLKW, &flock);
64110 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64111 + flock.fl_ops->fl_release_private(&flock);
64112 }
64113
64114 spin_lock(&inode->i_lock);
64115 diff --git a/fs/mount.h b/fs/mount.h
64116 index f82c628..9492b99 100644
64117 --- a/fs/mount.h
64118 +++ b/fs/mount.h
64119 @@ -11,7 +11,7 @@ struct mnt_namespace {
64120 u64 seq; /* Sequence number to prevent loops */
64121 wait_queue_head_t poll;
64122 u64 event;
64123 -};
64124 +} __randomize_layout;
64125
64126 struct mnt_pcp {
64127 int mnt_count;
64128 @@ -62,7 +62,7 @@ struct mount {
64129 int mnt_expiry_mark; /* true if marked for expiry */
64130 struct hlist_head mnt_pins;
64131 struct path mnt_ex_mountpoint;
64132 -};
64133 +} __randomize_layout;
64134
64135 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64136
64137 diff --git a/fs/namei.c b/fs/namei.c
64138 index db5fe86..ac769e4 100644
64139 --- a/fs/namei.c
64140 +++ b/fs/namei.c
64141 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64142 if (ret != -EACCES)
64143 return ret;
64144
64145 +#ifdef CONFIG_GRKERNSEC
64146 + /* we'll block if we have to log due to a denied capability use */
64147 + if (mask & MAY_NOT_BLOCK)
64148 + return -ECHILD;
64149 +#endif
64150 +
64151 if (S_ISDIR(inode->i_mode)) {
64152 /* DACs are overridable for directories */
64153 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64154 - return 0;
64155 if (!(mask & MAY_WRITE))
64156 - if (capable_wrt_inode_uidgid(inode,
64157 - CAP_DAC_READ_SEARCH))
64158 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64159 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64160 return 0;
64161 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64162 + return 0;
64163 return -EACCES;
64164 }
64165 /*
64166 + * Searching includes executable on directories, else just read.
64167 + */
64168 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64169 + if (mask == MAY_READ)
64170 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64171 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64172 + return 0;
64173 +
64174 + /*
64175 * Read/write DACs are always overridable.
64176 * Executable DACs are overridable when there is
64177 * at least one exec bit set.
64178 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64179 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64180 return 0;
64181
64182 - /*
64183 - * Searching includes executable on directories, else just read.
64184 - */
64185 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64186 - if (mask == MAY_READ)
64187 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64188 - return 0;
64189 -
64190 return -EACCES;
64191 }
64192 EXPORT_SYMBOL(generic_permission);
64193 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64194 {
64195 struct dentry *dentry = link->dentry;
64196 int error;
64197 - char *s;
64198 + const char *s;
64199
64200 BUG_ON(nd->flags & LOOKUP_RCU);
64201
64202 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64203 if (error)
64204 goto out_put_nd_path;
64205
64206 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64207 + dentry->d_inode, dentry, nd->path.mnt)) {
64208 + error = -EACCES;
64209 + goto out_put_nd_path;
64210 + }
64211 +
64212 nd->last_type = LAST_BIND;
64213 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64214 error = PTR_ERR(*p);
64215 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64216 if (res)
64217 break;
64218 res = walk_component(nd, path, LOOKUP_FOLLOW);
64219 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64220 + res = -EACCES;
64221 put_link(nd, &link, cookie);
64222 } while (res > 0);
64223
64224 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
64225 static inline u64 hash_name(const char *name)
64226 {
64227 unsigned long a, b, adata, bdata, mask, hash, len;
64228 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64229 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64230
64231 hash = a = 0;
64232 len = -sizeof(unsigned long);
64233 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
64234 if (err)
64235 break;
64236 err = lookup_last(nd, &path);
64237 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64238 + err = -EACCES;
64239 put_link(nd, &link, cookie);
64240 }
64241 }
64242 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
64243 if (!err)
64244 err = complete_walk(nd);
64245
64246 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64247 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64248 + path_put(&nd->path);
64249 + err = -ENOENT;
64250 + }
64251 + }
64252 +
64253 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64254 if (!d_can_lookup(nd->path.dentry)) {
64255 path_put(&nd->path);
64256 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
64257 retval = path_lookupat(dfd, name->name,
64258 flags | LOOKUP_REVAL, nd);
64259
64260 - if (likely(!retval))
64261 + if (likely(!retval)) {
64262 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64263 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64264 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64265 + path_put(&nd->path);
64266 + return -ENOENT;
64267 + }
64268 + }
64269 + }
64270 return retval;
64271 }
64272
64273 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64274 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64275 return -EPERM;
64276
64277 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64278 + return -EPERM;
64279 + if (gr_handle_rawio(inode))
64280 + return -EPERM;
64281 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64282 + return -EACCES;
64283 +
64284 return 0;
64285 }
64286
64287 @@ -2813,7 +2851,7 @@ looked_up:
64288 * cleared otherwise prior to returning.
64289 */
64290 static int lookup_open(struct nameidata *nd, struct path *path,
64291 - struct file *file,
64292 + struct path *link, struct file *file,
64293 const struct open_flags *op,
64294 bool got_write, int *opened)
64295 {
64296 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64297 /* Negative dentry, just create the file */
64298 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64299 umode_t mode = op->mode;
64300 +
64301 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64302 + error = -EACCES;
64303 + goto out_dput;
64304 + }
64305 +
64306 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64307 + error = -EACCES;
64308 + goto out_dput;
64309 + }
64310 +
64311 if (!IS_POSIXACL(dir->d_inode))
64312 mode &= ~current_umask();
64313 /*
64314 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64315 nd->flags & LOOKUP_EXCL);
64316 if (error)
64317 goto out_dput;
64318 + else
64319 + gr_handle_create(dentry, nd->path.mnt);
64320 }
64321 out_no_open:
64322 path->dentry = dentry;
64323 @@ -2883,7 +2934,7 @@ out_dput:
64324 /*
64325 * Handle the last step of open()
64326 */
64327 -static int do_last(struct nameidata *nd, struct path *path,
64328 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64329 struct file *file, const struct open_flags *op,
64330 int *opened, struct filename *name)
64331 {
64332 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64333 if (error)
64334 return error;
64335
64336 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64337 + error = -ENOENT;
64338 + goto out;
64339 + }
64340 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64341 + error = -EACCES;
64342 + goto out;
64343 + }
64344 +
64345 audit_inode(name, dir, LOOKUP_PARENT);
64346 error = -EISDIR;
64347 /* trailing slashes? */
64348 @@ -2952,7 +3012,7 @@ retry_lookup:
64349 */
64350 }
64351 mutex_lock(&dir->d_inode->i_mutex);
64352 - error = lookup_open(nd, path, file, op, got_write, opened);
64353 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64354 mutex_unlock(&dir->d_inode->i_mutex);
64355
64356 if (error <= 0) {
64357 @@ -2976,11 +3036,28 @@ retry_lookup:
64358 goto finish_open_created;
64359 }
64360
64361 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64362 + error = -ENOENT;
64363 + goto exit_dput;
64364 + }
64365 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64366 + error = -EACCES;
64367 + goto exit_dput;
64368 + }
64369 +
64370 /*
64371 * create/update audit record if it already exists.
64372 */
64373 - if (d_is_positive(path->dentry))
64374 + if (d_is_positive(path->dentry)) {
64375 + /* only check if O_CREAT is specified, all other checks need to go
64376 + into may_open */
64377 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64378 + error = -EACCES;
64379 + goto exit_dput;
64380 + }
64381 +
64382 audit_inode(name, path->dentry, 0);
64383 + }
64384
64385 /*
64386 * If atomic_open() acquired write access it is dropped now due to
64387 @@ -3021,6 +3098,11 @@ finish_lookup:
64388 }
64389 }
64390 BUG_ON(inode != path->dentry->d_inode);
64391 + /* if we're resolving a symlink to another symlink */
64392 + if (link && gr_handle_symlink_owner(link, inode)) {
64393 + error = -EACCES;
64394 + goto out;
64395 + }
64396 return 1;
64397 }
64398
64399 @@ -3040,7 +3122,18 @@ finish_open:
64400 path_put(&save_parent);
64401 return error;
64402 }
64403 +
64404 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64405 + error = -ENOENT;
64406 + goto out;
64407 + }
64408 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64409 + error = -EACCES;
64410 + goto out;
64411 + }
64412 +
64413 audit_inode(name, nd->path.dentry, 0);
64414 +
64415 error = -EISDIR;
64416 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64417 goto out;
64418 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64419 if (unlikely(error))
64420 goto out;
64421
64422 - error = do_last(nd, &path, file, op, &opened, pathname);
64423 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64424 while (unlikely(error > 0)) { /* trailing symlink */
64425 struct path link = path;
64426 void *cookie;
64427 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64428 error = follow_link(&link, nd, &cookie);
64429 if (unlikely(error))
64430 break;
64431 - error = do_last(nd, &path, file, op, &opened, pathname);
64432 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64433 put_link(nd, &link, cookie);
64434 }
64435 out:
64436 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64437 goto unlock;
64438
64439 error = -EEXIST;
64440 - if (d_is_positive(dentry))
64441 + if (d_is_positive(dentry)) {
64442 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64443 + error = -ENOENT;
64444 goto fail;
64445 -
64446 + }
64447 /*
64448 * Special case - lookup gave negative, but... we had foo/bar/
64449 * From the vfs_mknod() POV we just have a negative dentry -
64450 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64451 }
64452 EXPORT_SYMBOL(user_path_create);
64453
64454 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64455 +{
64456 + struct filename *tmp = getname(pathname);
64457 + struct dentry *res;
64458 + if (IS_ERR(tmp))
64459 + return ERR_CAST(tmp);
64460 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64461 + if (IS_ERR(res))
64462 + putname(tmp);
64463 + else
64464 + *to = tmp;
64465 + return res;
64466 +}
64467 +
64468 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64469 {
64470 int error = may_create(dir, dentry);
64471 @@ -3442,6 +3551,17 @@ retry:
64472
64473 if (!IS_POSIXACL(path.dentry->d_inode))
64474 mode &= ~current_umask();
64475 +
64476 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64477 + error = -EPERM;
64478 + goto out;
64479 + }
64480 +
64481 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64482 + error = -EACCES;
64483 + goto out;
64484 + }
64485 +
64486 error = security_path_mknod(&path, dentry, mode, dev);
64487 if (error)
64488 goto out;
64489 @@ -3457,6 +3577,8 @@ retry:
64490 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64491 break;
64492 }
64493 + if (!error)
64494 + gr_handle_create(dentry, path.mnt);
64495 out:
64496 done_path_create(&path, dentry);
64497 if (retry_estale(error, lookup_flags)) {
64498 @@ -3511,9 +3633,16 @@ retry:
64499
64500 if (!IS_POSIXACL(path.dentry->d_inode))
64501 mode &= ~current_umask();
64502 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64503 + error = -EACCES;
64504 + goto out;
64505 + }
64506 error = security_path_mkdir(&path, dentry, mode);
64507 if (!error)
64508 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64509 + if (!error)
64510 + gr_handle_create(dentry, path.mnt);
64511 +out:
64512 done_path_create(&path, dentry);
64513 if (retry_estale(error, lookup_flags)) {
64514 lookup_flags |= LOOKUP_REVAL;
64515 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64516 struct filename *name;
64517 struct dentry *dentry;
64518 struct nameidata nd;
64519 + ino_t saved_ino = 0;
64520 + dev_t saved_dev = 0;
64521 unsigned int lookup_flags = 0;
64522 retry:
64523 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64524 @@ -3629,10 +3760,21 @@ retry:
64525 error = -ENOENT;
64526 goto exit3;
64527 }
64528 +
64529 + saved_ino = dentry->d_inode->i_ino;
64530 + saved_dev = gr_get_dev_from_dentry(dentry);
64531 +
64532 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64533 + error = -EACCES;
64534 + goto exit3;
64535 + }
64536 +
64537 error = security_path_rmdir(&nd.path, dentry);
64538 if (error)
64539 goto exit3;
64540 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64541 + if (!error && (saved_dev || saved_ino))
64542 + gr_handle_delete(saved_ino, saved_dev);
64543 exit3:
64544 dput(dentry);
64545 exit2:
64546 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64547 struct nameidata nd;
64548 struct inode *inode = NULL;
64549 struct inode *delegated_inode = NULL;
64550 + ino_t saved_ino = 0;
64551 + dev_t saved_dev = 0;
64552 unsigned int lookup_flags = 0;
64553 retry:
64554 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64555 @@ -3751,10 +3895,22 @@ retry_deleg:
64556 if (d_is_negative(dentry))
64557 goto slashes;
64558 ihold(inode);
64559 +
64560 + if (inode->i_nlink <= 1) {
64561 + saved_ino = inode->i_ino;
64562 + saved_dev = gr_get_dev_from_dentry(dentry);
64563 + }
64564 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64565 + error = -EACCES;
64566 + goto exit2;
64567 + }
64568 +
64569 error = security_path_unlink(&nd.path, dentry);
64570 if (error)
64571 goto exit2;
64572 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64573 + if (!error && (saved_ino || saved_dev))
64574 + gr_handle_delete(saved_ino, saved_dev);
64575 exit2:
64576 dput(dentry);
64577 }
64578 @@ -3843,9 +3999,17 @@ retry:
64579 if (IS_ERR(dentry))
64580 goto out_putname;
64581
64582 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64583 + error = -EACCES;
64584 + goto out;
64585 + }
64586 +
64587 error = security_path_symlink(&path, dentry, from->name);
64588 if (!error)
64589 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64590 + if (!error)
64591 + gr_handle_create(dentry, path.mnt);
64592 +out:
64593 done_path_create(&path, dentry);
64594 if (retry_estale(error, lookup_flags)) {
64595 lookup_flags |= LOOKUP_REVAL;
64596 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64597 struct dentry *new_dentry;
64598 struct path old_path, new_path;
64599 struct inode *delegated_inode = NULL;
64600 + struct filename *to = NULL;
64601 int how = 0;
64602 int error;
64603
64604 @@ -3972,7 +4137,7 @@ retry:
64605 if (error)
64606 return error;
64607
64608 - new_dentry = user_path_create(newdfd, newname, &new_path,
64609 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64610 (how & LOOKUP_REVAL));
64611 error = PTR_ERR(new_dentry);
64612 if (IS_ERR(new_dentry))
64613 @@ -3984,11 +4149,28 @@ retry:
64614 error = may_linkat(&old_path);
64615 if (unlikely(error))
64616 goto out_dput;
64617 +
64618 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64619 + old_path.dentry->d_inode,
64620 + old_path.dentry->d_inode->i_mode, to)) {
64621 + error = -EACCES;
64622 + goto out_dput;
64623 + }
64624 +
64625 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64626 + old_path.dentry, old_path.mnt, to)) {
64627 + error = -EACCES;
64628 + goto out_dput;
64629 + }
64630 +
64631 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64632 if (error)
64633 goto out_dput;
64634 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64635 + if (!error)
64636 + gr_handle_create(new_dentry, new_path.mnt);
64637 out_dput:
64638 + putname(to);
64639 done_path_create(&new_path, new_dentry);
64640 if (delegated_inode) {
64641 error = break_deleg_wait(&delegated_inode);
64642 @@ -4304,6 +4486,20 @@ retry_deleg:
64643 if (new_dentry == trap)
64644 goto exit5;
64645
64646 + if (gr_bad_chroot_rename(old_dentry, oldnd.path.mnt, new_dentry, newnd.path.mnt)) {
64647 + /* use EXDEV error to cause 'mv' to switch to an alternative
64648 + * method for usability
64649 + */
64650 + error = -EXDEV;
64651 + goto exit5;
64652 + }
64653 +
64654 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64655 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64656 + to, flags);
64657 + if (error)
64658 + goto exit5;
64659 +
64660 error = security_path_rename(&oldnd.path, old_dentry,
64661 &newnd.path, new_dentry, flags);
64662 if (error)
64663 @@ -4311,6 +4507,9 @@ retry_deleg:
64664 error = vfs_rename(old_dir->d_inode, old_dentry,
64665 new_dir->d_inode, new_dentry,
64666 &delegated_inode, flags);
64667 + if (!error)
64668 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64669 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64670 exit5:
64671 dput(new_dentry);
64672 exit4:
64673 @@ -4367,14 +4566,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64674
64675 int readlink_copy(char __user *buffer, int buflen, const char *link)
64676 {
64677 + char tmpbuf[64];
64678 + const char *newlink;
64679 int len = PTR_ERR(link);
64680 +
64681 if (IS_ERR(link))
64682 goto out;
64683
64684 len = strlen(link);
64685 if (len > (unsigned) buflen)
64686 len = buflen;
64687 - if (copy_to_user(buffer, link, len))
64688 +
64689 + if (len < sizeof(tmpbuf)) {
64690 + memcpy(tmpbuf, link, len);
64691 + newlink = tmpbuf;
64692 + } else
64693 + newlink = link;
64694 +
64695 + if (copy_to_user(buffer, newlink, len))
64696 len = -EFAULT;
64697 out:
64698 return len;
64699 diff --git a/fs/namespace.c b/fs/namespace.c
64700 index bbde147..f4deeba 100644
64701 --- a/fs/namespace.c
64702 +++ b/fs/namespace.c
64703 @@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64704 if (!(sb->s_flags & MS_RDONLY))
64705 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64706 up_write(&sb->s_umount);
64707 +
64708 + gr_log_remount(mnt->mnt_devname, retval);
64709 +
64710 return retval;
64711 }
64712
64713 @@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64714 }
64715 unlock_mount_hash();
64716 namespace_unlock();
64717 +
64718 + gr_log_unmount(mnt->mnt_devname, retval);
64719 +
64720 return retval;
64721 }
64722
64723 @@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64724 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64725 */
64726
64727 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64728 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64729 {
64730 struct path path;
64731 struct mount *mnt;
64732 @@ -1564,7 +1570,7 @@ out:
64733 /*
64734 * The 2.0 compatible umount. No flags.
64735 */
64736 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64737 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64738 {
64739 return sys_umount(name, 0);
64740 }
64741 @@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64742 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64743 MS_STRICTATIME);
64744
64745 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64746 + retval = -EPERM;
64747 + goto dput_out;
64748 + }
64749 +
64750 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64751 + retval = -EPERM;
64752 + goto dput_out;
64753 + }
64754 +
64755 if (flags & MS_REMOUNT)
64756 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64757 data_page);
64758 @@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64759 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64760 dev_name, data_page);
64761 dput_out:
64762 + gr_log_mount(dev_name, &path, retval);
64763 +
64764 path_put(&path);
64765 +
64766 return retval;
64767 }
64768
64769 @@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64770 * number incrementing at 10Ghz will take 12,427 years to wrap which
64771 * is effectively never, so we can ignore the possibility.
64772 */
64773 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64774 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64775
64776 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64777 {
64778 @@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64779 kfree(new_ns);
64780 return ERR_PTR(ret);
64781 }
64782 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64783 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64784 atomic_set(&new_ns->count, 1);
64785 new_ns->root = NULL;
64786 INIT_LIST_HEAD(&new_ns->list);
64787 @@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64788 return new_ns;
64789 }
64790
64791 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64792 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64793 struct user_namespace *user_ns, struct fs_struct *new_fs)
64794 {
64795 struct mnt_namespace *new_ns;
64796 @@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64797 }
64798 EXPORT_SYMBOL(mount_subtree);
64799
64800 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64801 - char __user *, type, unsigned long, flags, void __user *, data)
64802 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64803 + const char __user *, type, unsigned long, flags, void __user *, data)
64804 {
64805 int ret;
64806 char *kernel_type;
64807 @@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64808 if (error)
64809 goto out2;
64810
64811 + if (gr_handle_chroot_pivot()) {
64812 + error = -EPERM;
64813 + goto out2;
64814 + }
64815 +
64816 get_fs_root(current->fs, &root);
64817 old_mp = lock_mount(&old);
64818 error = PTR_ERR(old_mp);
64819 @@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64820 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64821 return -EPERM;
64822
64823 - if (fs->users != 1)
64824 + if (atomic_read(&fs->users) != 1)
64825 return -EINVAL;
64826
64827 get_mnt_ns(mnt_ns);
64828 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64829 index f4ccfe6..a5cf064 100644
64830 --- a/fs/nfs/callback_xdr.c
64831 +++ b/fs/nfs/callback_xdr.c
64832 @@ -51,7 +51,7 @@ struct callback_op {
64833 callback_decode_arg_t decode_args;
64834 callback_encode_res_t encode_res;
64835 long res_maxsize;
64836 -};
64837 +} __do_const;
64838
64839 static struct callback_op callback_ops[];
64840
64841 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64842 index 00689a8..b162632 100644
64843 --- a/fs/nfs/inode.c
64844 +++ b/fs/nfs/inode.c
64845 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64846 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64847 }
64848
64849 -static atomic_long_t nfs_attr_generation_counter;
64850 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64851
64852 static unsigned long nfs_read_attr_generation_counter(void)
64853 {
64854 - return atomic_long_read(&nfs_attr_generation_counter);
64855 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64856 }
64857
64858 unsigned long nfs_inc_attr_generation_counter(void)
64859 {
64860 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64861 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64862 }
64863
64864 void nfs_fattr_init(struct nfs_fattr *fattr)
64865 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64866 index 0beb023..3f685ec 100644
64867 --- a/fs/nfsd/nfs4proc.c
64868 +++ b/fs/nfsd/nfs4proc.c
64869 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64870 nfsd4op_rsize op_rsize_bop;
64871 stateid_getter op_get_currentstateid;
64872 stateid_setter op_set_currentstateid;
64873 -};
64874 +} __do_const;
64875
64876 static struct nfsd4_operation nfsd4_ops[];
64877
64878 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64879 index 2a77603..68e0e37 100644
64880 --- a/fs/nfsd/nfs4xdr.c
64881 +++ b/fs/nfsd/nfs4xdr.c
64882 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64883
64884 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64885
64886 -static nfsd4_dec nfsd4_dec_ops[] = {
64887 +static const nfsd4_dec nfsd4_dec_ops[] = {
64888 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64889 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64890 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64891 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64892 index 122f691..a00e2e0 100644
64893 --- a/fs/nfsd/nfscache.c
64894 +++ b/fs/nfsd/nfscache.c
64895 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64896 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64897 u32 hash;
64898 struct nfsd_drc_bucket *b;
64899 - int len;
64900 + long len;
64901 size_t bufsize = 0;
64902
64903 if (!rp)
64904 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64905 hash = nfsd_cache_hash(rp->c_xid);
64906 b = &drc_hashtbl[hash];
64907
64908 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64909 - len >>= 2;
64910 + if (statp) {
64911 + len = (char*)statp - (char*)resv->iov_base;
64912 + len = resv->iov_len - len;
64913 + len >>= 2;
64914 + }
64915
64916 /* Don't cache excessive amounts of data and XDR failures */
64917 - if (!statp || len > (256 >> 2)) {
64918 + if (!statp || len > (256 >> 2) || len < 0) {
64919 nfsd_reply_cache_free(b, rp);
64920 return;
64921 }
64922 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64923 switch (cachetype) {
64924 case RC_REPLSTAT:
64925 if (len != 1)
64926 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64927 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64928 rp->c_replstat = *statp;
64929 break;
64930 case RC_REPLBUFF:
64931 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64932 index 989129e..42e019e 100644
64933 --- a/fs/nfsd/vfs.c
64934 +++ b/fs/nfsd/vfs.c
64935 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64936
64937 oldfs = get_fs();
64938 set_fs(KERNEL_DS);
64939 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64940 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64941 set_fs(oldfs);
64942 return nfsd_finish_read(file, count, host_err);
64943 }
64944 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64945
64946 /* Write the data. */
64947 oldfs = get_fs(); set_fs(KERNEL_DS);
64948 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64949 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64950 set_fs(oldfs);
64951 if (host_err < 0)
64952 goto out_nfserr;
64953 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64954 */
64955
64956 oldfs = get_fs(); set_fs(KERNEL_DS);
64957 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64958 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64959 set_fs(oldfs);
64960
64961 if (host_err < 0)
64962 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64963 index 52ccd34..7a6b202 100644
64964 --- a/fs/nls/nls_base.c
64965 +++ b/fs/nls/nls_base.c
64966 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64967
64968 int __register_nls(struct nls_table *nls, struct module *owner)
64969 {
64970 - struct nls_table ** tmp = &tables;
64971 + struct nls_table *tmp = tables;
64972
64973 if (nls->next)
64974 return -EBUSY;
64975
64976 - nls->owner = owner;
64977 + pax_open_kernel();
64978 + *(void **)&nls->owner = owner;
64979 + pax_close_kernel();
64980 spin_lock(&nls_lock);
64981 - while (*tmp) {
64982 - if (nls == *tmp) {
64983 + while (tmp) {
64984 + if (nls == tmp) {
64985 spin_unlock(&nls_lock);
64986 return -EBUSY;
64987 }
64988 - tmp = &(*tmp)->next;
64989 + tmp = tmp->next;
64990 }
64991 - nls->next = tables;
64992 + pax_open_kernel();
64993 + *(struct nls_table **)&nls->next = tables;
64994 + pax_close_kernel();
64995 tables = nls;
64996 spin_unlock(&nls_lock);
64997 return 0;
64998 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64999
65000 int unregister_nls(struct nls_table * nls)
65001 {
65002 - struct nls_table ** tmp = &tables;
65003 + struct nls_table * const * tmp = &tables;
65004
65005 spin_lock(&nls_lock);
65006 while (*tmp) {
65007 if (nls == *tmp) {
65008 - *tmp = nls->next;
65009 + pax_open_kernel();
65010 + *(struct nls_table **)tmp = nls->next;
65011 + pax_close_kernel();
65012 spin_unlock(&nls_lock);
65013 return 0;
65014 }
65015 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65016 return -EINVAL;
65017 }
65018
65019 -static struct nls_table *find_nls(char *charset)
65020 +static struct nls_table *find_nls(const char *charset)
65021 {
65022 struct nls_table *nls;
65023 spin_lock(&nls_lock);
65024 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65025 return nls;
65026 }
65027
65028 -struct nls_table *load_nls(char *charset)
65029 +struct nls_table *load_nls(const char *charset)
65030 {
65031 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65032 }
65033 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65034 index 162b3f1..6076a7c 100644
65035 --- a/fs/nls/nls_euc-jp.c
65036 +++ b/fs/nls/nls_euc-jp.c
65037 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65038 p_nls = load_nls("cp932");
65039
65040 if (p_nls) {
65041 - table.charset2upper = p_nls->charset2upper;
65042 - table.charset2lower = p_nls->charset2lower;
65043 + pax_open_kernel();
65044 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65045 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65046 + pax_close_kernel();
65047 return register_nls(&table);
65048 }
65049
65050 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65051 index a80a741..7b96e1b 100644
65052 --- a/fs/nls/nls_koi8-ru.c
65053 +++ b/fs/nls/nls_koi8-ru.c
65054 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65055 p_nls = load_nls("koi8-u");
65056
65057 if (p_nls) {
65058 - table.charset2upper = p_nls->charset2upper;
65059 - table.charset2lower = p_nls->charset2lower;
65060 + pax_open_kernel();
65061 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65062 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65063 + pax_close_kernel();
65064 return register_nls(&table);
65065 }
65066
65067 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65068 index c991616..5ae51af 100644
65069 --- a/fs/notify/fanotify/fanotify_user.c
65070 +++ b/fs/notify/fanotify/fanotify_user.c
65071 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65072
65073 fd = fanotify_event_metadata.fd;
65074 ret = -EFAULT;
65075 - if (copy_to_user(buf, &fanotify_event_metadata,
65076 - fanotify_event_metadata.event_len))
65077 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65078 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65079 goto out_close_fd;
65080
65081 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65082 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65083 index a95d8e0..a91a5fd 100644
65084 --- a/fs/notify/notification.c
65085 +++ b/fs/notify/notification.c
65086 @@ -48,7 +48,7 @@
65087 #include <linux/fsnotify_backend.h>
65088 #include "fsnotify.h"
65089
65090 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65091 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65092
65093 /**
65094 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65095 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65096 */
65097 u32 fsnotify_get_cookie(void)
65098 {
65099 - return atomic_inc_return(&fsnotify_sync_cookie);
65100 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65101 }
65102 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65103
65104 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65105 index 9e38daf..5727cae 100644
65106 --- a/fs/ntfs/dir.c
65107 +++ b/fs/ntfs/dir.c
65108 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65109 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65110 ~(s64)(ndir->itype.index.block_size - 1)));
65111 /* Bounds checks. */
65112 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65113 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65114 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65115 "inode 0x%lx or driver bug.", vdir->i_ino);
65116 goto err_out;
65117 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65118 index 643faa4..ef9027e 100644
65119 --- a/fs/ntfs/file.c
65120 +++ b/fs/ntfs/file.c
65121 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65122 char *addr;
65123 size_t total = 0;
65124 unsigned len;
65125 - int left;
65126 + unsigned left;
65127
65128 do {
65129 len = PAGE_CACHE_SIZE - ofs;
65130 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65131 index 9e1e112..241a52a 100644
65132 --- a/fs/ntfs/super.c
65133 +++ b/fs/ntfs/super.c
65134 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65135 if (!silent)
65136 ntfs_error(sb, "Primary boot sector is invalid.");
65137 } else if (!silent)
65138 - ntfs_error(sb, read_err_str, "primary");
65139 + ntfs_error(sb, read_err_str, "%s", "primary");
65140 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65141 if (bh_primary)
65142 brelse(bh_primary);
65143 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65144 goto hotfix_primary_boot_sector;
65145 brelse(bh_backup);
65146 } else if (!silent)
65147 - ntfs_error(sb, read_err_str, "backup");
65148 + ntfs_error(sb, read_err_str, "%s", "backup");
65149 /* Try to read NT3.51- backup boot sector. */
65150 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65151 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65152 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65153 "sector.");
65154 brelse(bh_backup);
65155 } else if (!silent)
65156 - ntfs_error(sb, read_err_str, "backup");
65157 + ntfs_error(sb, read_err_str, "%s", "backup");
65158 /* We failed. Cleanup and return. */
65159 if (bh_primary)
65160 brelse(bh_primary);
65161 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65162 index 0440134..d52c93a 100644
65163 --- a/fs/ocfs2/localalloc.c
65164 +++ b/fs/ocfs2/localalloc.c
65165 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65166 goto bail;
65167 }
65168
65169 - atomic_inc(&osb->alloc_stats.moves);
65170 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65171
65172 bail:
65173 if (handle)
65174 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65175 index bbec539..7b266d5 100644
65176 --- a/fs/ocfs2/ocfs2.h
65177 +++ b/fs/ocfs2/ocfs2.h
65178 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65179
65180 struct ocfs2_alloc_stats
65181 {
65182 - atomic_t moves;
65183 - atomic_t local_data;
65184 - atomic_t bitmap_data;
65185 - atomic_t bg_allocs;
65186 - atomic_t bg_extends;
65187 + atomic_unchecked_t moves;
65188 + atomic_unchecked_t local_data;
65189 + atomic_unchecked_t bitmap_data;
65190 + atomic_unchecked_t bg_allocs;
65191 + atomic_unchecked_t bg_extends;
65192 };
65193
65194 enum ocfs2_local_alloc_state
65195 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65196 index 0cb889a..6a26b24 100644
65197 --- a/fs/ocfs2/suballoc.c
65198 +++ b/fs/ocfs2/suballoc.c
65199 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65200 mlog_errno(status);
65201 goto bail;
65202 }
65203 - atomic_inc(&osb->alloc_stats.bg_extends);
65204 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65205
65206 /* You should never ask for this much metadata */
65207 BUG_ON(bits_wanted >
65208 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65209 mlog_errno(status);
65210 goto bail;
65211 }
65212 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65213 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65214
65215 *suballoc_loc = res.sr_bg_blkno;
65216 *suballoc_bit_start = res.sr_bit_offset;
65217 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65218 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65219 res->sr_bits);
65220
65221 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65222 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65223
65224 BUG_ON(res->sr_bits != 1);
65225
65226 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65227 mlog_errno(status);
65228 goto bail;
65229 }
65230 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65231 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65232
65233 BUG_ON(res.sr_bits != 1);
65234
65235 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65236 cluster_start,
65237 num_clusters);
65238 if (!status)
65239 - atomic_inc(&osb->alloc_stats.local_data);
65240 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65241 } else {
65242 if (min_clusters > (osb->bitmap_cpg - 1)) {
65243 /* The only paths asking for contiguousness
65244 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65245 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65246 res.sr_bg_blkno,
65247 res.sr_bit_offset);
65248 - atomic_inc(&osb->alloc_stats.bitmap_data);
65249 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65250 *num_clusters = res.sr_bits;
65251 }
65252 }
65253 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65254 index 93c85bc..02f68a4 100644
65255 --- a/fs/ocfs2/super.c
65256 +++ b/fs/ocfs2/super.c
65257 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65258 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65259 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65260 "Stats",
65261 - atomic_read(&osb->alloc_stats.bitmap_data),
65262 - atomic_read(&osb->alloc_stats.local_data),
65263 - atomic_read(&osb->alloc_stats.bg_allocs),
65264 - atomic_read(&osb->alloc_stats.moves),
65265 - atomic_read(&osb->alloc_stats.bg_extends));
65266 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65267 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65268 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65269 + atomic_read_unchecked(&osb->alloc_stats.moves),
65270 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65271
65272 out += snprintf(buf + out, len - out,
65273 "%10s => State: %u Descriptor: %llu Size: %u bits "
65274 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65275
65276 mutex_init(&osb->system_file_mutex);
65277
65278 - atomic_set(&osb->alloc_stats.moves, 0);
65279 - atomic_set(&osb->alloc_stats.local_data, 0);
65280 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65281 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65282 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65283 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65284 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65285 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65286 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65287 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65288
65289 /* Copy the blockcheck stats from the superblock probe */
65290 osb->osb_ecc_stats = *stats;
65291 diff --git a/fs/open.c b/fs/open.c
65292 index de92c13..52d2a6c 100644
65293 --- a/fs/open.c
65294 +++ b/fs/open.c
65295 @@ -32,6 +32,8 @@
65296 #include <linux/dnotify.h>
65297 #include <linux/compat.h>
65298
65299 +#define CREATE_TRACE_POINTS
65300 +#include <trace/events/fs.h>
65301 #include "internal.h"
65302
65303 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65304 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65305 error = locks_verify_truncate(inode, NULL, length);
65306 if (!error)
65307 error = security_path_truncate(path);
65308 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65309 + error = -EACCES;
65310 if (!error)
65311 error = do_truncate(path->dentry, length, 0, NULL);
65312
65313 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65314 error = locks_verify_truncate(inode, f.file, length);
65315 if (!error)
65316 error = security_path_truncate(&f.file->f_path);
65317 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65318 + error = -EACCES;
65319 if (!error)
65320 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65321 sb_end_write(inode->i_sb);
65322 @@ -380,6 +386,9 @@ retry:
65323 if (__mnt_is_readonly(path.mnt))
65324 res = -EROFS;
65325
65326 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65327 + res = -EACCES;
65328 +
65329 out_path_release:
65330 path_put(&path);
65331 if (retry_estale(res, lookup_flags)) {
65332 @@ -411,6 +420,8 @@ retry:
65333 if (error)
65334 goto dput_and_out;
65335
65336 + gr_log_chdir(path.dentry, path.mnt);
65337 +
65338 set_fs_pwd(current->fs, &path);
65339
65340 dput_and_out:
65341 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65342 goto out_putf;
65343
65344 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65345 +
65346 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65347 + error = -EPERM;
65348 +
65349 + if (!error)
65350 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65351 +
65352 if (!error)
65353 set_fs_pwd(current->fs, &f.file->f_path);
65354 out_putf:
65355 @@ -469,7 +487,13 @@ retry:
65356 if (error)
65357 goto dput_and_out;
65358
65359 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65360 + goto dput_and_out;
65361 +
65362 set_fs_root(current->fs, &path);
65363 +
65364 + gr_handle_chroot_chdir(&path);
65365 +
65366 error = 0;
65367 dput_and_out:
65368 path_put(&path);
65369 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65370 return error;
65371 retry_deleg:
65372 mutex_lock(&inode->i_mutex);
65373 +
65374 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65375 + error = -EACCES;
65376 + goto out_unlock;
65377 + }
65378 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65379 + error = -EACCES;
65380 + goto out_unlock;
65381 + }
65382 +
65383 error = security_path_chmod(path, mode);
65384 if (error)
65385 goto out_unlock;
65386 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65387 uid = make_kuid(current_user_ns(), user);
65388 gid = make_kgid(current_user_ns(), group);
65389
65390 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65391 + return -EACCES;
65392 +
65393 newattrs.ia_valid = ATTR_CTIME;
65394 if (user != (uid_t) -1) {
65395 if (!uid_valid(uid))
65396 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65397 } else {
65398 fsnotify_open(f);
65399 fd_install(fd, f);
65400 + trace_do_sys_open(tmp->name, flags, mode);
65401 }
65402 }
65403 putname(tmp);
65404 diff --git a/fs/pipe.c b/fs/pipe.c
65405 index 21981e5..3d5f55c 100644
65406 --- a/fs/pipe.c
65407 +++ b/fs/pipe.c
65408 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65409
65410 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65411 {
65412 - if (pipe->files)
65413 + if (atomic_read(&pipe->files))
65414 mutex_lock_nested(&pipe->mutex, subclass);
65415 }
65416
65417 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65418
65419 void pipe_unlock(struct pipe_inode_info *pipe)
65420 {
65421 - if (pipe->files)
65422 + if (atomic_read(&pipe->files))
65423 mutex_unlock(&pipe->mutex);
65424 }
65425 EXPORT_SYMBOL(pipe_unlock);
65426 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65427 }
65428 if (bufs) /* More to do? */
65429 continue;
65430 - if (!pipe->writers)
65431 + if (!atomic_read(&pipe->writers))
65432 break;
65433 - if (!pipe->waiting_writers) {
65434 + if (!atomic_read(&pipe->waiting_writers)) {
65435 /* syscall merging: Usually we must not sleep
65436 * if O_NONBLOCK is set, or if we got some data.
65437 * But if a writer sleeps in kernel space, then
65438 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65439
65440 __pipe_lock(pipe);
65441
65442 - if (!pipe->readers) {
65443 + if (!atomic_read(&pipe->readers)) {
65444 send_sig(SIGPIPE, current, 0);
65445 ret = -EPIPE;
65446 goto out;
65447 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65448 for (;;) {
65449 int bufs;
65450
65451 - if (!pipe->readers) {
65452 + if (!atomic_read(&pipe->readers)) {
65453 send_sig(SIGPIPE, current, 0);
65454 if (!ret)
65455 ret = -EPIPE;
65456 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65457 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65458 do_wakeup = 0;
65459 }
65460 - pipe->waiting_writers++;
65461 + atomic_inc(&pipe->waiting_writers);
65462 pipe_wait(pipe);
65463 - pipe->waiting_writers--;
65464 + atomic_dec(&pipe->waiting_writers);
65465 }
65466 out:
65467 __pipe_unlock(pipe);
65468 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65469 mask = 0;
65470 if (filp->f_mode & FMODE_READ) {
65471 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65472 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65473 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65474 mask |= POLLHUP;
65475 }
65476
65477 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65478 * Most Unices do not set POLLERR for FIFOs but on Linux they
65479 * behave exactly like pipes for poll().
65480 */
65481 - if (!pipe->readers)
65482 + if (!atomic_read(&pipe->readers))
65483 mask |= POLLERR;
65484 }
65485
65486 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65487 int kill = 0;
65488
65489 spin_lock(&inode->i_lock);
65490 - if (!--pipe->files) {
65491 + if (atomic_dec_and_test(&pipe->files)) {
65492 inode->i_pipe = NULL;
65493 kill = 1;
65494 }
65495 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65496
65497 __pipe_lock(pipe);
65498 if (file->f_mode & FMODE_READ)
65499 - pipe->readers--;
65500 + atomic_dec(&pipe->readers);
65501 if (file->f_mode & FMODE_WRITE)
65502 - pipe->writers--;
65503 + atomic_dec(&pipe->writers);
65504
65505 - if (pipe->readers || pipe->writers) {
65506 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65507 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65508 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65509 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65510 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65511 kfree(pipe);
65512 }
65513
65514 -static struct vfsmount *pipe_mnt __read_mostly;
65515 +struct vfsmount *pipe_mnt __read_mostly;
65516
65517 /*
65518 * pipefs_dname() is called from d_path().
65519 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65520 goto fail_iput;
65521
65522 inode->i_pipe = pipe;
65523 - pipe->files = 2;
65524 - pipe->readers = pipe->writers = 1;
65525 + atomic_set(&pipe->files, 2);
65526 + atomic_set(&pipe->readers, 1);
65527 + atomic_set(&pipe->writers, 1);
65528 inode->i_fop = &pipefifo_fops;
65529
65530 /*
65531 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65532 spin_lock(&inode->i_lock);
65533 if (inode->i_pipe) {
65534 pipe = inode->i_pipe;
65535 - pipe->files++;
65536 + atomic_inc(&pipe->files);
65537 spin_unlock(&inode->i_lock);
65538 } else {
65539 spin_unlock(&inode->i_lock);
65540 pipe = alloc_pipe_info();
65541 if (!pipe)
65542 return -ENOMEM;
65543 - pipe->files = 1;
65544 + atomic_set(&pipe->files, 1);
65545 spin_lock(&inode->i_lock);
65546 if (unlikely(inode->i_pipe)) {
65547 - inode->i_pipe->files++;
65548 + atomic_inc(&inode->i_pipe->files);
65549 spin_unlock(&inode->i_lock);
65550 free_pipe_info(pipe);
65551 pipe = inode->i_pipe;
65552 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65553 * opened, even when there is no process writing the FIFO.
65554 */
65555 pipe->r_counter++;
65556 - if (pipe->readers++ == 0)
65557 + if (atomic_inc_return(&pipe->readers) == 1)
65558 wake_up_partner(pipe);
65559
65560 - if (!is_pipe && !pipe->writers) {
65561 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65562 if ((filp->f_flags & O_NONBLOCK)) {
65563 /* suppress POLLHUP until we have
65564 * seen a writer */
65565 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65566 * errno=ENXIO when there is no process reading the FIFO.
65567 */
65568 ret = -ENXIO;
65569 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65570 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65571 goto err;
65572
65573 pipe->w_counter++;
65574 - if (!pipe->writers++)
65575 + if (atomic_inc_return(&pipe->writers) == 1)
65576 wake_up_partner(pipe);
65577
65578 - if (!is_pipe && !pipe->readers) {
65579 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65580 if (wait_for_partner(pipe, &pipe->r_counter))
65581 goto err_wr;
65582 }
65583 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65584 * the process can at least talk to itself.
65585 */
65586
65587 - pipe->readers++;
65588 - pipe->writers++;
65589 + atomic_inc(&pipe->readers);
65590 + atomic_inc(&pipe->writers);
65591 pipe->r_counter++;
65592 pipe->w_counter++;
65593 - if (pipe->readers == 1 || pipe->writers == 1)
65594 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65595 wake_up_partner(pipe);
65596 break;
65597
65598 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65599 return 0;
65600
65601 err_rd:
65602 - if (!--pipe->readers)
65603 + if (atomic_dec_and_test(&pipe->readers))
65604 wake_up_interruptible(&pipe->wait);
65605 ret = -ERESTARTSYS;
65606 goto err;
65607
65608 err_wr:
65609 - if (!--pipe->writers)
65610 + if (atomic_dec_and_test(&pipe->writers))
65611 wake_up_interruptible(&pipe->wait);
65612 ret = -ERESTARTSYS;
65613 goto err;
65614 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65615 index 0855f77..6787d50 100644
65616 --- a/fs/posix_acl.c
65617 +++ b/fs/posix_acl.c
65618 @@ -20,6 +20,7 @@
65619 #include <linux/xattr.h>
65620 #include <linux/export.h>
65621 #include <linux/user_namespace.h>
65622 +#include <linux/grsecurity.h>
65623
65624 struct posix_acl **acl_by_type(struct inode *inode, int type)
65625 {
65626 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65627 }
65628 }
65629 if (mode_p)
65630 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65631 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65632 return not_equiv;
65633 }
65634 EXPORT_SYMBOL(posix_acl_equiv_mode);
65635 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65636 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65637 }
65638
65639 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65640 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65641 return not_equiv;
65642 }
65643
65644 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65645 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65646 int err = -ENOMEM;
65647 if (clone) {
65648 + *mode_p &= ~gr_acl_umask();
65649 +
65650 err = posix_acl_create_masq(clone, mode_p);
65651 if (err < 0) {
65652 posix_acl_release(clone);
65653 @@ -659,11 +662,12 @@ struct posix_acl *
65654 posix_acl_from_xattr(struct user_namespace *user_ns,
65655 const void *value, size_t size)
65656 {
65657 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65658 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65659 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65660 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65661 int count;
65662 struct posix_acl *acl;
65663 struct posix_acl_entry *acl_e;
65664 + umode_t umask = gr_acl_umask();
65665
65666 if (!value)
65667 return NULL;
65668 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65669
65670 switch(acl_e->e_tag) {
65671 case ACL_USER_OBJ:
65672 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65673 + break;
65674 case ACL_GROUP_OBJ:
65675 case ACL_MASK:
65676 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65677 + break;
65678 case ACL_OTHER:
65679 + acl_e->e_perm &= ~(umask & S_IRWXO);
65680 break;
65681
65682 case ACL_USER:
65683 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65684 acl_e->e_uid =
65685 make_kuid(user_ns,
65686 le32_to_cpu(entry->e_id));
65687 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65688 goto fail;
65689 break;
65690 case ACL_GROUP:
65691 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65692 acl_e->e_gid =
65693 make_kgid(user_ns,
65694 le32_to_cpu(entry->e_id));
65695 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65696 index 2183fcf..3c32a98 100644
65697 --- a/fs/proc/Kconfig
65698 +++ b/fs/proc/Kconfig
65699 @@ -30,7 +30,7 @@ config PROC_FS
65700
65701 config PROC_KCORE
65702 bool "/proc/kcore support" if !ARM
65703 - depends on PROC_FS && MMU
65704 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65705 help
65706 Provides a virtual ELF core file of the live kernel. This can
65707 be read with gdb and other ELF tools. No modifications can be
65708 @@ -38,8 +38,8 @@ config PROC_KCORE
65709
65710 config PROC_VMCORE
65711 bool "/proc/vmcore support"
65712 - depends on PROC_FS && CRASH_DUMP
65713 - default y
65714 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65715 + default n
65716 help
65717 Exports the dump image of crashed kernel in ELF format.
65718
65719 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65720 limited in memory.
65721
65722 config PROC_PAGE_MONITOR
65723 - default y
65724 - depends on PROC_FS && MMU
65725 + default n
65726 + depends on PROC_FS && MMU && !GRKERNSEC
65727 bool "Enable /proc page monitoring" if EXPERT
65728 help
65729 Various /proc files exist to monitor process memory utilization:
65730 diff --git a/fs/proc/array.c b/fs/proc/array.c
65731 index cd3653e..9b9b79a 100644
65732 --- a/fs/proc/array.c
65733 +++ b/fs/proc/array.c
65734 @@ -60,6 +60,7 @@
65735 #include <linux/tty.h>
65736 #include <linux/string.h>
65737 #include <linux/mman.h>
65738 +#include <linux/grsecurity.h>
65739 #include <linux/proc_fs.h>
65740 #include <linux/ioport.h>
65741 #include <linux/uaccess.h>
65742 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65743 seq_putc(m, '\n');
65744 }
65745
65746 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65747 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65748 +{
65749 + if (p->mm)
65750 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65751 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65752 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65753 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65754 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65755 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65756 + else
65757 + seq_printf(m, "PaX:\t-----\n");
65758 +}
65759 +#endif
65760 +
65761 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65762 struct pid *pid, struct task_struct *task)
65763 {
65764 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65765 task_cpus_allowed(m, task);
65766 cpuset_task_status_allowed(m, task);
65767 task_context_switch_counts(m, task);
65768 +
65769 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65770 + task_pax(m, task);
65771 +#endif
65772 +
65773 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65774 + task_grsec_rbac(m, task);
65775 +#endif
65776 +
65777 return 0;
65778 }
65779
65780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65781 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65782 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65783 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65784 +#endif
65785 +
65786 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65787 struct pid *pid, struct task_struct *task, int whole)
65788 {
65789 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65790 char tcomm[sizeof(task->comm)];
65791 unsigned long flags;
65792
65793 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65794 + if (current->exec_id != m->exec_id) {
65795 + gr_log_badprocpid("stat");
65796 + return 0;
65797 + }
65798 +#endif
65799 +
65800 state = *get_task_state(task);
65801 vsize = eip = esp = 0;
65802 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65803 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65804 gtime = task_gtime(task);
65805 }
65806
65807 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65808 + if (PAX_RAND_FLAGS(mm)) {
65809 + eip = 0;
65810 + esp = 0;
65811 + wchan = 0;
65812 + }
65813 +#endif
65814 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65815 + wchan = 0;
65816 + eip =0;
65817 + esp =0;
65818 +#endif
65819 +
65820 /* scale priority and nice values from timeslices to -20..20 */
65821 /* to make it look like a "normal" Unix priority/nice value */
65822 priority = task_prio(task);
65823 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65824 seq_put_decimal_ull(m, ' ', vsize);
65825 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65826 seq_put_decimal_ull(m, ' ', rsslim);
65827 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65828 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65829 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65830 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65831 +#else
65832 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65833 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65834 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65835 +#endif
65836 seq_put_decimal_ull(m, ' ', esp);
65837 seq_put_decimal_ull(m, ' ', eip);
65838 /* The signal information here is obsolete.
65839 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65840 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65841 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65842
65843 - if (mm && permitted) {
65844 + if (mm && permitted
65845 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65846 + && !PAX_RAND_FLAGS(mm)
65847 +#endif
65848 + ) {
65849 seq_put_decimal_ull(m, ' ', mm->start_data);
65850 seq_put_decimal_ull(m, ' ', mm->end_data);
65851 seq_put_decimal_ull(m, ' ', mm->start_brk);
65852 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65853 struct pid *pid, struct task_struct *task)
65854 {
65855 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65856 - struct mm_struct *mm = get_task_mm(task);
65857 + struct mm_struct *mm;
65858
65859 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65860 + if (current->exec_id != m->exec_id) {
65861 + gr_log_badprocpid("statm");
65862 + return 0;
65863 + }
65864 +#endif
65865 + mm = get_task_mm(task);
65866 if (mm) {
65867 size = task_statm(mm, &shared, &text, &data, &resident);
65868 mmput(mm);
65869 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65870 return 0;
65871 }
65872
65873 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65874 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65875 +{
65876 + unsigned long flags;
65877 + u32 curr_ip = 0;
65878 +
65879 + if (lock_task_sighand(task, &flags)) {
65880 + curr_ip = task->signal->curr_ip;
65881 + unlock_task_sighand(task, &flags);
65882 + }
65883 + return seq_printf(m, "%pI4\n", &curr_ip);
65884 +}
65885 +#endif
65886 +
65887 #ifdef CONFIG_CHECKPOINT_RESTORE
65888 static struct pid *
65889 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65890 diff --git a/fs/proc/base.c b/fs/proc/base.c
65891 index 7dc3ea8..a08077e 100644
65892 --- a/fs/proc/base.c
65893 +++ b/fs/proc/base.c
65894 @@ -113,6 +113,14 @@ struct pid_entry {
65895 union proc_op op;
65896 };
65897
65898 +struct getdents_callback {
65899 + struct linux_dirent __user * current_dir;
65900 + struct linux_dirent __user * previous;
65901 + struct file * file;
65902 + int count;
65903 + int error;
65904 +};
65905 +
65906 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65907 .name = (NAME), \
65908 .len = sizeof(NAME) - 1, \
65909 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65910 return 0;
65911 }
65912
65913 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65914 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65915 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65916 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65917 +#endif
65918 +
65919 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65920 struct pid *pid, struct task_struct *task)
65921 {
65922 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65923 if (mm && !IS_ERR(mm)) {
65924 unsigned int nwords = 0;
65925 +
65926 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65927 + /* allow if we're currently ptracing this task */
65928 + if (PAX_RAND_FLAGS(mm) &&
65929 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65930 + mmput(mm);
65931 + return 0;
65932 + }
65933 +#endif
65934 +
65935 do {
65936 nwords += 2;
65937 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65938 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65939 }
65940
65941
65942 -#ifdef CONFIG_KALLSYMS
65943 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65944 /*
65945 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65946 * Returns the resolved symbol. If that fails, simply return the address.
65947 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65948 mutex_unlock(&task->signal->cred_guard_mutex);
65949 }
65950
65951 -#ifdef CONFIG_STACKTRACE
65952 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65953
65954 #define MAX_STACK_TRACE_DEPTH 64
65955
65956 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65957 return 0;
65958 }
65959
65960 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65961 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65962 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65963 struct pid *pid, struct task_struct *task)
65964 {
65965 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65966 /************************************************************************/
65967
65968 /* permission checks */
65969 -static int proc_fd_access_allowed(struct inode *inode)
65970 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65971 {
65972 struct task_struct *task;
65973 int allowed = 0;
65974 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65975 */
65976 task = get_proc_task(inode);
65977 if (task) {
65978 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65979 + if (log)
65980 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65981 + else
65982 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65983 put_task_struct(task);
65984 }
65985 return allowed;
65986 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65987 struct task_struct *task,
65988 int hide_pid_min)
65989 {
65990 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65991 + return false;
65992 +
65993 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65994 + rcu_read_lock();
65995 + {
65996 + const struct cred *tmpcred = current_cred();
65997 + const struct cred *cred = __task_cred(task);
65998 +
65999 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66000 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66001 + || in_group_p(grsec_proc_gid)
66002 +#endif
66003 + ) {
66004 + rcu_read_unlock();
66005 + return true;
66006 + }
66007 + }
66008 + rcu_read_unlock();
66009 +
66010 + if (!pid->hide_pid)
66011 + return false;
66012 +#endif
66013 +
66014 if (pid->hide_pid < hide_pid_min)
66015 return true;
66016 if (in_group_p(pid->pid_gid))
66017 return true;
66018 +
66019 return ptrace_may_access(task, PTRACE_MODE_READ);
66020 }
66021
66022 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66023 put_task_struct(task);
66024
66025 if (!has_perms) {
66026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66027 + {
66028 +#else
66029 if (pid->hide_pid == 2) {
66030 +#endif
66031 /*
66032 * Let's make getdents(), stat(), and open()
66033 * consistent with each other. If a process
66034 @@ -609,6 +665,10 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
66035
66036 if (task) {
66037 mm = mm_access(task, mode);
66038 + if (!IS_ERR_OR_NULL(mm) && gr_acl_handle_procpidmem(task)) {
66039 + mmput(mm);
66040 + mm = ERR_PTR(-EPERM);
66041 + }
66042 put_task_struct(task);
66043
66044 if (!IS_ERR_OR_NULL(mm)) {
66045 @@ -630,6 +690,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66046 return PTR_ERR(mm);
66047
66048 file->private_data = mm;
66049 +
66050 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66051 + file->f_version = current->exec_id;
66052 +#endif
66053 +
66054 return 0;
66055 }
66056
66057 @@ -651,6 +716,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66058 ssize_t copied;
66059 char *page;
66060
66061 +#ifdef CONFIG_GRKERNSEC
66062 + if (write)
66063 + return -EPERM;
66064 +#endif
66065 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66066 + if (file->f_version != current->exec_id) {
66067 + gr_log_badprocpid("mem");
66068 + return 0;
66069 + }
66070 +#endif
66071 +
66072 if (!mm)
66073 return 0;
66074
66075 @@ -663,7 +739,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66076 goto free;
66077
66078 while (count > 0) {
66079 - int this_len = min_t(int, count, PAGE_SIZE);
66080 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66081
66082 if (write && copy_from_user(page, buf, this_len)) {
66083 copied = -EFAULT;
66084 @@ -755,6 +831,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66085 if (!mm)
66086 return 0;
66087
66088 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66089 + if (file->f_version != current->exec_id) {
66090 + gr_log_badprocpid("environ");
66091 + return 0;
66092 + }
66093 +#endif
66094 +
66095 page = (char *)__get_free_page(GFP_TEMPORARY);
66096 if (!page)
66097 return -ENOMEM;
66098 @@ -764,7 +847,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66099 goto free;
66100 while (count > 0) {
66101 size_t this_len, max_len;
66102 - int retval;
66103 + ssize_t retval;
66104
66105 if (src >= (mm->env_end - mm->env_start))
66106 break;
66107 @@ -1378,7 +1461,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66108 int error = -EACCES;
66109
66110 /* Are we allowed to snoop on the tasks file descriptors? */
66111 - if (!proc_fd_access_allowed(inode))
66112 + if (!proc_fd_access_allowed(inode, 0))
66113 goto out;
66114
66115 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66116 @@ -1422,8 +1505,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66117 struct path path;
66118
66119 /* Are we allowed to snoop on the tasks file descriptors? */
66120 - if (!proc_fd_access_allowed(inode))
66121 - goto out;
66122 + /* logging this is needed for learning on chromium to work properly,
66123 + but we don't want to flood the logs from 'ps' which does a readlink
66124 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66125 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66126 + */
66127 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66128 + if (!proc_fd_access_allowed(inode,0))
66129 + goto out;
66130 + } else {
66131 + if (!proc_fd_access_allowed(inode,1))
66132 + goto out;
66133 + }
66134
66135 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66136 if (error)
66137 @@ -1473,7 +1566,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66138 rcu_read_lock();
66139 cred = __task_cred(task);
66140 inode->i_uid = cred->euid;
66141 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66142 + inode->i_gid = grsec_proc_gid;
66143 +#else
66144 inode->i_gid = cred->egid;
66145 +#endif
66146 rcu_read_unlock();
66147 }
66148 security_task_to_inode(task, inode);
66149 @@ -1509,10 +1606,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66150 return -ENOENT;
66151 }
66152 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66153 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66154 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66155 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66156 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66157 +#endif
66158 task_dumpable(task)) {
66159 cred = __task_cred(task);
66160 stat->uid = cred->euid;
66161 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66162 + stat->gid = grsec_proc_gid;
66163 +#else
66164 stat->gid = cred->egid;
66165 +#endif
66166 }
66167 }
66168 rcu_read_unlock();
66169 @@ -1550,11 +1656,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66170
66171 if (task) {
66172 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66173 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66174 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66175 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66176 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66177 +#endif
66178 task_dumpable(task)) {
66179 rcu_read_lock();
66180 cred = __task_cred(task);
66181 inode->i_uid = cred->euid;
66182 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66183 + inode->i_gid = grsec_proc_gid;
66184 +#else
66185 inode->i_gid = cred->egid;
66186 +#endif
66187 rcu_read_unlock();
66188 } else {
66189 inode->i_uid = GLOBAL_ROOT_UID;
66190 @@ -2085,6 +2200,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66191 if (!task)
66192 goto out_no_task;
66193
66194 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66195 + goto out;
66196 +
66197 /*
66198 * Yes, it does not scale. And it should not. Don't add
66199 * new entries into /proc/<tgid>/ without very good reasons.
66200 @@ -2115,6 +2233,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66201 if (!task)
66202 return -ENOENT;
66203
66204 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66205 + goto out;
66206 +
66207 if (!dir_emit_dots(file, ctx))
66208 goto out;
66209
66210 @@ -2557,7 +2678,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66211 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66212 #endif
66213 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66214 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66215 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66216 ONE("syscall", S_IRUSR, proc_pid_syscall),
66217 #endif
66218 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66219 @@ -2582,10 +2703,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66220 #ifdef CONFIG_SECURITY
66221 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66222 #endif
66223 -#ifdef CONFIG_KALLSYMS
66224 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66225 ONE("wchan", S_IRUGO, proc_pid_wchan),
66226 #endif
66227 -#ifdef CONFIG_STACKTRACE
66228 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66229 ONE("stack", S_IRUSR, proc_pid_stack),
66230 #endif
66231 #ifdef CONFIG_SCHEDSTATS
66232 @@ -2619,6 +2740,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66233 #ifdef CONFIG_HARDWALL
66234 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66235 #endif
66236 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66237 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66238 +#endif
66239 #ifdef CONFIG_USER_NS
66240 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66241 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66242 @@ -2748,7 +2872,14 @@ static int proc_pid_instantiate(struct inode *dir,
66243 if (!inode)
66244 goto out;
66245
66246 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66247 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66248 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66249 + inode->i_gid = grsec_proc_gid;
66250 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66251 +#else
66252 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66253 +#endif
66254 inode->i_op = &proc_tgid_base_inode_operations;
66255 inode->i_fop = &proc_tgid_base_operations;
66256 inode->i_flags|=S_IMMUTABLE;
66257 @@ -2786,7 +2917,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66258 if (!task)
66259 goto out;
66260
66261 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66262 + goto out_put_task;
66263 +
66264 result = proc_pid_instantiate(dir, dentry, task, NULL);
66265 +out_put_task:
66266 put_task_struct(task);
66267 out:
66268 return ERR_PTR(result);
66269 @@ -2900,7 +3035,7 @@ static const struct pid_entry tid_base_stuff[] = {
66270 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66271 #endif
66272 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66273 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66274 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66275 ONE("syscall", S_IRUSR, proc_pid_syscall),
66276 #endif
66277 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66278 @@ -2927,10 +3062,10 @@ static const struct pid_entry tid_base_stuff[] = {
66279 #ifdef CONFIG_SECURITY
66280 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66281 #endif
66282 -#ifdef CONFIG_KALLSYMS
66283 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66284 ONE("wchan", S_IRUGO, proc_pid_wchan),
66285 #endif
66286 -#ifdef CONFIG_STACKTRACE
66287 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66288 ONE("stack", S_IRUSR, proc_pid_stack),
66289 #endif
66290 #ifdef CONFIG_SCHEDSTATS
66291 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66292 index cbd82df..c0407d2 100644
66293 --- a/fs/proc/cmdline.c
66294 +++ b/fs/proc/cmdline.c
66295 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66296
66297 static int __init proc_cmdline_init(void)
66298 {
66299 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66300 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66301 +#else
66302 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66303 +#endif
66304 return 0;
66305 }
66306 fs_initcall(proc_cmdline_init);
66307 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66308 index 50493ed..248166b 100644
66309 --- a/fs/proc/devices.c
66310 +++ b/fs/proc/devices.c
66311 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66312
66313 static int __init proc_devices_init(void)
66314 {
66315 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66316 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66317 +#else
66318 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66319 +#endif
66320 return 0;
66321 }
66322 fs_initcall(proc_devices_init);
66323 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66324 index e11d7c5..9128ce06 100644
66325 --- a/fs/proc/fd.c
66326 +++ b/fs/proc/fd.c
66327 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66328 if (!task)
66329 return -ENOENT;
66330
66331 - files = get_files_struct(task);
66332 + if (!gr_acl_handle_procpidmem(task))
66333 + files = get_files_struct(task);
66334 put_task_struct(task);
66335
66336 if (files) {
66337 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66338 */
66339 int proc_fd_permission(struct inode *inode, int mask)
66340 {
66341 + struct task_struct *task;
66342 int rv = generic_permission(inode, mask);
66343 - if (rv == 0)
66344 - return 0;
66345 +
66346 if (task_tgid(current) == proc_pid(inode))
66347 rv = 0;
66348 +
66349 + task = get_proc_task(inode);
66350 + if (task == NULL)
66351 + return rv;
66352 +
66353 + if (gr_acl_handle_procpidmem(task))
66354 + rv = -EACCES;
66355 +
66356 + put_task_struct(task);
66357 +
66358 return rv;
66359 }
66360
66361 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66362 index 317b726..e329aed 100644
66363 --- a/fs/proc/generic.c
66364 +++ b/fs/proc/generic.c
66365 @@ -23,6 +23,7 @@
66366 #include <linux/bitops.h>
66367 #include <linux/spinlock.h>
66368 #include <linux/completion.h>
66369 +#include <linux/grsecurity.h>
66370 #include <asm/uaccess.h>
66371
66372 #include "internal.h"
66373 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66374 return proc_lookup_de(PDE(dir), dir, dentry);
66375 }
66376
66377 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66378 + unsigned int flags)
66379 +{
66380 + if (gr_proc_is_restricted())
66381 + return ERR_PTR(-EACCES);
66382 +
66383 + return proc_lookup_de(PDE(dir), dir, dentry);
66384 +}
66385 +
66386 /*
66387 * This returns non-zero if at EOF, so that the /proc
66388 * root directory can use this and check if it should
66389 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66390 return proc_readdir_de(PDE(inode), file, ctx);
66391 }
66392
66393 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66394 +{
66395 + struct inode *inode = file_inode(file);
66396 +
66397 + if (gr_proc_is_restricted())
66398 + return -EACCES;
66399 +
66400 + return proc_readdir_de(PDE(inode), file, ctx);
66401 +}
66402 +
66403 /*
66404 * These are the generic /proc directory operations. They
66405 * use the in-memory "struct proc_dir_entry" tree to parse
66406 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66407 .iterate = proc_readdir,
66408 };
66409
66410 +static const struct file_operations proc_dir_restricted_operations = {
66411 + .llseek = generic_file_llseek,
66412 + .read = generic_read_dir,
66413 + .iterate = proc_readdir_restrict,
66414 +};
66415 +
66416 /*
66417 * proc directories can do almost nothing..
66418 */
66419 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66420 .setattr = proc_notify_change,
66421 };
66422
66423 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66424 + .lookup = proc_lookup_restrict,
66425 + .getattr = proc_getattr,
66426 + .setattr = proc_notify_change,
66427 +};
66428 +
66429 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66430 {
66431 struct proc_dir_entry *tmp;
66432 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66433 return ret;
66434
66435 if (S_ISDIR(dp->mode)) {
66436 - dp->proc_fops = &proc_dir_operations;
66437 - dp->proc_iops = &proc_dir_inode_operations;
66438 + if (dp->restricted) {
66439 + dp->proc_fops = &proc_dir_restricted_operations;
66440 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66441 + } else {
66442 + dp->proc_fops = &proc_dir_operations;
66443 + dp->proc_iops = &proc_dir_inode_operations;
66444 + }
66445 dir->nlink++;
66446 } else if (S_ISLNK(dp->mode)) {
66447 dp->proc_iops = &proc_link_inode_operations;
66448 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66449 }
66450 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66451
66452 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66453 + struct proc_dir_entry *parent, void *data)
66454 +{
66455 + struct proc_dir_entry *ent;
66456 +
66457 + if (mode == 0)
66458 + mode = S_IRUGO | S_IXUGO;
66459 +
66460 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66461 + if (ent) {
66462 + ent->data = data;
66463 + ent->restricted = 1;
66464 + if (proc_register(parent, ent) < 0) {
66465 + kfree(ent);
66466 + ent = NULL;
66467 + }
66468 + }
66469 + return ent;
66470 +}
66471 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66472 +
66473 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66474 struct proc_dir_entry *parent)
66475 {
66476 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66477 }
66478 EXPORT_SYMBOL(proc_mkdir);
66479
66480 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66481 + struct proc_dir_entry *parent)
66482 +{
66483 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66484 +}
66485 +EXPORT_SYMBOL(proc_mkdir_restrict);
66486 +
66487 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66488 struct proc_dir_entry *parent,
66489 const struct file_operations *proc_fops,
66490 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66491 index 333080d..0a35ec4 100644
66492 --- a/fs/proc/inode.c
66493 +++ b/fs/proc/inode.c
66494 @@ -23,11 +23,17 @@
66495 #include <linux/slab.h>
66496 #include <linux/mount.h>
66497 #include <linux/magic.h>
66498 +#include <linux/grsecurity.h>
66499
66500 #include <asm/uaccess.h>
66501
66502 #include "internal.h"
66503
66504 +#ifdef CONFIG_PROC_SYSCTL
66505 +extern const struct inode_operations proc_sys_inode_operations;
66506 +extern const struct inode_operations proc_sys_dir_operations;
66507 +#endif
66508 +
66509 static void proc_evict_inode(struct inode *inode)
66510 {
66511 struct proc_dir_entry *de;
66512 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66513 ns = PROC_I(inode)->ns.ns;
66514 if (ns_ops && ns)
66515 ns_ops->put(ns);
66516 +
66517 +#ifdef CONFIG_PROC_SYSCTL
66518 + if (inode->i_op == &proc_sys_inode_operations ||
66519 + inode->i_op == &proc_sys_dir_operations)
66520 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66521 +#endif
66522 +
66523 }
66524
66525 static struct kmem_cache * proc_inode_cachep;
66526 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66527 if (de->mode) {
66528 inode->i_mode = de->mode;
66529 inode->i_uid = de->uid;
66530 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66531 + inode->i_gid = grsec_proc_gid;
66532 +#else
66533 inode->i_gid = de->gid;
66534 +#endif
66535 }
66536 if (de->size)
66537 inode->i_size = de->size;
66538 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66539 index aa7a0ee..f2318df 100644
66540 --- a/fs/proc/internal.h
66541 +++ b/fs/proc/internal.h
66542 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66543 struct completion *pde_unload_completion;
66544 struct list_head pde_openers; /* who did ->open, but not ->release */
66545 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66546 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66547 u8 namelen;
66548 char name[];
66549 -};
66550 +} __randomize_layout;
66551
66552 union proc_op {
66553 int (*proc_get_link)(struct dentry *, struct path *);
66554 @@ -66,7 +67,7 @@ struct proc_inode {
66555 struct ctl_table *sysctl_entry;
66556 struct proc_ns ns;
66557 struct inode vfs_inode;
66558 -};
66559 +} __randomize_layout;
66560
66561 /*
66562 * General functions
66563 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66564 struct pid *, struct task_struct *);
66565 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66566 struct pid *, struct task_struct *);
66567 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66568 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66569 + struct pid *, struct task_struct *);
66570 +#endif
66571
66572 /*
66573 * base.c
66574 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66575 * generic.c
66576 */
66577 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66578 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66579 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66580 struct dentry *);
66581 extern int proc_readdir(struct file *, struct dir_context *);
66582 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66583 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66584
66585 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66586 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66587 index a352d57..cb94a5c 100644
66588 --- a/fs/proc/interrupts.c
66589 +++ b/fs/proc/interrupts.c
66590 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66591
66592 static int __init proc_interrupts_init(void)
66593 {
66594 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66595 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66596 +#else
66597 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66598 +#endif
66599 return 0;
66600 }
66601 fs_initcall(proc_interrupts_init);
66602 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66603 index 91a4e64..cb007c0 100644
66604 --- a/fs/proc/kcore.c
66605 +++ b/fs/proc/kcore.c
66606 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66607 * the addresses in the elf_phdr on our list.
66608 */
66609 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66610 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66611 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66612 + if (tsz > buflen)
66613 tsz = buflen;
66614 -
66615 +
66616 while (buflen) {
66617 struct kcore_list *m;
66618
66619 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66620 kfree(elf_buf);
66621 } else {
66622 if (kern_addr_valid(start)) {
66623 - unsigned long n;
66624 + char *elf_buf;
66625 + mm_segment_t oldfs;
66626
66627 - n = copy_to_user(buffer, (char *)start, tsz);
66628 - /*
66629 - * We cannot distinguish between fault on source
66630 - * and fault on destination. When this happens
66631 - * we clear too and hope it will trigger the
66632 - * EFAULT again.
66633 - */
66634 - if (n) {
66635 - if (clear_user(buffer + tsz - n,
66636 - n))
66637 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66638 + if (!elf_buf)
66639 + return -ENOMEM;
66640 + oldfs = get_fs();
66641 + set_fs(KERNEL_DS);
66642 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66643 + set_fs(oldfs);
66644 + if (copy_to_user(buffer, elf_buf, tsz)) {
66645 + kfree(elf_buf);
66646 return -EFAULT;
66647 + }
66648 }
66649 + set_fs(oldfs);
66650 + kfree(elf_buf);
66651 } else {
66652 if (clear_user(buffer, tsz))
66653 return -EFAULT;
66654 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66655
66656 static int open_kcore(struct inode *inode, struct file *filp)
66657 {
66658 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66659 + return -EPERM;
66660 +#endif
66661 if (!capable(CAP_SYS_RAWIO))
66662 return -EPERM;
66663 if (kcore_need_update)
66664 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66665 index aa1eee0..03dda72 100644
66666 --- a/fs/proc/meminfo.c
66667 +++ b/fs/proc/meminfo.c
66668 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66669 vmi.used >> 10,
66670 vmi.largest_chunk >> 10
66671 #ifdef CONFIG_MEMORY_FAILURE
66672 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66673 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66674 #endif
66675 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66676 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66677 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66678 index d4a3574..b421ce9 100644
66679 --- a/fs/proc/nommu.c
66680 +++ b/fs/proc/nommu.c
66681 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66682
66683 if (file) {
66684 seq_pad(m, ' ');
66685 - seq_path(m, &file->f_path, "");
66686 + seq_path(m, &file->f_path, "\n\\");
66687 }
66688
66689 seq_putc(m, '\n');
66690 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66691 index a63af3e..b4f262a 100644
66692 --- a/fs/proc/proc_net.c
66693 +++ b/fs/proc/proc_net.c
66694 @@ -23,9 +23,27 @@
66695 #include <linux/nsproxy.h>
66696 #include <net/net_namespace.h>
66697 #include <linux/seq_file.h>
66698 +#include <linux/grsecurity.h>
66699
66700 #include "internal.h"
66701
66702 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66703 +static struct seq_operations *ipv6_seq_ops_addr;
66704 +
66705 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66706 +{
66707 + ipv6_seq_ops_addr = addr;
66708 +}
66709 +
66710 +void unregister_ipv6_seq_ops_addr(void)
66711 +{
66712 + ipv6_seq_ops_addr = NULL;
66713 +}
66714 +
66715 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66716 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66717 +#endif
66718 +
66719 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66720 {
66721 return pde->parent->data;
66722 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66723 return maybe_get_net(PDE_NET(PDE(inode)));
66724 }
66725
66726 +extern const struct seq_operations dev_seq_ops;
66727 +
66728 int seq_open_net(struct inode *ino, struct file *f,
66729 const struct seq_operations *ops, int size)
66730 {
66731 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66732
66733 BUG_ON(size < sizeof(*p));
66734
66735 + /* only permit access to /proc/net/dev */
66736 + if (
66737 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66738 + ops != ipv6_seq_ops_addr &&
66739 +#endif
66740 + ops != &dev_seq_ops && gr_proc_is_restricted())
66741 + return -EACCES;
66742 +
66743 net = get_proc_net(ino);
66744 if (net == NULL)
66745 return -ENXIO;
66746 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66747 int err;
66748 struct net *net;
66749
66750 + if (gr_proc_is_restricted())
66751 + return -EACCES;
66752 +
66753 err = -ENXIO;
66754 net = get_proc_net(inode);
66755 if (net == NULL)
66756 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66757 index f92d5dd..26398ac 100644
66758 --- a/fs/proc/proc_sysctl.c
66759 +++ b/fs/proc/proc_sysctl.c
66760 @@ -11,13 +11,21 @@
66761 #include <linux/namei.h>
66762 #include <linux/mm.h>
66763 #include <linux/module.h>
66764 +#include <linux/nsproxy.h>
66765 +#ifdef CONFIG_GRKERNSEC
66766 +#include <net/net_namespace.h>
66767 +#endif
66768 #include "internal.h"
66769
66770 +extern int gr_handle_chroot_sysctl(const int op);
66771 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66772 + const int op);
66773 +
66774 static const struct dentry_operations proc_sys_dentry_operations;
66775 static const struct file_operations proc_sys_file_operations;
66776 -static const struct inode_operations proc_sys_inode_operations;
66777 +const struct inode_operations proc_sys_inode_operations;
66778 static const struct file_operations proc_sys_dir_file_operations;
66779 -static const struct inode_operations proc_sys_dir_operations;
66780 +const struct inode_operations proc_sys_dir_operations;
66781
66782 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66783 {
66784 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66785
66786 err = NULL;
66787 d_set_d_op(dentry, &proc_sys_dentry_operations);
66788 +
66789 + gr_handle_proc_create(dentry, inode);
66790 +
66791 d_add(dentry, inode);
66792
66793 out:
66794 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66795 struct inode *inode = file_inode(filp);
66796 struct ctl_table_header *head = grab_header(inode);
66797 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66798 + int op = write ? MAY_WRITE : MAY_READ;
66799 ssize_t error;
66800 size_t res;
66801
66802 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66803 * and won't be until we finish.
66804 */
66805 error = -EPERM;
66806 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66807 + if (sysctl_perm(head, table, op))
66808 goto out;
66809
66810 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66811 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66812 if (!table->proc_handler)
66813 goto out;
66814
66815 +#ifdef CONFIG_GRKERNSEC
66816 + error = -EPERM;
66817 + if (gr_handle_chroot_sysctl(op))
66818 + goto out;
66819 + dget(filp->f_path.dentry);
66820 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66821 + dput(filp->f_path.dentry);
66822 + goto out;
66823 + }
66824 + dput(filp->f_path.dentry);
66825 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66826 + goto out;
66827 + if (write) {
66828 + if (current->nsproxy->net_ns != table->extra2) {
66829 + if (!capable(CAP_SYS_ADMIN))
66830 + goto out;
66831 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66832 + goto out;
66833 + }
66834 +#endif
66835 +
66836 /* careful: calling conventions are nasty here */
66837 res = count;
66838 error = table->proc_handler(table, write, buf, &res, ppos);
66839 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66840 return false;
66841 } else {
66842 d_set_d_op(child, &proc_sys_dentry_operations);
66843 +
66844 + gr_handle_proc_create(child, inode);
66845 +
66846 d_add(child, inode);
66847 }
66848 } else {
66849 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66850 if ((*pos)++ < ctx->pos)
66851 return true;
66852
66853 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66854 + return 0;
66855 +
66856 if (unlikely(S_ISLNK(table->mode)))
66857 res = proc_sys_link_fill_cache(file, ctx, head, table);
66858 else
66859 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66860 if (IS_ERR(head))
66861 return PTR_ERR(head);
66862
66863 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66864 + return -ENOENT;
66865 +
66866 generic_fillattr(inode, stat);
66867 if (table)
66868 stat->mode = (stat->mode & S_IFMT) | table->mode;
66869 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66870 .llseek = generic_file_llseek,
66871 };
66872
66873 -static const struct inode_operations proc_sys_inode_operations = {
66874 +const struct inode_operations proc_sys_inode_operations = {
66875 .permission = proc_sys_permission,
66876 .setattr = proc_sys_setattr,
66877 .getattr = proc_sys_getattr,
66878 };
66879
66880 -static const struct inode_operations proc_sys_dir_operations = {
66881 +const struct inode_operations proc_sys_dir_operations = {
66882 .lookup = proc_sys_lookup,
66883 .permission = proc_sys_permission,
66884 .setattr = proc_sys_setattr,
66885 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66886 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66887 const char *name, int namelen)
66888 {
66889 - struct ctl_table *table;
66890 + ctl_table_no_const *table;
66891 struct ctl_dir *new;
66892 struct ctl_node *node;
66893 char *new_name;
66894 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66895 return NULL;
66896
66897 node = (struct ctl_node *)(new + 1);
66898 - table = (struct ctl_table *)(node + 1);
66899 + table = (ctl_table_no_const *)(node + 1);
66900 new_name = (char *)(table + 2);
66901 memcpy(new_name, name, namelen);
66902 new_name[namelen] = '\0';
66903 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66904 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66905 struct ctl_table_root *link_root)
66906 {
66907 - struct ctl_table *link_table, *entry, *link;
66908 + ctl_table_no_const *link_table, *link;
66909 + struct ctl_table *entry;
66910 struct ctl_table_header *links;
66911 struct ctl_node *node;
66912 char *link_name;
66913 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66914 return NULL;
66915
66916 node = (struct ctl_node *)(links + 1);
66917 - link_table = (struct ctl_table *)(node + nr_entries);
66918 + link_table = (ctl_table_no_const *)(node + nr_entries);
66919 link_name = (char *)&link_table[nr_entries + 1];
66920
66921 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66922 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66923 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66924 struct ctl_table *table)
66925 {
66926 - struct ctl_table *ctl_table_arg = NULL;
66927 - struct ctl_table *entry, *files;
66928 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66929 + struct ctl_table *entry;
66930 int nr_files = 0;
66931 int nr_dirs = 0;
66932 int err = -ENOMEM;
66933 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66934 nr_files++;
66935 }
66936
66937 - files = table;
66938 /* If there are mixed files and directories we need a new table */
66939 if (nr_dirs && nr_files) {
66940 - struct ctl_table *new;
66941 + ctl_table_no_const *new;
66942 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66943 GFP_KERNEL);
66944 if (!files)
66945 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66946 /* Register everything except a directory full of subdirectories */
66947 if (nr_files || !nr_dirs) {
66948 struct ctl_table_header *header;
66949 - header = __register_sysctl_table(set, path, files);
66950 + header = __register_sysctl_table(set, path, files ? files : table);
66951 if (!header) {
66952 kfree(ctl_table_arg);
66953 goto out;
66954 diff --git a/fs/proc/root.c b/fs/proc/root.c
66955 index 094e44d..085a877 100644
66956 --- a/fs/proc/root.c
66957 +++ b/fs/proc/root.c
66958 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66959 proc_mkdir("openprom", NULL);
66960 #endif
66961 proc_tty_init();
66962 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66963 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66964 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66965 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66966 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66967 +#endif
66968 +#else
66969 proc_mkdir("bus", NULL);
66970 +#endif
66971 proc_sys_init();
66972 }
66973
66974 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66975 index 510413eb..34d9a8c 100644
66976 --- a/fs/proc/stat.c
66977 +++ b/fs/proc/stat.c
66978 @@ -11,6 +11,7 @@
66979 #include <linux/irqnr.h>
66980 #include <linux/cputime.h>
66981 #include <linux/tick.h>
66982 +#include <linux/grsecurity.h>
66983
66984 #ifndef arch_irq_stat_cpu
66985 #define arch_irq_stat_cpu(cpu) 0
66986 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66987 u64 sum_softirq = 0;
66988 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66989 struct timespec boottime;
66990 + int unrestricted = 1;
66991 +
66992 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66993 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66994 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66995 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66996 + && !in_group_p(grsec_proc_gid)
66997 +#endif
66998 + )
66999 + unrestricted = 0;
67000 +#endif
67001 +#endif
67002
67003 user = nice = system = idle = iowait =
67004 irq = softirq = steal = 0;
67005 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67006 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67007 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67008 idle += get_idle_time(i);
67009 - iowait += get_iowait_time(i);
67010 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67011 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67012 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67013 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67014 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67015 - sum += kstat_cpu_irqs_sum(i);
67016 - sum += arch_irq_stat_cpu(i);
67017 + if (unrestricted) {
67018 + iowait += get_iowait_time(i);
67019 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67020 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67021 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67022 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67023 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67024 + sum += kstat_cpu_irqs_sum(i);
67025 + sum += arch_irq_stat_cpu(i);
67026 + for (j = 0; j < NR_SOFTIRQS; j++) {
67027 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67028
67029 - for (j = 0; j < NR_SOFTIRQS; j++) {
67030 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67031 -
67032 - per_softirq_sums[j] += softirq_stat;
67033 - sum_softirq += softirq_stat;
67034 + per_softirq_sums[j] += softirq_stat;
67035 + sum_softirq += softirq_stat;
67036 + }
67037 }
67038 }
67039 - sum += arch_irq_stat();
67040 + if (unrestricted)
67041 + sum += arch_irq_stat();
67042
67043 seq_puts(p, "cpu ");
67044 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67045 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67046 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67047 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67048 idle = get_idle_time(i);
67049 - iowait = get_iowait_time(i);
67050 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67051 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67052 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67053 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67054 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67055 + if (unrestricted) {
67056 + iowait = get_iowait_time(i);
67057 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67058 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67059 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67060 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67061 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67062 + }
67063 seq_printf(p, "cpu%d", i);
67064 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67065 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67066 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67067
67068 /* sum again ? it could be updated? */
67069 for_each_irq_nr(j)
67070 - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
67071 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs_usr(j) : 0ULL);
67072
67073 seq_printf(p,
67074 "\nctxt %llu\n"
67075 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67076 "processes %lu\n"
67077 "procs_running %lu\n"
67078 "procs_blocked %lu\n",
67079 - nr_context_switches(),
67080 + unrestricted ? nr_context_switches() : 0ULL,
67081 (unsigned long)jif,
67082 - total_forks,
67083 - nr_running(),
67084 - nr_iowait());
67085 + unrestricted ? total_forks : 0UL,
67086 + unrestricted ? nr_running() : 0UL,
67087 + unrestricted ? nr_iowait() : 0UL);
67088
67089 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67090
67091 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67092 index 4e0388c..fc6a0e1 100644
67093 --- a/fs/proc/task_mmu.c
67094 +++ b/fs/proc/task_mmu.c
67095 @@ -13,12 +13,19 @@
67096 #include <linux/swap.h>
67097 #include <linux/swapops.h>
67098 #include <linux/mmu_notifier.h>
67099 +#include <linux/grsecurity.h>
67100
67101 #include <asm/elf.h>
67102 #include <asm/uaccess.h>
67103 #include <asm/tlbflush.h>
67104 #include "internal.h"
67105
67106 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67107 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67108 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67109 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67110 +#endif
67111 +
67112 void task_mem(struct seq_file *m, struct mm_struct *mm)
67113 {
67114 unsigned long data, text, lib, swap;
67115 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67116 "VmExe:\t%8lu kB\n"
67117 "VmLib:\t%8lu kB\n"
67118 "VmPTE:\t%8lu kB\n"
67119 - "VmSwap:\t%8lu kB\n",
67120 - hiwater_vm << (PAGE_SHIFT-10),
67121 + "VmSwap:\t%8lu kB\n"
67122 +
67123 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67124 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67125 +#endif
67126 +
67127 + ,hiwater_vm << (PAGE_SHIFT-10),
67128 total_vm << (PAGE_SHIFT-10),
67129 mm->locked_vm << (PAGE_SHIFT-10),
67130 mm->pinned_vm << (PAGE_SHIFT-10),
67131 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67132 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67133 (PTRS_PER_PTE * sizeof(pte_t) *
67134 atomic_long_read(&mm->nr_ptes)) >> 10,
67135 - swap << (PAGE_SHIFT-10));
67136 + swap << (PAGE_SHIFT-10)
67137 +
67138 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67139 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67140 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67141 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67142 +#else
67143 + , mm->context.user_cs_base
67144 + , mm->context.user_cs_limit
67145 +#endif
67146 +#endif
67147 +
67148 + );
67149 }
67150
67151 unsigned long task_vsize(struct mm_struct *mm)
67152 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67153 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67154 }
67155
67156 - /* We don't show the stack guard page in /proc/maps */
67157 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67158 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67159 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67160 +#else
67161 start = vma->vm_start;
67162 - if (stack_guard_page_start(vma, start))
67163 - start += PAGE_SIZE;
67164 end = vma->vm_end;
67165 - if (stack_guard_page_end(vma, end))
67166 - end -= PAGE_SIZE;
67167 +#endif
67168
67169 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67170 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67171 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67172 flags & VM_WRITE ? 'w' : '-',
67173 flags & VM_EXEC ? 'x' : '-',
67174 flags & VM_MAYSHARE ? 's' : 'p',
67175 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67176 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67177 +#else
67178 pgoff,
67179 +#endif
67180 MAJOR(dev), MINOR(dev), ino);
67181
67182 /*
67183 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67184 */
67185 if (file) {
67186 seq_pad(m, ' ');
67187 - seq_path(m, &file->f_path, "\n");
67188 + seq_path(m, &file->f_path, "\n\\");
67189 goto done;
67190 }
67191
67192 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67193 * Thread stack in /proc/PID/task/TID/maps or
67194 * the main process stack.
67195 */
67196 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67197 - vma->vm_end >= mm->start_stack)) {
67198 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67199 + (vma->vm_start <= mm->start_stack &&
67200 + vma->vm_end >= mm->start_stack)) {
67201 name = "[stack]";
67202 } else {
67203 /* Thread stack in /proc/PID/maps */
67204 @@ -359,6 +388,12 @@ done:
67205
67206 static int show_map(struct seq_file *m, void *v, int is_pid)
67207 {
67208 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67209 + if (current->exec_id != m->exec_id) {
67210 + gr_log_badprocpid("maps");
67211 + return 0;
67212 + }
67213 +#endif
67214 show_map_vma(m, v, is_pid);
67215 m_cache_vma(m, v);
67216 return 0;
67217 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67218 .private = &mss,
67219 };
67220
67221 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67222 + if (current->exec_id != m->exec_id) {
67223 + gr_log_badprocpid("smaps");
67224 + return 0;
67225 + }
67226 +#endif
67227 memset(&mss, 0, sizeof mss);
67228 - mss.vma = vma;
67229 - /* mmap_sem is held in m_start */
67230 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67231 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67232 -
67233 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67234 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67235 +#endif
67236 + mss.vma = vma;
67237 + /* mmap_sem is held in m_start */
67238 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67239 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67240 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67241 + }
67242 +#endif
67243 show_map_vma(m, vma, is_pid);
67244
67245 seq_printf(m,
67246 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67247 "KernelPageSize: %8lu kB\n"
67248 "MMUPageSize: %8lu kB\n"
67249 "Locked: %8lu kB\n",
67250 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67251 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67252 +#else
67253 (vma->vm_end - vma->vm_start) >> 10,
67254 +#endif
67255 mss.resident >> 10,
67256 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67257 mss.shared_clean >> 10,
67258 @@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67259 char buffer[64];
67260 int nid;
67261
67262 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67263 + if (current->exec_id != m->exec_id) {
67264 + gr_log_badprocpid("numa_maps");
67265 + return 0;
67266 + }
67267 +#endif
67268 +
67269 if (!mm)
67270 return 0;
67271
67272 @@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67273 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
67274 }
67275
67276 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67277 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67278 +#else
67279 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67280 +#endif
67281
67282 if (file) {
67283 seq_puts(m, " file=");
67284 - seq_path(m, &file->f_path, "\n\t= ");
67285 + seq_path(m, &file->f_path, "\n\t\\= ");
67286 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67287 seq_puts(m, " heap");
67288 } else {
67289 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67290 index 599ec2e..f1413ae 100644
67291 --- a/fs/proc/task_nommu.c
67292 +++ b/fs/proc/task_nommu.c
67293 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67294 else
67295 bytes += kobjsize(mm);
67296
67297 - if (current->fs && current->fs->users > 1)
67298 + if (current->fs && atomic_read(&current->fs->users) > 1)
67299 sbytes += kobjsize(current->fs);
67300 else
67301 bytes += kobjsize(current->fs);
67302 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67303
67304 if (file) {
67305 seq_pad(m, ' ');
67306 - seq_path(m, &file->f_path, "");
67307 + seq_path(m, &file->f_path, "\n\\");
67308 } else if (mm) {
67309 pid_t tid = pid_of_stack(priv, vma, is_pid);
67310
67311 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67312 index a90d6d35..d08047c 100644
67313 --- a/fs/proc/vmcore.c
67314 +++ b/fs/proc/vmcore.c
67315 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67316 nr_bytes = count;
67317
67318 /* If pfn is not ram, return zeros for sparse dump files */
67319 - if (pfn_is_ram(pfn) == 0)
67320 - memset(buf, 0, nr_bytes);
67321 - else {
67322 + if (pfn_is_ram(pfn) == 0) {
67323 + if (userbuf) {
67324 + if (clear_user((char __force_user *)buf, nr_bytes))
67325 + return -EFAULT;
67326 + } else
67327 + memset(buf, 0, nr_bytes);
67328 + } else {
67329 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67330 offset, userbuf);
67331 if (tmp < 0)
67332 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67333 static int copy_to(void *target, void *src, size_t size, int userbuf)
67334 {
67335 if (userbuf) {
67336 - if (copy_to_user((char __user *) target, src, size))
67337 + if (copy_to_user((char __force_user *) target, src, size))
67338 return -EFAULT;
67339 } else {
67340 memcpy(target, src, size);
67341 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67342 if (*fpos < m->offset + m->size) {
67343 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67344 start = m->paddr + *fpos - m->offset;
67345 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67346 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67347 if (tmp < 0)
67348 return tmp;
67349 buflen -= tsz;
67350 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67351 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67352 size_t buflen, loff_t *fpos)
67353 {
67354 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67355 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67356 }
67357
67358 /*
67359 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67360 index d3fb2b6..43a8140 100644
67361 --- a/fs/qnx6/qnx6.h
67362 +++ b/fs/qnx6/qnx6.h
67363 @@ -74,7 +74,7 @@ enum {
67364 BYTESEX_BE,
67365 };
67366
67367 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67368 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67369 {
67370 if (sbi->s_bytesex == BYTESEX_LE)
67371 return le64_to_cpu((__force __le64)n);
67372 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67373 return (__force __fs64)cpu_to_be64(n);
67374 }
67375
67376 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67377 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67378 {
67379 if (sbi->s_bytesex == BYTESEX_LE)
67380 return le32_to_cpu((__force __le32)n);
67381 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67382 index bb2869f..d34ada8 100644
67383 --- a/fs/quota/netlink.c
67384 +++ b/fs/quota/netlink.c
67385 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67386 void quota_send_warning(struct kqid qid, dev_t dev,
67387 const char warntype)
67388 {
67389 - static atomic_t seq;
67390 + static atomic_unchecked_t seq;
67391 struct sk_buff *skb;
67392 void *msg_head;
67393 int ret;
67394 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67395 "VFS: Not enough memory to send quota warning.\n");
67396 return;
67397 }
67398 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67399 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67400 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67401 if (!msg_head) {
67402 printk(KERN_ERR
67403 diff --git a/fs/read_write.c b/fs/read_write.c
67404 index 7d9318c..51b336f 100644
67405 --- a/fs/read_write.c
67406 +++ b/fs/read_write.c
67407 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67408
67409 old_fs = get_fs();
67410 set_fs(get_ds());
67411 - p = (__force const char __user *)buf;
67412 + p = (const char __force_user *)buf;
67413 if (count > MAX_RW_COUNT)
67414 count = MAX_RW_COUNT;
67415 if (file->f_op->write)
67416 diff --git a/fs/readdir.c b/fs/readdir.c
67417 index 33fd922..e0d6094 100644
67418 --- a/fs/readdir.c
67419 +++ b/fs/readdir.c
67420 @@ -18,6 +18,7 @@
67421 #include <linux/security.h>
67422 #include <linux/syscalls.h>
67423 #include <linux/unistd.h>
67424 +#include <linux/namei.h>
67425
67426 #include <asm/uaccess.h>
67427
67428 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67429 struct readdir_callback {
67430 struct dir_context ctx;
67431 struct old_linux_dirent __user * dirent;
67432 + struct file * file;
67433 int result;
67434 };
67435
67436 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67437 buf->result = -EOVERFLOW;
67438 return -EOVERFLOW;
67439 }
67440 +
67441 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67442 + return 0;
67443 +
67444 buf->result++;
67445 dirent = buf->dirent;
67446 if (!access_ok(VERIFY_WRITE, dirent,
67447 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67448 if (!f.file)
67449 return -EBADF;
67450
67451 + buf.file = f.file;
67452 error = iterate_dir(f.file, &buf.ctx);
67453 if (buf.result)
67454 error = buf.result;
67455 @@ -144,6 +151,7 @@ struct getdents_callback {
67456 struct dir_context ctx;
67457 struct linux_dirent __user * current_dir;
67458 struct linux_dirent __user * previous;
67459 + struct file * file;
67460 int count;
67461 int error;
67462 };
67463 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67464 buf->error = -EOVERFLOW;
67465 return -EOVERFLOW;
67466 }
67467 +
67468 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67469 + return 0;
67470 +
67471 dirent = buf->previous;
67472 if (dirent) {
67473 if (__put_user(offset, &dirent->d_off))
67474 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67475 if (!f.file)
67476 return -EBADF;
67477
67478 + buf.file = f.file;
67479 error = iterate_dir(f.file, &buf.ctx);
67480 if (error >= 0)
67481 error = buf.error;
67482 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67483 struct dir_context ctx;
67484 struct linux_dirent64 __user * current_dir;
67485 struct linux_dirent64 __user * previous;
67486 + struct file *file;
67487 int count;
67488 int error;
67489 };
67490 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67491 buf->error = -EINVAL; /* only used if we fail.. */
67492 if (reclen > buf->count)
67493 return -EINVAL;
67494 +
67495 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67496 + return 0;
67497 +
67498 dirent = buf->previous;
67499 if (dirent) {
67500 if (__put_user(offset, &dirent->d_off))
67501 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67502 if (!f.file)
67503 return -EBADF;
67504
67505 + buf.file = f.file;
67506 error = iterate_dir(f.file, &buf.ctx);
67507 if (error >= 0)
67508 error = buf.error;
67509 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67510 index 9c02d96..6562c10 100644
67511 --- a/fs/reiserfs/do_balan.c
67512 +++ b/fs/reiserfs/do_balan.c
67513 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67514 return;
67515 }
67516
67517 - atomic_inc(&fs_generation(tb->tb_sb));
67518 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67519 do_balance_starts(tb);
67520
67521 /*
67522 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67523 index aca73dd..e3c558d 100644
67524 --- a/fs/reiserfs/item_ops.c
67525 +++ b/fs/reiserfs/item_ops.c
67526 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67527 }
67528
67529 static struct item_operations errcatch_ops = {
67530 - errcatch_bytes_number,
67531 - errcatch_decrement_key,
67532 - errcatch_is_left_mergeable,
67533 - errcatch_print_item,
67534 - errcatch_check_item,
67535 + .bytes_number = errcatch_bytes_number,
67536 + .decrement_key = errcatch_decrement_key,
67537 + .is_left_mergeable = errcatch_is_left_mergeable,
67538 + .print_item = errcatch_print_item,
67539 + .check_item = errcatch_check_item,
67540
67541 - errcatch_create_vi,
67542 - errcatch_check_left,
67543 - errcatch_check_right,
67544 - errcatch_part_size,
67545 - errcatch_unit_num,
67546 - errcatch_print_vi
67547 + .create_vi = errcatch_create_vi,
67548 + .check_left = errcatch_check_left,
67549 + .check_right = errcatch_check_right,
67550 + .part_size = errcatch_part_size,
67551 + .unit_num = errcatch_unit_num,
67552 + .print_vi = errcatch_print_vi
67553 };
67554
67555 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67556 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67557 index 621b9f3..af527fd 100644
67558 --- a/fs/reiserfs/procfs.c
67559 +++ b/fs/reiserfs/procfs.c
67560 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67561 "SMALL_TAILS " : "NO_TAILS ",
67562 replay_only(sb) ? "REPLAY_ONLY " : "",
67563 convert_reiserfs(sb) ? "CONV " : "",
67564 - atomic_read(&r->s_generation_counter),
67565 + atomic_read_unchecked(&r->s_generation_counter),
67566 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67567 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67568 SF(s_good_search_by_key_reada), SF(s_bmaps),
67569 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67570 index 1894d96..1dfd1c2 100644
67571 --- a/fs/reiserfs/reiserfs.h
67572 +++ b/fs/reiserfs/reiserfs.h
67573 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67574 /* Comment? -Hans */
67575 wait_queue_head_t s_wait;
67576 /* increased by one every time the tree gets re-balanced */
67577 - atomic_t s_generation_counter;
67578 + atomic_unchecked_t s_generation_counter;
67579
67580 /* File system properties. Currently holds on-disk FS format */
67581 unsigned long s_properties;
67582 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67583 #define REISERFS_USER_MEM 1 /* user memory mode */
67584
67585 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67586 -#define get_generation(s) atomic_read (&fs_generation(s))
67587 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67588 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67589 #define __fs_changed(gen,s) (gen != get_generation (s))
67590 #define fs_changed(gen,s) \
67591 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67592 index b27ef35..d9c6c18 100644
67593 --- a/fs/reiserfs/super.c
67594 +++ b/fs/reiserfs/super.c
67595 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67596 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67597 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67598 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67599 +#ifdef CONFIG_REISERFS_FS_XATTR
67600 + /* turn on user xattrs by default */
67601 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67602 +#endif
67603 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67604 sbi->s_alloc_options.preallocmin = 0;
67605 /* Preallocate by 16 blocks (17-1) at once */
67606 diff --git a/fs/select.c b/fs/select.c
67607 index 467bb1c..cf9d65a 100644
67608 --- a/fs/select.c
67609 +++ b/fs/select.c
67610 @@ -20,6 +20,7 @@
67611 #include <linux/export.h>
67612 #include <linux/slab.h>
67613 #include <linux/poll.h>
67614 +#include <linux/security.h>
67615 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67616 #include <linux/file.h>
67617 #include <linux/fdtable.h>
67618 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67619 struct poll_list *walk = head;
67620 unsigned long todo = nfds;
67621
67622 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67623 if (nfds > rlimit(RLIMIT_NOFILE))
67624 return -EINVAL;
67625
67626 diff --git a/fs/seq_file.c b/fs/seq_file.c
67627 index 3857b72..0b7281e 100644
67628 --- a/fs/seq_file.c
67629 +++ b/fs/seq_file.c
67630 @@ -12,6 +12,8 @@
67631 #include <linux/slab.h>
67632 #include <linux/cred.h>
67633 #include <linux/mm.h>
67634 +#include <linux/sched.h>
67635 +#include <linux/grsecurity.h>
67636
67637 #include <asm/uaccess.h>
67638 #include <asm/page.h>
67639 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67640
67641 static void *seq_buf_alloc(unsigned long size)
67642 {
67643 - void *buf;
67644 -
67645 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67646 - if (!buf && size > PAGE_SIZE)
67647 - buf = vmalloc(size);
67648 - return buf;
67649 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67650 }
67651
67652 /**
67653 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67654 #ifdef CONFIG_USER_NS
67655 p->user_ns = file->f_cred->user_ns;
67656 #endif
67657 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67658 + p->exec_id = current->exec_id;
67659 +#endif
67660
67661 /*
67662 * Wrappers around seq_open(e.g. swaps_open) need to be
67663 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67664 }
67665 EXPORT_SYMBOL(seq_open);
67666
67667 +
67668 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67669 +{
67670 + if (gr_proc_is_restricted())
67671 + return -EACCES;
67672 +
67673 + return seq_open(file, op);
67674 +}
67675 +EXPORT_SYMBOL(seq_open_restrict);
67676 +
67677 static int traverse(struct seq_file *m, loff_t offset)
67678 {
67679 loff_t pos = 0, index;
67680 @@ -165,7 +175,7 @@ Eoverflow:
67681 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67682 {
67683 struct seq_file *m = file->private_data;
67684 - size_t copied = 0;
67685 + ssize_t copied = 0;
67686 loff_t pos;
67687 size_t n;
67688 void *p;
67689 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67690 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67691 void *data)
67692 {
67693 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67694 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67695 int res = -ENOMEM;
67696
67697 if (op) {
67698 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67699 }
67700 EXPORT_SYMBOL(single_open_size);
67701
67702 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67703 + void *data)
67704 +{
67705 + if (gr_proc_is_restricted())
67706 + return -EACCES;
67707 +
67708 + return single_open(file, show, data);
67709 +}
67710 +EXPORT_SYMBOL(single_open_restrict);
67711 +
67712 +
67713 int single_release(struct inode *inode, struct file *file)
67714 {
67715 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67716 diff --git a/fs/splice.c b/fs/splice.c
67717 index 75c6058..770d40c 100644
67718 --- a/fs/splice.c
67719 +++ b/fs/splice.c
67720 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67721 pipe_lock(pipe);
67722
67723 for (;;) {
67724 - if (!pipe->readers) {
67725 + if (!atomic_read(&pipe->readers)) {
67726 send_sig(SIGPIPE, current, 0);
67727 if (!ret)
67728 ret = -EPIPE;
67729 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67730 page_nr++;
67731 ret += buf->len;
67732
67733 - if (pipe->files)
67734 + if (atomic_read(&pipe->files))
67735 do_wakeup = 1;
67736
67737 if (!--spd->nr_pages)
67738 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67739 do_wakeup = 0;
67740 }
67741
67742 - pipe->waiting_writers++;
67743 + atomic_inc(&pipe->waiting_writers);
67744 pipe_wait(pipe);
67745 - pipe->waiting_writers--;
67746 + atomic_dec(&pipe->waiting_writers);
67747 }
67748
67749 pipe_unlock(pipe);
67750 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67751 old_fs = get_fs();
67752 set_fs(get_ds());
67753 /* The cast to a user pointer is valid due to the set_fs() */
67754 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67755 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67756 set_fs(old_fs);
67757
67758 return res;
67759 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67760 old_fs = get_fs();
67761 set_fs(get_ds());
67762 /* The cast to a user pointer is valid due to the set_fs() */
67763 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67764 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67765 set_fs(old_fs);
67766
67767 return res;
67768 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67769 goto err;
67770
67771 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67772 - vec[i].iov_base = (void __user *) page_address(page);
67773 + vec[i].iov_base = (void __force_user *) page_address(page);
67774 vec[i].iov_len = this_len;
67775 spd.pages[i] = page;
67776 spd.nr_pages++;
67777 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67778 ops->release(pipe, buf);
67779 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67780 pipe->nrbufs--;
67781 - if (pipe->files)
67782 + if (atomic_read(&pipe->files))
67783 sd->need_wakeup = true;
67784 }
67785
67786 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67787 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67788 {
67789 while (!pipe->nrbufs) {
67790 - if (!pipe->writers)
67791 + if (!atomic_read(&pipe->writers))
67792 return 0;
67793
67794 - if (!pipe->waiting_writers && sd->num_spliced)
67795 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67796 return 0;
67797
67798 if (sd->flags & SPLICE_F_NONBLOCK)
67799 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67800 ops->release(pipe, buf);
67801 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67802 pipe->nrbufs--;
67803 - if (pipe->files)
67804 + if (atomic_read(&pipe->files))
67805 sd.need_wakeup = true;
67806 } else {
67807 buf->offset += ret;
67808 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67809 * out of the pipe right after the splice_to_pipe(). So set
67810 * PIPE_READERS appropriately.
67811 */
67812 - pipe->readers = 1;
67813 + atomic_set(&pipe->readers, 1);
67814
67815 current->splice_pipe = pipe;
67816 }
67817 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67818
67819 partial[buffers].offset = off;
67820 partial[buffers].len = plen;
67821 + partial[buffers].private = 0;
67822
67823 off = 0;
67824 len -= plen;
67825 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67826 ret = -ERESTARTSYS;
67827 break;
67828 }
67829 - if (!pipe->writers)
67830 + if (!atomic_read(&pipe->writers))
67831 break;
67832 - if (!pipe->waiting_writers) {
67833 + if (!atomic_read(&pipe->waiting_writers)) {
67834 if (flags & SPLICE_F_NONBLOCK) {
67835 ret = -EAGAIN;
67836 break;
67837 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67838 pipe_lock(pipe);
67839
67840 while (pipe->nrbufs >= pipe->buffers) {
67841 - if (!pipe->readers) {
67842 + if (!atomic_read(&pipe->readers)) {
67843 send_sig(SIGPIPE, current, 0);
67844 ret = -EPIPE;
67845 break;
67846 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67847 ret = -ERESTARTSYS;
67848 break;
67849 }
67850 - pipe->waiting_writers++;
67851 + atomic_inc(&pipe->waiting_writers);
67852 pipe_wait(pipe);
67853 - pipe->waiting_writers--;
67854 + atomic_dec(&pipe->waiting_writers);
67855 }
67856
67857 pipe_unlock(pipe);
67858 @@ -1818,14 +1819,14 @@ retry:
67859 pipe_double_lock(ipipe, opipe);
67860
67861 do {
67862 - if (!opipe->readers) {
67863 + if (!atomic_read(&opipe->readers)) {
67864 send_sig(SIGPIPE, current, 0);
67865 if (!ret)
67866 ret = -EPIPE;
67867 break;
67868 }
67869
67870 - if (!ipipe->nrbufs && !ipipe->writers)
67871 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67872 break;
67873
67874 /*
67875 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67876 pipe_double_lock(ipipe, opipe);
67877
67878 do {
67879 - if (!opipe->readers) {
67880 + if (!atomic_read(&opipe->readers)) {
67881 send_sig(SIGPIPE, current, 0);
67882 if (!ret)
67883 ret = -EPIPE;
67884 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67885 * return EAGAIN if we have the potential of some data in the
67886 * future, otherwise just return 0
67887 */
67888 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67889 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67890 ret = -EAGAIN;
67891
67892 pipe_unlock(ipipe);
67893 diff --git a/fs/stat.c b/fs/stat.c
67894 index ae0c3ce..9ee641c 100644
67895 --- a/fs/stat.c
67896 +++ b/fs/stat.c
67897 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67898 stat->gid = inode->i_gid;
67899 stat->rdev = inode->i_rdev;
67900 stat->size = i_size_read(inode);
67901 - stat->atime = inode->i_atime;
67902 - stat->mtime = inode->i_mtime;
67903 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67904 + stat->atime = inode->i_ctime;
67905 + stat->mtime = inode->i_ctime;
67906 + } else {
67907 + stat->atime = inode->i_atime;
67908 + stat->mtime = inode->i_mtime;
67909 + }
67910 stat->ctime = inode->i_ctime;
67911 stat->blksize = (1 << inode->i_blkbits);
67912 stat->blocks = inode->i_blocks;
67913 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67914 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67915 {
67916 struct inode *inode = path->dentry->d_inode;
67917 + int retval;
67918
67919 - if (inode->i_op->getattr)
67920 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67921 + if (inode->i_op->getattr) {
67922 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67923 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67924 + stat->atime = stat->ctime;
67925 + stat->mtime = stat->ctime;
67926 + }
67927 + return retval;
67928 + }
67929
67930 generic_fillattr(inode, stat);
67931 return 0;
67932 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67933 index 0b45ff4..847de5b 100644
67934 --- a/fs/sysfs/dir.c
67935 +++ b/fs/sysfs/dir.c
67936 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67937 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67938 {
67939 struct kernfs_node *parent, *kn;
67940 + const char *name;
67941 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67942 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67943 + const char *parent_name;
67944 +#endif
67945
67946 BUG_ON(!kobj);
67947
67948 + name = kobject_name(kobj);
67949 +
67950 if (kobj->parent)
67951 parent = kobj->parent->sd;
67952 else
67953 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67954 if (!parent)
67955 return -ENOENT;
67956
67957 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67958 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67959 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67960 + parent_name = parent->name;
67961 + mode = S_IRWXU;
67962 +
67963 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67964 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67965 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67966 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67967 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
67968 +#endif
67969 +
67970 + kn = kernfs_create_dir_ns(parent, name,
67971 + mode, kobj, ns);
67972 if (IS_ERR(kn)) {
67973 if (PTR_ERR(kn) == -EEXIST)
67974 - sysfs_warn_dup(parent, kobject_name(kobj));
67975 + sysfs_warn_dup(parent, name);
67976 return PTR_ERR(kn);
67977 }
67978
67979 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67980 index 69d4889..a810bd4 100644
67981 --- a/fs/sysv/sysv.h
67982 +++ b/fs/sysv/sysv.h
67983 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67984 #endif
67985 }
67986
67987 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67988 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67989 {
67990 if (sbi->s_bytesex == BYTESEX_PDP)
67991 return PDP_swab((__force __u32)n);
67992 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67993 index fb08b0c..65fcc7e 100644
67994 --- a/fs/ubifs/io.c
67995 +++ b/fs/ubifs/io.c
67996 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67997 return err;
67998 }
67999
68000 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68001 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68002 {
68003 int err;
68004
68005 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68006 index c175b4d..8f36a16 100644
68007 --- a/fs/udf/misc.c
68008 +++ b/fs/udf/misc.c
68009 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68010
68011 u8 udf_tag_checksum(const struct tag *t)
68012 {
68013 - u8 *data = (u8 *)t;
68014 + const u8 *data = (const u8 *)t;
68015 u8 checksum = 0;
68016 int i;
68017 for (i = 0; i < sizeof(struct tag); ++i)
68018 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68019 index 8d974c4..b82f6ec 100644
68020 --- a/fs/ufs/swab.h
68021 +++ b/fs/ufs/swab.h
68022 @@ -22,7 +22,7 @@ enum {
68023 BYTESEX_BE
68024 };
68025
68026 -static inline u64
68027 +static inline u64 __intentional_overflow(-1)
68028 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68029 {
68030 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68031 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68032 return (__force __fs64)cpu_to_be64(n);
68033 }
68034
68035 -static inline u32
68036 +static inline u32 __intentional_overflow(-1)
68037 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68038 {
68039 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68040 diff --git a/fs/utimes.c b/fs/utimes.c
68041 index aa138d6..5f3a811 100644
68042 --- a/fs/utimes.c
68043 +++ b/fs/utimes.c
68044 @@ -1,6 +1,7 @@
68045 #include <linux/compiler.h>
68046 #include <linux/file.h>
68047 #include <linux/fs.h>
68048 +#include <linux/security.h>
68049 #include <linux/linkage.h>
68050 #include <linux/mount.h>
68051 #include <linux/namei.h>
68052 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68053 }
68054 }
68055 retry_deleg:
68056 +
68057 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68058 + error = -EACCES;
68059 + goto mnt_drop_write_and_out;
68060 + }
68061 +
68062 mutex_lock(&inode->i_mutex);
68063 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68064 mutex_unlock(&inode->i_mutex);
68065 diff --git a/fs/xattr.c b/fs/xattr.c
68066 index 64e83ef..b6be154 100644
68067 --- a/fs/xattr.c
68068 +++ b/fs/xattr.c
68069 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68070 return rc;
68071 }
68072
68073 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68074 +ssize_t
68075 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68076 +{
68077 + struct inode *inode = dentry->d_inode;
68078 + ssize_t error;
68079 +
68080 + error = inode_permission(inode, MAY_EXEC);
68081 + if (error)
68082 + return error;
68083 +
68084 + if (inode->i_op->getxattr)
68085 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68086 + else
68087 + error = -EOPNOTSUPP;
68088 +
68089 + return error;
68090 +}
68091 +EXPORT_SYMBOL(pax_getxattr);
68092 +#endif
68093 +
68094 ssize_t
68095 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68096 {
68097 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68098 * Extended attribute SET operations
68099 */
68100 static long
68101 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68102 +setxattr(struct path *path, const char __user *name, const void __user *value,
68103 size_t size, int flags)
68104 {
68105 int error;
68106 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68107 posix_acl_fix_xattr_from_user(kvalue, size);
68108 }
68109
68110 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68111 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68112 + error = -EACCES;
68113 + goto out;
68114 + }
68115 +
68116 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68117 out:
68118 if (vvalue)
68119 vfree(vvalue);
68120 @@ -376,7 +402,7 @@ retry:
68121 return error;
68122 error = mnt_want_write(path.mnt);
68123 if (!error) {
68124 - error = setxattr(path.dentry, name, value, size, flags);
68125 + error = setxattr(&path, name, value, size, flags);
68126 mnt_drop_write(path.mnt);
68127 }
68128 path_put(&path);
68129 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68130 const void __user *,value, size_t, size, int, flags)
68131 {
68132 struct fd f = fdget(fd);
68133 - struct dentry *dentry;
68134 int error = -EBADF;
68135
68136 if (!f.file)
68137 return error;
68138 - dentry = f.file->f_path.dentry;
68139 - audit_inode(NULL, dentry, 0);
68140 + audit_inode(NULL, f.file->f_path.dentry, 0);
68141 error = mnt_want_write_file(f.file);
68142 if (!error) {
68143 - error = setxattr(dentry, name, value, size, flags);
68144 + error = setxattr(&f.file->f_path, name, value, size, flags);
68145 mnt_drop_write_file(f.file);
68146 }
68147 fdput(f);
68148 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68149 * Extended attribute REMOVE operations
68150 */
68151 static long
68152 -removexattr(struct dentry *d, const char __user *name)
68153 +removexattr(struct path *path, const char __user *name)
68154 {
68155 int error;
68156 char kname[XATTR_NAME_MAX + 1];
68157 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68158 if (error < 0)
68159 return error;
68160
68161 - return vfs_removexattr(d, kname);
68162 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68163 + return -EACCES;
68164 +
68165 + return vfs_removexattr(path->dentry, kname);
68166 }
68167
68168 static int path_removexattr(const char __user *pathname,
68169 @@ -625,7 +652,7 @@ retry:
68170 return error;
68171 error = mnt_want_write(path.mnt);
68172 if (!error) {
68173 - error = removexattr(path.dentry, name);
68174 + error = removexattr(&path, name);
68175 mnt_drop_write(path.mnt);
68176 }
68177 path_put(&path);
68178 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68179 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68180 {
68181 struct fd f = fdget(fd);
68182 - struct dentry *dentry;
68183 + struct path *path;
68184 int error = -EBADF;
68185
68186 if (!f.file)
68187 return error;
68188 - dentry = f.file->f_path.dentry;
68189 - audit_inode(NULL, dentry, 0);
68190 + path = &f.file->f_path;
68191 + audit_inode(NULL, path->dentry, 0);
68192 error = mnt_want_write_file(f.file);
68193 if (!error) {
68194 - error = removexattr(dentry, name);
68195 + error = removexattr(path, name);
68196 mnt_drop_write_file(f.file);
68197 }
68198 fdput(f);
68199 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68200 index 79c9819..22226b4 100644
68201 --- a/fs/xfs/libxfs/xfs_bmap.c
68202 +++ b/fs/xfs/libxfs/xfs_bmap.c
68203 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68204
68205 #else
68206 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68207 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68208 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68209 #endif /* DEBUG */
68210
68211 /*
68212 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68213 index f1b69ed..3d0222f 100644
68214 --- a/fs/xfs/xfs_dir2_readdir.c
68215 +++ b/fs/xfs/xfs_dir2_readdir.c
68216 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68217 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68218 filetype = dp->d_ops->sf_get_ftype(sfep);
68219 ctx->pos = off & 0x7fffffff;
68220 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68221 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68222 + char name[sfep->namelen];
68223 + memcpy(name, sfep->name, sfep->namelen);
68224 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68225 + return 0;
68226 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68227 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68228 return 0;
68229 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68230 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68231 index 24c926b6..8726af88 100644
68232 --- a/fs/xfs/xfs_ioctl.c
68233 +++ b/fs/xfs/xfs_ioctl.c
68234 @@ -122,7 +122,7 @@ xfs_find_handle(
68235 }
68236
68237 error = -EFAULT;
68238 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68239 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68240 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68241 goto out_put;
68242
68243 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68244 index 6a51619..9592e1b 100644
68245 --- a/fs/xfs/xfs_linux.h
68246 +++ b/fs/xfs/xfs_linux.h
68247 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68248 * of the compiler which do not like us using do_div in the middle
68249 * of large functions.
68250 */
68251 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68252 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68253 {
68254 __u32 mod;
68255
68256 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68257 return 0;
68258 }
68259 #else
68260 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68261 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68262 {
68263 __u32 mod;
68264
68265 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68266 new file mode 100644
68267 index 0000000..31f8fe4
68268 --- /dev/null
68269 +++ b/grsecurity/Kconfig
68270 @@ -0,0 +1,1182 @@
68271 +#
68272 +# grecurity configuration
68273 +#
68274 +menu "Memory Protections"
68275 +depends on GRKERNSEC
68276 +
68277 +config GRKERNSEC_KMEM
68278 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68279 + default y if GRKERNSEC_CONFIG_AUTO
68280 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68281 + help
68282 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68283 + be written to or read from to modify or leak the contents of the running
68284 + kernel. /dev/port will also not be allowed to be opened, writing to
68285 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68286 + If you have module support disabled, enabling this will close up several
68287 + ways that are currently used to insert malicious code into the running
68288 + kernel.
68289 +
68290 + Even with this feature enabled, we still highly recommend that
68291 + you use the RBAC system, as it is still possible for an attacker to
68292 + modify the running kernel through other more obscure methods.
68293 +
68294 + It is highly recommended that you say Y here if you meet all the
68295 + conditions above.
68296 +
68297 +config GRKERNSEC_VM86
68298 + bool "Restrict VM86 mode"
68299 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68300 + depends on X86_32
68301 +
68302 + help
68303 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68304 + make use of a special execution mode on 32bit x86 processors called
68305 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68306 + video cards and will still work with this option enabled. The purpose
68307 + of the option is to prevent exploitation of emulation errors in
68308 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68309 + Nearly all users should be able to enable this option.
68310 +
68311 +config GRKERNSEC_IO
68312 + bool "Disable privileged I/O"
68313 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68314 + depends on X86
68315 + select RTC_CLASS
68316 + select RTC_INTF_DEV
68317 + select RTC_DRV_CMOS
68318 +
68319 + help
68320 + If you say Y here, all ioperm and iopl calls will return an error.
68321 + Ioperm and iopl can be used to modify the running kernel.
68322 + Unfortunately, some programs need this access to operate properly,
68323 + the most notable of which are XFree86 and hwclock. hwclock can be
68324 + remedied by having RTC support in the kernel, so real-time
68325 + clock support is enabled if this option is enabled, to ensure
68326 + that hwclock operates correctly. If hwclock still does not work,
68327 + either update udev or symlink /dev/rtc to /dev/rtc0.
68328 +
68329 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68330 + you may not be able to boot into a graphical environment with this
68331 + option enabled. In this case, you should use the RBAC system instead.
68332 +
68333 +config GRKERNSEC_BPF_HARDEN
68334 + bool "Harden BPF interpreter"
68335 + default y if GRKERNSEC_CONFIG_AUTO
68336 + help
68337 + Unlike previous versions of grsecurity that hardened both the BPF
68338 + interpreted code against corruption at rest as well as the JIT code
68339 + against JIT-spray attacks and attacker-controlled immediate values
68340 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68341 + and will ensure the interpreted code is read-only at rest. This feature
68342 + may be removed at a later time when eBPF stabilizes to entirely revert
68343 + back to the more secure pre-3.16 BPF interpreter/JIT.
68344 +
68345 + If you're using KERNEXEC, it's recommended that you enable this option
68346 + to supplement the hardening of the kernel.
68347 +
68348 +config GRKERNSEC_PERF_HARDEN
68349 + bool "Disable unprivileged PERF_EVENTS usage by default"
68350 + default y if GRKERNSEC_CONFIG_AUTO
68351 + depends on PERF_EVENTS
68352 + help
68353 + If you say Y here, the range of acceptable values for the
68354 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68355 + default to a new value: 3. When the sysctl is set to this value, no
68356 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68357 +
68358 + Though PERF_EVENTS can be used legitimately for performance monitoring
68359 + and low-level application profiling, it is forced on regardless of
68360 + configuration, has been at fault for several vulnerabilities, and
68361 + creates new opportunities for side channels and other information leaks.
68362 +
68363 + This feature puts PERF_EVENTS into a secure default state and permits
68364 + the administrator to change out of it temporarily if unprivileged
68365 + application profiling is needed.
68366 +
68367 +config GRKERNSEC_RAND_THREADSTACK
68368 + bool "Insert random gaps between thread stacks"
68369 + default y if GRKERNSEC_CONFIG_AUTO
68370 + depends on PAX_RANDMMAP && !PPC
68371 + help
68372 + If you say Y here, a random-sized gap will be enforced between allocated
68373 + thread stacks. Glibc's NPTL and other threading libraries that
68374 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68375 + The implementation currently provides 8 bits of entropy for the gap.
68376 +
68377 + Many distributions do not compile threaded remote services with the
68378 + -fstack-check argument to GCC, causing the variable-sized stack-based
68379 + allocator, alloca(), to not probe the stack on allocation. This
68380 + permits an unbounded alloca() to skip over any guard page and potentially
68381 + modify another thread's stack reliably. An enforced random gap
68382 + reduces the reliability of such an attack and increases the chance
68383 + that such a read/write to another thread's stack instead lands in
68384 + an unmapped area, causing a crash and triggering grsecurity's
68385 + anti-bruteforcing logic.
68386 +
68387 +config GRKERNSEC_PROC_MEMMAP
68388 + bool "Harden ASLR against information leaks and entropy reduction"
68389 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68390 + depends on PAX_NOEXEC || PAX_ASLR
68391 + help
68392 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68393 + give no information about the addresses of its mappings if
68394 + PaX features that rely on random addresses are enabled on the task.
68395 + In addition to sanitizing this information and disabling other
68396 + dangerous sources of information, this option causes reads of sensitive
68397 + /proc/<pid> entries where the file descriptor was opened in a different
68398 + task than the one performing the read. Such attempts are logged.
68399 + This option also limits argv/env strings for suid/sgid binaries
68400 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68401 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68402 + binaries to prevent alternative mmap layouts from being abused.
68403 +
68404 + If you use PaX it is essential that you say Y here as it closes up
68405 + several holes that make full ASLR useless locally.
68406 +
68407 +
68408 +config GRKERNSEC_KSTACKOVERFLOW
68409 + bool "Prevent kernel stack overflows"
68410 + default y if GRKERNSEC_CONFIG_AUTO
68411 + depends on !IA64 && 64BIT
68412 + help
68413 + If you say Y here, the kernel's process stacks will be allocated
68414 + with vmalloc instead of the kernel's default allocator. This
68415 + introduces guard pages that in combination with the alloca checking
68416 + of the STACKLEAK feature prevents all forms of kernel process stack
68417 + overflow abuse. Note that this is different from kernel stack
68418 + buffer overflows.
68419 +
68420 +config GRKERNSEC_BRUTE
68421 + bool "Deter exploit bruteforcing"
68422 + default y if GRKERNSEC_CONFIG_AUTO
68423 + help
68424 + If you say Y here, attempts to bruteforce exploits against forking
68425 + daemons such as apache or sshd, as well as against suid/sgid binaries
68426 + will be deterred. When a child of a forking daemon is killed by PaX
68427 + or crashes due to an illegal instruction or other suspicious signal,
68428 + the parent process will be delayed 30 seconds upon every subsequent
68429 + fork until the administrator is able to assess the situation and
68430 + restart the daemon.
68431 + In the suid/sgid case, the attempt is logged, the user has all their
68432 + existing instances of the suid/sgid binary terminated and will
68433 + be unable to execute any suid/sgid binaries for 15 minutes.
68434 +
68435 + It is recommended that you also enable signal logging in the auditing
68436 + section so that logs are generated when a process triggers a suspicious
68437 + signal.
68438 + If the sysctl option is enabled, a sysctl option with name
68439 + "deter_bruteforce" is created.
68440 +
68441 +config GRKERNSEC_MODHARDEN
68442 + bool "Harden module auto-loading"
68443 + default y if GRKERNSEC_CONFIG_AUTO
68444 + depends on MODULES
68445 + help
68446 + If you say Y here, module auto-loading in response to use of some
68447 + feature implemented by an unloaded module will be restricted to
68448 + root users. Enabling this option helps defend against attacks
68449 + by unprivileged users who abuse the auto-loading behavior to
68450 + cause a vulnerable module to load that is then exploited.
68451 +
68452 + If this option prevents a legitimate use of auto-loading for a
68453 + non-root user, the administrator can execute modprobe manually
68454 + with the exact name of the module mentioned in the alert log.
68455 + Alternatively, the administrator can add the module to the list
68456 + of modules loaded at boot by modifying init scripts.
68457 +
68458 + Modification of init scripts will most likely be needed on
68459 + Ubuntu servers with encrypted home directory support enabled,
68460 + as the first non-root user logging in will cause the ecb(aes),
68461 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68462 +
68463 +config GRKERNSEC_HIDESYM
68464 + bool "Hide kernel symbols"
68465 + default y if GRKERNSEC_CONFIG_AUTO
68466 + select PAX_USERCOPY_SLABS
68467 + help
68468 + If you say Y here, getting information on loaded modules, and
68469 + displaying all kernel symbols through a syscall will be restricted
68470 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68471 + /proc/kallsyms will be restricted to the root user. The RBAC
68472 + system can hide that entry even from root.
68473 +
68474 + This option also prevents leaking of kernel addresses through
68475 + several /proc entries.
68476 +
68477 + Note that this option is only effective provided the following
68478 + conditions are met:
68479 + 1) The kernel using grsecurity is not precompiled by some distribution
68480 + 2) You have also enabled GRKERNSEC_DMESG
68481 + 3) You are using the RBAC system and hiding other files such as your
68482 + kernel image and System.map. Alternatively, enabling this option
68483 + causes the permissions on /boot, /lib/modules, and the kernel
68484 + source directory to change at compile time to prevent
68485 + reading by non-root users.
68486 + If the above conditions are met, this option will aid in providing a
68487 + useful protection against local kernel exploitation of overflows
68488 + and arbitrary read/write vulnerabilities.
68489 +
68490 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68491 + in addition to this feature.
68492 +
68493 +config GRKERNSEC_RANDSTRUCT
68494 + bool "Randomize layout of sensitive kernel structures"
68495 + default y if GRKERNSEC_CONFIG_AUTO
68496 + select GRKERNSEC_HIDESYM
68497 + select MODVERSIONS if MODULES
68498 + help
68499 + If you say Y here, the layouts of a number of sensitive kernel
68500 + structures (task, fs, cred, etc) and all structures composed entirely
68501 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68502 + This can introduce the requirement of an additional infoleak
68503 + vulnerability for exploits targeting these structure types.
68504 +
68505 + Enabling this feature will introduce some performance impact, slightly
68506 + increase memory usage, and prevent the use of forensic tools like
68507 + Volatility against the system (unless the kernel source tree isn't
68508 + cleaned after kernel installation).
68509 +
68510 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68511 + It remains after a make clean to allow for external modules to be compiled
68512 + with the existing seed and will be removed by a make mrproper or
68513 + make distclean.
68514 +
68515 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68516 + to install the supporting headers explicitly in addition to the normal
68517 + gcc package.
68518 +
68519 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68520 + bool "Use cacheline-aware structure randomization"
68521 + depends on GRKERNSEC_RANDSTRUCT
68522 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68523 + help
68524 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68525 + at restricting randomization to cacheline-sized groups of elements. It
68526 + will further not randomize bitfields in structures. This reduces the
68527 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68528 +
68529 +config GRKERNSEC_KERN_LOCKOUT
68530 + bool "Active kernel exploit response"
68531 + default y if GRKERNSEC_CONFIG_AUTO
68532 + depends on X86 || ARM || PPC || SPARC
68533 + help
68534 + If you say Y here, when a PaX alert is triggered due to suspicious
68535 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68536 + or an OOPS occurs due to bad memory accesses, instead of just
68537 + terminating the offending process (and potentially allowing
68538 + a subsequent exploit from the same user), we will take one of two
68539 + actions:
68540 + If the user was root, we will panic the system
68541 + If the user was non-root, we will log the attempt, terminate
68542 + all processes owned by the user, then prevent them from creating
68543 + any new processes until the system is restarted
68544 + This deters repeated kernel exploitation/bruteforcing attempts
68545 + and is useful for later forensics.
68546 +
68547 +config GRKERNSEC_OLD_ARM_USERLAND
68548 + bool "Old ARM userland compatibility"
68549 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68550 + help
68551 + If you say Y here, stubs of executable code to perform such operations
68552 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68553 + table. This is unfortunately needed for old ARM userland meant to run
68554 + across a wide range of processors. Without this option enabled,
68555 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68556 + which is enough for Linaro userlands or other userlands designed for v6
68557 + and newer ARM CPUs. It's recommended that you try without this option enabled
68558 + first, and only enable it if your userland does not boot (it will likely fail
68559 + at init time).
68560 +
68561 +endmenu
68562 +menu "Role Based Access Control Options"
68563 +depends on GRKERNSEC
68564 +
68565 +config GRKERNSEC_RBAC_DEBUG
68566 + bool
68567 +
68568 +config GRKERNSEC_NO_RBAC
68569 + bool "Disable RBAC system"
68570 + help
68571 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68572 + preventing the RBAC system from being enabled. You should only say Y
68573 + here if you have no intention of using the RBAC system, so as to prevent
68574 + an attacker with root access from misusing the RBAC system to hide files
68575 + and processes when loadable module support and /dev/[k]mem have been
68576 + locked down.
68577 +
68578 +config GRKERNSEC_ACL_HIDEKERN
68579 + bool "Hide kernel processes"
68580 + help
68581 + If you say Y here, all kernel threads will be hidden to all
68582 + processes but those whose subject has the "view hidden processes"
68583 + flag.
68584 +
68585 +config GRKERNSEC_ACL_MAXTRIES
68586 + int "Maximum tries before password lockout"
68587 + default 3
68588 + help
68589 + This option enforces the maximum number of times a user can attempt
68590 + to authorize themselves with the grsecurity RBAC system before being
68591 + denied the ability to attempt authorization again for a specified time.
68592 + The lower the number, the harder it will be to brute-force a password.
68593 +
68594 +config GRKERNSEC_ACL_TIMEOUT
68595 + int "Time to wait after max password tries, in seconds"
68596 + default 30
68597 + help
68598 + This option specifies the time the user must wait after attempting to
68599 + authorize to the RBAC system with the maximum number of invalid
68600 + passwords. The higher the number, the harder it will be to brute-force
68601 + a password.
68602 +
68603 +endmenu
68604 +menu "Filesystem Protections"
68605 +depends on GRKERNSEC
68606 +
68607 +config GRKERNSEC_PROC
68608 + bool "Proc restrictions"
68609 + default y if GRKERNSEC_CONFIG_AUTO
68610 + help
68611 + If you say Y here, the permissions of the /proc filesystem
68612 + will be altered to enhance system security and privacy. You MUST
68613 + choose either a user only restriction or a user and group restriction.
68614 + Depending upon the option you choose, you can either restrict users to
68615 + see only the processes they themselves run, or choose a group that can
68616 + view all processes and files normally restricted to root if you choose
68617 + the "restrict to user only" option. NOTE: If you're running identd or
68618 + ntpd as a non-root user, you will have to run it as the group you
68619 + specify here.
68620 +
68621 +config GRKERNSEC_PROC_USER
68622 + bool "Restrict /proc to user only"
68623 + depends on GRKERNSEC_PROC
68624 + help
68625 + If you say Y here, non-root users will only be able to view their own
68626 + processes, and restricts them from viewing network-related information,
68627 + and viewing kernel symbol and module information.
68628 +
68629 +config GRKERNSEC_PROC_USERGROUP
68630 + bool "Allow special group"
68631 + default y if GRKERNSEC_CONFIG_AUTO
68632 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68633 + help
68634 + If you say Y here, you will be able to select a group that will be
68635 + able to view all processes and network-related information. If you've
68636 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68637 + remain hidden. This option is useful if you want to run identd as
68638 + a non-root user. The group you select may also be chosen at boot time
68639 + via "grsec_proc_gid=" on the kernel commandline.
68640 +
68641 +config GRKERNSEC_PROC_GID
68642 + int "GID for special group"
68643 + depends on GRKERNSEC_PROC_USERGROUP
68644 + default 1001
68645 +
68646 +config GRKERNSEC_PROC_ADD
68647 + bool "Additional restrictions"
68648 + default y if GRKERNSEC_CONFIG_AUTO
68649 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68650 + help
68651 + If you say Y here, additional restrictions will be placed on
68652 + /proc that keep normal users from viewing device information and
68653 + slabinfo information that could be useful for exploits.
68654 +
68655 +config GRKERNSEC_LINK
68656 + bool "Linking restrictions"
68657 + default y if GRKERNSEC_CONFIG_AUTO
68658 + help
68659 + If you say Y here, /tmp race exploits will be prevented, since users
68660 + will no longer be able to follow symlinks owned by other users in
68661 + world-writable +t directories (e.g. /tmp), unless the owner of the
68662 + symlink is the owner of the directory. users will also not be
68663 + able to hardlink to files they do not own. If the sysctl option is
68664 + enabled, a sysctl option with name "linking_restrictions" is created.
68665 +
68666 +config GRKERNSEC_SYMLINKOWN
68667 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68668 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68669 + help
68670 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68671 + that prevents it from being used as a security feature. As Apache
68672 + verifies the symlink by performing a stat() against the target of
68673 + the symlink before it is followed, an attacker can setup a symlink
68674 + to point to a same-owned file, then replace the symlink with one
68675 + that targets another user's file just after Apache "validates" the
68676 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68677 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68678 + will be in place for the group you specify. If the sysctl option
68679 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68680 + created.
68681 +
68682 +config GRKERNSEC_SYMLINKOWN_GID
68683 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68684 + depends on GRKERNSEC_SYMLINKOWN
68685 + default 1006
68686 + help
68687 + Setting this GID determines what group kernel-enforced
68688 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68689 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68690 +
68691 +config GRKERNSEC_FIFO
68692 + bool "FIFO restrictions"
68693 + default y if GRKERNSEC_CONFIG_AUTO
68694 + help
68695 + If you say Y here, users will not be able to write to FIFOs they don't
68696 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68697 + the FIFO is the same owner of the directory it's held in. If the sysctl
68698 + option is enabled, a sysctl option with name "fifo_restrictions" is
68699 + created.
68700 +
68701 +config GRKERNSEC_SYSFS_RESTRICT
68702 + bool "Sysfs/debugfs restriction"
68703 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68704 + depends on SYSFS
68705 + help
68706 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68707 + any filesystem normally mounted under it (e.g. debugfs) will be
68708 + mostly accessible only by root. These filesystems generally provide access
68709 + to hardware and debug information that isn't appropriate for unprivileged
68710 + users of the system. Sysfs and debugfs have also become a large source
68711 + of new vulnerabilities, ranging from infoleaks to local compromise.
68712 + There has been very little oversight with an eye toward security involved
68713 + in adding new exporters of information to these filesystems, so their
68714 + use is discouraged.
68715 + For reasons of compatibility, a few directories have been whitelisted
68716 + for access by non-root users:
68717 + /sys/fs/selinux
68718 + /sys/fs/fuse
68719 + /sys/devices/system/cpu
68720 +
68721 +config GRKERNSEC_ROFS
68722 + bool "Runtime read-only mount protection"
68723 + depends on SYSCTL
68724 + help
68725 + If you say Y here, a sysctl option with name "romount_protect" will
68726 + be created. By setting this option to 1 at runtime, filesystems
68727 + will be protected in the following ways:
68728 + * No new writable mounts will be allowed
68729 + * Existing read-only mounts won't be able to be remounted read/write
68730 + * Write operations will be denied on all block devices
68731 + This option acts independently of grsec_lock: once it is set to 1,
68732 + it cannot be turned off. Therefore, please be mindful of the resulting
68733 + behavior if this option is enabled in an init script on a read-only
68734 + filesystem.
68735 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68736 + and GRKERNSEC_IO should be enabled and module loading disabled via
68737 + config or at runtime.
68738 + This feature is mainly intended for secure embedded systems.
68739 +
68740 +
68741 +config GRKERNSEC_DEVICE_SIDECHANNEL
68742 + bool "Eliminate stat/notify-based device sidechannels"
68743 + default y if GRKERNSEC_CONFIG_AUTO
68744 + help
68745 + If you say Y here, timing analyses on block or character
68746 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68747 + will be thwarted for unprivileged users. If a process without
68748 + CAP_MKNOD stats such a device, the last access and last modify times
68749 + will match the device's create time. No access or modify events
68750 + will be triggered through inotify/dnotify/fanotify for such devices.
68751 + This feature will prevent attacks that may at a minimum
68752 + allow an attacker to determine the administrator's password length.
68753 +
68754 +config GRKERNSEC_CHROOT
68755 + bool "Chroot jail restrictions"
68756 + default y if GRKERNSEC_CONFIG_AUTO
68757 + help
68758 + If you say Y here, you will be able to choose several options that will
68759 + make breaking out of a chrooted jail much more difficult. If you
68760 + encounter no software incompatibilities with the following options, it
68761 + is recommended that you enable each one.
68762 +
68763 + Note that the chroot restrictions are not intended to apply to "chroots"
68764 + to directories that are simple bind mounts of the global root filesystem.
68765 + For several other reasons, a user shouldn't expect any significant
68766 + security by performing such a chroot.
68767 +
68768 +config GRKERNSEC_CHROOT_MOUNT
68769 + bool "Deny mounts"
68770 + default y if GRKERNSEC_CONFIG_AUTO
68771 + depends on GRKERNSEC_CHROOT
68772 + help
68773 + If you say Y here, processes inside a chroot will not be able to
68774 + mount or remount filesystems. If the sysctl option is enabled, a
68775 + sysctl option with name "chroot_deny_mount" is created.
68776 +
68777 +config GRKERNSEC_CHROOT_DOUBLE
68778 + bool "Deny double-chroots"
68779 + default y if GRKERNSEC_CONFIG_AUTO
68780 + depends on GRKERNSEC_CHROOT
68781 + help
68782 + If you say Y here, processes inside a chroot will not be able to chroot
68783 + again outside the chroot. This is a widely used method of breaking
68784 + out of a chroot jail and should not be allowed. If the sysctl
68785 + option is enabled, a sysctl option with name
68786 + "chroot_deny_chroot" is created.
68787 +
68788 +config GRKERNSEC_CHROOT_PIVOT
68789 + bool "Deny pivot_root in chroot"
68790 + default y if GRKERNSEC_CONFIG_AUTO
68791 + depends on GRKERNSEC_CHROOT
68792 + help
68793 + If you say Y here, processes inside a chroot will not be able to use
68794 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68795 + works similar to chroot in that it changes the root filesystem. This
68796 + function could be misused in a chrooted process to attempt to break out
68797 + of the chroot, and therefore should not be allowed. If the sysctl
68798 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68799 + created.
68800 +
68801 +config GRKERNSEC_CHROOT_CHDIR
68802 + bool "Enforce chdir(\"/\") on all chroots"
68803 + default y if GRKERNSEC_CONFIG_AUTO
68804 + depends on GRKERNSEC_CHROOT
68805 + help
68806 + If you say Y here, the current working directory of all newly-chrooted
68807 + applications will be set to the the root directory of the chroot.
68808 + The man page on chroot(2) states:
68809 + Note that this call does not change the current working
68810 + directory, so that `.' can be outside the tree rooted at
68811 + `/'. In particular, the super-user can escape from a
68812 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68813 +
68814 + It is recommended that you say Y here, since it's not known to break
68815 + any software. If the sysctl option is enabled, a sysctl option with
68816 + name "chroot_enforce_chdir" is created.
68817 +
68818 +config GRKERNSEC_CHROOT_CHMOD
68819 + bool "Deny (f)chmod +s"
68820 + default y if GRKERNSEC_CONFIG_AUTO
68821 + depends on GRKERNSEC_CHROOT
68822 + help
68823 + If you say Y here, processes inside a chroot will not be able to chmod
68824 + or fchmod files to make them have suid or sgid bits. This protects
68825 + against another published method of breaking a chroot. If the sysctl
68826 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68827 + created.
68828 +
68829 +config GRKERNSEC_CHROOT_FCHDIR
68830 + bool "Deny fchdir and fhandle out of chroot"
68831 + default y if GRKERNSEC_CONFIG_AUTO
68832 + depends on GRKERNSEC_CHROOT
68833 + help
68834 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68835 + to a file descriptor of the chrooting process that points to a directory
68836 + outside the filesystem will be stopped. Additionally, this option prevents
68837 + use of the recently-created syscall for opening files by a guessable "file
68838 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68839 + with name "chroot_deny_fchdir" is created.
68840 +
68841 +config GRKERNSEC_CHROOT_MKNOD
68842 + bool "Deny mknod"
68843 + default y if GRKERNSEC_CONFIG_AUTO
68844 + depends on GRKERNSEC_CHROOT
68845 + help
68846 + If you say Y here, processes inside a chroot will not be allowed to
68847 + mknod. The problem with using mknod inside a chroot is that it
68848 + would allow an attacker to create a device entry that is the same
68849 + as one on the physical root of your system, which could range from
68850 + anything from the console device to a device for your harddrive (which
68851 + they could then use to wipe the drive or steal data). It is recommended
68852 + that you say Y here, unless you run into software incompatibilities.
68853 + If the sysctl option is enabled, a sysctl option with name
68854 + "chroot_deny_mknod" is created.
68855 +
68856 +config GRKERNSEC_CHROOT_SHMAT
68857 + bool "Deny shmat() out of chroot"
68858 + default y if GRKERNSEC_CONFIG_AUTO
68859 + depends on GRKERNSEC_CHROOT
68860 + help
68861 + If you say Y here, processes inside a chroot will not be able to attach
68862 + to shared memory segments that were created outside of the chroot jail.
68863 + It is recommended that you say Y here. If the sysctl option is enabled,
68864 + a sysctl option with name "chroot_deny_shmat" is created.
68865 +
68866 +config GRKERNSEC_CHROOT_UNIX
68867 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68868 + default y if GRKERNSEC_CONFIG_AUTO
68869 + depends on GRKERNSEC_CHROOT
68870 + help
68871 + If you say Y here, processes inside a chroot will not be able to
68872 + connect to abstract (meaning not belonging to a filesystem) Unix
68873 + domain sockets that were bound outside of a chroot. It is recommended
68874 + that you say Y here. If the sysctl option is enabled, a sysctl option
68875 + with name "chroot_deny_unix" is created.
68876 +
68877 +config GRKERNSEC_CHROOT_FINDTASK
68878 + bool "Protect outside processes"
68879 + default y if GRKERNSEC_CONFIG_AUTO
68880 + depends on GRKERNSEC_CHROOT
68881 + help
68882 + If you say Y here, processes inside a chroot will not be able to
68883 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68884 + getsid, or view any process outside of the chroot. If the sysctl
68885 + option is enabled, a sysctl option with name "chroot_findtask" is
68886 + created.
68887 +
68888 +config GRKERNSEC_CHROOT_NICE
68889 + bool "Restrict priority changes"
68890 + default y if GRKERNSEC_CONFIG_AUTO
68891 + depends on GRKERNSEC_CHROOT
68892 + help
68893 + If you say Y here, processes inside a chroot will not be able to raise
68894 + the priority of processes in the chroot, or alter the priority of
68895 + processes outside the chroot. This provides more security than simply
68896 + removing CAP_SYS_NICE from the process' capability set. If the
68897 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68898 + is created.
68899 +
68900 +config GRKERNSEC_CHROOT_SYSCTL
68901 + bool "Deny sysctl writes"
68902 + default y if GRKERNSEC_CONFIG_AUTO
68903 + depends on GRKERNSEC_CHROOT
68904 + help
68905 + If you say Y here, an attacker in a chroot will not be able to
68906 + write to sysctl entries, either by sysctl(2) or through a /proc
68907 + interface. It is strongly recommended that you say Y here. If the
68908 + sysctl option is enabled, a sysctl option with name
68909 + "chroot_deny_sysctl" is created.
68910 +
68911 +config GRKERNSEC_CHROOT_RENAME
68912 + bool "Deny bad renames"
68913 + default y if GRKERNSEC_CONFIG_AUTO
68914 + depends on GRKERNSEC_CHROOT
68915 + help
68916 + If you say Y here, an attacker in a chroot will not be able to
68917 + abuse the ability to create double chroots to break out of the
68918 + chroot by exploiting a race condition between a rename of a directory
68919 + within a chroot against an open of a symlink with relative path
68920 + components. This feature will likewise prevent an accomplice outside
68921 + a chroot from enabling a user inside the chroot to break out and make
68922 + use of their credentials on the global filesystem. Enabling this
68923 + feature is essential to prevent root users from breaking out of a
68924 + chroot. If the sysctl option is enabled, a sysctl option with name
68925 + "chroot_deny_bad_rename" is created.
68926 +
68927 +config GRKERNSEC_CHROOT_CAPS
68928 + bool "Capability restrictions"
68929 + default y if GRKERNSEC_CONFIG_AUTO
68930 + depends on GRKERNSEC_CHROOT
68931 + help
68932 + If you say Y here, the capabilities on all processes within a
68933 + chroot jail will be lowered to stop module insertion, raw i/o,
68934 + system and net admin tasks, rebooting the system, modifying immutable
68935 + files, modifying IPC owned by another, and changing the system time.
68936 + This is left an option because it can break some apps. Disable this
68937 + if your chrooted apps are having problems performing those kinds of
68938 + tasks. If the sysctl option is enabled, a sysctl option with
68939 + name "chroot_caps" is created.
68940 +
68941 +config GRKERNSEC_CHROOT_INITRD
68942 + bool "Exempt initrd tasks from restrictions"
68943 + default y if GRKERNSEC_CONFIG_AUTO
68944 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68945 + help
68946 + If you say Y here, tasks started prior to init will be exempted from
68947 + grsecurity's chroot restrictions. This option is mainly meant to
68948 + resolve Plymouth's performing privileged operations unnecessarily
68949 + in a chroot.
68950 +
68951 +endmenu
68952 +menu "Kernel Auditing"
68953 +depends on GRKERNSEC
68954 +
68955 +config GRKERNSEC_AUDIT_GROUP
68956 + bool "Single group for auditing"
68957 + help
68958 + If you say Y here, the exec and chdir logging features will only operate
68959 + on a group you specify. This option is recommended if you only want to
68960 + watch certain users instead of having a large amount of logs from the
68961 + entire system. If the sysctl option is enabled, a sysctl option with
68962 + name "audit_group" is created.
68963 +
68964 +config GRKERNSEC_AUDIT_GID
68965 + int "GID for auditing"
68966 + depends on GRKERNSEC_AUDIT_GROUP
68967 + default 1007
68968 +
68969 +config GRKERNSEC_EXECLOG
68970 + bool "Exec logging"
68971 + help
68972 + If you say Y here, all execve() calls will be logged (since the
68973 + other exec*() calls are frontends to execve(), all execution
68974 + will be logged). Useful for shell-servers that like to keep track
68975 + of their users. If the sysctl option is enabled, a sysctl option with
68976 + name "exec_logging" is created.
68977 + WARNING: This option when enabled will produce a LOT of logs, especially
68978 + on an active system.
68979 +
68980 +config GRKERNSEC_RESLOG
68981 + bool "Resource logging"
68982 + default y if GRKERNSEC_CONFIG_AUTO
68983 + help
68984 + If you say Y here, all attempts to overstep resource limits will
68985 + be logged with the resource name, the requested size, and the current
68986 + limit. It is highly recommended that you say Y here. If the sysctl
68987 + option is enabled, a sysctl option with name "resource_logging" is
68988 + created. If the RBAC system is enabled, the sysctl value is ignored.
68989 +
68990 +config GRKERNSEC_CHROOT_EXECLOG
68991 + bool "Log execs within chroot"
68992 + help
68993 + If you say Y here, all executions inside a chroot jail will be logged
68994 + to syslog. This can cause a large amount of logs if certain
68995 + applications (eg. djb's daemontools) are installed on the system, and
68996 + is therefore left as an option. If the sysctl option is enabled, a
68997 + sysctl option with name "chroot_execlog" is created.
68998 +
68999 +config GRKERNSEC_AUDIT_PTRACE
69000 + bool "Ptrace logging"
69001 + help
69002 + If you say Y here, all attempts to attach to a process via ptrace
69003 + will be logged. If the sysctl option is enabled, a sysctl option
69004 + with name "audit_ptrace" is created.
69005 +
69006 +config GRKERNSEC_AUDIT_CHDIR
69007 + bool "Chdir logging"
69008 + help
69009 + If you say Y here, all chdir() calls will be logged. If the sysctl
69010 + option is enabled, a sysctl option with name "audit_chdir" is created.
69011 +
69012 +config GRKERNSEC_AUDIT_MOUNT
69013 + bool "(Un)Mount logging"
69014 + help
69015 + If you say Y here, all mounts and unmounts will be logged. If the
69016 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69017 + created.
69018 +
69019 +config GRKERNSEC_SIGNAL
69020 + bool "Signal logging"
69021 + default y if GRKERNSEC_CONFIG_AUTO
69022 + help
69023 + If you say Y here, certain important signals will be logged, such as
69024 + SIGSEGV, which will as a result inform you of when a error in a program
69025 + occurred, which in some cases could mean a possible exploit attempt.
69026 + If the sysctl option is enabled, a sysctl option with name
69027 + "signal_logging" is created.
69028 +
69029 +config GRKERNSEC_FORKFAIL
69030 + bool "Fork failure logging"
69031 + help
69032 + If you say Y here, all failed fork() attempts will be logged.
69033 + This could suggest a fork bomb, or someone attempting to overstep
69034 + their process limit. If the sysctl option is enabled, a sysctl option
69035 + with name "forkfail_logging" is created.
69036 +
69037 +config GRKERNSEC_TIME
69038 + bool "Time change logging"
69039 + default y if GRKERNSEC_CONFIG_AUTO
69040 + help
69041 + If you say Y here, any changes of the system clock will be logged.
69042 + If the sysctl option is enabled, a sysctl option with name
69043 + "timechange_logging" is created.
69044 +
69045 +config GRKERNSEC_PROC_IPADDR
69046 + bool "/proc/<pid>/ipaddr support"
69047 + default y if GRKERNSEC_CONFIG_AUTO
69048 + help
69049 + If you say Y here, a new entry will be added to each /proc/<pid>
69050 + directory that contains the IP address of the person using the task.
69051 + The IP is carried across local TCP and AF_UNIX stream sockets.
69052 + This information can be useful for IDS/IPSes to perform remote response
69053 + to a local attack. The entry is readable by only the owner of the
69054 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69055 + the RBAC system), and thus does not create privacy concerns.
69056 +
69057 +config GRKERNSEC_RWXMAP_LOG
69058 + bool 'Denied RWX mmap/mprotect logging'
69059 + default y if GRKERNSEC_CONFIG_AUTO
69060 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69061 + help
69062 + If you say Y here, calls to mmap() and mprotect() with explicit
69063 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69064 + denied by the PAX_MPROTECT feature. This feature will also
69065 + log other problematic scenarios that can occur when PAX_MPROTECT
69066 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69067 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69068 + is created.
69069 +
69070 +endmenu
69071 +
69072 +menu "Executable Protections"
69073 +depends on GRKERNSEC
69074 +
69075 +config GRKERNSEC_DMESG
69076 + bool "Dmesg(8) restriction"
69077 + default y if GRKERNSEC_CONFIG_AUTO
69078 + help
69079 + If you say Y here, non-root users will not be able to use dmesg(8)
69080 + to view the contents of the kernel's circular log buffer.
69081 + The kernel's log buffer often contains kernel addresses and other
69082 + identifying information useful to an attacker in fingerprinting a
69083 + system for a targeted exploit.
69084 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69085 + created.
69086 +
69087 +config GRKERNSEC_HARDEN_PTRACE
69088 + bool "Deter ptrace-based process snooping"
69089 + default y if GRKERNSEC_CONFIG_AUTO
69090 + help
69091 + If you say Y here, TTY sniffers and other malicious monitoring
69092 + programs implemented through ptrace will be defeated. If you
69093 + have been using the RBAC system, this option has already been
69094 + enabled for several years for all users, with the ability to make
69095 + fine-grained exceptions.
69096 +
69097 + This option only affects the ability of non-root users to ptrace
69098 + processes that are not a descendent of the ptracing process.
69099 + This means that strace ./binary and gdb ./binary will still work,
69100 + but attaching to arbitrary processes will not. If the sysctl
69101 + option is enabled, a sysctl option with name "harden_ptrace" is
69102 + created.
69103 +
69104 +config GRKERNSEC_PTRACE_READEXEC
69105 + bool "Require read access to ptrace sensitive binaries"
69106 + default y if GRKERNSEC_CONFIG_AUTO
69107 + help
69108 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69109 + binaries. This option is useful in environments that
69110 + remove the read bits (e.g. file mode 4711) from suid binaries to
69111 + prevent infoleaking of their contents. This option adds
69112 + consistency to the use of that file mode, as the binary could normally
69113 + be read out when run without privileges while ptracing.
69114 +
69115 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69116 + is created.
69117 +
69118 +config GRKERNSEC_SETXID
69119 + bool "Enforce consistent multithreaded privileges"
69120 + default y if GRKERNSEC_CONFIG_AUTO
69121 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69122 + help
69123 + If you say Y here, a change from a root uid to a non-root uid
69124 + in a multithreaded application will cause the resulting uids,
69125 + gids, supplementary groups, and capabilities in that thread
69126 + to be propagated to the other threads of the process. In most
69127 + cases this is unnecessary, as glibc will emulate this behavior
69128 + on behalf of the application. Other libcs do not act in the
69129 + same way, allowing the other threads of the process to continue
69130 + running with root privileges. If the sysctl option is enabled,
69131 + a sysctl option with name "consistent_setxid" is created.
69132 +
69133 +config GRKERNSEC_HARDEN_IPC
69134 + bool "Disallow access to overly-permissive IPC objects"
69135 + default y if GRKERNSEC_CONFIG_AUTO
69136 + depends on SYSVIPC
69137 + help
69138 + If you say Y here, access to overly-permissive IPC objects (shared
69139 + memory, message queues, and semaphores) will be denied for processes
69140 + given the following criteria beyond normal permission checks:
69141 + 1) If the IPC object is world-accessible and the euid doesn't match
69142 + that of the creator or current uid for the IPC object
69143 + 2) If the IPC object is group-accessible and the egid doesn't
69144 + match that of the creator or current gid for the IPC object
69145 + It's a common error to grant too much permission to these objects,
69146 + with impact ranging from denial of service and information leaking to
69147 + privilege escalation. This feature was developed in response to
69148 + research by Tim Brown:
69149 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69150 + who found hundreds of such insecure usages. Processes with
69151 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69152 + If the sysctl option is enabled, a sysctl option with name
69153 + "harden_ipc" is created.
69154 +
69155 +config GRKERNSEC_TPE
69156 + bool "Trusted Path Execution (TPE)"
69157 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69158 + help
69159 + If you say Y here, you will be able to choose a gid to add to the
69160 + supplementary groups of users you want to mark as "untrusted."
69161 + These users will not be able to execute any files that are not in
69162 + root-owned directories writable only by root. If the sysctl option
69163 + is enabled, a sysctl option with name "tpe" is created.
69164 +
69165 +config GRKERNSEC_TPE_ALL
69166 + bool "Partially restrict all non-root users"
69167 + depends on GRKERNSEC_TPE
69168 + help
69169 + If you say Y here, all non-root users will be covered under
69170 + a weaker TPE restriction. This is separate from, and in addition to,
69171 + the main TPE options that you have selected elsewhere. Thus, if a
69172 + "trusted" GID is chosen, this restriction applies to even that GID.
69173 + Under this restriction, all non-root users will only be allowed to
69174 + execute files in directories they own that are not group or
69175 + world-writable, or in directories owned by root and writable only by
69176 + root. If the sysctl option is enabled, a sysctl option with name
69177 + "tpe_restrict_all" is created.
69178 +
69179 +config GRKERNSEC_TPE_INVERT
69180 + bool "Invert GID option"
69181 + depends on GRKERNSEC_TPE
69182 + help
69183 + If you say Y here, the group you specify in the TPE configuration will
69184 + decide what group TPE restrictions will be *disabled* for. This
69185 + option is useful if you want TPE restrictions to be applied to most
69186 + users on the system. If the sysctl option is enabled, a sysctl option
69187 + with name "tpe_invert" is created. Unlike other sysctl options, this
69188 + entry will default to on for backward-compatibility.
69189 +
69190 +config GRKERNSEC_TPE_GID
69191 + int
69192 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69193 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69194 +
69195 +config GRKERNSEC_TPE_UNTRUSTED_GID
69196 + int "GID for TPE-untrusted users"
69197 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69198 + default 1005
69199 + help
69200 + Setting this GID determines what group TPE restrictions will be
69201 + *enabled* for. If the sysctl option is enabled, a sysctl option
69202 + with name "tpe_gid" is created.
69203 +
69204 +config GRKERNSEC_TPE_TRUSTED_GID
69205 + int "GID for TPE-trusted users"
69206 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69207 + default 1005
69208 + help
69209 + Setting this GID determines what group TPE restrictions will be
69210 + *disabled* for. If the sysctl option is enabled, a sysctl option
69211 + with name "tpe_gid" is created.
69212 +
69213 +endmenu
69214 +menu "Network Protections"
69215 +depends on GRKERNSEC
69216 +
69217 +config GRKERNSEC_BLACKHOLE
69218 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69219 + default y if GRKERNSEC_CONFIG_AUTO
69220 + depends on NET
69221 + help
69222 + If you say Y here, neither TCP resets nor ICMP
69223 + destination-unreachable packets will be sent in response to packets
69224 + sent to ports for which no associated listening process exists.
69225 + It will also prevent the sending of ICMP protocol unreachable packets
69226 + in response to packets with unknown protocols.
69227 + This feature supports both IPV4 and IPV6 and exempts the
69228 + loopback interface from blackholing. Enabling this feature
69229 + makes a host more resilient to DoS attacks and reduces network
69230 + visibility against scanners.
69231 +
69232 + The blackhole feature as-implemented is equivalent to the FreeBSD
69233 + blackhole feature, as it prevents RST responses to all packets, not
69234 + just SYNs. Under most application behavior this causes no
69235 + problems, but applications (like haproxy) may not close certain
69236 + connections in a way that cleanly terminates them on the remote
69237 + end, leaving the remote host in LAST_ACK state. Because of this
69238 + side-effect and to prevent intentional LAST_ACK DoSes, this
69239 + feature also adds automatic mitigation against such attacks.
69240 + The mitigation drastically reduces the amount of time a socket
69241 + can spend in LAST_ACK state. If you're using haproxy and not
69242 + all servers it connects to have this option enabled, consider
69243 + disabling this feature on the haproxy host.
69244 +
69245 + If the sysctl option is enabled, two sysctl options with names
69246 + "ip_blackhole" and "lastack_retries" will be created.
69247 + While "ip_blackhole" takes the standard zero/non-zero on/off
69248 + toggle, "lastack_retries" uses the same kinds of values as
69249 + "tcp_retries1" and "tcp_retries2". The default value of 4
69250 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69251 + state.
69252 +
69253 +config GRKERNSEC_NO_SIMULT_CONNECT
69254 + bool "Disable TCP Simultaneous Connect"
69255 + default y if GRKERNSEC_CONFIG_AUTO
69256 + depends on NET
69257 + help
69258 + If you say Y here, a feature by Willy Tarreau will be enabled that
69259 + removes a weakness in Linux's strict implementation of TCP that
69260 + allows two clients to connect to each other without either entering
69261 + a listening state. The weakness allows an attacker to easily prevent
69262 + a client from connecting to a known server provided the source port
69263 + for the connection is guessed correctly.
69264 +
69265 + As the weakness could be used to prevent an antivirus or IPS from
69266 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69267 + it should be eliminated by enabling this option. Though Linux is
69268 + one of few operating systems supporting simultaneous connect, it
69269 + has no legitimate use in practice and is rarely supported by firewalls.
69270 +
69271 +config GRKERNSEC_SOCKET
69272 + bool "Socket restrictions"
69273 + depends on NET
69274 + help
69275 + If you say Y here, you will be able to choose from several options.
69276 + If you assign a GID on your system and add it to the supplementary
69277 + groups of users you want to restrict socket access to, this patch
69278 + will perform up to three things, based on the option(s) you choose.
69279 +
69280 +config GRKERNSEC_SOCKET_ALL
69281 + bool "Deny any sockets to group"
69282 + depends on GRKERNSEC_SOCKET
69283 + help
69284 + If you say Y here, you will be able to choose a GID of whose users will
69285 + be unable to connect to other hosts from your machine or run server
69286 + applications from your machine. If the sysctl option is enabled, a
69287 + sysctl option with name "socket_all" is created.
69288 +
69289 +config GRKERNSEC_SOCKET_ALL_GID
69290 + int "GID to deny all sockets for"
69291 + depends on GRKERNSEC_SOCKET_ALL
69292 + default 1004
69293 + help
69294 + Here you can choose the GID to disable socket access for. Remember to
69295 + add the users you want socket access disabled for to the GID
69296 + specified here. If the sysctl option is enabled, a sysctl option
69297 + with name "socket_all_gid" is created.
69298 +
69299 +config GRKERNSEC_SOCKET_CLIENT
69300 + bool "Deny client sockets to group"
69301 + depends on GRKERNSEC_SOCKET
69302 + help
69303 + If you say Y here, you will be able to choose a GID of whose users will
69304 + be unable to connect to other hosts from your machine, but will be
69305 + able to run servers. If this option is enabled, all users in the group
69306 + you specify will have to use passive mode when initiating ftp transfers
69307 + from the shell on your machine. If the sysctl option is enabled, a
69308 + sysctl option with name "socket_client" is created.
69309 +
69310 +config GRKERNSEC_SOCKET_CLIENT_GID
69311 + int "GID to deny client sockets for"
69312 + depends on GRKERNSEC_SOCKET_CLIENT
69313 + default 1003
69314 + help
69315 + Here you can choose the GID to disable client socket access for.
69316 + Remember to add the users you want client socket access disabled for to
69317 + the GID specified here. If the sysctl option is enabled, a sysctl
69318 + option with name "socket_client_gid" is created.
69319 +
69320 +config GRKERNSEC_SOCKET_SERVER
69321 + bool "Deny server sockets to group"
69322 + depends on GRKERNSEC_SOCKET
69323 + help
69324 + If you say Y here, you will be able to choose a GID of whose users will
69325 + be unable to run server applications from your machine. If the sysctl
69326 + option is enabled, a sysctl option with name "socket_server" is created.
69327 +
69328 +config GRKERNSEC_SOCKET_SERVER_GID
69329 + int "GID to deny server sockets for"
69330 + depends on GRKERNSEC_SOCKET_SERVER
69331 + default 1002
69332 + help
69333 + Here you can choose the GID to disable server socket access for.
69334 + Remember to add the users you want server socket access disabled for to
69335 + the GID specified here. If the sysctl option is enabled, a sysctl
69336 + option with name "socket_server_gid" is created.
69337 +
69338 +endmenu
69339 +
69340 +menu "Physical Protections"
69341 +depends on GRKERNSEC
69342 +
69343 +config GRKERNSEC_DENYUSB
69344 + bool "Deny new USB connections after toggle"
69345 + default y if GRKERNSEC_CONFIG_AUTO
69346 + depends on SYSCTL && USB_SUPPORT
69347 + help
69348 + If you say Y here, a new sysctl option with name "deny_new_usb"
69349 + will be created. Setting its value to 1 will prevent any new
69350 + USB devices from being recognized by the OS. Any attempted USB
69351 + device insertion will be logged. This option is intended to be
69352 + used against custom USB devices designed to exploit vulnerabilities
69353 + in various USB device drivers.
69354 +
69355 + For greatest effectiveness, this sysctl should be set after any
69356 + relevant init scripts. This option is safe to enable in distros
69357 + as each user can choose whether or not to toggle the sysctl.
69358 +
69359 +config GRKERNSEC_DENYUSB_FORCE
69360 + bool "Reject all USB devices not connected at boot"
69361 + select USB
69362 + depends on GRKERNSEC_DENYUSB
69363 + help
69364 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69365 + that doesn't involve a sysctl entry. This option should only be
69366 + enabled if you're sure you want to deny all new USB connections
69367 + at runtime and don't want to modify init scripts. This should not
69368 + be enabled by distros. It forces the core USB code to be built
69369 + into the kernel image so that all devices connected at boot time
69370 + can be recognized and new USB device connections can be prevented
69371 + prior to init running.
69372 +
69373 +endmenu
69374 +
69375 +menu "Sysctl Support"
69376 +depends on GRKERNSEC && SYSCTL
69377 +
69378 +config GRKERNSEC_SYSCTL
69379 + bool "Sysctl support"
69380 + default y if GRKERNSEC_CONFIG_AUTO
69381 + help
69382 + If you say Y here, you will be able to change the options that
69383 + grsecurity runs with at bootup, without having to recompile your
69384 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69385 + to enable (1) or disable (0) various features. All the sysctl entries
69386 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69387 + All features enabled in the kernel configuration are disabled at boot
69388 + if you do not say Y to the "Turn on features by default" option.
69389 + All options should be set at startup, and the grsec_lock entry should
69390 + be set to a non-zero value after all the options are set.
69391 + *THIS IS EXTREMELY IMPORTANT*
69392 +
69393 +config GRKERNSEC_SYSCTL_DISTRO
69394 + bool "Extra sysctl support for distro makers (READ HELP)"
69395 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69396 + help
69397 + If you say Y here, additional sysctl options will be created
69398 + for features that affect processes running as root. Therefore,
69399 + it is critical when using this option that the grsec_lock entry be
69400 + enabled after boot. Only distros with prebuilt kernel packages
69401 + with this option enabled that can ensure grsec_lock is enabled
69402 + after boot should use this option.
69403 + *Failure to set grsec_lock after boot makes all grsec features
69404 + this option covers useless*
69405 +
69406 + Currently this option creates the following sysctl entries:
69407 + "Disable Privileged I/O": "disable_priv_io"
69408 +
69409 +config GRKERNSEC_SYSCTL_ON
69410 + bool "Turn on features by default"
69411 + default y if GRKERNSEC_CONFIG_AUTO
69412 + depends on GRKERNSEC_SYSCTL
69413 + help
69414 + If you say Y here, instead of having all features enabled in the
69415 + kernel configuration disabled at boot time, the features will be
69416 + enabled at boot time. It is recommended you say Y here unless
69417 + there is some reason you would want all sysctl-tunable features to
69418 + be disabled by default. As mentioned elsewhere, it is important
69419 + to enable the grsec_lock entry once you have finished modifying
69420 + the sysctl entries.
69421 +
69422 +endmenu
69423 +menu "Logging Options"
69424 +depends on GRKERNSEC
69425 +
69426 +config GRKERNSEC_FLOODTIME
69427 + int "Seconds in between log messages (minimum)"
69428 + default 10
69429 + help
69430 + This option allows you to enforce the number of seconds between
69431 + grsecurity log messages. The default should be suitable for most
69432 + people, however, if you choose to change it, choose a value small enough
69433 + to allow informative logs to be produced, but large enough to
69434 + prevent flooding.
69435 +
69436 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69437 + any rate limiting on grsecurity log messages.
69438 +
69439 +config GRKERNSEC_FLOODBURST
69440 + int "Number of messages in a burst (maximum)"
69441 + default 6
69442 + help
69443 + This option allows you to choose the maximum number of messages allowed
69444 + within the flood time interval you chose in a separate option. The
69445 + default should be suitable for most people, however if you find that
69446 + many of your logs are being interpreted as flooding, you may want to
69447 + raise this value.
69448 +
69449 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69450 + any rate limiting on grsecurity log messages.
69451 +
69452 +endmenu
69453 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69454 new file mode 100644
69455 index 0000000..30ababb
69456 --- /dev/null
69457 +++ b/grsecurity/Makefile
69458 @@ -0,0 +1,54 @@
69459 +# grsecurity – access control and security hardening for Linux
69460 +# All code in this directory and various hooks located throughout the Linux kernel are
69461 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69462 +# http://www.grsecurity.net spender@grsecurity.net
69463 +#
69464 +# This program is free software; you can redistribute it and/or
69465 +# modify it under the terms of the GNU General Public License version 2
69466 +# as published by the Free Software Foundation.
69467 +#
69468 +# This program is distributed in the hope that it will be useful,
69469 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69470 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69471 +# GNU General Public License for more details.
69472 +#
69473 +# You should have received a copy of the GNU General Public License
69474 +# along with this program; if not, write to the Free Software
69475 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69476 +
69477 +KBUILD_CFLAGS += -Werror
69478 +
69479 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69480 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69481 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69482 + grsec_usb.o grsec_ipc.o grsec_proc.o
69483 +
69484 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69485 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69486 + gracl_learn.o grsec_log.o gracl_policy.o
69487 +ifdef CONFIG_COMPAT
69488 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69489 +endif
69490 +
69491 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69492 +
69493 +ifdef CONFIG_NET
69494 +obj-y += grsec_sock.o
69495 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69496 +endif
69497 +
69498 +ifndef CONFIG_GRKERNSEC
69499 +obj-y += grsec_disabled.o
69500 +endif
69501 +
69502 +ifdef CONFIG_GRKERNSEC_HIDESYM
69503 +extra-y := grsec_hidesym.o
69504 +$(obj)/grsec_hidesym.o:
69505 + @-chmod -f 500 /boot
69506 + @-chmod -f 500 /lib/modules
69507 + @-chmod -f 500 /lib64/modules
69508 + @-chmod -f 500 /lib32/modules
69509 + @-chmod -f 700 .
69510 + @-chmod -f 700 $(objtree)
69511 + @echo ' grsec: protected kernel image paths'
69512 +endif
69513 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69514 new file mode 100644
69515 index 0000000..9c2d930
69516 --- /dev/null
69517 +++ b/grsecurity/gracl.c
69518 @@ -0,0 +1,2721 @@
69519 +#include <linux/kernel.h>
69520 +#include <linux/module.h>
69521 +#include <linux/sched.h>
69522 +#include <linux/mm.h>
69523 +#include <linux/file.h>
69524 +#include <linux/fs.h>
69525 +#include <linux/namei.h>
69526 +#include <linux/mount.h>
69527 +#include <linux/tty.h>
69528 +#include <linux/proc_fs.h>
69529 +#include <linux/lglock.h>
69530 +#include <linux/slab.h>
69531 +#include <linux/vmalloc.h>
69532 +#include <linux/types.h>
69533 +#include <linux/sysctl.h>
69534 +#include <linux/netdevice.h>
69535 +#include <linux/ptrace.h>
69536 +#include <linux/gracl.h>
69537 +#include <linux/gralloc.h>
69538 +#include <linux/security.h>
69539 +#include <linux/grinternal.h>
69540 +#include <linux/pid_namespace.h>
69541 +#include <linux/stop_machine.h>
69542 +#include <linux/fdtable.h>
69543 +#include <linux/percpu.h>
69544 +#include <linux/lglock.h>
69545 +#include <linux/hugetlb.h>
69546 +#include <linux/posix-timers.h>
69547 +#include <linux/prefetch.h>
69548 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69549 +#include <linux/magic.h>
69550 +#include <linux/pagemap.h>
69551 +#include "../fs/btrfs/async-thread.h"
69552 +#include "../fs/btrfs/ctree.h"
69553 +#include "../fs/btrfs/btrfs_inode.h"
69554 +#endif
69555 +#include "../fs/mount.h"
69556 +
69557 +#include <asm/uaccess.h>
69558 +#include <asm/errno.h>
69559 +#include <asm/mman.h>
69560 +
69561 +#define FOR_EACH_ROLE_START(role) \
69562 + role = running_polstate.role_list; \
69563 + while (role) {
69564 +
69565 +#define FOR_EACH_ROLE_END(role) \
69566 + role = role->prev; \
69567 + }
69568 +
69569 +extern struct path gr_real_root;
69570 +
69571 +static struct gr_policy_state running_polstate;
69572 +struct gr_policy_state *polstate = &running_polstate;
69573 +extern struct gr_alloc_state *current_alloc_state;
69574 +
69575 +extern char *gr_shared_page[4];
69576 +DEFINE_RWLOCK(gr_inode_lock);
69577 +
69578 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69579 +
69580 +#ifdef CONFIG_NET
69581 +extern struct vfsmount *sock_mnt;
69582 +#endif
69583 +
69584 +extern struct vfsmount *pipe_mnt;
69585 +extern struct vfsmount *shm_mnt;
69586 +
69587 +#ifdef CONFIG_HUGETLBFS
69588 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69589 +#endif
69590 +
69591 +extern u16 acl_sp_role_value;
69592 +extern struct acl_object_label *fakefs_obj_rw;
69593 +extern struct acl_object_label *fakefs_obj_rwx;
69594 +
69595 +int gr_acl_is_enabled(void)
69596 +{
69597 + return (gr_status & GR_READY);
69598 +}
69599 +
69600 +void gr_enable_rbac_system(void)
69601 +{
69602 + pax_open_kernel();
69603 + gr_status |= GR_READY;
69604 + pax_close_kernel();
69605 +}
69606 +
69607 +int gr_rbac_disable(void *unused)
69608 +{
69609 + pax_open_kernel();
69610 + gr_status &= ~GR_READY;
69611 + pax_close_kernel();
69612 +
69613 + return 0;
69614 +}
69615 +
69616 +static inline dev_t __get_dev(const struct dentry *dentry)
69617 +{
69618 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69619 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69620 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69621 + else
69622 +#endif
69623 + return dentry->d_sb->s_dev;
69624 +}
69625 +
69626 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69627 +{
69628 + return __get_dev(dentry);
69629 +}
69630 +
69631 +static char gr_task_roletype_to_char(struct task_struct *task)
69632 +{
69633 + switch (task->role->roletype &
69634 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69635 + GR_ROLE_SPECIAL)) {
69636 + case GR_ROLE_DEFAULT:
69637 + return 'D';
69638 + case GR_ROLE_USER:
69639 + return 'U';
69640 + case GR_ROLE_GROUP:
69641 + return 'G';
69642 + case GR_ROLE_SPECIAL:
69643 + return 'S';
69644 + }
69645 +
69646 + return 'X';
69647 +}
69648 +
69649 +char gr_roletype_to_char(void)
69650 +{
69651 + return gr_task_roletype_to_char(current);
69652 +}
69653 +
69654 +__inline__ int
69655 +gr_acl_tpe_check(void)
69656 +{
69657 + if (unlikely(!(gr_status & GR_READY)))
69658 + return 0;
69659 + if (current->role->roletype & GR_ROLE_TPE)
69660 + return 1;
69661 + else
69662 + return 0;
69663 +}
69664 +
69665 +int
69666 +gr_handle_rawio(const struct inode *inode)
69667 +{
69668 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69669 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69670 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69671 + !capable(CAP_SYS_RAWIO))
69672 + return 1;
69673 +#endif
69674 + return 0;
69675 +}
69676 +
69677 +int
69678 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69679 +{
69680 + if (likely(lena != lenb))
69681 + return 0;
69682 +
69683 + return !memcmp(a, b, lena);
69684 +}
69685 +
69686 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69687 +{
69688 + *buflen -= namelen;
69689 + if (*buflen < 0)
69690 + return -ENAMETOOLONG;
69691 + *buffer -= namelen;
69692 + memcpy(*buffer, str, namelen);
69693 + return 0;
69694 +}
69695 +
69696 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69697 +{
69698 + return prepend(buffer, buflen, name->name, name->len);
69699 +}
69700 +
69701 +static int prepend_path(const struct path *path, struct path *root,
69702 + char **buffer, int *buflen)
69703 +{
69704 + struct dentry *dentry = path->dentry;
69705 + struct vfsmount *vfsmnt = path->mnt;
69706 + struct mount *mnt = real_mount(vfsmnt);
69707 + bool slash = false;
69708 + int error = 0;
69709 +
69710 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69711 + struct dentry * parent;
69712 +
69713 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69714 + /* Global root? */
69715 + if (!mnt_has_parent(mnt)) {
69716 + goto out;
69717 + }
69718 + dentry = mnt->mnt_mountpoint;
69719 + mnt = mnt->mnt_parent;
69720 + vfsmnt = &mnt->mnt;
69721 + continue;
69722 + }
69723 + parent = dentry->d_parent;
69724 + prefetch(parent);
69725 + spin_lock(&dentry->d_lock);
69726 + error = prepend_name(buffer, buflen, &dentry->d_name);
69727 + spin_unlock(&dentry->d_lock);
69728 + if (!error)
69729 + error = prepend(buffer, buflen, "/", 1);
69730 + if (error)
69731 + break;
69732 +
69733 + slash = true;
69734 + dentry = parent;
69735 + }
69736 +
69737 +out:
69738 + if (!error && !slash)
69739 + error = prepend(buffer, buflen, "/", 1);
69740 +
69741 + return error;
69742 +}
69743 +
69744 +/* this must be called with mount_lock and rename_lock held */
69745 +
69746 +static char *__our_d_path(const struct path *path, struct path *root,
69747 + char *buf, int buflen)
69748 +{
69749 + char *res = buf + buflen;
69750 + int error;
69751 +
69752 + prepend(&res, &buflen, "\0", 1);
69753 + error = prepend_path(path, root, &res, &buflen);
69754 + if (error)
69755 + return ERR_PTR(error);
69756 +
69757 + return res;
69758 +}
69759 +
69760 +static char *
69761 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69762 +{
69763 + char *retval;
69764 +
69765 + retval = __our_d_path(path, root, buf, buflen);
69766 + if (unlikely(IS_ERR(retval)))
69767 + retval = strcpy(buf, "<path too long>");
69768 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69769 + retval[1] = '\0';
69770 +
69771 + return retval;
69772 +}
69773 +
69774 +static char *
69775 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69776 + char *buf, int buflen)
69777 +{
69778 + struct path path;
69779 + char *res;
69780 +
69781 + path.dentry = (struct dentry *)dentry;
69782 + path.mnt = (struct vfsmount *)vfsmnt;
69783 +
69784 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69785 + by the RBAC system */
69786 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69787 +
69788 + return res;
69789 +}
69790 +
69791 +static char *
69792 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69793 + char *buf, int buflen)
69794 +{
69795 + char *res;
69796 + struct path path;
69797 + struct path root;
69798 + struct task_struct *reaper = init_pid_ns.child_reaper;
69799 +
69800 + path.dentry = (struct dentry *)dentry;
69801 + path.mnt = (struct vfsmount *)vfsmnt;
69802 +
69803 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69804 + get_fs_root(reaper->fs, &root);
69805 +
69806 + read_seqlock_excl(&mount_lock);
69807 + write_seqlock(&rename_lock);
69808 + res = gen_full_path(&path, &root, buf, buflen);
69809 + write_sequnlock(&rename_lock);
69810 + read_sequnlock_excl(&mount_lock);
69811 +
69812 + path_put(&root);
69813 + return res;
69814 +}
69815 +
69816 +char *
69817 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69818 +{
69819 + char *ret;
69820 + read_seqlock_excl(&mount_lock);
69821 + write_seqlock(&rename_lock);
69822 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69823 + PAGE_SIZE);
69824 + write_sequnlock(&rename_lock);
69825 + read_sequnlock_excl(&mount_lock);
69826 + return ret;
69827 +}
69828 +
69829 +static char *
69830 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69831 +{
69832 + char *ret;
69833 + char *buf;
69834 + int buflen;
69835 +
69836 + read_seqlock_excl(&mount_lock);
69837 + write_seqlock(&rename_lock);
69838 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69839 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69840 + buflen = (int)(ret - buf);
69841 + if (buflen >= 5)
69842 + prepend(&ret, &buflen, "/proc", 5);
69843 + else
69844 + ret = strcpy(buf, "<path too long>");
69845 + write_sequnlock(&rename_lock);
69846 + read_sequnlock_excl(&mount_lock);
69847 + return ret;
69848 +}
69849 +
69850 +char *
69851 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69852 +{
69853 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69854 + PAGE_SIZE);
69855 +}
69856 +
69857 +char *
69858 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69859 +{
69860 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69861 + PAGE_SIZE);
69862 +}
69863 +
69864 +char *
69865 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69866 +{
69867 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69868 + PAGE_SIZE);
69869 +}
69870 +
69871 +char *
69872 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69873 +{
69874 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69875 + PAGE_SIZE);
69876 +}
69877 +
69878 +char *
69879 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69880 +{
69881 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69882 + PAGE_SIZE);
69883 +}
69884 +
69885 +__inline__ __u32
69886 +to_gr_audit(const __u32 reqmode)
69887 +{
69888 + /* masks off auditable permission flags, then shifts them to create
69889 + auditing flags, and adds the special case of append auditing if
69890 + we're requesting write */
69891 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69892 +}
69893 +
69894 +struct acl_role_label *
69895 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69896 + const gid_t gid)
69897 +{
69898 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69899 + struct acl_role_label *match;
69900 + struct role_allowed_ip *ipp;
69901 + unsigned int x;
69902 + u32 curr_ip = task->signal->saved_ip;
69903 +
69904 + match = state->acl_role_set.r_hash[index];
69905 +
69906 + while (match) {
69907 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69908 + for (x = 0; x < match->domain_child_num; x++) {
69909 + if (match->domain_children[x] == uid)
69910 + goto found;
69911 + }
69912 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69913 + break;
69914 + match = match->next;
69915 + }
69916 +found:
69917 + if (match == NULL) {
69918 + try_group:
69919 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69920 + match = state->acl_role_set.r_hash[index];
69921 +
69922 + while (match) {
69923 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69924 + for (x = 0; x < match->domain_child_num; x++) {
69925 + if (match->domain_children[x] == gid)
69926 + goto found2;
69927 + }
69928 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69929 + break;
69930 + match = match->next;
69931 + }
69932 +found2:
69933 + if (match == NULL)
69934 + match = state->default_role;
69935 + if (match->allowed_ips == NULL)
69936 + return match;
69937 + else {
69938 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69939 + if (likely
69940 + ((ntohl(curr_ip) & ipp->netmask) ==
69941 + (ntohl(ipp->addr) & ipp->netmask)))
69942 + return match;
69943 + }
69944 + match = state->default_role;
69945 + }
69946 + } else if (match->allowed_ips == NULL) {
69947 + return match;
69948 + } else {
69949 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69950 + if (likely
69951 + ((ntohl(curr_ip) & ipp->netmask) ==
69952 + (ntohl(ipp->addr) & ipp->netmask)))
69953 + return match;
69954 + }
69955 + goto try_group;
69956 + }
69957 +
69958 + return match;
69959 +}
69960 +
69961 +static struct acl_role_label *
69962 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69963 + const gid_t gid)
69964 +{
69965 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69966 +}
69967 +
69968 +struct acl_subject_label *
69969 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69970 + const struct acl_role_label *role)
69971 +{
69972 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69973 + struct acl_subject_label *match;
69974 +
69975 + match = role->subj_hash[index];
69976 +
69977 + while (match && (match->inode != ino || match->device != dev ||
69978 + (match->mode & GR_DELETED))) {
69979 + match = match->next;
69980 + }
69981 +
69982 + if (match && !(match->mode & GR_DELETED))
69983 + return match;
69984 + else
69985 + return NULL;
69986 +}
69987 +
69988 +struct acl_subject_label *
69989 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69990 + const struct acl_role_label *role)
69991 +{
69992 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69993 + struct acl_subject_label *match;
69994 +
69995 + match = role->subj_hash[index];
69996 +
69997 + while (match && (match->inode != ino || match->device != dev ||
69998 + !(match->mode & GR_DELETED))) {
69999 + match = match->next;
70000 + }
70001 +
70002 + if (match && (match->mode & GR_DELETED))
70003 + return match;
70004 + else
70005 + return NULL;
70006 +}
70007 +
70008 +static struct acl_object_label *
70009 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70010 + const struct acl_subject_label *subj)
70011 +{
70012 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70013 + struct acl_object_label *match;
70014 +
70015 + match = subj->obj_hash[index];
70016 +
70017 + while (match && (match->inode != ino || match->device != dev ||
70018 + (match->mode & GR_DELETED))) {
70019 + match = match->next;
70020 + }
70021 +
70022 + if (match && !(match->mode & GR_DELETED))
70023 + return match;
70024 + else
70025 + return NULL;
70026 +}
70027 +
70028 +static struct acl_object_label *
70029 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70030 + const struct acl_subject_label *subj)
70031 +{
70032 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70033 + struct acl_object_label *match;
70034 +
70035 + match = subj->obj_hash[index];
70036 +
70037 + while (match && (match->inode != ino || match->device != dev ||
70038 + !(match->mode & GR_DELETED))) {
70039 + match = match->next;
70040 + }
70041 +
70042 + if (match && (match->mode & GR_DELETED))
70043 + return match;
70044 +
70045 + match = subj->obj_hash[index];
70046 +
70047 + while (match && (match->inode != ino || match->device != dev ||
70048 + (match->mode & GR_DELETED))) {
70049 + match = match->next;
70050 + }
70051 +
70052 + if (match && !(match->mode & GR_DELETED))
70053 + return match;
70054 + else
70055 + return NULL;
70056 +}
70057 +
70058 +struct name_entry *
70059 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70060 +{
70061 + unsigned int len = strlen(name);
70062 + unsigned int key = full_name_hash(name, len);
70063 + unsigned int index = key % state->name_set.n_size;
70064 + struct name_entry *match;
70065 +
70066 + match = state->name_set.n_hash[index];
70067 +
70068 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70069 + match = match->next;
70070 +
70071 + return match;
70072 +}
70073 +
70074 +static struct name_entry *
70075 +lookup_name_entry(const char *name)
70076 +{
70077 + return __lookup_name_entry(&running_polstate, name);
70078 +}
70079 +
70080 +static struct name_entry *
70081 +lookup_name_entry_create(const char *name)
70082 +{
70083 + unsigned int len = strlen(name);
70084 + unsigned int key = full_name_hash(name, len);
70085 + unsigned int index = key % running_polstate.name_set.n_size;
70086 + struct name_entry *match;
70087 +
70088 + match = running_polstate.name_set.n_hash[index];
70089 +
70090 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70091 + !match->deleted))
70092 + match = match->next;
70093 +
70094 + if (match && match->deleted)
70095 + return match;
70096 +
70097 + match = running_polstate.name_set.n_hash[index];
70098 +
70099 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70100 + match->deleted))
70101 + match = match->next;
70102 +
70103 + if (match && !match->deleted)
70104 + return match;
70105 + else
70106 + return NULL;
70107 +}
70108 +
70109 +static struct inodev_entry *
70110 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70111 +{
70112 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70113 + struct inodev_entry *match;
70114 +
70115 + match = running_polstate.inodev_set.i_hash[index];
70116 +
70117 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70118 + match = match->next;
70119 +
70120 + return match;
70121 +}
70122 +
70123 +void
70124 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70125 +{
70126 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70127 + state->inodev_set.i_size);
70128 + struct inodev_entry **curr;
70129 +
70130 + entry->prev = NULL;
70131 +
70132 + curr = &state->inodev_set.i_hash[index];
70133 + if (*curr != NULL)
70134 + (*curr)->prev = entry;
70135 +
70136 + entry->next = *curr;
70137 + *curr = entry;
70138 +
70139 + return;
70140 +}
70141 +
70142 +static void
70143 +insert_inodev_entry(struct inodev_entry *entry)
70144 +{
70145 + __insert_inodev_entry(&running_polstate, entry);
70146 +}
70147 +
70148 +void
70149 +insert_acl_obj_label(struct acl_object_label *obj,
70150 + struct acl_subject_label *subj)
70151 +{
70152 + unsigned int index =
70153 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70154 + struct acl_object_label **curr;
70155 +
70156 + obj->prev = NULL;
70157 +
70158 + curr = &subj->obj_hash[index];
70159 + if (*curr != NULL)
70160 + (*curr)->prev = obj;
70161 +
70162 + obj->next = *curr;
70163 + *curr = obj;
70164 +
70165 + return;
70166 +}
70167 +
70168 +void
70169 +insert_acl_subj_label(struct acl_subject_label *obj,
70170 + struct acl_role_label *role)
70171 +{
70172 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70173 + struct acl_subject_label **curr;
70174 +
70175 + obj->prev = NULL;
70176 +
70177 + curr = &role->subj_hash[index];
70178 + if (*curr != NULL)
70179 + (*curr)->prev = obj;
70180 +
70181 + obj->next = *curr;
70182 + *curr = obj;
70183 +
70184 + return;
70185 +}
70186 +
70187 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70188 +
70189 +static int
70190 +glob_match(const char *p, const char *n)
70191 +{
70192 + char c;
70193 +
70194 + while ((c = *p++) != '\0') {
70195 + switch (c) {
70196 + case '?':
70197 + if (*n == '\0')
70198 + return 1;
70199 + else if (*n == '/')
70200 + return 1;
70201 + break;
70202 + case '\\':
70203 + if (*n != c)
70204 + return 1;
70205 + break;
70206 + case '*':
70207 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70208 + if (*n == '/')
70209 + return 1;
70210 + else if (c == '?') {
70211 + if (*n == '\0')
70212 + return 1;
70213 + else
70214 + ++n;
70215 + }
70216 + }
70217 + if (c == '\0') {
70218 + return 0;
70219 + } else {
70220 + const char *endp;
70221 +
70222 + if ((endp = strchr(n, '/')) == NULL)
70223 + endp = n + strlen(n);
70224 +
70225 + if (c == '[') {
70226 + for (--p; n < endp; ++n)
70227 + if (!glob_match(p, n))
70228 + return 0;
70229 + } else if (c == '/') {
70230 + while (*n != '\0' && *n != '/')
70231 + ++n;
70232 + if (*n == '/' && !glob_match(p, n + 1))
70233 + return 0;
70234 + } else {
70235 + for (--p; n < endp; ++n)
70236 + if (*n == c && !glob_match(p, n))
70237 + return 0;
70238 + }
70239 +
70240 + return 1;
70241 + }
70242 + case '[':
70243 + {
70244 + int not;
70245 + char cold;
70246 +
70247 + if (*n == '\0' || *n == '/')
70248 + return 1;
70249 +
70250 + not = (*p == '!' || *p == '^');
70251 + if (not)
70252 + ++p;
70253 +
70254 + c = *p++;
70255 + for (;;) {
70256 + unsigned char fn = (unsigned char)*n;
70257 +
70258 + if (c == '\0')
70259 + return 1;
70260 + else {
70261 + if (c == fn)
70262 + goto matched;
70263 + cold = c;
70264 + c = *p++;
70265 +
70266 + if (c == '-' && *p != ']') {
70267 + unsigned char cend = *p++;
70268 +
70269 + if (cend == '\0')
70270 + return 1;
70271 +
70272 + if (cold <= fn && fn <= cend)
70273 + goto matched;
70274 +
70275 + c = *p++;
70276 + }
70277 + }
70278 +
70279 + if (c == ']')
70280 + break;
70281 + }
70282 + if (!not)
70283 + return 1;
70284 + break;
70285 + matched:
70286 + while (c != ']') {
70287 + if (c == '\0')
70288 + return 1;
70289 +
70290 + c = *p++;
70291 + }
70292 + if (not)
70293 + return 1;
70294 + }
70295 + break;
70296 + default:
70297 + if (c != *n)
70298 + return 1;
70299 + }
70300 +
70301 + ++n;
70302 + }
70303 +
70304 + if (*n == '\0')
70305 + return 0;
70306 +
70307 + if (*n == '/')
70308 + return 0;
70309 +
70310 + return 1;
70311 +}
70312 +
70313 +static struct acl_object_label *
70314 +chk_glob_label(struct acl_object_label *globbed,
70315 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70316 +{
70317 + struct acl_object_label *tmp;
70318 +
70319 + if (*path == NULL)
70320 + *path = gr_to_filename_nolock(dentry, mnt);
70321 +
70322 + tmp = globbed;
70323 +
70324 + while (tmp) {
70325 + if (!glob_match(tmp->filename, *path))
70326 + return tmp;
70327 + tmp = tmp->next;
70328 + }
70329 +
70330 + return NULL;
70331 +}
70332 +
70333 +static struct acl_object_label *
70334 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70335 + const ino_t curr_ino, const dev_t curr_dev,
70336 + const struct acl_subject_label *subj, char **path, const int checkglob)
70337 +{
70338 + struct acl_subject_label *tmpsubj;
70339 + struct acl_object_label *retval;
70340 + struct acl_object_label *retval2;
70341 +
70342 + tmpsubj = (struct acl_subject_label *) subj;
70343 + read_lock(&gr_inode_lock);
70344 + do {
70345 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70346 + if (retval) {
70347 + if (checkglob && retval->globbed) {
70348 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70349 + if (retval2)
70350 + retval = retval2;
70351 + }
70352 + break;
70353 + }
70354 + } while ((tmpsubj = tmpsubj->parent_subject));
70355 + read_unlock(&gr_inode_lock);
70356 +
70357 + return retval;
70358 +}
70359 +
70360 +static __inline__ struct acl_object_label *
70361 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70362 + struct dentry *curr_dentry,
70363 + const struct acl_subject_label *subj, char **path, const int checkglob)
70364 +{
70365 + int newglob = checkglob;
70366 + ino_t inode;
70367 + dev_t device;
70368 +
70369 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70370 + as we don't want a / * rule to match instead of the / object
70371 + don't do this for create lookups that call this function though, since they're looking up
70372 + on the parent and thus need globbing checks on all paths
70373 + */
70374 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70375 + newglob = GR_NO_GLOB;
70376 +
70377 + spin_lock(&curr_dentry->d_lock);
70378 + inode = curr_dentry->d_inode->i_ino;
70379 + device = __get_dev(curr_dentry);
70380 + spin_unlock(&curr_dentry->d_lock);
70381 +
70382 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70383 +}
70384 +
70385 +#ifdef CONFIG_HUGETLBFS
70386 +static inline bool
70387 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70388 +{
70389 + int i;
70390 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70391 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70392 + return true;
70393 + }
70394 +
70395 + return false;
70396 +}
70397 +#endif
70398 +
70399 +static struct acl_object_label *
70400 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70401 + const struct acl_subject_label *subj, char *path, const int checkglob)
70402 +{
70403 + struct dentry *dentry = (struct dentry *) l_dentry;
70404 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70405 + struct mount *real_mnt = real_mount(mnt);
70406 + struct acl_object_label *retval;
70407 + struct dentry *parent;
70408 +
70409 + read_seqlock_excl(&mount_lock);
70410 + write_seqlock(&rename_lock);
70411 +
70412 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70413 +#ifdef CONFIG_NET
70414 + mnt == sock_mnt ||
70415 +#endif
70416 +#ifdef CONFIG_HUGETLBFS
70417 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70418 +#endif
70419 + /* ignore Eric Biederman */
70420 + IS_PRIVATE(l_dentry->d_inode))) {
70421 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70422 + goto out;
70423 + }
70424 +
70425 + for (;;) {
70426 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70427 + break;
70428 +
70429 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70430 + if (!mnt_has_parent(real_mnt))
70431 + break;
70432 +
70433 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70434 + if (retval != NULL)
70435 + goto out;
70436 +
70437 + dentry = real_mnt->mnt_mountpoint;
70438 + real_mnt = real_mnt->mnt_parent;
70439 + mnt = &real_mnt->mnt;
70440 + continue;
70441 + }
70442 +
70443 + parent = dentry->d_parent;
70444 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70445 + if (retval != NULL)
70446 + goto out;
70447 +
70448 + dentry = parent;
70449 + }
70450 +
70451 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70452 +
70453 + /* gr_real_root is pinned so we don't have to hold a reference */
70454 + if (retval == NULL)
70455 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70456 +out:
70457 + write_sequnlock(&rename_lock);
70458 + read_sequnlock_excl(&mount_lock);
70459 +
70460 + BUG_ON(retval == NULL);
70461 +
70462 + return retval;
70463 +}
70464 +
70465 +static __inline__ struct acl_object_label *
70466 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70467 + const struct acl_subject_label *subj)
70468 +{
70469 + char *path = NULL;
70470 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70471 +}
70472 +
70473 +static __inline__ struct acl_object_label *
70474 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70475 + const struct acl_subject_label *subj)
70476 +{
70477 + char *path = NULL;
70478 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70479 +}
70480 +
70481 +static __inline__ struct acl_object_label *
70482 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70483 + const struct acl_subject_label *subj, char *path)
70484 +{
70485 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70486 +}
70487 +
70488 +struct acl_subject_label *
70489 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70490 + const struct acl_role_label *role)
70491 +{
70492 + struct dentry *dentry = (struct dentry *) l_dentry;
70493 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70494 + struct mount *real_mnt = real_mount(mnt);
70495 + struct acl_subject_label *retval;
70496 + struct dentry *parent;
70497 +
70498 + read_seqlock_excl(&mount_lock);
70499 + write_seqlock(&rename_lock);
70500 +
70501 + for (;;) {
70502 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70503 + break;
70504 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70505 + if (!mnt_has_parent(real_mnt))
70506 + break;
70507 +
70508 + spin_lock(&dentry->d_lock);
70509 + read_lock(&gr_inode_lock);
70510 + retval =
70511 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70512 + __get_dev(dentry), role);
70513 + read_unlock(&gr_inode_lock);
70514 + spin_unlock(&dentry->d_lock);
70515 + if (retval != NULL)
70516 + goto out;
70517 +
70518 + dentry = real_mnt->mnt_mountpoint;
70519 + real_mnt = real_mnt->mnt_parent;
70520 + mnt = &real_mnt->mnt;
70521 + continue;
70522 + }
70523 +
70524 + spin_lock(&dentry->d_lock);
70525 + read_lock(&gr_inode_lock);
70526 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70527 + __get_dev(dentry), role);
70528 + read_unlock(&gr_inode_lock);
70529 + parent = dentry->d_parent;
70530 + spin_unlock(&dentry->d_lock);
70531 +
70532 + if (retval != NULL)
70533 + goto out;
70534 +
70535 + dentry = parent;
70536 + }
70537 +
70538 + spin_lock(&dentry->d_lock);
70539 + read_lock(&gr_inode_lock);
70540 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70541 + __get_dev(dentry), role);
70542 + read_unlock(&gr_inode_lock);
70543 + spin_unlock(&dentry->d_lock);
70544 +
70545 + if (unlikely(retval == NULL)) {
70546 + /* gr_real_root is pinned, we don't need to hold a reference */
70547 + read_lock(&gr_inode_lock);
70548 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70549 + __get_dev(gr_real_root.dentry), role);
70550 + read_unlock(&gr_inode_lock);
70551 + }
70552 +out:
70553 + write_sequnlock(&rename_lock);
70554 + read_sequnlock_excl(&mount_lock);
70555 +
70556 + BUG_ON(retval == NULL);
70557 +
70558 + return retval;
70559 +}
70560 +
70561 +void
70562 +assign_special_role(const char *rolename)
70563 +{
70564 + struct acl_object_label *obj;
70565 + struct acl_role_label *r;
70566 + struct acl_role_label *assigned = NULL;
70567 + struct task_struct *tsk;
70568 + struct file *filp;
70569 +
70570 + FOR_EACH_ROLE_START(r)
70571 + if (!strcmp(rolename, r->rolename) &&
70572 + (r->roletype & GR_ROLE_SPECIAL)) {
70573 + assigned = r;
70574 + break;
70575 + }
70576 + FOR_EACH_ROLE_END(r)
70577 +
70578 + if (!assigned)
70579 + return;
70580 +
70581 + read_lock(&tasklist_lock);
70582 + read_lock(&grsec_exec_file_lock);
70583 +
70584 + tsk = current->real_parent;
70585 + if (tsk == NULL)
70586 + goto out_unlock;
70587 +
70588 + filp = tsk->exec_file;
70589 + if (filp == NULL)
70590 + goto out_unlock;
70591 +
70592 + tsk->is_writable = 0;
70593 + tsk->inherited = 0;
70594 +
70595 + tsk->acl_sp_role = 1;
70596 + tsk->acl_role_id = ++acl_sp_role_value;
70597 + tsk->role = assigned;
70598 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70599 +
70600 + /* ignore additional mmap checks for processes that are writable
70601 + by the default ACL */
70602 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70603 + if (unlikely(obj->mode & GR_WRITE))
70604 + tsk->is_writable = 1;
70605 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70606 + if (unlikely(obj->mode & GR_WRITE))
70607 + tsk->is_writable = 1;
70608 +
70609 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70610 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70611 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70612 +#endif
70613 +
70614 +out_unlock:
70615 + read_unlock(&grsec_exec_file_lock);
70616 + read_unlock(&tasklist_lock);
70617 + return;
70618 +}
70619 +
70620 +
70621 +static void
70622 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70623 +{
70624 + struct task_struct *task = current;
70625 + const struct cred *cred = current_cred();
70626 +
70627 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70628 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70629 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70630 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70631 +
70632 + return;
70633 +}
70634 +
70635 +static void
70636 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70637 +{
70638 + struct task_struct *task = current;
70639 + const struct cred *cred = current_cred();
70640 +
70641 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70642 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70643 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70644 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70645 +
70646 + return;
70647 +}
70648 +
70649 +static void
70650 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70651 +{
70652 + struct task_struct *task = current;
70653 + const struct cred *cred = current_cred();
70654 +
70655 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70656 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70657 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70658 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70659 +
70660 + return;
70661 +}
70662 +
70663 +static void
70664 +gr_set_proc_res(struct task_struct *task)
70665 +{
70666 + struct acl_subject_label *proc;
70667 + unsigned short i;
70668 +
70669 + proc = task->acl;
70670 +
70671 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70672 + return;
70673 +
70674 + for (i = 0; i < RLIM_NLIMITS; i++) {
70675 + if (!(proc->resmask & (1U << i)))
70676 + continue;
70677 +
70678 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70679 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70680 +
70681 + if (i == RLIMIT_CPU)
70682 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70683 + }
70684 +
70685 + return;
70686 +}
70687 +
70688 +/* both of the below must be called with
70689 + rcu_read_lock();
70690 + read_lock(&tasklist_lock);
70691 + read_lock(&grsec_exec_file_lock);
70692 + except in the case of gr_set_role_label() (for __gr_get_subject_for_task)
70693 +*/
70694 +
70695 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback)
70696 +{
70697 + char *tmpname;
70698 + struct acl_subject_label *tmpsubj;
70699 + struct file *filp;
70700 + struct name_entry *nmatch;
70701 +
70702 + filp = task->exec_file;
70703 + if (filp == NULL)
70704 + return NULL;
70705 +
70706 + /* the following is to apply the correct subject
70707 + on binaries running when the RBAC system
70708 + is enabled, when the binaries have been
70709 + replaced or deleted since their execution
70710 + -----
70711 + when the RBAC system starts, the inode/dev
70712 + from exec_file will be one the RBAC system
70713 + is unaware of. It only knows the inode/dev
70714 + of the present file on disk, or the absence
70715 + of it.
70716 + */
70717 +
70718 + if (filename)
70719 + nmatch = __lookup_name_entry(state, filename);
70720 + else {
70721 + preempt_disable();
70722 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70723 +
70724 + nmatch = __lookup_name_entry(state, tmpname);
70725 + preempt_enable();
70726 + }
70727 + tmpsubj = NULL;
70728 + if (nmatch) {
70729 + if (nmatch->deleted)
70730 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70731 + else
70732 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70733 + }
70734 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70735 + then we fall back to a normal lookup based on the binary's ino/dev
70736 + */
70737 + if (tmpsubj == NULL && fallback)
70738 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70739 +
70740 + return tmpsubj;
70741 +}
70742 +
70743 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename, int fallback)
70744 +{
70745 + return __gr_get_subject_for_task(&running_polstate, task, filename, fallback);
70746 +}
70747 +
70748 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70749 +{
70750 + struct acl_object_label *obj;
70751 + struct file *filp;
70752 +
70753 + filp = task->exec_file;
70754 +
70755 + task->acl = subj;
70756 + task->is_writable = 0;
70757 + /* ignore additional mmap checks for processes that are writable
70758 + by the default ACL */
70759 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70760 + if (unlikely(obj->mode & GR_WRITE))
70761 + task->is_writable = 1;
70762 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70763 + if (unlikely(obj->mode & GR_WRITE))
70764 + task->is_writable = 1;
70765 +
70766 + gr_set_proc_res(task);
70767 +
70768 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70769 + 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);
70770 +#endif
70771 +}
70772 +
70773 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70774 +{
70775 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70776 +}
70777 +
70778 +__u32
70779 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70780 + const struct vfsmount * mnt)
70781 +{
70782 + __u32 retval = mode;
70783 + struct acl_subject_label *curracl;
70784 + struct acl_object_label *currobj;
70785 +
70786 + if (unlikely(!(gr_status & GR_READY)))
70787 + return (mode & ~GR_AUDITS);
70788 +
70789 + curracl = current->acl;
70790 +
70791 + currobj = chk_obj_label(dentry, mnt, curracl);
70792 + retval = currobj->mode & mode;
70793 +
70794 + /* if we're opening a specified transfer file for writing
70795 + (e.g. /dev/initctl), then transfer our role to init
70796 + */
70797 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70798 + current->role->roletype & GR_ROLE_PERSIST)) {
70799 + struct task_struct *task = init_pid_ns.child_reaper;
70800 +
70801 + if (task->role != current->role) {
70802 + struct acl_subject_label *subj;
70803 +
70804 + task->acl_sp_role = 0;
70805 + task->acl_role_id = current->acl_role_id;
70806 + task->role = current->role;
70807 + rcu_read_lock();
70808 + read_lock(&grsec_exec_file_lock);
70809 + subj = gr_get_subject_for_task(task, NULL, 1);
70810 + gr_apply_subject_to_task(task, subj);
70811 + read_unlock(&grsec_exec_file_lock);
70812 + rcu_read_unlock();
70813 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70814 + }
70815 + }
70816 +
70817 + if (unlikely
70818 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70819 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70820 + __u32 new_mode = mode;
70821 +
70822 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70823 +
70824 + retval = new_mode;
70825 +
70826 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70827 + new_mode |= GR_INHERIT;
70828 +
70829 + if (!(mode & GR_NOLEARN))
70830 + gr_log_learn(dentry, mnt, new_mode);
70831 + }
70832 +
70833 + return retval;
70834 +}
70835 +
70836 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70837 + const struct dentry *parent,
70838 + const struct vfsmount *mnt)
70839 +{
70840 + struct name_entry *match;
70841 + struct acl_object_label *matchpo;
70842 + struct acl_subject_label *curracl;
70843 + char *path;
70844 +
70845 + if (unlikely(!(gr_status & GR_READY)))
70846 + return NULL;
70847 +
70848 + preempt_disable();
70849 + path = gr_to_filename_rbac(new_dentry, mnt);
70850 + match = lookup_name_entry_create(path);
70851 +
70852 + curracl = current->acl;
70853 +
70854 + if (match) {
70855 + read_lock(&gr_inode_lock);
70856 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70857 + read_unlock(&gr_inode_lock);
70858 +
70859 + if (matchpo) {
70860 + preempt_enable();
70861 + return matchpo;
70862 + }
70863 + }
70864 +
70865 + // lookup parent
70866 +
70867 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70868 +
70869 + preempt_enable();
70870 + return matchpo;
70871 +}
70872 +
70873 +__u32
70874 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70875 + const struct vfsmount * mnt, const __u32 mode)
70876 +{
70877 + struct acl_object_label *matchpo;
70878 + __u32 retval;
70879 +
70880 + if (unlikely(!(gr_status & GR_READY)))
70881 + return (mode & ~GR_AUDITS);
70882 +
70883 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70884 +
70885 + retval = matchpo->mode & mode;
70886 +
70887 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70888 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70889 + __u32 new_mode = mode;
70890 +
70891 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70892 +
70893 + gr_log_learn(new_dentry, mnt, new_mode);
70894 + return new_mode;
70895 + }
70896 +
70897 + return retval;
70898 +}
70899 +
70900 +__u32
70901 +gr_check_link(const struct dentry * new_dentry,
70902 + const struct dentry * parent_dentry,
70903 + const struct vfsmount * parent_mnt,
70904 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70905 +{
70906 + struct acl_object_label *obj;
70907 + __u32 oldmode, newmode;
70908 + __u32 needmode;
70909 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70910 + GR_DELETE | GR_INHERIT;
70911 +
70912 + if (unlikely(!(gr_status & GR_READY)))
70913 + return (GR_CREATE | GR_LINK);
70914 +
70915 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70916 + oldmode = obj->mode;
70917 +
70918 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70919 + newmode = obj->mode;
70920 +
70921 + needmode = newmode & checkmodes;
70922 +
70923 + // old name for hardlink must have at least the permissions of the new name
70924 + if ((oldmode & needmode) != needmode)
70925 + goto bad;
70926 +
70927 + // if old name had restrictions/auditing, make sure the new name does as well
70928 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70929 +
70930 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70931 + if (is_privileged_binary(old_dentry))
70932 + needmode |= GR_SETID;
70933 +
70934 + if ((newmode & needmode) != needmode)
70935 + goto bad;
70936 +
70937 + // enforce minimum permissions
70938 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70939 + return newmode;
70940 +bad:
70941 + needmode = oldmode;
70942 + if (is_privileged_binary(old_dentry))
70943 + needmode |= GR_SETID;
70944 +
70945 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70946 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70947 + return (GR_CREATE | GR_LINK);
70948 + } else if (newmode & GR_SUPPRESS)
70949 + return GR_SUPPRESS;
70950 + else
70951 + return 0;
70952 +}
70953 +
70954 +int
70955 +gr_check_hidden_task(const struct task_struct *task)
70956 +{
70957 + if (unlikely(!(gr_status & GR_READY)))
70958 + return 0;
70959 +
70960 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70961 + return 1;
70962 +
70963 + return 0;
70964 +}
70965 +
70966 +int
70967 +gr_check_protected_task(const struct task_struct *task)
70968 +{
70969 + if (unlikely(!(gr_status & GR_READY) || !task))
70970 + return 0;
70971 +
70972 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70973 + task->acl != current->acl)
70974 + return 1;
70975 +
70976 + return 0;
70977 +}
70978 +
70979 +int
70980 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70981 +{
70982 + struct task_struct *p;
70983 + int ret = 0;
70984 +
70985 + if (unlikely(!(gr_status & GR_READY) || !pid))
70986 + return ret;
70987 +
70988 + read_lock(&tasklist_lock);
70989 + do_each_pid_task(pid, type, p) {
70990 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70991 + p->acl != current->acl) {
70992 + ret = 1;
70993 + goto out;
70994 + }
70995 + } while_each_pid_task(pid, type, p);
70996 +out:
70997 + read_unlock(&tasklist_lock);
70998 +
70999 + return ret;
71000 +}
71001 +
71002 +void
71003 +gr_copy_label(struct task_struct *tsk)
71004 +{
71005 + struct task_struct *p = current;
71006 +
71007 + tsk->inherited = p->inherited;
71008 + tsk->acl_sp_role = 0;
71009 + tsk->acl_role_id = p->acl_role_id;
71010 + tsk->acl = p->acl;
71011 + tsk->role = p->role;
71012 + tsk->signal->used_accept = 0;
71013 + tsk->signal->curr_ip = p->signal->curr_ip;
71014 + tsk->signal->saved_ip = p->signal->saved_ip;
71015 + if (p->exec_file)
71016 + get_file(p->exec_file);
71017 + tsk->exec_file = p->exec_file;
71018 + tsk->is_writable = p->is_writable;
71019 + if (unlikely(p->signal->used_accept)) {
71020 + p->signal->curr_ip = 0;
71021 + p->signal->saved_ip = 0;
71022 + }
71023 +
71024 + return;
71025 +}
71026 +
71027 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71028 +
71029 +int
71030 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71031 +{
71032 + unsigned int i;
71033 + __u16 num;
71034 + uid_t *uidlist;
71035 + uid_t curuid;
71036 + int realok = 0;
71037 + int effectiveok = 0;
71038 + int fsok = 0;
71039 + uid_t globalreal, globaleffective, globalfs;
71040 +
71041 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71042 + struct user_struct *user;
71043 +
71044 + if (!uid_valid(real))
71045 + goto skipit;
71046 +
71047 + /* find user based on global namespace */
71048 +
71049 + globalreal = GR_GLOBAL_UID(real);
71050 +
71051 + user = find_user(make_kuid(&init_user_ns, globalreal));
71052 + if (user == NULL)
71053 + goto skipit;
71054 +
71055 + if (gr_process_kernel_setuid_ban(user)) {
71056 + /* for find_user */
71057 + free_uid(user);
71058 + return 1;
71059 + }
71060 +
71061 + /* for find_user */
71062 + free_uid(user);
71063 +
71064 +skipit:
71065 +#endif
71066 +
71067 + if (unlikely(!(gr_status & GR_READY)))
71068 + return 0;
71069 +
71070 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71071 + gr_log_learn_uid_change(real, effective, fs);
71072 +
71073 + num = current->acl->user_trans_num;
71074 + uidlist = current->acl->user_transitions;
71075 +
71076 + if (uidlist == NULL)
71077 + return 0;
71078 +
71079 + if (!uid_valid(real)) {
71080 + realok = 1;
71081 + globalreal = (uid_t)-1;
71082 + } else {
71083 + globalreal = GR_GLOBAL_UID(real);
71084 + }
71085 + if (!uid_valid(effective)) {
71086 + effectiveok = 1;
71087 + globaleffective = (uid_t)-1;
71088 + } else {
71089 + globaleffective = GR_GLOBAL_UID(effective);
71090 + }
71091 + if (!uid_valid(fs)) {
71092 + fsok = 1;
71093 + globalfs = (uid_t)-1;
71094 + } else {
71095 + globalfs = GR_GLOBAL_UID(fs);
71096 + }
71097 +
71098 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71099 + for (i = 0; i < num; i++) {
71100 + curuid = uidlist[i];
71101 + if (globalreal == curuid)
71102 + realok = 1;
71103 + if (globaleffective == curuid)
71104 + effectiveok = 1;
71105 + if (globalfs == curuid)
71106 + fsok = 1;
71107 + }
71108 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71109 + for (i = 0; i < num; i++) {
71110 + curuid = uidlist[i];
71111 + if (globalreal == curuid)
71112 + break;
71113 + if (globaleffective == curuid)
71114 + break;
71115 + if (globalfs == curuid)
71116 + break;
71117 + }
71118 + /* not in deny list */
71119 + if (i == num) {
71120 + realok = 1;
71121 + effectiveok = 1;
71122 + fsok = 1;
71123 + }
71124 + }
71125 +
71126 + if (realok && effectiveok && fsok)
71127 + return 0;
71128 + else {
71129 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71130 + return 1;
71131 + }
71132 +}
71133 +
71134 +int
71135 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71136 +{
71137 + unsigned int i;
71138 + __u16 num;
71139 + gid_t *gidlist;
71140 + gid_t curgid;
71141 + int realok = 0;
71142 + int effectiveok = 0;
71143 + int fsok = 0;
71144 + gid_t globalreal, globaleffective, globalfs;
71145 +
71146 + if (unlikely(!(gr_status & GR_READY)))
71147 + return 0;
71148 +
71149 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71150 + gr_log_learn_gid_change(real, effective, fs);
71151 +
71152 + num = current->acl->group_trans_num;
71153 + gidlist = current->acl->group_transitions;
71154 +
71155 + if (gidlist == NULL)
71156 + return 0;
71157 +
71158 + if (!gid_valid(real)) {
71159 + realok = 1;
71160 + globalreal = (gid_t)-1;
71161 + } else {
71162 + globalreal = GR_GLOBAL_GID(real);
71163 + }
71164 + if (!gid_valid(effective)) {
71165 + effectiveok = 1;
71166 + globaleffective = (gid_t)-1;
71167 + } else {
71168 + globaleffective = GR_GLOBAL_GID(effective);
71169 + }
71170 + if (!gid_valid(fs)) {
71171 + fsok = 1;
71172 + globalfs = (gid_t)-1;
71173 + } else {
71174 + globalfs = GR_GLOBAL_GID(fs);
71175 + }
71176 +
71177 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71178 + for (i = 0; i < num; i++) {
71179 + curgid = gidlist[i];
71180 + if (globalreal == curgid)
71181 + realok = 1;
71182 + if (globaleffective == curgid)
71183 + effectiveok = 1;
71184 + if (globalfs == curgid)
71185 + fsok = 1;
71186 + }
71187 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71188 + for (i = 0; i < num; i++) {
71189 + curgid = gidlist[i];
71190 + if (globalreal == curgid)
71191 + break;
71192 + if (globaleffective == curgid)
71193 + break;
71194 + if (globalfs == curgid)
71195 + break;
71196 + }
71197 + /* not in deny list */
71198 + if (i == num) {
71199 + realok = 1;
71200 + effectiveok = 1;
71201 + fsok = 1;
71202 + }
71203 + }
71204 +
71205 + if (realok && effectiveok && fsok)
71206 + return 0;
71207 + else {
71208 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71209 + return 1;
71210 + }
71211 +}
71212 +
71213 +extern int gr_acl_is_capable(const int cap);
71214 +
71215 +void
71216 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71217 +{
71218 + struct acl_role_label *role = task->role;
71219 + struct acl_role_label *origrole = role;
71220 + struct acl_subject_label *subj = NULL;
71221 + struct acl_object_label *obj;
71222 + struct file *filp;
71223 + uid_t uid;
71224 + gid_t gid;
71225 +
71226 + if (unlikely(!(gr_status & GR_READY)))
71227 + return;
71228 +
71229 + uid = GR_GLOBAL_UID(kuid);
71230 + gid = GR_GLOBAL_GID(kgid);
71231 +
71232 + filp = task->exec_file;
71233 +
71234 + /* kernel process, we'll give them the kernel role */
71235 + if (unlikely(!filp)) {
71236 + task->role = running_polstate.kernel_role;
71237 + task->acl = running_polstate.kernel_role->root_label;
71238 + return;
71239 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71240 + /* save the current ip at time of role lookup so that the proper
71241 + IP will be learned for role_allowed_ip */
71242 + task->signal->saved_ip = task->signal->curr_ip;
71243 + role = lookup_acl_role_label(task, uid, gid);
71244 + }
71245 +
71246 + /* don't change the role if we're not a privileged process */
71247 + if (role && task->role != role &&
71248 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71249 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71250 + return;
71251 +
71252 + task->role = role;
71253 +
71254 + if (task->inherited) {
71255 + /* if we reached our subject through inheritance, then first see
71256 + if there's a subject of the same name in the new role that has
71257 + an object that would result in the same inherited subject
71258 + */
71259 + subj = gr_get_subject_for_task(task, task->acl->filename, 0);
71260 + if (subj) {
71261 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, subj);
71262 + if (!(obj->mode & GR_INHERIT))
71263 + subj = NULL;
71264 + }
71265 +
71266 + }
71267 + if (subj == NULL) {
71268 + /* otherwise:
71269 + perform subject lookup in possibly new role
71270 + we can use this result below in the case where role == task->role
71271 + */
71272 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71273 + }
71274 +
71275 + /* if we changed uid/gid, but result in the same role
71276 + and are using inheritance, don't lose the inherited subject
71277 + if current subject is other than what normal lookup
71278 + would result in, we arrived via inheritance, don't
71279 + lose subject
71280 + */
71281 + if (role != origrole || (!(task->acl->mode & GR_INHERITLEARN) &&
71282 + (subj == task->acl)))
71283 + task->acl = subj;
71284 +
71285 + /* leave task->inherited unaffected */
71286 +
71287 + task->is_writable = 0;
71288 +
71289 + /* ignore additional mmap checks for processes that are writable
71290 + by the default ACL */
71291 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71292 + if (unlikely(obj->mode & GR_WRITE))
71293 + task->is_writable = 1;
71294 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71295 + if (unlikely(obj->mode & GR_WRITE))
71296 + task->is_writable = 1;
71297 +
71298 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71299 + 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);
71300 +#endif
71301 +
71302 + gr_set_proc_res(task);
71303 +
71304 + return;
71305 +}
71306 +
71307 +int
71308 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71309 + const int unsafe_flags)
71310 +{
71311 + struct task_struct *task = current;
71312 + struct acl_subject_label *newacl;
71313 + struct acl_object_label *obj;
71314 + __u32 retmode;
71315 +
71316 + if (unlikely(!(gr_status & GR_READY)))
71317 + return 0;
71318 +
71319 + newacl = chk_subj_label(dentry, mnt, task->role);
71320 +
71321 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71322 + did an exec
71323 + */
71324 + rcu_read_lock();
71325 + read_lock(&tasklist_lock);
71326 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71327 + (task->parent->acl->mode & GR_POVERRIDE))) {
71328 + read_unlock(&tasklist_lock);
71329 + rcu_read_unlock();
71330 + goto skip_check;
71331 + }
71332 + read_unlock(&tasklist_lock);
71333 + rcu_read_unlock();
71334 +
71335 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71336 + !(task->role->roletype & GR_ROLE_GOD) &&
71337 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71338 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71339 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71340 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71341 + else
71342 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71343 + return -EACCES;
71344 + }
71345 +
71346 +skip_check:
71347 +
71348 + obj = chk_obj_label(dentry, mnt, task->acl);
71349 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71350 +
71351 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71352 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71353 + if (obj->nested)
71354 + task->acl = obj->nested;
71355 + else
71356 + task->acl = newacl;
71357 + task->inherited = 0;
71358 + } else {
71359 + task->inherited = 1;
71360 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71361 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71362 + }
71363 +
71364 + task->is_writable = 0;
71365 +
71366 + /* ignore additional mmap checks for processes that are writable
71367 + by the default ACL */
71368 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71369 + if (unlikely(obj->mode & GR_WRITE))
71370 + task->is_writable = 1;
71371 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71372 + if (unlikely(obj->mode & GR_WRITE))
71373 + task->is_writable = 1;
71374 +
71375 + gr_set_proc_res(task);
71376 +
71377 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71378 + 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);
71379 +#endif
71380 + return 0;
71381 +}
71382 +
71383 +/* always called with valid inodev ptr */
71384 +static void
71385 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71386 +{
71387 + struct acl_object_label *matchpo;
71388 + struct acl_subject_label *matchps;
71389 + struct acl_subject_label *subj;
71390 + struct acl_role_label *role;
71391 + unsigned int x;
71392 +
71393 + FOR_EACH_ROLE_START(role)
71394 + FOR_EACH_SUBJECT_START(role, subj, x)
71395 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71396 + matchpo->mode |= GR_DELETED;
71397 + FOR_EACH_SUBJECT_END(subj,x)
71398 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71399 + /* nested subjects aren't in the role's subj_hash table */
71400 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71401 + matchpo->mode |= GR_DELETED;
71402 + FOR_EACH_NESTED_SUBJECT_END(subj)
71403 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71404 + matchps->mode |= GR_DELETED;
71405 + FOR_EACH_ROLE_END(role)
71406 +
71407 + inodev->nentry->deleted = 1;
71408 +
71409 + return;
71410 +}
71411 +
71412 +void
71413 +gr_handle_delete(const ino_t ino, const dev_t dev)
71414 +{
71415 + struct inodev_entry *inodev;
71416 +
71417 + if (unlikely(!(gr_status & GR_READY)))
71418 + return;
71419 +
71420 + write_lock(&gr_inode_lock);
71421 + inodev = lookup_inodev_entry(ino, dev);
71422 + if (inodev != NULL)
71423 + do_handle_delete(inodev, ino, dev);
71424 + write_unlock(&gr_inode_lock);
71425 +
71426 + return;
71427 +}
71428 +
71429 +static void
71430 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71431 + const ino_t newinode, const dev_t newdevice,
71432 + struct acl_subject_label *subj)
71433 +{
71434 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71435 + struct acl_object_label *match;
71436 +
71437 + match = subj->obj_hash[index];
71438 +
71439 + while (match && (match->inode != oldinode ||
71440 + match->device != olddevice ||
71441 + !(match->mode & GR_DELETED)))
71442 + match = match->next;
71443 +
71444 + if (match && (match->inode == oldinode)
71445 + && (match->device == olddevice)
71446 + && (match->mode & GR_DELETED)) {
71447 + if (match->prev == NULL) {
71448 + subj->obj_hash[index] = match->next;
71449 + if (match->next != NULL)
71450 + match->next->prev = NULL;
71451 + } else {
71452 + match->prev->next = match->next;
71453 + if (match->next != NULL)
71454 + match->next->prev = match->prev;
71455 + }
71456 + match->prev = NULL;
71457 + match->next = NULL;
71458 + match->inode = newinode;
71459 + match->device = newdevice;
71460 + match->mode &= ~GR_DELETED;
71461 +
71462 + insert_acl_obj_label(match, subj);
71463 + }
71464 +
71465 + return;
71466 +}
71467 +
71468 +static void
71469 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71470 + const ino_t newinode, const dev_t newdevice,
71471 + struct acl_role_label *role)
71472 +{
71473 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71474 + struct acl_subject_label *match;
71475 +
71476 + match = role->subj_hash[index];
71477 +
71478 + while (match && (match->inode != oldinode ||
71479 + match->device != olddevice ||
71480 + !(match->mode & GR_DELETED)))
71481 + match = match->next;
71482 +
71483 + if (match && (match->inode == oldinode)
71484 + && (match->device == olddevice)
71485 + && (match->mode & GR_DELETED)) {
71486 + if (match->prev == NULL) {
71487 + role->subj_hash[index] = match->next;
71488 + if (match->next != NULL)
71489 + match->next->prev = NULL;
71490 + } else {
71491 + match->prev->next = match->next;
71492 + if (match->next != NULL)
71493 + match->next->prev = match->prev;
71494 + }
71495 + match->prev = NULL;
71496 + match->next = NULL;
71497 + match->inode = newinode;
71498 + match->device = newdevice;
71499 + match->mode &= ~GR_DELETED;
71500 +
71501 + insert_acl_subj_label(match, role);
71502 + }
71503 +
71504 + return;
71505 +}
71506 +
71507 +static void
71508 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71509 + const ino_t newinode, const dev_t newdevice)
71510 +{
71511 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71512 + struct inodev_entry *match;
71513 +
71514 + match = running_polstate.inodev_set.i_hash[index];
71515 +
71516 + while (match && (match->nentry->inode != oldinode ||
71517 + match->nentry->device != olddevice || !match->nentry->deleted))
71518 + match = match->next;
71519 +
71520 + if (match && (match->nentry->inode == oldinode)
71521 + && (match->nentry->device == olddevice) &&
71522 + match->nentry->deleted) {
71523 + if (match->prev == NULL) {
71524 + running_polstate.inodev_set.i_hash[index] = match->next;
71525 + if (match->next != NULL)
71526 + match->next->prev = NULL;
71527 + } else {
71528 + match->prev->next = match->next;
71529 + if (match->next != NULL)
71530 + match->next->prev = match->prev;
71531 + }
71532 + match->prev = NULL;
71533 + match->next = NULL;
71534 + match->nentry->inode = newinode;
71535 + match->nentry->device = newdevice;
71536 + match->nentry->deleted = 0;
71537 +
71538 + insert_inodev_entry(match);
71539 + }
71540 +
71541 + return;
71542 +}
71543 +
71544 +static void
71545 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71546 +{
71547 + struct acl_subject_label *subj;
71548 + struct acl_role_label *role;
71549 + unsigned int x;
71550 +
71551 + FOR_EACH_ROLE_START(role)
71552 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71553 +
71554 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71555 + if ((subj->inode == ino) && (subj->device == dev)) {
71556 + subj->inode = ino;
71557 + subj->device = dev;
71558 + }
71559 + /* nested subjects aren't in the role's subj_hash table */
71560 + update_acl_obj_label(matchn->inode, matchn->device,
71561 + ino, dev, subj);
71562 + FOR_EACH_NESTED_SUBJECT_END(subj)
71563 + FOR_EACH_SUBJECT_START(role, subj, x)
71564 + update_acl_obj_label(matchn->inode, matchn->device,
71565 + ino, dev, subj);
71566 + FOR_EACH_SUBJECT_END(subj,x)
71567 + FOR_EACH_ROLE_END(role)
71568 +
71569 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71570 +
71571 + return;
71572 +}
71573 +
71574 +static void
71575 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71576 + const struct vfsmount *mnt)
71577 +{
71578 + ino_t ino = dentry->d_inode->i_ino;
71579 + dev_t dev = __get_dev(dentry);
71580 +
71581 + __do_handle_create(matchn, ino, dev);
71582 +
71583 + return;
71584 +}
71585 +
71586 +void
71587 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71588 +{
71589 + struct name_entry *matchn;
71590 +
71591 + if (unlikely(!(gr_status & GR_READY)))
71592 + return;
71593 +
71594 + preempt_disable();
71595 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71596 +
71597 + if (unlikely((unsigned long)matchn)) {
71598 + write_lock(&gr_inode_lock);
71599 + do_handle_create(matchn, dentry, mnt);
71600 + write_unlock(&gr_inode_lock);
71601 + }
71602 + preempt_enable();
71603 +
71604 + return;
71605 +}
71606 +
71607 +void
71608 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71609 +{
71610 + struct name_entry *matchn;
71611 +
71612 + if (unlikely(!(gr_status & GR_READY)))
71613 + return;
71614 +
71615 + preempt_disable();
71616 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71617 +
71618 + if (unlikely((unsigned long)matchn)) {
71619 + write_lock(&gr_inode_lock);
71620 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71621 + write_unlock(&gr_inode_lock);
71622 + }
71623 + preempt_enable();
71624 +
71625 + return;
71626 +}
71627 +
71628 +void
71629 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71630 + struct dentry *old_dentry,
71631 + struct dentry *new_dentry,
71632 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71633 +{
71634 + struct name_entry *matchn;
71635 + struct name_entry *matchn2 = NULL;
71636 + struct inodev_entry *inodev;
71637 + struct inode *inode = new_dentry->d_inode;
71638 + ino_t old_ino = old_dentry->d_inode->i_ino;
71639 + dev_t old_dev = __get_dev(old_dentry);
71640 + unsigned int exchange = flags & RENAME_EXCHANGE;
71641 +
71642 + /* vfs_rename swaps the name and parent link for old_dentry and
71643 + new_dentry
71644 + at this point, old_dentry has the new name, parent link, and inode
71645 + for the renamed file
71646 + if a file is being replaced by a rename, new_dentry has the inode
71647 + and name for the replaced file
71648 + */
71649 +
71650 + if (unlikely(!(gr_status & GR_READY)))
71651 + return;
71652 +
71653 + preempt_disable();
71654 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71655 +
71656 + /* exchange cases:
71657 + a filename exists for the source, but not dest
71658 + do a recreate on source
71659 + a filename exists for the dest, but not source
71660 + do a recreate on dest
71661 + a filename exists for both source and dest
71662 + delete source and dest, then create source and dest
71663 + a filename exists for neither source nor dest
71664 + no updates needed
71665 +
71666 + the name entry lookups get us the old inode/dev associated with
71667 + each name, so do the deletes first (if possible) so that when
71668 + we do the create, we pick up on the right entries
71669 + */
71670 +
71671 + if (exchange)
71672 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71673 +
71674 + /* we wouldn't have to check d_inode if it weren't for
71675 + NFS silly-renaming
71676 + */
71677 +
71678 + write_lock(&gr_inode_lock);
71679 + if (unlikely((replace || exchange) && inode)) {
71680 + ino_t new_ino = inode->i_ino;
71681 + dev_t new_dev = __get_dev(new_dentry);
71682 +
71683 + inodev = lookup_inodev_entry(new_ino, new_dev);
71684 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71685 + do_handle_delete(inodev, new_ino, new_dev);
71686 + }
71687 +
71688 + inodev = lookup_inodev_entry(old_ino, old_dev);
71689 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71690 + do_handle_delete(inodev, old_ino, old_dev);
71691 +
71692 + if (unlikely(matchn != NULL))
71693 + do_handle_create(matchn, old_dentry, mnt);
71694 +
71695 + if (unlikely(matchn2 != NULL))
71696 + do_handle_create(matchn2, new_dentry, mnt);
71697 +
71698 + write_unlock(&gr_inode_lock);
71699 + preempt_enable();
71700 +
71701 + return;
71702 +}
71703 +
71704 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71705 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71706 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71707 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71708 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71709 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71710 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71711 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71712 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71713 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71714 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71715 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71716 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71717 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71718 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71719 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71720 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71721 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71722 +};
71723 +
71724 +void
71725 +gr_learn_resource(const struct task_struct *task,
71726 + const int res, const unsigned long wanted, const int gt)
71727 +{
71728 + struct acl_subject_label *acl;
71729 + const struct cred *cred;
71730 +
71731 + if (unlikely((gr_status & GR_READY) &&
71732 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71733 + goto skip_reslog;
71734 +
71735 + gr_log_resource(task, res, wanted, gt);
71736 +skip_reslog:
71737 +
71738 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71739 + return;
71740 +
71741 + acl = task->acl;
71742 +
71743 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71744 + !(acl->resmask & (1U << (unsigned short) res))))
71745 + return;
71746 +
71747 + if (wanted >= acl->res[res].rlim_cur) {
71748 + unsigned long res_add;
71749 +
71750 + res_add = wanted + res_learn_bumps[res];
71751 +
71752 + acl->res[res].rlim_cur = res_add;
71753 +
71754 + if (wanted > acl->res[res].rlim_max)
71755 + acl->res[res].rlim_max = res_add;
71756 +
71757 + /* only log the subject filename, since resource logging is supported for
71758 + single-subject learning only */
71759 + rcu_read_lock();
71760 + cred = __task_cred(task);
71761 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71762 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71763 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71764 + "", (unsigned long) res, &task->signal->saved_ip);
71765 + rcu_read_unlock();
71766 + }
71767 +
71768 + return;
71769 +}
71770 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71771 +#endif
71772 +
71773 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71774 +void
71775 +pax_set_initial_flags(struct linux_binprm *bprm)
71776 +{
71777 + struct task_struct *task = current;
71778 + struct acl_subject_label *proc;
71779 + unsigned long flags;
71780 +
71781 + if (unlikely(!(gr_status & GR_READY)))
71782 + return;
71783 +
71784 + flags = pax_get_flags(task);
71785 +
71786 + proc = task->acl;
71787 +
71788 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71789 + flags &= ~MF_PAX_PAGEEXEC;
71790 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71791 + flags &= ~MF_PAX_SEGMEXEC;
71792 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71793 + flags &= ~MF_PAX_RANDMMAP;
71794 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71795 + flags &= ~MF_PAX_EMUTRAMP;
71796 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71797 + flags &= ~MF_PAX_MPROTECT;
71798 +
71799 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71800 + flags |= MF_PAX_PAGEEXEC;
71801 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71802 + flags |= MF_PAX_SEGMEXEC;
71803 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71804 + flags |= MF_PAX_RANDMMAP;
71805 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71806 + flags |= MF_PAX_EMUTRAMP;
71807 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71808 + flags |= MF_PAX_MPROTECT;
71809 +
71810 + pax_set_flags(task, flags);
71811 +
71812 + return;
71813 +}
71814 +#endif
71815 +
71816 +int
71817 +gr_handle_proc_ptrace(struct task_struct *task)
71818 +{
71819 + struct file *filp;
71820 + struct task_struct *tmp = task;
71821 + struct task_struct *curtemp = current;
71822 + __u32 retmode;
71823 +
71824 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71825 + if (unlikely(!(gr_status & GR_READY)))
71826 + return 0;
71827 +#endif
71828 +
71829 + read_lock(&tasklist_lock);
71830 + read_lock(&grsec_exec_file_lock);
71831 + filp = task->exec_file;
71832 +
71833 + while (task_pid_nr(tmp) > 0) {
71834 + if (tmp == curtemp)
71835 + break;
71836 + tmp = tmp->real_parent;
71837 + }
71838 +
71839 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71840 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71841 + read_unlock(&grsec_exec_file_lock);
71842 + read_unlock(&tasklist_lock);
71843 + return 1;
71844 + }
71845 +
71846 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71847 + if (!(gr_status & GR_READY)) {
71848 + read_unlock(&grsec_exec_file_lock);
71849 + read_unlock(&tasklist_lock);
71850 + return 0;
71851 + }
71852 +#endif
71853 +
71854 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71855 + read_unlock(&grsec_exec_file_lock);
71856 + read_unlock(&tasklist_lock);
71857 +
71858 + if (retmode & GR_NOPTRACE)
71859 + return 1;
71860 +
71861 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71862 + && (current->acl != task->acl || (current->acl != current->role->root_label
71863 + && task_pid_nr(current) != task_pid_nr(task))))
71864 + return 1;
71865 +
71866 + return 0;
71867 +}
71868 +
71869 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71870 +{
71871 + if (unlikely(!(gr_status & GR_READY)))
71872 + return;
71873 +
71874 + if (!(current->role->roletype & GR_ROLE_GOD))
71875 + return;
71876 +
71877 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71878 + p->role->rolename, gr_task_roletype_to_char(p),
71879 + p->acl->filename);
71880 +}
71881 +
71882 +int
71883 +gr_handle_ptrace(struct task_struct *task, const long request)
71884 +{
71885 + struct task_struct *tmp = task;
71886 + struct task_struct *curtemp = current;
71887 + __u32 retmode;
71888 +
71889 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71890 + if (unlikely(!(gr_status & GR_READY)))
71891 + return 0;
71892 +#endif
71893 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71894 + read_lock(&tasklist_lock);
71895 + while (task_pid_nr(tmp) > 0) {
71896 + if (tmp == curtemp)
71897 + break;
71898 + tmp = tmp->real_parent;
71899 + }
71900 +
71901 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71902 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71903 + read_unlock(&tasklist_lock);
71904 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71905 + return 1;
71906 + }
71907 + read_unlock(&tasklist_lock);
71908 + }
71909 +
71910 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71911 + if (!(gr_status & GR_READY))
71912 + return 0;
71913 +#endif
71914 +
71915 + read_lock(&grsec_exec_file_lock);
71916 + if (unlikely(!task->exec_file)) {
71917 + read_unlock(&grsec_exec_file_lock);
71918 + return 0;
71919 + }
71920 +
71921 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71922 + read_unlock(&grsec_exec_file_lock);
71923 +
71924 + if (retmode & GR_NOPTRACE) {
71925 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71926 + return 1;
71927 + }
71928 +
71929 + if (retmode & GR_PTRACERD) {
71930 + switch (request) {
71931 + case PTRACE_SEIZE:
71932 + case PTRACE_POKETEXT:
71933 + case PTRACE_POKEDATA:
71934 + case PTRACE_POKEUSR:
71935 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71936 + case PTRACE_SETREGS:
71937 + case PTRACE_SETFPREGS:
71938 +#endif
71939 +#ifdef CONFIG_X86
71940 + case PTRACE_SETFPXREGS:
71941 +#endif
71942 +#ifdef CONFIG_ALTIVEC
71943 + case PTRACE_SETVRREGS:
71944 +#endif
71945 + return 1;
71946 + default:
71947 + return 0;
71948 + }
71949 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71950 + !(current->role->roletype & GR_ROLE_GOD) &&
71951 + (current->acl != task->acl)) {
71952 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71953 + return 1;
71954 + }
71955 +
71956 + return 0;
71957 +}
71958 +
71959 +static int is_writable_mmap(const struct file *filp)
71960 +{
71961 + struct task_struct *task = current;
71962 + struct acl_object_label *obj, *obj2;
71963 +
71964 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71965 + !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))) {
71966 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71967 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71968 + task->role->root_label);
71969 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71970 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71971 + return 1;
71972 + }
71973 + }
71974 + return 0;
71975 +}
71976 +
71977 +int
71978 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71979 +{
71980 + __u32 mode;
71981 +
71982 + if (unlikely(!file || !(prot & PROT_EXEC)))
71983 + return 1;
71984 +
71985 + if (is_writable_mmap(file))
71986 + return 0;
71987 +
71988 + mode =
71989 + gr_search_file(file->f_path.dentry,
71990 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71991 + file->f_path.mnt);
71992 +
71993 + if (!gr_tpe_allow(file))
71994 + return 0;
71995 +
71996 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71997 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71998 + return 0;
71999 + } else if (unlikely(!(mode & GR_EXEC))) {
72000 + return 0;
72001 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72002 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72003 + return 1;
72004 + }
72005 +
72006 + return 1;
72007 +}
72008 +
72009 +int
72010 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72011 +{
72012 + __u32 mode;
72013 +
72014 + if (unlikely(!file || !(prot & PROT_EXEC)))
72015 + return 1;
72016 +
72017 + if (is_writable_mmap(file))
72018 + return 0;
72019 +
72020 + mode =
72021 + gr_search_file(file->f_path.dentry,
72022 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72023 + file->f_path.mnt);
72024 +
72025 + if (!gr_tpe_allow(file))
72026 + return 0;
72027 +
72028 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72029 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72030 + return 0;
72031 + } else if (unlikely(!(mode & GR_EXEC))) {
72032 + return 0;
72033 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72034 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72035 + return 1;
72036 + }
72037 +
72038 + return 1;
72039 +}
72040 +
72041 +void
72042 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72043 +{
72044 + unsigned long runtime, cputime;
72045 + cputime_t utime, stime;
72046 + unsigned int wday, cday;
72047 + __u8 whr, chr;
72048 + __u8 wmin, cmin;
72049 + __u8 wsec, csec;
72050 + struct timespec curtime, starttime;
72051 +
72052 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72053 + !(task->acl->mode & GR_PROCACCT)))
72054 + return;
72055 +
72056 + curtime = ns_to_timespec(ktime_get_ns());
72057 + starttime = ns_to_timespec(task->start_time);
72058 + runtime = curtime.tv_sec - starttime.tv_sec;
72059 + wday = runtime / (60 * 60 * 24);
72060 + runtime -= wday * (60 * 60 * 24);
72061 + whr = runtime / (60 * 60);
72062 + runtime -= whr * (60 * 60);
72063 + wmin = runtime / 60;
72064 + runtime -= wmin * 60;
72065 + wsec = runtime;
72066 +
72067 + task_cputime(task, &utime, &stime);
72068 + cputime = cputime_to_secs(utime + stime);
72069 + cday = cputime / (60 * 60 * 24);
72070 + cputime -= cday * (60 * 60 * 24);
72071 + chr = cputime / (60 * 60);
72072 + cputime -= chr * (60 * 60);
72073 + cmin = cputime / 60;
72074 + cputime -= cmin * 60;
72075 + csec = cputime;
72076 +
72077 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72078 +
72079 + return;
72080 +}
72081 +
72082 +#ifdef CONFIG_TASKSTATS
72083 +int gr_is_taskstats_denied(int pid)
72084 +{
72085 + struct task_struct *task;
72086 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72087 + const struct cred *cred;
72088 +#endif
72089 + int ret = 0;
72090 +
72091 + /* restrict taskstats viewing to un-chrooted root users
72092 + who have the 'view' subject flag if the RBAC system is enabled
72093 + */
72094 +
72095 + rcu_read_lock();
72096 + read_lock(&tasklist_lock);
72097 + task = find_task_by_vpid(pid);
72098 + if (task) {
72099 +#ifdef CONFIG_GRKERNSEC_CHROOT
72100 + if (proc_is_chrooted(task))
72101 + ret = -EACCES;
72102 +#endif
72103 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72104 + cred = __task_cred(task);
72105 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72106 + if (gr_is_global_nonroot(cred->uid))
72107 + ret = -EACCES;
72108 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72109 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72110 + ret = -EACCES;
72111 +#endif
72112 +#endif
72113 + if (gr_status & GR_READY) {
72114 + if (!(task->acl->mode & GR_VIEW))
72115 + ret = -EACCES;
72116 + }
72117 + } else
72118 + ret = -ENOENT;
72119 +
72120 + read_unlock(&tasklist_lock);
72121 + rcu_read_unlock();
72122 +
72123 + return ret;
72124 +}
72125 +#endif
72126 +
72127 +/* AUXV entries are filled via a descendant of search_binary_handler
72128 + after we've already applied the subject for the target
72129 +*/
72130 +int gr_acl_enable_at_secure(void)
72131 +{
72132 + if (unlikely(!(gr_status & GR_READY)))
72133 + return 0;
72134 +
72135 + if (current->acl->mode & GR_ATSECURE)
72136 + return 1;
72137 +
72138 + return 0;
72139 +}
72140 +
72141 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72142 +{
72143 + struct task_struct *task = current;
72144 + struct dentry *dentry = file->f_path.dentry;
72145 + struct vfsmount *mnt = file->f_path.mnt;
72146 + struct acl_object_label *obj, *tmp;
72147 + struct acl_subject_label *subj;
72148 + unsigned int bufsize;
72149 + int is_not_root;
72150 + char *path;
72151 + dev_t dev = __get_dev(dentry);
72152 +
72153 + if (unlikely(!(gr_status & GR_READY)))
72154 + return 1;
72155 +
72156 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72157 + return 1;
72158 +
72159 + /* ignore Eric Biederman */
72160 + if (IS_PRIVATE(dentry->d_inode))
72161 + return 1;
72162 +
72163 + subj = task->acl;
72164 + read_lock(&gr_inode_lock);
72165 + do {
72166 + obj = lookup_acl_obj_label(ino, dev, subj);
72167 + if (obj != NULL) {
72168 + read_unlock(&gr_inode_lock);
72169 + return (obj->mode & GR_FIND) ? 1 : 0;
72170 + }
72171 + } while ((subj = subj->parent_subject));
72172 + read_unlock(&gr_inode_lock);
72173 +
72174 + /* this is purely an optimization since we're looking for an object
72175 + for the directory we're doing a readdir on
72176 + if it's possible for any globbed object to match the entry we're
72177 + filling into the directory, then the object we find here will be
72178 + an anchor point with attached globbed objects
72179 + */
72180 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72181 + if (obj->globbed == NULL)
72182 + return (obj->mode & GR_FIND) ? 1 : 0;
72183 +
72184 + is_not_root = ((obj->filename[0] == '/') &&
72185 + (obj->filename[1] == '\0')) ? 0 : 1;
72186 + bufsize = PAGE_SIZE - namelen - is_not_root;
72187 +
72188 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72189 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72190 + return 1;
72191 +
72192 + preempt_disable();
72193 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72194 + bufsize);
72195 +
72196 + bufsize = strlen(path);
72197 +
72198 + /* if base is "/", don't append an additional slash */
72199 + if (is_not_root)
72200 + *(path + bufsize) = '/';
72201 + memcpy(path + bufsize + is_not_root, name, namelen);
72202 + *(path + bufsize + namelen + is_not_root) = '\0';
72203 +
72204 + tmp = obj->globbed;
72205 + while (tmp) {
72206 + if (!glob_match(tmp->filename, path)) {
72207 + preempt_enable();
72208 + return (tmp->mode & GR_FIND) ? 1 : 0;
72209 + }
72210 + tmp = tmp->next;
72211 + }
72212 + preempt_enable();
72213 + return (obj->mode & GR_FIND) ? 1 : 0;
72214 +}
72215 +
72216 +void gr_put_exec_file(struct task_struct *task)
72217 +{
72218 + struct file *filp;
72219 +
72220 + write_lock(&grsec_exec_file_lock);
72221 + filp = task->exec_file;
72222 + task->exec_file = NULL;
72223 + write_unlock(&grsec_exec_file_lock);
72224 +
72225 + if (filp)
72226 + fput(filp);
72227 +
72228 + return;
72229 +}
72230 +
72231 +
72232 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72233 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72234 +#endif
72235 +#ifdef CONFIG_SECURITY
72236 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72237 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72238 +#endif
72239 +
72240 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72241 new file mode 100644
72242 index 0000000..18ffbbd
72243 --- /dev/null
72244 +++ b/grsecurity/gracl_alloc.c
72245 @@ -0,0 +1,105 @@
72246 +#include <linux/kernel.h>
72247 +#include <linux/mm.h>
72248 +#include <linux/slab.h>
72249 +#include <linux/vmalloc.h>
72250 +#include <linux/gracl.h>
72251 +#include <linux/grsecurity.h>
72252 +
72253 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72254 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72255 +
72256 +static __inline__ int
72257 +alloc_pop(void)
72258 +{
72259 + if (current_alloc_state->alloc_stack_next == 1)
72260 + return 0;
72261 +
72262 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72263 +
72264 + current_alloc_state->alloc_stack_next--;
72265 +
72266 + return 1;
72267 +}
72268 +
72269 +static __inline__ int
72270 +alloc_push(void *buf)
72271 +{
72272 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72273 + return 1;
72274 +
72275 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72276 +
72277 + current_alloc_state->alloc_stack_next++;
72278 +
72279 + return 0;
72280 +}
72281 +
72282 +void *
72283 +acl_alloc(unsigned long len)
72284 +{
72285 + void *ret = NULL;
72286 +
72287 + if (!len || len > PAGE_SIZE)
72288 + goto out;
72289 +
72290 + ret = kmalloc(len, GFP_KERNEL);
72291 +
72292 + if (ret) {
72293 + if (alloc_push(ret)) {
72294 + kfree(ret);
72295 + ret = NULL;
72296 + }
72297 + }
72298 +
72299 +out:
72300 + return ret;
72301 +}
72302 +
72303 +void *
72304 +acl_alloc_num(unsigned long num, unsigned long len)
72305 +{
72306 + if (!len || (num > (PAGE_SIZE / len)))
72307 + return NULL;
72308 +
72309 + return acl_alloc(num * len);
72310 +}
72311 +
72312 +void
72313 +acl_free_all(void)
72314 +{
72315 + if (!current_alloc_state->alloc_stack)
72316 + return;
72317 +
72318 + while (alloc_pop()) ;
72319 +
72320 + if (current_alloc_state->alloc_stack) {
72321 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72322 + kfree(current_alloc_state->alloc_stack);
72323 + else
72324 + vfree(current_alloc_state->alloc_stack);
72325 + }
72326 +
72327 + current_alloc_state->alloc_stack = NULL;
72328 + current_alloc_state->alloc_stack_size = 1;
72329 + current_alloc_state->alloc_stack_next = 1;
72330 +
72331 + return;
72332 +}
72333 +
72334 +int
72335 +acl_alloc_stack_init(unsigned long size)
72336 +{
72337 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72338 + current_alloc_state->alloc_stack =
72339 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72340 + else
72341 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72342 +
72343 + current_alloc_state->alloc_stack_size = size;
72344 + current_alloc_state->alloc_stack_next = 1;
72345 +
72346 + if (!current_alloc_state->alloc_stack)
72347 + return 0;
72348 + else
72349 + return 1;
72350 +}
72351 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72352 new file mode 100644
72353 index 0000000..1a94c11
72354 --- /dev/null
72355 +++ b/grsecurity/gracl_cap.c
72356 @@ -0,0 +1,127 @@
72357 +#include <linux/kernel.h>
72358 +#include <linux/module.h>
72359 +#include <linux/sched.h>
72360 +#include <linux/gracl.h>
72361 +#include <linux/grsecurity.h>
72362 +#include <linux/grinternal.h>
72363 +
72364 +extern const char *captab_log[];
72365 +extern int captab_log_entries;
72366 +
72367 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72368 +{
72369 + struct acl_subject_label *curracl;
72370 +
72371 + if (!gr_acl_is_enabled())
72372 + return 1;
72373 +
72374 + curracl = task->acl;
72375 +
72376 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72377 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72378 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72379 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72380 + gr_to_filename(task->exec_file->f_path.dentry,
72381 + task->exec_file->f_path.mnt) : curracl->filename,
72382 + curracl->filename, 0UL,
72383 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72384 + return 1;
72385 + }
72386 +
72387 + return 0;
72388 +}
72389 +
72390 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72391 +{
72392 + struct acl_subject_label *curracl;
72393 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72394 + kernel_cap_t cap_audit = __cap_empty_set;
72395 +
72396 + if (!gr_acl_is_enabled())
72397 + return 1;
72398 +
72399 + curracl = task->acl;
72400 +
72401 + cap_drop = curracl->cap_lower;
72402 + cap_mask = curracl->cap_mask;
72403 + cap_audit = curracl->cap_invert_audit;
72404 +
72405 + while ((curracl = curracl->parent_subject)) {
72406 + /* if the cap isn't specified in the current computed mask but is specified in the
72407 + current level subject, and is lowered in the current level subject, then add
72408 + it to the set of dropped capabilities
72409 + otherwise, add the current level subject's mask to the current computed mask
72410 + */
72411 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72412 + cap_raise(cap_mask, cap);
72413 + if (cap_raised(curracl->cap_lower, cap))
72414 + cap_raise(cap_drop, cap);
72415 + if (cap_raised(curracl->cap_invert_audit, cap))
72416 + cap_raise(cap_audit, cap);
72417 + }
72418 + }
72419 +
72420 + if (!cap_raised(cap_drop, cap)) {
72421 + if (cap_raised(cap_audit, cap))
72422 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72423 + return 1;
72424 + }
72425 +
72426 + /* only learn the capability use if the process has the capability in the
72427 + general case, the two uses in sys.c of gr_learn_cap are an exception
72428 + to this rule to ensure any role transition involves what the full-learned
72429 + policy believes in a privileged process
72430 + */
72431 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72432 + return 1;
72433 +
72434 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72435 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72436 +
72437 + return 0;
72438 +}
72439 +
72440 +int
72441 +gr_acl_is_capable(const int cap)
72442 +{
72443 + return gr_task_acl_is_capable(current, current_cred(), cap);
72444 +}
72445 +
72446 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72447 +{
72448 + struct acl_subject_label *curracl;
72449 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72450 +
72451 + if (!gr_acl_is_enabled())
72452 + return 1;
72453 +
72454 + curracl = task->acl;
72455 +
72456 + cap_drop = curracl->cap_lower;
72457 + cap_mask = curracl->cap_mask;
72458 +
72459 + while ((curracl = curracl->parent_subject)) {
72460 + /* if the cap isn't specified in the current computed mask but is specified in the
72461 + current level subject, and is lowered in the current level subject, then add
72462 + it to the set of dropped capabilities
72463 + otherwise, add the current level subject's mask to the current computed mask
72464 + */
72465 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72466 + cap_raise(cap_mask, cap);
72467 + if (cap_raised(curracl->cap_lower, cap))
72468 + cap_raise(cap_drop, cap);
72469 + }
72470 + }
72471 +
72472 + if (!cap_raised(cap_drop, cap))
72473 + return 1;
72474 +
72475 + return 0;
72476 +}
72477 +
72478 +int
72479 +gr_acl_is_capable_nolog(const int cap)
72480 +{
72481 + return gr_task_acl_is_capable_nolog(current, cap);
72482 +}
72483 +
72484 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72485 new file mode 100644
72486 index 0000000..ca25605
72487 --- /dev/null
72488 +++ b/grsecurity/gracl_compat.c
72489 @@ -0,0 +1,270 @@
72490 +#include <linux/kernel.h>
72491 +#include <linux/gracl.h>
72492 +#include <linux/compat.h>
72493 +#include <linux/gracl_compat.h>
72494 +
72495 +#include <asm/uaccess.h>
72496 +
72497 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72498 +{
72499 + struct gr_arg_wrapper_compat uwrapcompat;
72500 +
72501 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72502 + return -EFAULT;
72503 +
72504 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72505 + (uwrapcompat.version != 0x2901)) ||
72506 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72507 + return -EINVAL;
72508 +
72509 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72510 + uwrap->version = uwrapcompat.version;
72511 + uwrap->size = sizeof(struct gr_arg);
72512 +
72513 + return 0;
72514 +}
72515 +
72516 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72517 +{
72518 + struct gr_arg_compat argcompat;
72519 +
72520 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72521 + return -EFAULT;
72522 +
72523 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72524 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72525 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72526 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72527 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72528 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72529 +
72530 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72531 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72532 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72533 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72534 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72535 + arg->segv_device = argcompat.segv_device;
72536 + arg->segv_inode = argcompat.segv_inode;
72537 + arg->segv_uid = argcompat.segv_uid;
72538 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72539 + arg->mode = argcompat.mode;
72540 +
72541 + return 0;
72542 +}
72543 +
72544 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72545 +{
72546 + struct acl_object_label_compat objcompat;
72547 +
72548 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72549 + return -EFAULT;
72550 +
72551 + obj->filename = compat_ptr(objcompat.filename);
72552 + obj->inode = objcompat.inode;
72553 + obj->device = objcompat.device;
72554 + obj->mode = objcompat.mode;
72555 +
72556 + obj->nested = compat_ptr(objcompat.nested);
72557 + obj->globbed = compat_ptr(objcompat.globbed);
72558 +
72559 + obj->prev = compat_ptr(objcompat.prev);
72560 + obj->next = compat_ptr(objcompat.next);
72561 +
72562 + return 0;
72563 +}
72564 +
72565 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72566 +{
72567 + unsigned int i;
72568 + struct acl_subject_label_compat subjcompat;
72569 +
72570 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72571 + return -EFAULT;
72572 +
72573 + subj->filename = compat_ptr(subjcompat.filename);
72574 + subj->inode = subjcompat.inode;
72575 + subj->device = subjcompat.device;
72576 + subj->mode = subjcompat.mode;
72577 + subj->cap_mask = subjcompat.cap_mask;
72578 + subj->cap_lower = subjcompat.cap_lower;
72579 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72580 +
72581 + for (i = 0; i < GR_NLIMITS; i++) {
72582 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72583 + subj->res[i].rlim_cur = RLIM_INFINITY;
72584 + else
72585 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72586 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72587 + subj->res[i].rlim_max = RLIM_INFINITY;
72588 + else
72589 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72590 + }
72591 + subj->resmask = subjcompat.resmask;
72592 +
72593 + subj->user_trans_type = subjcompat.user_trans_type;
72594 + subj->group_trans_type = subjcompat.group_trans_type;
72595 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72596 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72597 + subj->user_trans_num = subjcompat.user_trans_num;
72598 + subj->group_trans_num = subjcompat.group_trans_num;
72599 +
72600 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72601 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72602 + subj->ip_type = subjcompat.ip_type;
72603 + subj->ips = compat_ptr(subjcompat.ips);
72604 + subj->ip_num = subjcompat.ip_num;
72605 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72606 +
72607 + subj->crashes = subjcompat.crashes;
72608 + subj->expires = subjcompat.expires;
72609 +
72610 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72611 + subj->hash = compat_ptr(subjcompat.hash);
72612 + subj->prev = compat_ptr(subjcompat.prev);
72613 + subj->next = compat_ptr(subjcompat.next);
72614 +
72615 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72616 + subj->obj_hash_size = subjcompat.obj_hash_size;
72617 + subj->pax_flags = subjcompat.pax_flags;
72618 +
72619 + return 0;
72620 +}
72621 +
72622 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72623 +{
72624 + struct acl_role_label_compat rolecompat;
72625 +
72626 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72627 + return -EFAULT;
72628 +
72629 + role->rolename = compat_ptr(rolecompat.rolename);
72630 + role->uidgid = rolecompat.uidgid;
72631 + role->roletype = rolecompat.roletype;
72632 +
72633 + role->auth_attempts = rolecompat.auth_attempts;
72634 + role->expires = rolecompat.expires;
72635 +
72636 + role->root_label = compat_ptr(rolecompat.root_label);
72637 + role->hash = compat_ptr(rolecompat.hash);
72638 +
72639 + role->prev = compat_ptr(rolecompat.prev);
72640 + role->next = compat_ptr(rolecompat.next);
72641 +
72642 + role->transitions = compat_ptr(rolecompat.transitions);
72643 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72644 + role->domain_children = compat_ptr(rolecompat.domain_children);
72645 + role->domain_child_num = rolecompat.domain_child_num;
72646 +
72647 + role->umask = rolecompat.umask;
72648 +
72649 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72650 + role->subj_hash_size = rolecompat.subj_hash_size;
72651 +
72652 + return 0;
72653 +}
72654 +
72655 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72656 +{
72657 + struct role_allowed_ip_compat roleip_compat;
72658 +
72659 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72660 + return -EFAULT;
72661 +
72662 + roleip->addr = roleip_compat.addr;
72663 + roleip->netmask = roleip_compat.netmask;
72664 +
72665 + roleip->prev = compat_ptr(roleip_compat.prev);
72666 + roleip->next = compat_ptr(roleip_compat.next);
72667 +
72668 + return 0;
72669 +}
72670 +
72671 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72672 +{
72673 + struct role_transition_compat trans_compat;
72674 +
72675 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72676 + return -EFAULT;
72677 +
72678 + trans->rolename = compat_ptr(trans_compat.rolename);
72679 +
72680 + trans->prev = compat_ptr(trans_compat.prev);
72681 + trans->next = compat_ptr(trans_compat.next);
72682 +
72683 + return 0;
72684 +
72685 +}
72686 +
72687 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72688 +{
72689 + struct gr_hash_struct_compat hash_compat;
72690 +
72691 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72692 + return -EFAULT;
72693 +
72694 + hash->table = compat_ptr(hash_compat.table);
72695 + hash->nametable = compat_ptr(hash_compat.nametable);
72696 + hash->first = compat_ptr(hash_compat.first);
72697 +
72698 + hash->table_size = hash_compat.table_size;
72699 + hash->used_size = hash_compat.used_size;
72700 +
72701 + hash->type = hash_compat.type;
72702 +
72703 + return 0;
72704 +}
72705 +
72706 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72707 +{
72708 + compat_uptr_t ptrcompat;
72709 +
72710 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72711 + return -EFAULT;
72712 +
72713 + *(void **)ptr = compat_ptr(ptrcompat);
72714 +
72715 + return 0;
72716 +}
72717 +
72718 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72719 +{
72720 + struct acl_ip_label_compat ip_compat;
72721 +
72722 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72723 + return -EFAULT;
72724 +
72725 + ip->iface = compat_ptr(ip_compat.iface);
72726 + ip->addr = ip_compat.addr;
72727 + ip->netmask = ip_compat.netmask;
72728 + ip->low = ip_compat.low;
72729 + ip->high = ip_compat.high;
72730 + ip->mode = ip_compat.mode;
72731 + ip->type = ip_compat.type;
72732 +
72733 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72734 +
72735 + ip->prev = compat_ptr(ip_compat.prev);
72736 + ip->next = compat_ptr(ip_compat.next);
72737 +
72738 + return 0;
72739 +}
72740 +
72741 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72742 +{
72743 + struct sprole_pw_compat pw_compat;
72744 +
72745 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72746 + return -EFAULT;
72747 +
72748 + pw->rolename = compat_ptr(pw_compat.rolename);
72749 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72750 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72751 +
72752 + return 0;
72753 +}
72754 +
72755 +size_t get_gr_arg_wrapper_size_compat(void)
72756 +{
72757 + return sizeof(struct gr_arg_wrapper_compat);
72758 +}
72759 +
72760 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72761 new file mode 100644
72762 index 0000000..8ee8e4f
72763 --- /dev/null
72764 +++ b/grsecurity/gracl_fs.c
72765 @@ -0,0 +1,447 @@
72766 +#include <linux/kernel.h>
72767 +#include <linux/sched.h>
72768 +#include <linux/types.h>
72769 +#include <linux/fs.h>
72770 +#include <linux/file.h>
72771 +#include <linux/stat.h>
72772 +#include <linux/grsecurity.h>
72773 +#include <linux/grinternal.h>
72774 +#include <linux/gracl.h>
72775 +
72776 +umode_t
72777 +gr_acl_umask(void)
72778 +{
72779 + if (unlikely(!gr_acl_is_enabled()))
72780 + return 0;
72781 +
72782 + return current->role->umask;
72783 +}
72784 +
72785 +__u32
72786 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72787 + const struct vfsmount * mnt)
72788 +{
72789 + __u32 mode;
72790 +
72791 + if (unlikely(d_is_negative(dentry)))
72792 + return GR_FIND;
72793 +
72794 + mode =
72795 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72796 +
72797 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72798 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72799 + return mode;
72800 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72801 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72802 + return 0;
72803 + } else if (unlikely(!(mode & GR_FIND)))
72804 + return 0;
72805 +
72806 + return GR_FIND;
72807 +}
72808 +
72809 +__u32
72810 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72811 + int acc_mode)
72812 +{
72813 + __u32 reqmode = GR_FIND;
72814 + __u32 mode;
72815 +
72816 + if (unlikely(d_is_negative(dentry)))
72817 + return reqmode;
72818 +
72819 + if (acc_mode & MAY_APPEND)
72820 + reqmode |= GR_APPEND;
72821 + else if (acc_mode & MAY_WRITE)
72822 + reqmode |= GR_WRITE;
72823 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72824 + reqmode |= GR_READ;
72825 +
72826 + mode =
72827 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72828 + mnt);
72829 +
72830 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72831 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72832 + reqmode & GR_READ ? " reading" : "",
72833 + reqmode & GR_WRITE ? " writing" : reqmode &
72834 + GR_APPEND ? " appending" : "");
72835 + return reqmode;
72836 + } else
72837 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72838 + {
72839 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72840 + reqmode & GR_READ ? " reading" : "",
72841 + reqmode & GR_WRITE ? " writing" : reqmode &
72842 + GR_APPEND ? " appending" : "");
72843 + return 0;
72844 + } else if (unlikely((mode & reqmode) != reqmode))
72845 + return 0;
72846 +
72847 + return reqmode;
72848 +}
72849 +
72850 +__u32
72851 +gr_acl_handle_creat(const struct dentry * dentry,
72852 + const struct dentry * p_dentry,
72853 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72854 + const int imode)
72855 +{
72856 + __u32 reqmode = GR_WRITE | GR_CREATE;
72857 + __u32 mode;
72858 +
72859 + if (acc_mode & MAY_APPEND)
72860 + reqmode |= GR_APPEND;
72861 + // if a directory was required or the directory already exists, then
72862 + // don't count this open as a read
72863 + if ((acc_mode & MAY_READ) &&
72864 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72865 + reqmode |= GR_READ;
72866 + if ((open_flags & O_CREAT) &&
72867 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72868 + reqmode |= GR_SETID;
72869 +
72870 + mode =
72871 + gr_check_create(dentry, p_dentry, p_mnt,
72872 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72873 +
72874 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72875 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72876 + reqmode & GR_READ ? " reading" : "",
72877 + reqmode & GR_WRITE ? " writing" : reqmode &
72878 + GR_APPEND ? " appending" : "");
72879 + return reqmode;
72880 + } else
72881 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72882 + {
72883 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72884 + reqmode & GR_READ ? " reading" : "",
72885 + reqmode & GR_WRITE ? " writing" : reqmode &
72886 + GR_APPEND ? " appending" : "");
72887 + return 0;
72888 + } else if (unlikely((mode & reqmode) != reqmode))
72889 + return 0;
72890 +
72891 + return reqmode;
72892 +}
72893 +
72894 +__u32
72895 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72896 + const int fmode)
72897 +{
72898 + __u32 mode, reqmode = GR_FIND;
72899 +
72900 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72901 + reqmode |= GR_EXEC;
72902 + if (fmode & S_IWOTH)
72903 + reqmode |= GR_WRITE;
72904 + if (fmode & S_IROTH)
72905 + reqmode |= GR_READ;
72906 +
72907 + mode =
72908 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72909 + mnt);
72910 +
72911 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72912 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72913 + reqmode & GR_READ ? " reading" : "",
72914 + reqmode & GR_WRITE ? " writing" : "",
72915 + reqmode & GR_EXEC ? " executing" : "");
72916 + return reqmode;
72917 + } else
72918 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72919 + {
72920 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72921 + reqmode & GR_READ ? " reading" : "",
72922 + reqmode & GR_WRITE ? " writing" : "",
72923 + reqmode & GR_EXEC ? " executing" : "");
72924 + return 0;
72925 + } else if (unlikely((mode & reqmode) != reqmode))
72926 + return 0;
72927 +
72928 + return reqmode;
72929 +}
72930 +
72931 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72932 +{
72933 + __u32 mode;
72934 +
72935 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72936 +
72937 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72938 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72939 + return mode;
72940 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72941 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72942 + return 0;
72943 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72944 + return 0;
72945 +
72946 + return (reqmode);
72947 +}
72948 +
72949 +__u32
72950 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72951 +{
72952 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72953 +}
72954 +
72955 +__u32
72956 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72957 +{
72958 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72959 +}
72960 +
72961 +__u32
72962 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72963 +{
72964 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72965 +}
72966 +
72967 +__u32
72968 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72969 +{
72970 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72971 +}
72972 +
72973 +__u32
72974 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72975 + umode_t *modeptr)
72976 +{
72977 + umode_t mode;
72978 +
72979 + *modeptr &= ~gr_acl_umask();
72980 + mode = *modeptr;
72981 +
72982 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72983 + return 1;
72984 +
72985 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72986 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72987 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72988 + GR_CHMOD_ACL_MSG);
72989 + } else {
72990 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72991 + }
72992 +}
72993 +
72994 +__u32
72995 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72996 +{
72997 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72998 +}
72999 +
73000 +__u32
73001 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73002 +{
73003 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73004 +}
73005 +
73006 +__u32
73007 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73008 +{
73009 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73010 +}
73011 +
73012 +__u32
73013 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73014 +{
73015 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73016 +}
73017 +
73018 +__u32
73019 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73020 +{
73021 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73022 + GR_UNIXCONNECT_ACL_MSG);
73023 +}
73024 +
73025 +/* hardlinks require at minimum create and link permission,
73026 + any additional privilege required is based on the
73027 + privilege of the file being linked to
73028 +*/
73029 +__u32
73030 +gr_acl_handle_link(const struct dentry * new_dentry,
73031 + const struct dentry * parent_dentry,
73032 + const struct vfsmount * parent_mnt,
73033 + const struct dentry * old_dentry,
73034 + const struct vfsmount * old_mnt, const struct filename *to)
73035 +{
73036 + __u32 mode;
73037 + __u32 needmode = GR_CREATE | GR_LINK;
73038 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73039 +
73040 + mode =
73041 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73042 + old_mnt);
73043 +
73044 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73045 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73046 + return mode;
73047 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73048 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73049 + return 0;
73050 + } else if (unlikely((mode & needmode) != needmode))
73051 + return 0;
73052 +
73053 + return 1;
73054 +}
73055 +
73056 +__u32
73057 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73058 + const struct dentry * parent_dentry,
73059 + const struct vfsmount * parent_mnt, const struct filename *from)
73060 +{
73061 + __u32 needmode = GR_WRITE | GR_CREATE;
73062 + __u32 mode;
73063 +
73064 + mode =
73065 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73066 + GR_CREATE | GR_AUDIT_CREATE |
73067 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73068 +
73069 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73070 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73071 + return mode;
73072 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73073 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73074 + return 0;
73075 + } else if (unlikely((mode & needmode) != needmode))
73076 + return 0;
73077 +
73078 + return (GR_WRITE | GR_CREATE);
73079 +}
73080 +
73081 +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)
73082 +{
73083 + __u32 mode;
73084 +
73085 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73086 +
73087 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73088 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73089 + return mode;
73090 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73091 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73092 + return 0;
73093 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73094 + return 0;
73095 +
73096 + return (reqmode);
73097 +}
73098 +
73099 +__u32
73100 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73101 + const struct dentry * parent_dentry,
73102 + const struct vfsmount * parent_mnt,
73103 + const int mode)
73104 +{
73105 + __u32 reqmode = GR_WRITE | GR_CREATE;
73106 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73107 + reqmode |= GR_SETID;
73108 +
73109 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73110 + reqmode, GR_MKNOD_ACL_MSG);
73111 +}
73112 +
73113 +__u32
73114 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73115 + const struct dentry *parent_dentry,
73116 + const struct vfsmount *parent_mnt)
73117 +{
73118 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73119 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73120 +}
73121 +
73122 +#define RENAME_CHECK_SUCCESS(old, new) \
73123 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73124 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73125 +
73126 +int
73127 +gr_acl_handle_rename(struct dentry *new_dentry,
73128 + struct dentry *parent_dentry,
73129 + const struct vfsmount *parent_mnt,
73130 + struct dentry *old_dentry,
73131 + struct inode *old_parent_inode,
73132 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73133 +{
73134 + __u32 comp1, comp2;
73135 + int error = 0;
73136 +
73137 + if (unlikely(!gr_acl_is_enabled()))
73138 + return 0;
73139 +
73140 + if (flags & RENAME_EXCHANGE) {
73141 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73142 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73143 + GR_SUPPRESS, parent_mnt);
73144 + comp2 =
73145 + gr_search_file(old_dentry,
73146 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73147 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73148 + } else if (d_is_negative(new_dentry)) {
73149 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73150 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73151 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73152 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73153 + GR_DELETE | GR_AUDIT_DELETE |
73154 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73155 + GR_SUPPRESS, old_mnt);
73156 + } else {
73157 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73158 + GR_CREATE | GR_DELETE |
73159 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73160 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73161 + GR_SUPPRESS, parent_mnt);
73162 + comp2 =
73163 + gr_search_file(old_dentry,
73164 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73165 + GR_DELETE | GR_AUDIT_DELETE |
73166 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73167 + }
73168 +
73169 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73170 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73171 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73172 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73173 + && !(comp2 & GR_SUPPRESS)) {
73174 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73175 + error = -EACCES;
73176 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73177 + error = -EACCES;
73178 +
73179 + return error;
73180 +}
73181 +
73182 +void
73183 +gr_acl_handle_exit(void)
73184 +{
73185 + u16 id;
73186 + char *rolename;
73187 +
73188 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73189 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73190 + id = current->acl_role_id;
73191 + rolename = current->role->rolename;
73192 + gr_set_acls(1);
73193 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73194 + }
73195 +
73196 + gr_put_exec_file(current);
73197 + return;
73198 +}
73199 +
73200 +int
73201 +gr_acl_handle_procpidmem(const struct task_struct *task)
73202 +{
73203 + if (unlikely(!gr_acl_is_enabled()))
73204 + return 0;
73205 +
73206 + if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
73207 + !(current->acl->mode & GR_POVERRIDE) &&
73208 + !(current->role->roletype & GR_ROLE_GOD))
73209 + return -EACCES;
73210 +
73211 + return 0;
73212 +}
73213 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73214 new file mode 100644
73215 index 0000000..f056b81
73216 --- /dev/null
73217 +++ b/grsecurity/gracl_ip.c
73218 @@ -0,0 +1,386 @@
73219 +#include <linux/kernel.h>
73220 +#include <asm/uaccess.h>
73221 +#include <asm/errno.h>
73222 +#include <net/sock.h>
73223 +#include <linux/file.h>
73224 +#include <linux/fs.h>
73225 +#include <linux/net.h>
73226 +#include <linux/in.h>
73227 +#include <linux/skbuff.h>
73228 +#include <linux/ip.h>
73229 +#include <linux/udp.h>
73230 +#include <linux/types.h>
73231 +#include <linux/sched.h>
73232 +#include <linux/netdevice.h>
73233 +#include <linux/inetdevice.h>
73234 +#include <linux/gracl.h>
73235 +#include <linux/grsecurity.h>
73236 +#include <linux/grinternal.h>
73237 +
73238 +#define GR_BIND 0x01
73239 +#define GR_CONNECT 0x02
73240 +#define GR_INVERT 0x04
73241 +#define GR_BINDOVERRIDE 0x08
73242 +#define GR_CONNECTOVERRIDE 0x10
73243 +#define GR_SOCK_FAMILY 0x20
73244 +
73245 +static const char * gr_protocols[IPPROTO_MAX] = {
73246 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73247 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73248 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73249 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73250 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73251 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73252 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73253 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73254 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73255 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73256 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73257 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73258 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73259 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73260 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73261 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73262 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73263 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73264 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73265 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73266 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73267 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73268 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73269 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73270 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73271 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73272 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73273 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73274 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73275 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73276 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73277 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73278 + };
73279 +
73280 +static const char * gr_socktypes[SOCK_MAX] = {
73281 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73282 + "unknown:7", "unknown:8", "unknown:9", "packet"
73283 + };
73284 +
73285 +static const char * gr_sockfamilies[AF_MAX+1] = {
73286 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73287 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73288 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73289 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73290 + };
73291 +
73292 +const char *
73293 +gr_proto_to_name(unsigned char proto)
73294 +{
73295 + return gr_protocols[proto];
73296 +}
73297 +
73298 +const char *
73299 +gr_socktype_to_name(unsigned char type)
73300 +{
73301 + return gr_socktypes[type];
73302 +}
73303 +
73304 +const char *
73305 +gr_sockfamily_to_name(unsigned char family)
73306 +{
73307 + return gr_sockfamilies[family];
73308 +}
73309 +
73310 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73311 +
73312 +int
73313 +gr_search_socket(const int domain, const int type, const int protocol)
73314 +{
73315 + struct acl_subject_label *curr;
73316 + const struct cred *cred = current_cred();
73317 +
73318 + if (unlikely(!gr_acl_is_enabled()))
73319 + goto exit;
73320 +
73321 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73322 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73323 + goto exit; // let the kernel handle it
73324 +
73325 + curr = current->acl;
73326 +
73327 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73328 + /* the family is allowed, if this is PF_INET allow it only if
73329 + the extra sock type/protocol checks pass */
73330 + if (domain == PF_INET)
73331 + goto inet_check;
73332 + goto exit;
73333 + } else {
73334 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73335 + __u32 fakeip = 0;
73336 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73337 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73338 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73339 + gr_to_filename(current->exec_file->f_path.dentry,
73340 + current->exec_file->f_path.mnt) :
73341 + curr->filename, curr->filename,
73342 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73343 + &current->signal->saved_ip);
73344 + goto exit;
73345 + }
73346 + goto exit_fail;
73347 + }
73348 +
73349 +inet_check:
73350 + /* the rest of this checking is for IPv4 only */
73351 + if (!curr->ips)
73352 + goto exit;
73353 +
73354 + if ((curr->ip_type & (1U << type)) &&
73355 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73356 + goto exit;
73357 +
73358 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73359 + /* we don't place acls on raw sockets , and sometimes
73360 + dgram/ip sockets are opened for ioctl and not
73361 + bind/connect, so we'll fake a bind learn log */
73362 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73363 + __u32 fakeip = 0;
73364 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73365 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73366 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73367 + gr_to_filename(current->exec_file->f_path.dentry,
73368 + current->exec_file->f_path.mnt) :
73369 + curr->filename, curr->filename,
73370 + &fakeip, 0, type,
73371 + protocol, GR_CONNECT, &current->signal->saved_ip);
73372 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73373 + __u32 fakeip = 0;
73374 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73375 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73376 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73377 + gr_to_filename(current->exec_file->f_path.dentry,
73378 + current->exec_file->f_path.mnt) :
73379 + curr->filename, curr->filename,
73380 + &fakeip, 0, type,
73381 + protocol, GR_BIND, &current->signal->saved_ip);
73382 + }
73383 + /* we'll log when they use connect or bind */
73384 + goto exit;
73385 + }
73386 +
73387 +exit_fail:
73388 + if (domain == PF_INET)
73389 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73390 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73391 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73392 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73393 + gr_socktype_to_name(type), protocol);
73394 +
73395 + return 0;
73396 +exit:
73397 + return 1;
73398 +}
73399 +
73400 +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)
73401 +{
73402 + if ((ip->mode & mode) &&
73403 + (ip_port >= ip->low) &&
73404 + (ip_port <= ip->high) &&
73405 + ((ntohl(ip_addr) & our_netmask) ==
73406 + (ntohl(our_addr) & our_netmask))
73407 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73408 + && (ip->type & (1U << type))) {
73409 + if (ip->mode & GR_INVERT)
73410 + return 2; // specifically denied
73411 + else
73412 + return 1; // allowed
73413 + }
73414 +
73415 + return 0; // not specifically allowed, may continue parsing
73416 +}
73417 +
73418 +static int
73419 +gr_search_connectbind(const int full_mode, struct sock *sk,
73420 + struct sockaddr_in *addr, const int type)
73421 +{
73422 + char iface[IFNAMSIZ] = {0};
73423 + struct acl_subject_label *curr;
73424 + struct acl_ip_label *ip;
73425 + struct inet_sock *isk;
73426 + struct net_device *dev;
73427 + struct in_device *idev;
73428 + unsigned long i;
73429 + int ret;
73430 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73431 + __u32 ip_addr = 0;
73432 + __u32 our_addr;
73433 + __u32 our_netmask;
73434 + char *p;
73435 + __u16 ip_port = 0;
73436 + const struct cred *cred = current_cred();
73437 +
73438 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73439 + return 0;
73440 +
73441 + curr = current->acl;
73442 + isk = inet_sk(sk);
73443 +
73444 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73445 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73446 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73447 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73448 + struct sockaddr_in saddr;
73449 + int err;
73450 +
73451 + saddr.sin_family = AF_INET;
73452 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73453 + saddr.sin_port = isk->inet_sport;
73454 +
73455 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73456 + if (err)
73457 + return err;
73458 +
73459 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73460 + if (err)
73461 + return err;
73462 + }
73463 +
73464 + if (!curr->ips)
73465 + return 0;
73466 +
73467 + ip_addr = addr->sin_addr.s_addr;
73468 + ip_port = ntohs(addr->sin_port);
73469 +
73470 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73471 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73472 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73473 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73474 + gr_to_filename(current->exec_file->f_path.dentry,
73475 + current->exec_file->f_path.mnt) :
73476 + curr->filename, curr->filename,
73477 + &ip_addr, ip_port, type,
73478 + sk->sk_protocol, mode, &current->signal->saved_ip);
73479 + return 0;
73480 + }
73481 +
73482 + for (i = 0; i < curr->ip_num; i++) {
73483 + ip = *(curr->ips + i);
73484 + if (ip->iface != NULL) {
73485 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73486 + p = strchr(iface, ':');
73487 + if (p != NULL)
73488 + *p = '\0';
73489 + dev = dev_get_by_name(sock_net(sk), iface);
73490 + if (dev == NULL)
73491 + continue;
73492 + idev = in_dev_get(dev);
73493 + if (idev == NULL) {
73494 + dev_put(dev);
73495 + continue;
73496 + }
73497 + rcu_read_lock();
73498 + for_ifa(idev) {
73499 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73500 + our_addr = ifa->ifa_address;
73501 + our_netmask = 0xffffffff;
73502 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73503 + if (ret == 1) {
73504 + rcu_read_unlock();
73505 + in_dev_put(idev);
73506 + dev_put(dev);
73507 + return 0;
73508 + } else if (ret == 2) {
73509 + rcu_read_unlock();
73510 + in_dev_put(idev);
73511 + dev_put(dev);
73512 + goto denied;
73513 + }
73514 + }
73515 + } endfor_ifa(idev);
73516 + rcu_read_unlock();
73517 + in_dev_put(idev);
73518 + dev_put(dev);
73519 + } else {
73520 + our_addr = ip->addr;
73521 + our_netmask = ip->netmask;
73522 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73523 + if (ret == 1)
73524 + return 0;
73525 + else if (ret == 2)
73526 + goto denied;
73527 + }
73528 + }
73529 +
73530 +denied:
73531 + if (mode == GR_BIND)
73532 + 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));
73533 + else if (mode == GR_CONNECT)
73534 + 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));
73535 +
73536 + return -EACCES;
73537 +}
73538 +
73539 +int
73540 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73541 +{
73542 + /* always allow disconnection of dgram sockets with connect */
73543 + if (addr->sin_family == AF_UNSPEC)
73544 + return 0;
73545 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73546 +}
73547 +
73548 +int
73549 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73550 +{
73551 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73552 +}
73553 +
73554 +int gr_search_listen(struct socket *sock)
73555 +{
73556 + struct sock *sk = sock->sk;
73557 + struct sockaddr_in addr;
73558 +
73559 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73560 + addr.sin_port = inet_sk(sk)->inet_sport;
73561 +
73562 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73563 +}
73564 +
73565 +int gr_search_accept(struct socket *sock)
73566 +{
73567 + struct sock *sk = sock->sk;
73568 + struct sockaddr_in addr;
73569 +
73570 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73571 + addr.sin_port = inet_sk(sk)->inet_sport;
73572 +
73573 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73574 +}
73575 +
73576 +int
73577 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73578 +{
73579 + if (addr)
73580 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73581 + else {
73582 + struct sockaddr_in sin;
73583 + const struct inet_sock *inet = inet_sk(sk);
73584 +
73585 + sin.sin_addr.s_addr = inet->inet_daddr;
73586 + sin.sin_port = inet->inet_dport;
73587 +
73588 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73589 + }
73590 +}
73591 +
73592 +int
73593 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73594 +{
73595 + struct sockaddr_in sin;
73596 +
73597 + if (unlikely(skb->len < sizeof (struct udphdr)))
73598 + return 0; // skip this packet
73599 +
73600 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73601 + sin.sin_port = udp_hdr(skb)->source;
73602 +
73603 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73604 +}
73605 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73606 new file mode 100644
73607 index 0000000..25f54ef
73608 --- /dev/null
73609 +++ b/grsecurity/gracl_learn.c
73610 @@ -0,0 +1,207 @@
73611 +#include <linux/kernel.h>
73612 +#include <linux/mm.h>
73613 +#include <linux/sched.h>
73614 +#include <linux/poll.h>
73615 +#include <linux/string.h>
73616 +#include <linux/file.h>
73617 +#include <linux/types.h>
73618 +#include <linux/vmalloc.h>
73619 +#include <linux/grinternal.h>
73620 +
73621 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73622 + size_t count, loff_t *ppos);
73623 +extern int gr_acl_is_enabled(void);
73624 +
73625 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73626 +static int gr_learn_attached;
73627 +
73628 +/* use a 512k buffer */
73629 +#define LEARN_BUFFER_SIZE (512 * 1024)
73630 +
73631 +static DEFINE_SPINLOCK(gr_learn_lock);
73632 +static DEFINE_MUTEX(gr_learn_user_mutex);
73633 +
73634 +/* we need to maintain two buffers, so that the kernel context of grlearn
73635 + uses a semaphore around the userspace copying, and the other kernel contexts
73636 + use a spinlock when copying into the buffer, since they cannot sleep
73637 +*/
73638 +static char *learn_buffer;
73639 +static char *learn_buffer_user;
73640 +static int learn_buffer_len;
73641 +static int learn_buffer_user_len;
73642 +
73643 +static ssize_t
73644 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73645 +{
73646 + DECLARE_WAITQUEUE(wait, current);
73647 + ssize_t retval = 0;
73648 +
73649 + add_wait_queue(&learn_wait, &wait);
73650 + set_current_state(TASK_INTERRUPTIBLE);
73651 + do {
73652 + mutex_lock(&gr_learn_user_mutex);
73653 + spin_lock(&gr_learn_lock);
73654 + if (learn_buffer_len)
73655 + break;
73656 + spin_unlock(&gr_learn_lock);
73657 + mutex_unlock(&gr_learn_user_mutex);
73658 + if (file->f_flags & O_NONBLOCK) {
73659 + retval = -EAGAIN;
73660 + goto out;
73661 + }
73662 + if (signal_pending(current)) {
73663 + retval = -ERESTARTSYS;
73664 + goto out;
73665 + }
73666 +
73667 + schedule();
73668 + } while (1);
73669 +
73670 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73671 + learn_buffer_user_len = learn_buffer_len;
73672 + retval = learn_buffer_len;
73673 + learn_buffer_len = 0;
73674 +
73675 + spin_unlock(&gr_learn_lock);
73676 +
73677 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73678 + retval = -EFAULT;
73679 +
73680 + mutex_unlock(&gr_learn_user_mutex);
73681 +out:
73682 + set_current_state(TASK_RUNNING);
73683 + remove_wait_queue(&learn_wait, &wait);
73684 + return retval;
73685 +}
73686 +
73687 +static unsigned int
73688 +poll_learn(struct file * file, poll_table * wait)
73689 +{
73690 + poll_wait(file, &learn_wait, wait);
73691 +
73692 + if (learn_buffer_len)
73693 + return (POLLIN | POLLRDNORM);
73694 +
73695 + return 0;
73696 +}
73697 +
73698 +void
73699 +gr_clear_learn_entries(void)
73700 +{
73701 + char *tmp;
73702 +
73703 + mutex_lock(&gr_learn_user_mutex);
73704 + spin_lock(&gr_learn_lock);
73705 + tmp = learn_buffer;
73706 + learn_buffer = NULL;
73707 + spin_unlock(&gr_learn_lock);
73708 + if (tmp)
73709 + vfree(tmp);
73710 + if (learn_buffer_user != NULL) {
73711 + vfree(learn_buffer_user);
73712 + learn_buffer_user = NULL;
73713 + }
73714 + learn_buffer_len = 0;
73715 + mutex_unlock(&gr_learn_user_mutex);
73716 +
73717 + return;
73718 +}
73719 +
73720 +void
73721 +gr_add_learn_entry(const char *fmt, ...)
73722 +{
73723 + va_list args;
73724 + unsigned int len;
73725 +
73726 + if (!gr_learn_attached)
73727 + return;
73728 +
73729 + spin_lock(&gr_learn_lock);
73730 +
73731 + /* leave a gap at the end so we know when it's "full" but don't have to
73732 + compute the exact length of the string we're trying to append
73733 + */
73734 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73735 + spin_unlock(&gr_learn_lock);
73736 + wake_up_interruptible(&learn_wait);
73737 + return;
73738 + }
73739 + if (learn_buffer == NULL) {
73740 + spin_unlock(&gr_learn_lock);
73741 + return;
73742 + }
73743 +
73744 + va_start(args, fmt);
73745 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73746 + va_end(args);
73747 +
73748 + learn_buffer_len += len + 1;
73749 +
73750 + spin_unlock(&gr_learn_lock);
73751 + wake_up_interruptible(&learn_wait);
73752 +
73753 + return;
73754 +}
73755 +
73756 +static int
73757 +open_learn(struct inode *inode, struct file *file)
73758 +{
73759 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73760 + return -EBUSY;
73761 + if (file->f_mode & FMODE_READ) {
73762 + int retval = 0;
73763 + mutex_lock(&gr_learn_user_mutex);
73764 + if (learn_buffer == NULL)
73765 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73766 + if (learn_buffer_user == NULL)
73767 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73768 + if (learn_buffer == NULL) {
73769 + retval = -ENOMEM;
73770 + goto out_error;
73771 + }
73772 + if (learn_buffer_user == NULL) {
73773 + retval = -ENOMEM;
73774 + goto out_error;
73775 + }
73776 + learn_buffer_len = 0;
73777 + learn_buffer_user_len = 0;
73778 + gr_learn_attached = 1;
73779 +out_error:
73780 + mutex_unlock(&gr_learn_user_mutex);
73781 + return retval;
73782 + }
73783 + return 0;
73784 +}
73785 +
73786 +static int
73787 +close_learn(struct inode *inode, struct file *file)
73788 +{
73789 + if (file->f_mode & FMODE_READ) {
73790 + char *tmp = NULL;
73791 + mutex_lock(&gr_learn_user_mutex);
73792 + spin_lock(&gr_learn_lock);
73793 + tmp = learn_buffer;
73794 + learn_buffer = NULL;
73795 + spin_unlock(&gr_learn_lock);
73796 + if (tmp)
73797 + vfree(tmp);
73798 + if (learn_buffer_user != NULL) {
73799 + vfree(learn_buffer_user);
73800 + learn_buffer_user = NULL;
73801 + }
73802 + learn_buffer_len = 0;
73803 + learn_buffer_user_len = 0;
73804 + gr_learn_attached = 0;
73805 + mutex_unlock(&gr_learn_user_mutex);
73806 + }
73807 +
73808 + return 0;
73809 +}
73810 +
73811 +const struct file_operations grsec_fops = {
73812 + .read = read_learn,
73813 + .write = write_grsec_handler,
73814 + .open = open_learn,
73815 + .release = close_learn,
73816 + .poll = poll_learn,
73817 +};
73818 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73819 new file mode 100644
73820 index 0000000..7949dcd
73821 --- /dev/null
73822 +++ b/grsecurity/gracl_policy.c
73823 @@ -0,0 +1,1782 @@
73824 +#include <linux/kernel.h>
73825 +#include <linux/module.h>
73826 +#include <linux/sched.h>
73827 +#include <linux/mm.h>
73828 +#include <linux/file.h>
73829 +#include <linux/fs.h>
73830 +#include <linux/namei.h>
73831 +#include <linux/mount.h>
73832 +#include <linux/tty.h>
73833 +#include <linux/proc_fs.h>
73834 +#include <linux/lglock.h>
73835 +#include <linux/slab.h>
73836 +#include <linux/vmalloc.h>
73837 +#include <linux/types.h>
73838 +#include <linux/sysctl.h>
73839 +#include <linux/netdevice.h>
73840 +#include <linux/ptrace.h>
73841 +#include <linux/gracl.h>
73842 +#include <linux/gralloc.h>
73843 +#include <linux/security.h>
73844 +#include <linux/grinternal.h>
73845 +#include <linux/pid_namespace.h>
73846 +#include <linux/stop_machine.h>
73847 +#include <linux/fdtable.h>
73848 +#include <linux/percpu.h>
73849 +#include <linux/lglock.h>
73850 +#include <linux/hugetlb.h>
73851 +#include <linux/posix-timers.h>
73852 +#include "../fs/mount.h"
73853 +
73854 +#include <asm/uaccess.h>
73855 +#include <asm/errno.h>
73856 +#include <asm/mman.h>
73857 +
73858 +extern struct gr_policy_state *polstate;
73859 +
73860 +#define FOR_EACH_ROLE_START(role) \
73861 + role = polstate->role_list; \
73862 + while (role) {
73863 +
73864 +#define FOR_EACH_ROLE_END(role) \
73865 + role = role->prev; \
73866 + }
73867 +
73868 +struct path gr_real_root;
73869 +
73870 +extern struct gr_alloc_state *current_alloc_state;
73871 +
73872 +u16 acl_sp_role_value;
73873 +
73874 +static DEFINE_MUTEX(gr_dev_mutex);
73875 +
73876 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73877 +extern void gr_clear_learn_entries(void);
73878 +
73879 +struct gr_arg *gr_usermode __read_only;
73880 +unsigned char *gr_system_salt __read_only;
73881 +unsigned char *gr_system_sum __read_only;
73882 +
73883 +static unsigned int gr_auth_attempts = 0;
73884 +static unsigned long gr_auth_expires = 0UL;
73885 +
73886 +struct acl_object_label *fakefs_obj_rw;
73887 +struct acl_object_label *fakefs_obj_rwx;
73888 +
73889 +extern int gr_init_uidset(void);
73890 +extern void gr_free_uidset(void);
73891 +extern void gr_remove_uid(uid_t uid);
73892 +extern int gr_find_uid(uid_t uid);
73893 +
73894 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback);
73895 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73896 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73897 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73898 +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);
73899 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73900 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73901 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73902 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73903 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73904 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73905 +extern void assign_special_role(const char *rolename);
73906 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73907 +extern int gr_rbac_disable(void *unused);
73908 +extern void gr_enable_rbac_system(void);
73909 +
73910 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73911 +{
73912 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73913 + return -EFAULT;
73914 +
73915 + return 0;
73916 +}
73917 +
73918 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73919 +{
73920 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73921 + return -EFAULT;
73922 +
73923 + return 0;
73924 +}
73925 +
73926 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73927 +{
73928 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73929 + return -EFAULT;
73930 +
73931 + return 0;
73932 +}
73933 +
73934 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73935 +{
73936 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73937 + return -EFAULT;
73938 +
73939 + return 0;
73940 +}
73941 +
73942 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73943 +{
73944 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73945 + return -EFAULT;
73946 +
73947 + return 0;
73948 +}
73949 +
73950 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73951 +{
73952 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73953 + return -EFAULT;
73954 +
73955 + return 0;
73956 +}
73957 +
73958 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73959 +{
73960 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73961 + return -EFAULT;
73962 +
73963 + return 0;
73964 +}
73965 +
73966 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73967 +{
73968 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73969 + return -EFAULT;
73970 +
73971 + return 0;
73972 +}
73973 +
73974 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73975 +{
73976 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73977 + return -EFAULT;
73978 +
73979 + return 0;
73980 +}
73981 +
73982 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73983 +{
73984 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73985 + return -EFAULT;
73986 +
73987 + if (((uwrap->version != GRSECURITY_VERSION) &&
73988 + (uwrap->version != 0x2901)) ||
73989 + (uwrap->size != sizeof(struct gr_arg)))
73990 + return -EINVAL;
73991 +
73992 + return 0;
73993 +}
73994 +
73995 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73996 +{
73997 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73998 + return -EFAULT;
73999 +
74000 + return 0;
74001 +}
74002 +
74003 +static size_t get_gr_arg_wrapper_size_normal(void)
74004 +{
74005 + return sizeof(struct gr_arg_wrapper);
74006 +}
74007 +
74008 +#ifdef CONFIG_COMPAT
74009 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74010 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74011 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74012 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74013 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74014 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74015 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74016 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74017 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74018 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74019 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74020 +extern size_t get_gr_arg_wrapper_size_compat(void);
74021 +
74022 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74023 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74024 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74025 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74026 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74027 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74028 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74029 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74030 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74031 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74032 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74033 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74034 +
74035 +#else
74036 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74037 +#define copy_gr_arg copy_gr_arg_normal
74038 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74039 +#define copy_acl_object_label copy_acl_object_label_normal
74040 +#define copy_acl_subject_label copy_acl_subject_label_normal
74041 +#define copy_acl_role_label copy_acl_role_label_normal
74042 +#define copy_acl_ip_label copy_acl_ip_label_normal
74043 +#define copy_pointer_from_array copy_pointer_from_array_normal
74044 +#define copy_sprole_pw copy_sprole_pw_normal
74045 +#define copy_role_transition copy_role_transition_normal
74046 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74047 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74048 +#endif
74049 +
74050 +static struct acl_subject_label *
74051 +lookup_subject_map(const struct acl_subject_label *userp)
74052 +{
74053 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74054 + struct subject_map *match;
74055 +
74056 + match = polstate->subj_map_set.s_hash[index];
74057 +
74058 + while (match && match->user != userp)
74059 + match = match->next;
74060 +
74061 + if (match != NULL)
74062 + return match->kernel;
74063 + else
74064 + return NULL;
74065 +}
74066 +
74067 +static void
74068 +insert_subj_map_entry(struct subject_map *subjmap)
74069 +{
74070 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74071 + struct subject_map **curr;
74072 +
74073 + subjmap->prev = NULL;
74074 +
74075 + curr = &polstate->subj_map_set.s_hash[index];
74076 + if (*curr != NULL)
74077 + (*curr)->prev = subjmap;
74078 +
74079 + subjmap->next = *curr;
74080 + *curr = subjmap;
74081 +
74082 + return;
74083 +}
74084 +
74085 +static void
74086 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74087 +{
74088 + unsigned int index =
74089 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74090 + struct acl_role_label **curr;
74091 + struct acl_role_label *tmp, *tmp2;
74092 +
74093 + curr = &polstate->acl_role_set.r_hash[index];
74094 +
74095 + /* simple case, slot is empty, just set it to our role */
74096 + if (*curr == NULL) {
74097 + *curr = role;
74098 + } else {
74099 + /* example:
74100 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74101 + 2 -> 3
74102 + */
74103 + /* first check to see if we can already be reached via this slot */
74104 + tmp = *curr;
74105 + while (tmp && tmp != role)
74106 + tmp = tmp->next;
74107 + if (tmp == role) {
74108 + /* we don't need to add ourselves to this slot's chain */
74109 + return;
74110 + }
74111 + /* we need to add ourselves to this chain, two cases */
74112 + if (role->next == NULL) {
74113 + /* simple case, append the current chain to our role */
74114 + role->next = *curr;
74115 + *curr = role;
74116 + } else {
74117 + /* 1 -> 2 -> 3 -> 4
74118 + 2 -> 3 -> 4
74119 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74120 + */
74121 + /* trickier case: walk our role's chain until we find
74122 + the role for the start of the current slot's chain */
74123 + tmp = role;
74124 + tmp2 = *curr;
74125 + while (tmp->next && tmp->next != tmp2)
74126 + tmp = tmp->next;
74127 + if (tmp->next == tmp2) {
74128 + /* from example above, we found 3, so just
74129 + replace this slot's chain with ours */
74130 + *curr = role;
74131 + } else {
74132 + /* we didn't find a subset of our role's chain
74133 + in the current slot's chain, so append their
74134 + chain to ours, and set us as the first role in
74135 + the slot's chain
74136 +
74137 + we could fold this case with the case above,
74138 + but making it explicit for clarity
74139 + */
74140 + tmp->next = tmp2;
74141 + *curr = role;
74142 + }
74143 + }
74144 + }
74145 +
74146 + return;
74147 +}
74148 +
74149 +static void
74150 +insert_acl_role_label(struct acl_role_label *role)
74151 +{
74152 + int i;
74153 +
74154 + if (polstate->role_list == NULL) {
74155 + polstate->role_list = role;
74156 + role->prev = NULL;
74157 + } else {
74158 + role->prev = polstate->role_list;
74159 + polstate->role_list = role;
74160 + }
74161 +
74162 + /* used for hash chains */
74163 + role->next = NULL;
74164 +
74165 + if (role->roletype & GR_ROLE_DOMAIN) {
74166 + for (i = 0; i < role->domain_child_num; i++)
74167 + __insert_acl_role_label(role, role->domain_children[i]);
74168 + } else
74169 + __insert_acl_role_label(role, role->uidgid);
74170 +}
74171 +
74172 +static int
74173 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74174 +{
74175 + struct name_entry **curr, *nentry;
74176 + struct inodev_entry *ientry;
74177 + unsigned int len = strlen(name);
74178 + unsigned int key = full_name_hash(name, len);
74179 + unsigned int index = key % polstate->name_set.n_size;
74180 +
74181 + curr = &polstate->name_set.n_hash[index];
74182 +
74183 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74184 + curr = &((*curr)->next);
74185 +
74186 + if (*curr != NULL)
74187 + return 1;
74188 +
74189 + nentry = acl_alloc(sizeof (struct name_entry));
74190 + if (nentry == NULL)
74191 + return 0;
74192 + ientry = acl_alloc(sizeof (struct inodev_entry));
74193 + if (ientry == NULL)
74194 + return 0;
74195 + ientry->nentry = nentry;
74196 +
74197 + nentry->key = key;
74198 + nentry->name = name;
74199 + nentry->inode = inode;
74200 + nentry->device = device;
74201 + nentry->len = len;
74202 + nentry->deleted = deleted;
74203 +
74204 + nentry->prev = NULL;
74205 + curr = &polstate->name_set.n_hash[index];
74206 + if (*curr != NULL)
74207 + (*curr)->prev = nentry;
74208 + nentry->next = *curr;
74209 + *curr = nentry;
74210 +
74211 + /* insert us into the table searchable by inode/dev */
74212 + __insert_inodev_entry(polstate, ientry);
74213 +
74214 + return 1;
74215 +}
74216 +
74217 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74218 +
74219 +static void *
74220 +create_table(__u32 * len, int elementsize)
74221 +{
74222 + unsigned int table_sizes[] = {
74223 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74224 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74225 + 4194301, 8388593, 16777213, 33554393, 67108859
74226 + };
74227 + void *newtable = NULL;
74228 + unsigned int pwr = 0;
74229 +
74230 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74231 + table_sizes[pwr] <= *len)
74232 + pwr++;
74233 +
74234 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74235 + return newtable;
74236 +
74237 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74238 + newtable =
74239 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74240 + else
74241 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74242 +
74243 + *len = table_sizes[pwr];
74244 +
74245 + return newtable;
74246 +}
74247 +
74248 +static int
74249 +init_variables(const struct gr_arg *arg, bool reload)
74250 +{
74251 + struct task_struct *reaper = init_pid_ns.child_reaper;
74252 + unsigned int stacksize;
74253 +
74254 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74255 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74256 + polstate->name_set.n_size = arg->role_db.num_objects;
74257 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74258 +
74259 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74260 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74261 + return 1;
74262 +
74263 + if (!reload) {
74264 + if (!gr_init_uidset())
74265 + return 1;
74266 + }
74267 +
74268 + /* set up the stack that holds allocation info */
74269 +
74270 + stacksize = arg->role_db.num_pointers + 5;
74271 +
74272 + if (!acl_alloc_stack_init(stacksize))
74273 + return 1;
74274 +
74275 + if (!reload) {
74276 + /* grab reference for the real root dentry and vfsmount */
74277 + get_fs_root(reaper->fs, &gr_real_root);
74278 +
74279 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74280 + 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);
74281 +#endif
74282 +
74283 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74284 + if (fakefs_obj_rw == NULL)
74285 + return 1;
74286 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74287 +
74288 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74289 + if (fakefs_obj_rwx == NULL)
74290 + return 1;
74291 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74292 + }
74293 +
74294 + polstate->subj_map_set.s_hash =
74295 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74296 + polstate->acl_role_set.r_hash =
74297 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74298 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74299 + polstate->inodev_set.i_hash =
74300 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74301 +
74302 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74303 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74304 + return 1;
74305 +
74306 + memset(polstate->subj_map_set.s_hash, 0,
74307 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74308 + memset(polstate->acl_role_set.r_hash, 0,
74309 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74310 + memset(polstate->name_set.n_hash, 0,
74311 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74312 + memset(polstate->inodev_set.i_hash, 0,
74313 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74314 +
74315 + return 0;
74316 +}
74317 +
74318 +/* free information not needed after startup
74319 + currently contains user->kernel pointer mappings for subjects
74320 +*/
74321 +
74322 +static void
74323 +free_init_variables(void)
74324 +{
74325 + __u32 i;
74326 +
74327 + if (polstate->subj_map_set.s_hash) {
74328 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74329 + if (polstate->subj_map_set.s_hash[i]) {
74330 + kfree(polstate->subj_map_set.s_hash[i]);
74331 + polstate->subj_map_set.s_hash[i] = NULL;
74332 + }
74333 + }
74334 +
74335 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74336 + PAGE_SIZE)
74337 + kfree(polstate->subj_map_set.s_hash);
74338 + else
74339 + vfree(polstate->subj_map_set.s_hash);
74340 + }
74341 +
74342 + return;
74343 +}
74344 +
74345 +static void
74346 +free_variables(bool reload)
74347 +{
74348 + struct acl_subject_label *s;
74349 + struct acl_role_label *r;
74350 + struct task_struct *task, *task2;
74351 + unsigned int x;
74352 +
74353 + if (!reload) {
74354 + gr_clear_learn_entries();
74355 +
74356 + read_lock(&tasklist_lock);
74357 + do_each_thread(task2, task) {
74358 + task->acl_sp_role = 0;
74359 + task->acl_role_id = 0;
74360 + task->inherited = 0;
74361 + task->acl = NULL;
74362 + task->role = NULL;
74363 + } while_each_thread(task2, task);
74364 + read_unlock(&tasklist_lock);
74365 +
74366 + kfree(fakefs_obj_rw);
74367 + fakefs_obj_rw = NULL;
74368 + kfree(fakefs_obj_rwx);
74369 + fakefs_obj_rwx = NULL;
74370 +
74371 + /* release the reference to the real root dentry and vfsmount */
74372 + path_put(&gr_real_root);
74373 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74374 + }
74375 +
74376 + /* free all object hash tables */
74377 +
74378 + FOR_EACH_ROLE_START(r)
74379 + if (r->subj_hash == NULL)
74380 + goto next_role;
74381 + FOR_EACH_SUBJECT_START(r, s, x)
74382 + if (s->obj_hash == NULL)
74383 + break;
74384 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74385 + kfree(s->obj_hash);
74386 + else
74387 + vfree(s->obj_hash);
74388 + FOR_EACH_SUBJECT_END(s, x)
74389 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74390 + if (s->obj_hash == NULL)
74391 + break;
74392 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74393 + kfree(s->obj_hash);
74394 + else
74395 + vfree(s->obj_hash);
74396 + FOR_EACH_NESTED_SUBJECT_END(s)
74397 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74398 + kfree(r->subj_hash);
74399 + else
74400 + vfree(r->subj_hash);
74401 + r->subj_hash = NULL;
74402 +next_role:
74403 + FOR_EACH_ROLE_END(r)
74404 +
74405 + acl_free_all();
74406 +
74407 + if (polstate->acl_role_set.r_hash) {
74408 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74409 + PAGE_SIZE)
74410 + kfree(polstate->acl_role_set.r_hash);
74411 + else
74412 + vfree(polstate->acl_role_set.r_hash);
74413 + }
74414 + if (polstate->name_set.n_hash) {
74415 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74416 + PAGE_SIZE)
74417 + kfree(polstate->name_set.n_hash);
74418 + else
74419 + vfree(polstate->name_set.n_hash);
74420 + }
74421 +
74422 + if (polstate->inodev_set.i_hash) {
74423 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74424 + PAGE_SIZE)
74425 + kfree(polstate->inodev_set.i_hash);
74426 + else
74427 + vfree(polstate->inodev_set.i_hash);
74428 + }
74429 +
74430 + if (!reload)
74431 + gr_free_uidset();
74432 +
74433 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74434 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74435 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74436 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74437 +
74438 + polstate->default_role = NULL;
74439 + polstate->kernel_role = NULL;
74440 + polstate->role_list = NULL;
74441 +
74442 + return;
74443 +}
74444 +
74445 +static struct acl_subject_label *
74446 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74447 +
74448 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74449 +{
74450 + unsigned int len = strnlen_user(*name, maxlen);
74451 + char *tmp;
74452 +
74453 + if (!len || len >= maxlen)
74454 + return -EINVAL;
74455 +
74456 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74457 + return -ENOMEM;
74458 +
74459 + if (copy_from_user(tmp, *name, len))
74460 + return -EFAULT;
74461 +
74462 + tmp[len-1] = '\0';
74463 + *name = tmp;
74464 +
74465 + return 0;
74466 +}
74467 +
74468 +static int
74469 +copy_user_glob(struct acl_object_label *obj)
74470 +{
74471 + struct acl_object_label *g_tmp, **guser;
74472 + int error;
74473 +
74474 + if (obj->globbed == NULL)
74475 + return 0;
74476 +
74477 + guser = &obj->globbed;
74478 + while (*guser) {
74479 + g_tmp = (struct acl_object_label *)
74480 + acl_alloc(sizeof (struct acl_object_label));
74481 + if (g_tmp == NULL)
74482 + return -ENOMEM;
74483 +
74484 + if (copy_acl_object_label(g_tmp, *guser))
74485 + return -EFAULT;
74486 +
74487 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74488 + if (error)
74489 + return error;
74490 +
74491 + *guser = g_tmp;
74492 + guser = &(g_tmp->next);
74493 + }
74494 +
74495 + return 0;
74496 +}
74497 +
74498 +static int
74499 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74500 + struct acl_role_label *role)
74501 +{
74502 + struct acl_object_label *o_tmp;
74503 + int ret;
74504 +
74505 + while (userp) {
74506 + if ((o_tmp = (struct acl_object_label *)
74507 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74508 + return -ENOMEM;
74509 +
74510 + if (copy_acl_object_label(o_tmp, userp))
74511 + return -EFAULT;
74512 +
74513 + userp = o_tmp->prev;
74514 +
74515 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74516 + if (ret)
74517 + return ret;
74518 +
74519 + insert_acl_obj_label(o_tmp, subj);
74520 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74521 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74522 + return -ENOMEM;
74523 +
74524 + ret = copy_user_glob(o_tmp);
74525 + if (ret)
74526 + return ret;
74527 +
74528 + if (o_tmp->nested) {
74529 + int already_copied;
74530 +
74531 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74532 + if (IS_ERR(o_tmp->nested))
74533 + return PTR_ERR(o_tmp->nested);
74534 +
74535 + /* insert into nested subject list if we haven't copied this one yet
74536 + to prevent duplicate entries */
74537 + if (!already_copied) {
74538 + o_tmp->nested->next = role->hash->first;
74539 + role->hash->first = o_tmp->nested;
74540 + }
74541 + }
74542 + }
74543 +
74544 + return 0;
74545 +}
74546 +
74547 +static __u32
74548 +count_user_subjs(struct acl_subject_label *userp)
74549 +{
74550 + struct acl_subject_label s_tmp;
74551 + __u32 num = 0;
74552 +
74553 + while (userp) {
74554 + if (copy_acl_subject_label(&s_tmp, userp))
74555 + break;
74556 +
74557 + userp = s_tmp.prev;
74558 + }
74559 +
74560 + return num;
74561 +}
74562 +
74563 +static int
74564 +copy_user_allowedips(struct acl_role_label *rolep)
74565 +{
74566 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74567 +
74568 + ruserip = rolep->allowed_ips;
74569 +
74570 + while (ruserip) {
74571 + rlast = rtmp;
74572 +
74573 + if ((rtmp = (struct role_allowed_ip *)
74574 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74575 + return -ENOMEM;
74576 +
74577 + if (copy_role_allowed_ip(rtmp, ruserip))
74578 + return -EFAULT;
74579 +
74580 + ruserip = rtmp->prev;
74581 +
74582 + if (!rlast) {
74583 + rtmp->prev = NULL;
74584 + rolep->allowed_ips = rtmp;
74585 + } else {
74586 + rlast->next = rtmp;
74587 + rtmp->prev = rlast;
74588 + }
74589 +
74590 + if (!ruserip)
74591 + rtmp->next = NULL;
74592 + }
74593 +
74594 + return 0;
74595 +}
74596 +
74597 +static int
74598 +copy_user_transitions(struct acl_role_label *rolep)
74599 +{
74600 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74601 + int error;
74602 +
74603 + rusertp = rolep->transitions;
74604 +
74605 + while (rusertp) {
74606 + rlast = rtmp;
74607 +
74608 + if ((rtmp = (struct role_transition *)
74609 + acl_alloc(sizeof (struct role_transition))) == NULL)
74610 + return -ENOMEM;
74611 +
74612 + if (copy_role_transition(rtmp, rusertp))
74613 + return -EFAULT;
74614 +
74615 + rusertp = rtmp->prev;
74616 +
74617 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74618 + if (error)
74619 + return error;
74620 +
74621 + if (!rlast) {
74622 + rtmp->prev = NULL;
74623 + rolep->transitions = rtmp;
74624 + } else {
74625 + rlast->next = rtmp;
74626 + rtmp->prev = rlast;
74627 + }
74628 +
74629 + if (!rusertp)
74630 + rtmp->next = NULL;
74631 + }
74632 +
74633 + return 0;
74634 +}
74635 +
74636 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74637 +{
74638 + struct acl_object_label o_tmp;
74639 + __u32 num = 0;
74640 +
74641 + while (userp) {
74642 + if (copy_acl_object_label(&o_tmp, userp))
74643 + break;
74644 +
74645 + userp = o_tmp.prev;
74646 + num++;
74647 + }
74648 +
74649 + return num;
74650 +}
74651 +
74652 +static struct acl_subject_label *
74653 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74654 +{
74655 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74656 + __u32 num_objs;
74657 + struct acl_ip_label **i_tmp, *i_utmp2;
74658 + struct gr_hash_struct ghash;
74659 + struct subject_map *subjmap;
74660 + unsigned int i_num;
74661 + int err;
74662 +
74663 + if (already_copied != NULL)
74664 + *already_copied = 0;
74665 +
74666 + s_tmp = lookup_subject_map(userp);
74667 +
74668 + /* we've already copied this subject into the kernel, just return
74669 + the reference to it, and don't copy it over again
74670 + */
74671 + if (s_tmp) {
74672 + if (already_copied != NULL)
74673 + *already_copied = 1;
74674 + return(s_tmp);
74675 + }
74676 +
74677 + if ((s_tmp = (struct acl_subject_label *)
74678 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74679 + return ERR_PTR(-ENOMEM);
74680 +
74681 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74682 + if (subjmap == NULL)
74683 + return ERR_PTR(-ENOMEM);
74684 +
74685 + subjmap->user = userp;
74686 + subjmap->kernel = s_tmp;
74687 + insert_subj_map_entry(subjmap);
74688 +
74689 + if (copy_acl_subject_label(s_tmp, userp))
74690 + return ERR_PTR(-EFAULT);
74691 +
74692 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74693 + if (err)
74694 + return ERR_PTR(err);
74695 +
74696 + if (!strcmp(s_tmp->filename, "/"))
74697 + role->root_label = s_tmp;
74698 +
74699 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74700 + return ERR_PTR(-EFAULT);
74701 +
74702 + /* copy user and group transition tables */
74703 +
74704 + if (s_tmp->user_trans_num) {
74705 + uid_t *uidlist;
74706 +
74707 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74708 + if (uidlist == NULL)
74709 + return ERR_PTR(-ENOMEM);
74710 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74711 + return ERR_PTR(-EFAULT);
74712 +
74713 + s_tmp->user_transitions = uidlist;
74714 + }
74715 +
74716 + if (s_tmp->group_trans_num) {
74717 + gid_t *gidlist;
74718 +
74719 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74720 + if (gidlist == NULL)
74721 + return ERR_PTR(-ENOMEM);
74722 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74723 + return ERR_PTR(-EFAULT);
74724 +
74725 + s_tmp->group_transitions = gidlist;
74726 + }
74727 +
74728 + /* set up object hash table */
74729 + num_objs = count_user_objs(ghash.first);
74730 +
74731 + s_tmp->obj_hash_size = num_objs;
74732 + s_tmp->obj_hash =
74733 + (struct acl_object_label **)
74734 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74735 +
74736 + if (!s_tmp->obj_hash)
74737 + return ERR_PTR(-ENOMEM);
74738 +
74739 + memset(s_tmp->obj_hash, 0,
74740 + s_tmp->obj_hash_size *
74741 + sizeof (struct acl_object_label *));
74742 +
74743 + /* add in objects */
74744 + err = copy_user_objs(ghash.first, s_tmp, role);
74745 +
74746 + if (err)
74747 + return ERR_PTR(err);
74748 +
74749 + /* set pointer for parent subject */
74750 + if (s_tmp->parent_subject) {
74751 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74752 +
74753 + if (IS_ERR(s_tmp2))
74754 + return s_tmp2;
74755 +
74756 + s_tmp->parent_subject = s_tmp2;
74757 + }
74758 +
74759 + /* add in ip acls */
74760 +
74761 + if (!s_tmp->ip_num) {
74762 + s_tmp->ips = NULL;
74763 + goto insert;
74764 + }
74765 +
74766 + i_tmp =
74767 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74768 + sizeof (struct acl_ip_label *));
74769 +
74770 + if (!i_tmp)
74771 + return ERR_PTR(-ENOMEM);
74772 +
74773 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74774 + *(i_tmp + i_num) =
74775 + (struct acl_ip_label *)
74776 + acl_alloc(sizeof (struct acl_ip_label));
74777 + if (!*(i_tmp + i_num))
74778 + return ERR_PTR(-ENOMEM);
74779 +
74780 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74781 + return ERR_PTR(-EFAULT);
74782 +
74783 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74784 + return ERR_PTR(-EFAULT);
74785 +
74786 + if ((*(i_tmp + i_num))->iface == NULL)
74787 + continue;
74788 +
74789 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74790 + if (err)
74791 + return ERR_PTR(err);
74792 + }
74793 +
74794 + s_tmp->ips = i_tmp;
74795 +
74796 +insert:
74797 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74798 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74799 + return ERR_PTR(-ENOMEM);
74800 +
74801 + return s_tmp;
74802 +}
74803 +
74804 +static int
74805 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74806 +{
74807 + struct acl_subject_label s_pre;
74808 + struct acl_subject_label * ret;
74809 + int err;
74810 +
74811 + while (userp) {
74812 + if (copy_acl_subject_label(&s_pre, userp))
74813 + return -EFAULT;
74814 +
74815 + ret = do_copy_user_subj(userp, role, NULL);
74816 +
74817 + err = PTR_ERR(ret);
74818 + if (IS_ERR(ret))
74819 + return err;
74820 +
74821 + insert_acl_subj_label(ret, role);
74822 +
74823 + userp = s_pre.prev;
74824 + }
74825 +
74826 + return 0;
74827 +}
74828 +
74829 +static int
74830 +copy_user_acl(struct gr_arg *arg)
74831 +{
74832 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74833 + struct acl_subject_label *subj_list;
74834 + struct sprole_pw *sptmp;
74835 + struct gr_hash_struct *ghash;
74836 + uid_t *domainlist;
74837 + unsigned int r_num;
74838 + int err = 0;
74839 + __u16 i;
74840 + __u32 num_subjs;
74841 +
74842 + /* we need a default and kernel role */
74843 + if (arg->role_db.num_roles < 2)
74844 + return -EINVAL;
74845 +
74846 + /* copy special role authentication info from userspace */
74847 +
74848 + polstate->num_sprole_pws = arg->num_sprole_pws;
74849 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74850 +
74851 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74852 + return -ENOMEM;
74853 +
74854 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74855 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74856 + if (!sptmp)
74857 + return -ENOMEM;
74858 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74859 + return -EFAULT;
74860 +
74861 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74862 + if (err)
74863 + return err;
74864 +
74865 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74866 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74867 +#endif
74868 +
74869 + polstate->acl_special_roles[i] = sptmp;
74870 + }
74871 +
74872 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74873 +
74874 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74875 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74876 +
74877 + if (!r_tmp)
74878 + return -ENOMEM;
74879 +
74880 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74881 + return -EFAULT;
74882 +
74883 + if (copy_acl_role_label(r_tmp, r_utmp2))
74884 + return -EFAULT;
74885 +
74886 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74887 + if (err)
74888 + return err;
74889 +
74890 + if (!strcmp(r_tmp->rolename, "default")
74891 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74892 + polstate->default_role = r_tmp;
74893 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74894 + polstate->kernel_role = r_tmp;
74895 + }
74896 +
74897 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74898 + return -ENOMEM;
74899 +
74900 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74901 + return -EFAULT;
74902 +
74903 + r_tmp->hash = ghash;
74904 +
74905 + num_subjs = count_user_subjs(r_tmp->hash->first);
74906 +
74907 + r_tmp->subj_hash_size = num_subjs;
74908 + r_tmp->subj_hash =
74909 + (struct acl_subject_label **)
74910 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74911 +
74912 + if (!r_tmp->subj_hash)
74913 + return -ENOMEM;
74914 +
74915 + err = copy_user_allowedips(r_tmp);
74916 + if (err)
74917 + return err;
74918 +
74919 + /* copy domain info */
74920 + if (r_tmp->domain_children != NULL) {
74921 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74922 + if (domainlist == NULL)
74923 + return -ENOMEM;
74924 +
74925 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74926 + return -EFAULT;
74927 +
74928 + r_tmp->domain_children = domainlist;
74929 + }
74930 +
74931 + err = copy_user_transitions(r_tmp);
74932 + if (err)
74933 + return err;
74934 +
74935 + memset(r_tmp->subj_hash, 0,
74936 + r_tmp->subj_hash_size *
74937 + sizeof (struct acl_subject_label *));
74938 +
74939 + /* acquire the list of subjects, then NULL out
74940 + the list prior to parsing the subjects for this role,
74941 + as during this parsing the list is replaced with a list
74942 + of *nested* subjects for the role
74943 + */
74944 + subj_list = r_tmp->hash->first;
74945 +
74946 + /* set nested subject list to null */
74947 + r_tmp->hash->first = NULL;
74948 +
74949 + err = copy_user_subjs(subj_list, r_tmp);
74950 +
74951 + if (err)
74952 + return err;
74953 +
74954 + insert_acl_role_label(r_tmp);
74955 + }
74956 +
74957 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74958 + return -EINVAL;
74959 +
74960 + return err;
74961 +}
74962 +
74963 +static int gracl_reload_apply_policies(void *reload)
74964 +{
74965 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74966 + struct task_struct *task, *task2;
74967 + struct acl_role_label *role, *rtmp;
74968 + struct acl_subject_label *subj;
74969 + const struct cred *cred;
74970 + int role_applied;
74971 + int ret = 0;
74972 +
74973 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74974 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74975 +
74976 + /* first make sure we'll be able to apply the new policy cleanly */
74977 + do_each_thread(task2, task) {
74978 + if (task->exec_file == NULL)
74979 + continue;
74980 + role_applied = 0;
74981 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74982 + /* preserve special roles */
74983 + FOR_EACH_ROLE_START(role)
74984 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74985 + rtmp = task->role;
74986 + task->role = role;
74987 + role_applied = 1;
74988 + break;
74989 + }
74990 + FOR_EACH_ROLE_END(role)
74991 + }
74992 + if (!role_applied) {
74993 + cred = __task_cred(task);
74994 + rtmp = task->role;
74995 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74996 + }
74997 + /* this handles non-nested inherited subjects, nested subjects will still
74998 + be dropped currently */
74999 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75000 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL, 1);
75001 + /* change the role back so that we've made no modifications to the policy */
75002 + task->role = rtmp;
75003 +
75004 + if (subj == NULL || task->tmpacl == NULL) {
75005 + ret = -EINVAL;
75006 + goto out;
75007 + }
75008 + } while_each_thread(task2, task);
75009 +
75010 + /* now actually apply the policy */
75011 +
75012 + do_each_thread(task2, task) {
75013 + if (task->exec_file) {
75014 + role_applied = 0;
75015 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75016 + /* preserve special roles */
75017 + FOR_EACH_ROLE_START(role)
75018 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75019 + task->role = role;
75020 + role_applied = 1;
75021 + break;
75022 + }
75023 + FOR_EACH_ROLE_END(role)
75024 + }
75025 + if (!role_applied) {
75026 + cred = __task_cred(task);
75027 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75028 + }
75029 + /* this handles non-nested inherited subjects, nested subjects will still
75030 + be dropped currently */
75031 + if (!reload_state->oldmode && task->inherited)
75032 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75033 + else {
75034 + /* looked up and tagged to the task previously */
75035 + subj = task->tmpacl;
75036 + }
75037 + /* subj will be non-null */
75038 + __gr_apply_subject_to_task(polstate, task, subj);
75039 + if (reload_state->oldmode) {
75040 + task->acl_role_id = 0;
75041 + task->acl_sp_role = 0;
75042 + task->inherited = 0;
75043 + }
75044 + } else {
75045 + // it's a kernel process
75046 + task->role = polstate->kernel_role;
75047 + task->acl = polstate->kernel_role->root_label;
75048 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75049 + task->acl->mode &= ~GR_PROCFIND;
75050 +#endif
75051 + }
75052 + } while_each_thread(task2, task);
75053 +
75054 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75055 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75056 +
75057 +out:
75058 +
75059 + return ret;
75060 +}
75061 +
75062 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75063 +{
75064 + struct gr_reload_state new_reload_state = { };
75065 + int err;
75066 +
75067 + new_reload_state.oldpolicy_ptr = polstate;
75068 + new_reload_state.oldalloc_ptr = current_alloc_state;
75069 + new_reload_state.oldmode = oldmode;
75070 +
75071 + current_alloc_state = &new_reload_state.newalloc;
75072 + polstate = &new_reload_state.newpolicy;
75073 +
75074 + /* everything relevant is now saved off, copy in the new policy */
75075 + if (init_variables(args, true)) {
75076 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75077 + err = -ENOMEM;
75078 + goto error;
75079 + }
75080 +
75081 + err = copy_user_acl(args);
75082 + free_init_variables();
75083 + if (err)
75084 + goto error;
75085 + /* the new policy is copied in, with the old policy available via saved_state
75086 + first go through applying roles, making sure to preserve special roles
75087 + then apply new subjects, making sure to preserve inherited and nested subjects,
75088 + though currently only inherited subjects will be preserved
75089 + */
75090 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75091 + if (err)
75092 + goto error;
75093 +
75094 + /* we've now applied the new policy, so restore the old policy state to free it */
75095 + polstate = &new_reload_state.oldpolicy;
75096 + current_alloc_state = &new_reload_state.oldalloc;
75097 + free_variables(true);
75098 +
75099 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75100 + to running_polstate/current_alloc_state inside stop_machine
75101 + */
75102 + err = 0;
75103 + goto out;
75104 +error:
75105 + /* on error of loading the new policy, we'll just keep the previous
75106 + policy set around
75107 + */
75108 + free_variables(true);
75109 +
75110 + /* doesn't affect runtime, but maintains consistent state */
75111 +out:
75112 + polstate = new_reload_state.oldpolicy_ptr;
75113 + current_alloc_state = new_reload_state.oldalloc_ptr;
75114 +
75115 + return err;
75116 +}
75117 +
75118 +static int
75119 +gracl_init(struct gr_arg *args)
75120 +{
75121 + int error = 0;
75122 +
75123 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75124 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75125 +
75126 + if (init_variables(args, false)) {
75127 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75128 + error = -ENOMEM;
75129 + goto out;
75130 + }
75131 +
75132 + error = copy_user_acl(args);
75133 + free_init_variables();
75134 + if (error)
75135 + goto out;
75136 +
75137 + error = gr_set_acls(0);
75138 + if (error)
75139 + goto out;
75140 +
75141 + gr_enable_rbac_system();
75142 +
75143 + return 0;
75144 +
75145 +out:
75146 + free_variables(false);
75147 + return error;
75148 +}
75149 +
75150 +static int
75151 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75152 + unsigned char **sum)
75153 +{
75154 + struct acl_role_label *r;
75155 + struct role_allowed_ip *ipp;
75156 + struct role_transition *trans;
75157 + unsigned int i;
75158 + int found = 0;
75159 + u32 curr_ip = current->signal->curr_ip;
75160 +
75161 + current->signal->saved_ip = curr_ip;
75162 +
75163 + /* check transition table */
75164 +
75165 + for (trans = current->role->transitions; trans; trans = trans->next) {
75166 + if (!strcmp(rolename, trans->rolename)) {
75167 + found = 1;
75168 + break;
75169 + }
75170 + }
75171 +
75172 + if (!found)
75173 + return 0;
75174 +
75175 + /* handle special roles that do not require authentication
75176 + and check ip */
75177 +
75178 + FOR_EACH_ROLE_START(r)
75179 + if (!strcmp(rolename, r->rolename) &&
75180 + (r->roletype & GR_ROLE_SPECIAL)) {
75181 + found = 0;
75182 + if (r->allowed_ips != NULL) {
75183 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75184 + if ((ntohl(curr_ip) & ipp->netmask) ==
75185 + (ntohl(ipp->addr) & ipp->netmask))
75186 + found = 1;
75187 + }
75188 + } else
75189 + found = 2;
75190 + if (!found)
75191 + return 0;
75192 +
75193 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75194 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75195 + *salt = NULL;
75196 + *sum = NULL;
75197 + return 1;
75198 + }
75199 + }
75200 + FOR_EACH_ROLE_END(r)
75201 +
75202 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75203 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75204 + *salt = polstate->acl_special_roles[i]->salt;
75205 + *sum = polstate->acl_special_roles[i]->sum;
75206 + return 1;
75207 + }
75208 + }
75209 +
75210 + return 0;
75211 +}
75212 +
75213 +int gr_check_secure_terminal(struct task_struct *task)
75214 +{
75215 + struct task_struct *p, *p2, *p3;
75216 + struct files_struct *files;
75217 + struct fdtable *fdt;
75218 + struct file *our_file = NULL, *file;
75219 + int i;
75220 +
75221 + if (task->signal->tty == NULL)
75222 + return 1;
75223 +
75224 + files = get_files_struct(task);
75225 + if (files != NULL) {
75226 + rcu_read_lock();
75227 + fdt = files_fdtable(files);
75228 + for (i=0; i < fdt->max_fds; i++) {
75229 + file = fcheck_files(files, i);
75230 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75231 + get_file(file);
75232 + our_file = file;
75233 + }
75234 + }
75235 + rcu_read_unlock();
75236 + put_files_struct(files);
75237 + }
75238 +
75239 + if (our_file == NULL)
75240 + return 1;
75241 +
75242 + read_lock(&tasklist_lock);
75243 + do_each_thread(p2, p) {
75244 + files = get_files_struct(p);
75245 + if (files == NULL ||
75246 + (p->signal && p->signal->tty == task->signal->tty)) {
75247 + if (files != NULL)
75248 + put_files_struct(files);
75249 + continue;
75250 + }
75251 + rcu_read_lock();
75252 + fdt = files_fdtable(files);
75253 + for (i=0; i < fdt->max_fds; i++) {
75254 + file = fcheck_files(files, i);
75255 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75256 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75257 + p3 = task;
75258 + while (task_pid_nr(p3) > 0) {
75259 + if (p3 == p)
75260 + break;
75261 + p3 = p3->real_parent;
75262 + }
75263 + if (p3 == p)
75264 + break;
75265 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75266 + gr_handle_alertkill(p);
75267 + rcu_read_unlock();
75268 + put_files_struct(files);
75269 + read_unlock(&tasklist_lock);
75270 + fput(our_file);
75271 + return 0;
75272 + }
75273 + }
75274 + rcu_read_unlock();
75275 + put_files_struct(files);
75276 + } while_each_thread(p2, p);
75277 + read_unlock(&tasklist_lock);
75278 +
75279 + fput(our_file);
75280 + return 1;
75281 +}
75282 +
75283 +ssize_t
75284 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75285 +{
75286 + struct gr_arg_wrapper uwrap;
75287 + unsigned char *sprole_salt = NULL;
75288 + unsigned char *sprole_sum = NULL;
75289 + int error = 0;
75290 + int error2 = 0;
75291 + size_t req_count = 0;
75292 + unsigned char oldmode = 0;
75293 +
75294 + mutex_lock(&gr_dev_mutex);
75295 +
75296 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75297 + error = -EPERM;
75298 + goto out;
75299 + }
75300 +
75301 +#ifdef CONFIG_COMPAT
75302 + pax_open_kernel();
75303 + if (is_compat_task()) {
75304 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75305 + copy_gr_arg = &copy_gr_arg_compat;
75306 + copy_acl_object_label = &copy_acl_object_label_compat;
75307 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75308 + copy_acl_role_label = &copy_acl_role_label_compat;
75309 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75310 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75311 + copy_role_transition = &copy_role_transition_compat;
75312 + copy_sprole_pw = &copy_sprole_pw_compat;
75313 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75314 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75315 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75316 + } else {
75317 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75318 + copy_gr_arg = &copy_gr_arg_normal;
75319 + copy_acl_object_label = &copy_acl_object_label_normal;
75320 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75321 + copy_acl_role_label = &copy_acl_role_label_normal;
75322 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75323 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75324 + copy_role_transition = &copy_role_transition_normal;
75325 + copy_sprole_pw = &copy_sprole_pw_normal;
75326 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75327 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75328 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75329 + }
75330 + pax_close_kernel();
75331 +#endif
75332 +
75333 + req_count = get_gr_arg_wrapper_size();
75334 +
75335 + if (count != req_count) {
75336 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75337 + error = -EINVAL;
75338 + goto out;
75339 + }
75340 +
75341 +
75342 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75343 + gr_auth_expires = 0;
75344 + gr_auth_attempts = 0;
75345 + }
75346 +
75347 + error = copy_gr_arg_wrapper(buf, &uwrap);
75348 + if (error)
75349 + goto out;
75350 +
75351 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75352 + if (error)
75353 + goto out;
75354 +
75355 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75356 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75357 + time_after(gr_auth_expires, get_seconds())) {
75358 + error = -EBUSY;
75359 + goto out;
75360 + }
75361 +
75362 + /* if non-root trying to do anything other than use a special role,
75363 + do not attempt authentication, do not count towards authentication
75364 + locking
75365 + */
75366 +
75367 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75368 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75369 + gr_is_global_nonroot(current_uid())) {
75370 + error = -EPERM;
75371 + goto out;
75372 + }
75373 +
75374 + /* ensure pw and special role name are null terminated */
75375 +
75376 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75377 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75378 +
75379 + /* Okay.
75380 + * We have our enough of the argument structure..(we have yet
75381 + * to copy_from_user the tables themselves) . Copy the tables
75382 + * only if we need them, i.e. for loading operations. */
75383 +
75384 + switch (gr_usermode->mode) {
75385 + case GR_STATUS:
75386 + if (gr_acl_is_enabled()) {
75387 + error = 1;
75388 + if (!gr_check_secure_terminal(current))
75389 + error = 3;
75390 + } else
75391 + error = 2;
75392 + goto out;
75393 + case GR_SHUTDOWN:
75394 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75395 + stop_machine(gr_rbac_disable, NULL, NULL);
75396 + free_variables(false);
75397 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75398 + memset(gr_system_salt, 0, GR_SALT_LEN);
75399 + memset(gr_system_sum, 0, GR_SHA_LEN);
75400 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75401 + } else if (gr_acl_is_enabled()) {
75402 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75403 + error = -EPERM;
75404 + } else {
75405 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75406 + error = -EAGAIN;
75407 + }
75408 + break;
75409 + case GR_ENABLE:
75410 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75411 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75412 + else {
75413 + if (gr_acl_is_enabled())
75414 + error = -EAGAIN;
75415 + else
75416 + error = error2;
75417 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75418 + }
75419 + break;
75420 + case GR_OLDRELOAD:
75421 + oldmode = 1;
75422 + case GR_RELOAD:
75423 + if (!gr_acl_is_enabled()) {
75424 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75425 + error = -EAGAIN;
75426 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75427 + error2 = gracl_reload(gr_usermode, oldmode);
75428 + if (!error2)
75429 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75430 + else {
75431 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75432 + error = error2;
75433 + }
75434 + } else {
75435 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75436 + error = -EPERM;
75437 + }
75438 + break;
75439 + case GR_SEGVMOD:
75440 + if (unlikely(!gr_acl_is_enabled())) {
75441 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75442 + error = -EAGAIN;
75443 + break;
75444 + }
75445 +
75446 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75447 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75448 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75449 + struct acl_subject_label *segvacl;
75450 + segvacl =
75451 + lookup_acl_subj_label(gr_usermode->segv_inode,
75452 + gr_usermode->segv_device,
75453 + current->role);
75454 + if (segvacl) {
75455 + segvacl->crashes = 0;
75456 + segvacl->expires = 0;
75457 + }
75458 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75459 + gr_remove_uid(gr_usermode->segv_uid);
75460 + }
75461 + } else {
75462 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75463 + error = -EPERM;
75464 + }
75465 + break;
75466 + case GR_SPROLE:
75467 + case GR_SPROLEPAM:
75468 + if (unlikely(!gr_acl_is_enabled())) {
75469 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75470 + error = -EAGAIN;
75471 + break;
75472 + }
75473 +
75474 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75475 + current->role->expires = 0;
75476 + current->role->auth_attempts = 0;
75477 + }
75478 +
75479 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75480 + time_after(current->role->expires, get_seconds())) {
75481 + error = -EBUSY;
75482 + goto out;
75483 + }
75484 +
75485 + if (lookup_special_role_auth
75486 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75487 + && ((!sprole_salt && !sprole_sum)
75488 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75489 + char *p = "";
75490 + assign_special_role(gr_usermode->sp_role);
75491 + read_lock(&tasklist_lock);
75492 + if (current->real_parent)
75493 + p = current->real_parent->role->rolename;
75494 + read_unlock(&tasklist_lock);
75495 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75496 + p, acl_sp_role_value);
75497 + } else {
75498 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75499 + error = -EPERM;
75500 + if(!(current->role->auth_attempts++))
75501 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75502 +
75503 + goto out;
75504 + }
75505 + break;
75506 + case GR_UNSPROLE:
75507 + if (unlikely(!gr_acl_is_enabled())) {
75508 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75509 + error = -EAGAIN;
75510 + break;
75511 + }
75512 +
75513 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75514 + char *p = "";
75515 + int i = 0;
75516 +
75517 + read_lock(&tasklist_lock);
75518 + if (current->real_parent) {
75519 + p = current->real_parent->role->rolename;
75520 + i = current->real_parent->acl_role_id;
75521 + }
75522 + read_unlock(&tasklist_lock);
75523 +
75524 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75525 + gr_set_acls(1);
75526 + } else {
75527 + error = -EPERM;
75528 + goto out;
75529 + }
75530 + break;
75531 + default:
75532 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75533 + error = -EINVAL;
75534 + break;
75535 + }
75536 +
75537 + if (error != -EPERM)
75538 + goto out;
75539 +
75540 + if(!(gr_auth_attempts++))
75541 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75542 +
75543 + out:
75544 + mutex_unlock(&gr_dev_mutex);
75545 +
75546 + if (!error)
75547 + error = req_count;
75548 +
75549 + return error;
75550 +}
75551 +
75552 +int
75553 +gr_set_acls(const int type)
75554 +{
75555 + struct task_struct *task, *task2;
75556 + struct acl_role_label *role = current->role;
75557 + struct acl_subject_label *subj;
75558 + __u16 acl_role_id = current->acl_role_id;
75559 + const struct cred *cred;
75560 + int ret;
75561 +
75562 + rcu_read_lock();
75563 + read_lock(&tasklist_lock);
75564 + read_lock(&grsec_exec_file_lock);
75565 + do_each_thread(task2, task) {
75566 + /* check to see if we're called from the exit handler,
75567 + if so, only replace ACLs that have inherited the admin
75568 + ACL */
75569 +
75570 + if (type && (task->role != role ||
75571 + task->acl_role_id != acl_role_id))
75572 + continue;
75573 +
75574 + task->acl_role_id = 0;
75575 + task->acl_sp_role = 0;
75576 + task->inherited = 0;
75577 +
75578 + if (task->exec_file) {
75579 + cred = __task_cred(task);
75580 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75581 + subj = __gr_get_subject_for_task(polstate, task, NULL, 1);
75582 + if (subj == NULL) {
75583 + ret = -EINVAL;
75584 + read_unlock(&grsec_exec_file_lock);
75585 + read_unlock(&tasklist_lock);
75586 + rcu_read_unlock();
75587 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75588 + return ret;
75589 + }
75590 + __gr_apply_subject_to_task(polstate, task, subj);
75591 + } else {
75592 + // it's a kernel process
75593 + task->role = polstate->kernel_role;
75594 + task->acl = polstate->kernel_role->root_label;
75595 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75596 + task->acl->mode &= ~GR_PROCFIND;
75597 +#endif
75598 + }
75599 + } while_each_thread(task2, task);
75600 + read_unlock(&grsec_exec_file_lock);
75601 + read_unlock(&tasklist_lock);
75602 + rcu_read_unlock();
75603 +
75604 + return 0;
75605 +}
75606 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75607 new file mode 100644
75608 index 0000000..39645c9
75609 --- /dev/null
75610 +++ b/grsecurity/gracl_res.c
75611 @@ -0,0 +1,68 @@
75612 +#include <linux/kernel.h>
75613 +#include <linux/sched.h>
75614 +#include <linux/gracl.h>
75615 +#include <linux/grinternal.h>
75616 +
75617 +static const char *restab_log[] = {
75618 + [RLIMIT_CPU] = "RLIMIT_CPU",
75619 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75620 + [RLIMIT_DATA] = "RLIMIT_DATA",
75621 + [RLIMIT_STACK] = "RLIMIT_STACK",
75622 + [RLIMIT_CORE] = "RLIMIT_CORE",
75623 + [RLIMIT_RSS] = "RLIMIT_RSS",
75624 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75625 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75626 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75627 + [RLIMIT_AS] = "RLIMIT_AS",
75628 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75629 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75630 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75631 + [RLIMIT_NICE] = "RLIMIT_NICE",
75632 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75633 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75634 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75635 +};
75636 +
75637 +void
75638 +gr_log_resource(const struct task_struct *task,
75639 + const int res, const unsigned long wanted, const int gt)
75640 +{
75641 + const struct cred *cred;
75642 + unsigned long rlim;
75643 +
75644 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75645 + return;
75646 +
75647 + // not yet supported resource
75648 + if (unlikely(!restab_log[res]))
75649 + return;
75650 +
75651 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75652 + rlim = task_rlimit_max(task, res);
75653 + else
75654 + rlim = task_rlimit(task, res);
75655 +
75656 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75657 + return;
75658 +
75659 + rcu_read_lock();
75660 + cred = __task_cred(task);
75661 +
75662 + if (res == RLIMIT_NPROC &&
75663 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75664 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75665 + goto out_rcu_unlock;
75666 + else if (res == RLIMIT_MEMLOCK &&
75667 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75668 + goto out_rcu_unlock;
75669 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75670 + goto out_rcu_unlock;
75671 + rcu_read_unlock();
75672 +
75673 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75674 +
75675 + return;
75676 +out_rcu_unlock:
75677 + rcu_read_unlock();
75678 + return;
75679 +}
75680 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75681 new file mode 100644
75682 index 0000000..2040e61
75683 --- /dev/null
75684 +++ b/grsecurity/gracl_segv.c
75685 @@ -0,0 +1,313 @@
75686 +#include <linux/kernel.h>
75687 +#include <linux/mm.h>
75688 +#include <asm/uaccess.h>
75689 +#include <asm/errno.h>
75690 +#include <asm/mman.h>
75691 +#include <net/sock.h>
75692 +#include <linux/file.h>
75693 +#include <linux/fs.h>
75694 +#include <linux/net.h>
75695 +#include <linux/in.h>
75696 +#include <linux/slab.h>
75697 +#include <linux/types.h>
75698 +#include <linux/sched.h>
75699 +#include <linux/timer.h>
75700 +#include <linux/gracl.h>
75701 +#include <linux/grsecurity.h>
75702 +#include <linux/grinternal.h>
75703 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75704 +#include <linux/magic.h>
75705 +#include <linux/pagemap.h>
75706 +#include "../fs/btrfs/async-thread.h"
75707 +#include "../fs/btrfs/ctree.h"
75708 +#include "../fs/btrfs/btrfs_inode.h"
75709 +#endif
75710 +
75711 +static struct crash_uid *uid_set;
75712 +static unsigned short uid_used;
75713 +static DEFINE_SPINLOCK(gr_uid_lock);
75714 +extern rwlock_t gr_inode_lock;
75715 +extern struct acl_subject_label *
75716 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75717 + struct acl_role_label *role);
75718 +
75719 +static inline dev_t __get_dev(const struct dentry *dentry)
75720 +{
75721 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75722 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75723 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75724 + else
75725 +#endif
75726 + return dentry->d_sb->s_dev;
75727 +}
75728 +
75729 +int
75730 +gr_init_uidset(void)
75731 +{
75732 + uid_set =
75733 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75734 + uid_used = 0;
75735 +
75736 + return uid_set ? 1 : 0;
75737 +}
75738 +
75739 +void
75740 +gr_free_uidset(void)
75741 +{
75742 + if (uid_set) {
75743 + struct crash_uid *tmpset;
75744 + spin_lock(&gr_uid_lock);
75745 + tmpset = uid_set;
75746 + uid_set = NULL;
75747 + uid_used = 0;
75748 + spin_unlock(&gr_uid_lock);
75749 + if (tmpset)
75750 + kfree(tmpset);
75751 + }
75752 +
75753 + return;
75754 +}
75755 +
75756 +int
75757 +gr_find_uid(const uid_t uid)
75758 +{
75759 + struct crash_uid *tmp = uid_set;
75760 + uid_t buid;
75761 + int low = 0, high = uid_used - 1, mid;
75762 +
75763 + while (high >= low) {
75764 + mid = (low + high) >> 1;
75765 + buid = tmp[mid].uid;
75766 + if (buid == uid)
75767 + return mid;
75768 + if (buid > uid)
75769 + high = mid - 1;
75770 + if (buid < uid)
75771 + low = mid + 1;
75772 + }
75773 +
75774 + return -1;
75775 +}
75776 +
75777 +static __inline__ void
75778 +gr_insertsort(void)
75779 +{
75780 + unsigned short i, j;
75781 + struct crash_uid index;
75782 +
75783 + for (i = 1; i < uid_used; i++) {
75784 + index = uid_set[i];
75785 + j = i;
75786 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75787 + uid_set[j] = uid_set[j - 1];
75788 + j--;
75789 + }
75790 + uid_set[j] = index;
75791 + }
75792 +
75793 + return;
75794 +}
75795 +
75796 +static __inline__ void
75797 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75798 +{
75799 + int loc;
75800 + uid_t uid = GR_GLOBAL_UID(kuid);
75801 +
75802 + if (uid_used == GR_UIDTABLE_MAX)
75803 + return;
75804 +
75805 + loc = gr_find_uid(uid);
75806 +
75807 + if (loc >= 0) {
75808 + uid_set[loc].expires = expires;
75809 + return;
75810 + }
75811 +
75812 + uid_set[uid_used].uid = uid;
75813 + uid_set[uid_used].expires = expires;
75814 + uid_used++;
75815 +
75816 + gr_insertsort();
75817 +
75818 + return;
75819 +}
75820 +
75821 +void
75822 +gr_remove_uid(const unsigned short loc)
75823 +{
75824 + unsigned short i;
75825 +
75826 + for (i = loc + 1; i < uid_used; i++)
75827 + uid_set[i - 1] = uid_set[i];
75828 +
75829 + uid_used--;
75830 +
75831 + return;
75832 +}
75833 +
75834 +int
75835 +gr_check_crash_uid(const kuid_t kuid)
75836 +{
75837 + int loc;
75838 + int ret = 0;
75839 + uid_t uid;
75840 +
75841 + if (unlikely(!gr_acl_is_enabled()))
75842 + return 0;
75843 +
75844 + uid = GR_GLOBAL_UID(kuid);
75845 +
75846 + spin_lock(&gr_uid_lock);
75847 + loc = gr_find_uid(uid);
75848 +
75849 + if (loc < 0)
75850 + goto out_unlock;
75851 +
75852 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75853 + gr_remove_uid(loc);
75854 + else
75855 + ret = 1;
75856 +
75857 +out_unlock:
75858 + spin_unlock(&gr_uid_lock);
75859 + return ret;
75860 +}
75861 +
75862 +static __inline__ int
75863 +proc_is_setxid(const struct cred *cred)
75864 +{
75865 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75866 + !uid_eq(cred->uid, cred->fsuid))
75867 + return 1;
75868 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75869 + !gid_eq(cred->gid, cred->fsgid))
75870 + return 1;
75871 +
75872 + return 0;
75873 +}
75874 +
75875 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75876 +
75877 +void
75878 +gr_handle_crash(struct task_struct *task, const int sig)
75879 +{
75880 + struct acl_subject_label *curr;
75881 + struct task_struct *tsk, *tsk2;
75882 + const struct cred *cred;
75883 + const struct cred *cred2;
75884 +
75885 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75886 + return;
75887 +
75888 + if (unlikely(!gr_acl_is_enabled()))
75889 + return;
75890 +
75891 + curr = task->acl;
75892 +
75893 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75894 + return;
75895 +
75896 + if (time_before_eq(curr->expires, get_seconds())) {
75897 + curr->expires = 0;
75898 + curr->crashes = 0;
75899 + }
75900 +
75901 + curr->crashes++;
75902 +
75903 + if (!curr->expires)
75904 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75905 +
75906 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75907 + time_after(curr->expires, get_seconds())) {
75908 + rcu_read_lock();
75909 + cred = __task_cred(task);
75910 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75911 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75912 + spin_lock(&gr_uid_lock);
75913 + gr_insert_uid(cred->uid, curr->expires);
75914 + spin_unlock(&gr_uid_lock);
75915 + curr->expires = 0;
75916 + curr->crashes = 0;
75917 + read_lock(&tasklist_lock);
75918 + do_each_thread(tsk2, tsk) {
75919 + cred2 = __task_cred(tsk);
75920 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75921 + gr_fake_force_sig(SIGKILL, tsk);
75922 + } while_each_thread(tsk2, tsk);
75923 + read_unlock(&tasklist_lock);
75924 + } else {
75925 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75926 + read_lock(&tasklist_lock);
75927 + read_lock(&grsec_exec_file_lock);
75928 + do_each_thread(tsk2, tsk) {
75929 + if (likely(tsk != task)) {
75930 + // if this thread has the same subject as the one that triggered
75931 + // RES_CRASH and it's the same binary, kill it
75932 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75933 + gr_fake_force_sig(SIGKILL, tsk);
75934 + }
75935 + } while_each_thread(tsk2, tsk);
75936 + read_unlock(&grsec_exec_file_lock);
75937 + read_unlock(&tasklist_lock);
75938 + }
75939 + rcu_read_unlock();
75940 + }
75941 +
75942 + return;
75943 +}
75944 +
75945 +int
75946 +gr_check_crash_exec(const struct file *filp)
75947 +{
75948 + struct acl_subject_label *curr;
75949 +
75950 + if (unlikely(!gr_acl_is_enabled()))
75951 + return 0;
75952 +
75953 + read_lock(&gr_inode_lock);
75954 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75955 + __get_dev(filp->f_path.dentry),
75956 + current->role);
75957 + read_unlock(&gr_inode_lock);
75958 +
75959 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75960 + (!curr->crashes && !curr->expires))
75961 + return 0;
75962 +
75963 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75964 + time_after(curr->expires, get_seconds()))
75965 + return 1;
75966 + else if (time_before_eq(curr->expires, get_seconds())) {
75967 + curr->crashes = 0;
75968 + curr->expires = 0;
75969 + }
75970 +
75971 + return 0;
75972 +}
75973 +
75974 +void
75975 +gr_handle_alertkill(struct task_struct *task)
75976 +{
75977 + struct acl_subject_label *curracl;
75978 + __u32 curr_ip;
75979 + struct task_struct *p, *p2;
75980 +
75981 + if (unlikely(!gr_acl_is_enabled()))
75982 + return;
75983 +
75984 + curracl = task->acl;
75985 + curr_ip = task->signal->curr_ip;
75986 +
75987 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75988 + read_lock(&tasklist_lock);
75989 + do_each_thread(p2, p) {
75990 + if (p->signal->curr_ip == curr_ip)
75991 + gr_fake_force_sig(SIGKILL, p);
75992 + } while_each_thread(p2, p);
75993 + read_unlock(&tasklist_lock);
75994 + } else if (curracl->mode & GR_KILLPROC)
75995 + gr_fake_force_sig(SIGKILL, task);
75996 +
75997 + return;
75998 +}
75999 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76000 new file mode 100644
76001 index 0000000..6b0c9cc
76002 --- /dev/null
76003 +++ b/grsecurity/gracl_shm.c
76004 @@ -0,0 +1,40 @@
76005 +#include <linux/kernel.h>
76006 +#include <linux/mm.h>
76007 +#include <linux/sched.h>
76008 +#include <linux/file.h>
76009 +#include <linux/ipc.h>
76010 +#include <linux/gracl.h>
76011 +#include <linux/grsecurity.h>
76012 +#include <linux/grinternal.h>
76013 +
76014 +int
76015 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76016 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76017 +{
76018 + struct task_struct *task;
76019 +
76020 + if (!gr_acl_is_enabled())
76021 + return 1;
76022 +
76023 + rcu_read_lock();
76024 + read_lock(&tasklist_lock);
76025 +
76026 + task = find_task_by_vpid(shm_cprid);
76027 +
76028 + if (unlikely(!task))
76029 + task = find_task_by_vpid(shm_lapid);
76030 +
76031 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76032 + (task_pid_nr(task) == shm_lapid)) &&
76033 + (task->acl->mode & GR_PROTSHM) &&
76034 + (task->acl != current->acl))) {
76035 + read_unlock(&tasklist_lock);
76036 + rcu_read_unlock();
76037 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76038 + return 0;
76039 + }
76040 + read_unlock(&tasklist_lock);
76041 + rcu_read_unlock();
76042 +
76043 + return 1;
76044 +}
76045 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76046 new file mode 100644
76047 index 0000000..bc0be01
76048 --- /dev/null
76049 +++ b/grsecurity/grsec_chdir.c
76050 @@ -0,0 +1,19 @@
76051 +#include <linux/kernel.h>
76052 +#include <linux/sched.h>
76053 +#include <linux/fs.h>
76054 +#include <linux/file.h>
76055 +#include <linux/grsecurity.h>
76056 +#include <linux/grinternal.h>
76057 +
76058 +void
76059 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76060 +{
76061 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76062 + if ((grsec_enable_chdir && grsec_enable_group &&
76063 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76064 + !grsec_enable_group)) {
76065 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76066 + }
76067 +#endif
76068 + return;
76069 +}
76070 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76071 new file mode 100644
76072 index 0000000..114ea4f
76073 --- /dev/null
76074 +++ b/grsecurity/grsec_chroot.c
76075 @@ -0,0 +1,467 @@
76076 +#include <linux/kernel.h>
76077 +#include <linux/module.h>
76078 +#include <linux/sched.h>
76079 +#include <linux/file.h>
76080 +#include <linux/fs.h>
76081 +#include <linux/mount.h>
76082 +#include <linux/types.h>
76083 +#include "../fs/mount.h"
76084 +#include <linux/grsecurity.h>
76085 +#include <linux/grinternal.h>
76086 +
76087 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76088 +int gr_init_ran;
76089 +#endif
76090 +
76091 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76092 +{
76093 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76094 + struct dentry *tmpd = dentry;
76095 +
76096 + read_seqlock_excl(&mount_lock);
76097 + write_seqlock(&rename_lock);
76098 +
76099 + while (tmpd != mnt->mnt_root) {
76100 + atomic_inc(&tmpd->chroot_refcnt);
76101 + tmpd = tmpd->d_parent;
76102 + }
76103 + atomic_inc(&tmpd->chroot_refcnt);
76104 +
76105 + write_sequnlock(&rename_lock);
76106 + read_sequnlock_excl(&mount_lock);
76107 +#endif
76108 +}
76109 +
76110 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76111 +{
76112 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76113 + struct dentry *tmpd = dentry;
76114 +
76115 + read_seqlock_excl(&mount_lock);
76116 + write_seqlock(&rename_lock);
76117 +
76118 + while (tmpd != mnt->mnt_root) {
76119 + atomic_dec(&tmpd->chroot_refcnt);
76120 + tmpd = tmpd->d_parent;
76121 + }
76122 + atomic_dec(&tmpd->chroot_refcnt);
76123 +
76124 + write_sequnlock(&rename_lock);
76125 + read_sequnlock_excl(&mount_lock);
76126 +#endif
76127 +}
76128 +
76129 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76130 +static struct dentry *get_closest_chroot(struct dentry *dentry)
76131 +{
76132 + write_seqlock(&rename_lock);
76133 + do {
76134 + if (atomic_read(&dentry->chroot_refcnt)) {
76135 + write_sequnlock(&rename_lock);
76136 + return dentry;
76137 + }
76138 + dentry = dentry->d_parent;
76139 + } while (!IS_ROOT(dentry));
76140 + write_sequnlock(&rename_lock);
76141 + return NULL;
76142 +}
76143 +#endif
76144 +
76145 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
76146 + struct dentry *newdentry, struct vfsmount *newmnt)
76147 +{
76148 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76149 + struct dentry *chroot;
76150 +
76151 + if (unlikely(!grsec_enable_chroot_rename))
76152 + return 0;
76153 +
76154 + if (likely(!proc_is_chrooted(current) && gr_is_global_root(current_uid())))
76155 + return 0;
76156 +
76157 + chroot = get_closest_chroot(olddentry);
76158 +
76159 + if (chroot == NULL)
76160 + return 0;
76161 +
76162 + if (is_subdir(newdentry, chroot))
76163 + return 0;
76164 +
76165 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_RENAME_MSG, olddentry, oldmnt);
76166 +
76167 + return 1;
76168 +#else
76169 + return 0;
76170 +#endif
76171 +}
76172 +
76173 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76174 +{
76175 +#ifdef CONFIG_GRKERNSEC
76176 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76177 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76178 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76179 + && gr_init_ran
76180 +#endif
76181 + )
76182 + task->gr_is_chrooted = 1;
76183 + else {
76184 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76185 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76186 + gr_init_ran = 1;
76187 +#endif
76188 + task->gr_is_chrooted = 0;
76189 + }
76190 +
76191 + task->gr_chroot_dentry = path->dentry;
76192 +#endif
76193 + return;
76194 +}
76195 +
76196 +void gr_clear_chroot_entries(struct task_struct *task)
76197 +{
76198 +#ifdef CONFIG_GRKERNSEC
76199 + task->gr_is_chrooted = 0;
76200 + task->gr_chroot_dentry = NULL;
76201 +#endif
76202 + return;
76203 +}
76204 +
76205 +int
76206 +gr_handle_chroot_unix(const pid_t pid)
76207 +{
76208 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76209 + struct task_struct *p;
76210 +
76211 + if (unlikely(!grsec_enable_chroot_unix))
76212 + return 1;
76213 +
76214 + if (likely(!proc_is_chrooted(current)))
76215 + return 1;
76216 +
76217 + rcu_read_lock();
76218 + read_lock(&tasklist_lock);
76219 + p = find_task_by_vpid_unrestricted(pid);
76220 + if (unlikely(p && !have_same_root(current, p))) {
76221 + read_unlock(&tasklist_lock);
76222 + rcu_read_unlock();
76223 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76224 + return 0;
76225 + }
76226 + read_unlock(&tasklist_lock);
76227 + rcu_read_unlock();
76228 +#endif
76229 + return 1;
76230 +}
76231 +
76232 +int
76233 +gr_handle_chroot_nice(void)
76234 +{
76235 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76236 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76237 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76238 + return -EPERM;
76239 + }
76240 +#endif
76241 + return 0;
76242 +}
76243 +
76244 +int
76245 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76246 +{
76247 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76248 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76249 + && proc_is_chrooted(current)) {
76250 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76251 + return -EACCES;
76252 + }
76253 +#endif
76254 + return 0;
76255 +}
76256 +
76257 +int
76258 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76259 +{
76260 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76261 + struct task_struct *p;
76262 + int ret = 0;
76263 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76264 + return ret;
76265 +
76266 + read_lock(&tasklist_lock);
76267 + do_each_pid_task(pid, type, p) {
76268 + if (!have_same_root(current, p)) {
76269 + ret = 1;
76270 + goto out;
76271 + }
76272 + } while_each_pid_task(pid, type, p);
76273 +out:
76274 + read_unlock(&tasklist_lock);
76275 + return ret;
76276 +#endif
76277 + return 0;
76278 +}
76279 +
76280 +int
76281 +gr_pid_is_chrooted(struct task_struct *p)
76282 +{
76283 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76284 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76285 + return 0;
76286 +
76287 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76288 + !have_same_root(current, p)) {
76289 + return 1;
76290 + }
76291 +#endif
76292 + return 0;
76293 +}
76294 +
76295 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76296 +
76297 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76298 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76299 +{
76300 + struct path path, currentroot;
76301 + int ret = 0;
76302 +
76303 + path.dentry = (struct dentry *)u_dentry;
76304 + path.mnt = (struct vfsmount *)u_mnt;
76305 + get_fs_root(current->fs, &currentroot);
76306 + if (path_is_under(&path, &currentroot))
76307 + ret = 1;
76308 + path_put(&currentroot);
76309 +
76310 + return ret;
76311 +}
76312 +#endif
76313 +
76314 +int
76315 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76316 +{
76317 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76318 + if (!grsec_enable_chroot_fchdir)
76319 + return 1;
76320 +
76321 + if (!proc_is_chrooted(current))
76322 + return 1;
76323 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76324 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76325 + return 0;
76326 + }
76327 +#endif
76328 + return 1;
76329 +}
76330 +
76331 +int
76332 +gr_chroot_fhandle(void)
76333 +{
76334 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76335 + if (!grsec_enable_chroot_fchdir)
76336 + return 1;
76337 +
76338 + if (!proc_is_chrooted(current))
76339 + return 1;
76340 + else {
76341 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76342 + return 0;
76343 + }
76344 +#endif
76345 + return 1;
76346 +}
76347 +
76348 +int
76349 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76350 + const u64 shm_createtime)
76351 +{
76352 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76353 + struct task_struct *p;
76354 +
76355 + if (unlikely(!grsec_enable_chroot_shmat))
76356 + return 1;
76357 +
76358 + if (likely(!proc_is_chrooted(current)))
76359 + return 1;
76360 +
76361 + rcu_read_lock();
76362 + read_lock(&tasklist_lock);
76363 +
76364 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76365 + if (time_before_eq64(p->start_time, shm_createtime)) {
76366 + if (have_same_root(current, p)) {
76367 + goto allow;
76368 + } else {
76369 + read_unlock(&tasklist_lock);
76370 + rcu_read_unlock();
76371 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76372 + return 0;
76373 + }
76374 + }
76375 + /* creator exited, pid reuse, fall through to next check */
76376 + }
76377 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76378 + if (unlikely(!have_same_root(current, p))) {
76379 + read_unlock(&tasklist_lock);
76380 + rcu_read_unlock();
76381 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76382 + return 0;
76383 + }
76384 + }
76385 +
76386 +allow:
76387 + read_unlock(&tasklist_lock);
76388 + rcu_read_unlock();
76389 +#endif
76390 + return 1;
76391 +}
76392 +
76393 +void
76394 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76395 +{
76396 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76397 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76398 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76399 +#endif
76400 + return;
76401 +}
76402 +
76403 +int
76404 +gr_handle_chroot_mknod(const struct dentry *dentry,
76405 + const struct vfsmount *mnt, const int mode)
76406 +{
76407 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76408 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76409 + proc_is_chrooted(current)) {
76410 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76411 + return -EPERM;
76412 + }
76413 +#endif
76414 + return 0;
76415 +}
76416 +
76417 +int
76418 +gr_handle_chroot_mount(const struct dentry *dentry,
76419 + const struct vfsmount *mnt, const char *dev_name)
76420 +{
76421 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76422 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76423 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76424 + return -EPERM;
76425 + }
76426 +#endif
76427 + return 0;
76428 +}
76429 +
76430 +int
76431 +gr_handle_chroot_pivot(void)
76432 +{
76433 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76434 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76435 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76436 + return -EPERM;
76437 + }
76438 +#endif
76439 + return 0;
76440 +}
76441 +
76442 +int
76443 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76444 +{
76445 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76446 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76447 + !gr_is_outside_chroot(dentry, mnt)) {
76448 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76449 + return -EPERM;
76450 + }
76451 +#endif
76452 + return 0;
76453 +}
76454 +
76455 +extern const char *captab_log[];
76456 +extern int captab_log_entries;
76457 +
76458 +int
76459 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76460 +{
76461 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76462 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76463 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76464 + if (cap_raised(chroot_caps, cap)) {
76465 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76466 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76467 + }
76468 + return 0;
76469 + }
76470 + }
76471 +#endif
76472 + return 1;
76473 +}
76474 +
76475 +int
76476 +gr_chroot_is_capable(const int cap)
76477 +{
76478 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76479 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76480 +#endif
76481 + return 1;
76482 +}
76483 +
76484 +int
76485 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76486 +{
76487 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76488 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76489 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76490 + if (cap_raised(chroot_caps, cap)) {
76491 + return 0;
76492 + }
76493 + }
76494 +#endif
76495 + return 1;
76496 +}
76497 +
76498 +int
76499 +gr_chroot_is_capable_nolog(const int cap)
76500 +{
76501 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76502 + return gr_task_chroot_is_capable_nolog(current, cap);
76503 +#endif
76504 + return 1;
76505 +}
76506 +
76507 +int
76508 +gr_handle_chroot_sysctl(const int op)
76509 +{
76510 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76511 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76512 + proc_is_chrooted(current))
76513 + return -EACCES;
76514 +#endif
76515 + return 0;
76516 +}
76517 +
76518 +void
76519 +gr_handle_chroot_chdir(const struct path *path)
76520 +{
76521 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76522 + if (grsec_enable_chroot_chdir)
76523 + set_fs_pwd(current->fs, path);
76524 +#endif
76525 + return;
76526 +}
76527 +
76528 +int
76529 +gr_handle_chroot_chmod(const struct dentry *dentry,
76530 + const struct vfsmount *mnt, const int mode)
76531 +{
76532 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76533 + /* allow chmod +s on directories, but not files */
76534 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76535 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76536 + proc_is_chrooted(current)) {
76537 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76538 + return -EPERM;
76539 + }
76540 +#endif
76541 + return 0;
76542 +}
76543 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76544 new file mode 100644
76545 index 0000000..0f9ac91
76546 --- /dev/null
76547 +++ b/grsecurity/grsec_disabled.c
76548 @@ -0,0 +1,440 @@
76549 +#include <linux/kernel.h>
76550 +#include <linux/module.h>
76551 +#include <linux/sched.h>
76552 +#include <linux/file.h>
76553 +#include <linux/fs.h>
76554 +#include <linux/kdev_t.h>
76555 +#include <linux/net.h>
76556 +#include <linux/in.h>
76557 +#include <linux/ip.h>
76558 +#include <linux/skbuff.h>
76559 +#include <linux/sysctl.h>
76560 +
76561 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76562 +void
76563 +pax_set_initial_flags(struct linux_binprm *bprm)
76564 +{
76565 + return;
76566 +}
76567 +#endif
76568 +
76569 +#ifdef CONFIG_SYSCTL
76570 +__u32
76571 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76572 +{
76573 + return 0;
76574 +}
76575 +#endif
76576 +
76577 +#ifdef CONFIG_TASKSTATS
76578 +int gr_is_taskstats_denied(int pid)
76579 +{
76580 + return 0;
76581 +}
76582 +#endif
76583 +
76584 +int
76585 +gr_acl_is_enabled(void)
76586 +{
76587 + return 0;
76588 +}
76589 +
76590 +int
76591 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76592 +{
76593 + return 0;
76594 +}
76595 +
76596 +void
76597 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76598 +{
76599 + return;
76600 +}
76601 +
76602 +int
76603 +gr_handle_rawio(const struct inode *inode)
76604 +{
76605 + return 0;
76606 +}
76607 +
76608 +void
76609 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76610 +{
76611 + return;
76612 +}
76613 +
76614 +int
76615 +gr_handle_ptrace(struct task_struct *task, const long request)
76616 +{
76617 + return 0;
76618 +}
76619 +
76620 +int
76621 +gr_handle_proc_ptrace(struct task_struct *task)
76622 +{
76623 + return 0;
76624 +}
76625 +
76626 +int
76627 +gr_set_acls(const int type)
76628 +{
76629 + return 0;
76630 +}
76631 +
76632 +int
76633 +gr_check_hidden_task(const struct task_struct *tsk)
76634 +{
76635 + return 0;
76636 +}
76637 +
76638 +int
76639 +gr_check_protected_task(const struct task_struct *task)
76640 +{
76641 + return 0;
76642 +}
76643 +
76644 +int
76645 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76646 +{
76647 + return 0;
76648 +}
76649 +
76650 +void
76651 +gr_copy_label(struct task_struct *tsk)
76652 +{
76653 + return;
76654 +}
76655 +
76656 +void
76657 +gr_set_pax_flags(struct task_struct *task)
76658 +{
76659 + return;
76660 +}
76661 +
76662 +int
76663 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76664 + const int unsafe_share)
76665 +{
76666 + return 0;
76667 +}
76668 +
76669 +void
76670 +gr_handle_delete(const ino_t ino, const dev_t dev)
76671 +{
76672 + return;
76673 +}
76674 +
76675 +void
76676 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76677 +{
76678 + return;
76679 +}
76680 +
76681 +void
76682 +gr_handle_crash(struct task_struct *task, const int sig)
76683 +{
76684 + return;
76685 +}
76686 +
76687 +int
76688 +gr_check_crash_exec(const struct file *filp)
76689 +{
76690 + return 0;
76691 +}
76692 +
76693 +int
76694 +gr_check_crash_uid(const kuid_t uid)
76695 +{
76696 + return 0;
76697 +}
76698 +
76699 +void
76700 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76701 + struct dentry *old_dentry,
76702 + struct dentry *new_dentry,
76703 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76704 +{
76705 + return;
76706 +}
76707 +
76708 +int
76709 +gr_search_socket(const int family, const int type, const int protocol)
76710 +{
76711 + return 1;
76712 +}
76713 +
76714 +int
76715 +gr_search_connectbind(const int mode, const struct socket *sock,
76716 + const struct sockaddr_in *addr)
76717 +{
76718 + return 0;
76719 +}
76720 +
76721 +void
76722 +gr_handle_alertkill(struct task_struct *task)
76723 +{
76724 + return;
76725 +}
76726 +
76727 +__u32
76728 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76729 +{
76730 + return 1;
76731 +}
76732 +
76733 +__u32
76734 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76735 + const struct vfsmount * mnt)
76736 +{
76737 + return 1;
76738 +}
76739 +
76740 +__u32
76741 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76742 + int acc_mode)
76743 +{
76744 + return 1;
76745 +}
76746 +
76747 +__u32
76748 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76749 +{
76750 + return 1;
76751 +}
76752 +
76753 +__u32
76754 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76755 +{
76756 + return 1;
76757 +}
76758 +
76759 +int
76760 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76761 + unsigned int *vm_flags)
76762 +{
76763 + return 1;
76764 +}
76765 +
76766 +__u32
76767 +gr_acl_handle_truncate(const struct dentry * dentry,
76768 + const struct vfsmount * mnt)
76769 +{
76770 + return 1;
76771 +}
76772 +
76773 +__u32
76774 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76775 +{
76776 + return 1;
76777 +}
76778 +
76779 +__u32
76780 +gr_acl_handle_access(const struct dentry * dentry,
76781 + const struct vfsmount * mnt, const int fmode)
76782 +{
76783 + return 1;
76784 +}
76785 +
76786 +__u32
76787 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76788 + umode_t *mode)
76789 +{
76790 + return 1;
76791 +}
76792 +
76793 +__u32
76794 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76795 +{
76796 + return 1;
76797 +}
76798 +
76799 +__u32
76800 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76801 +{
76802 + return 1;
76803 +}
76804 +
76805 +__u32
76806 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76807 +{
76808 + return 1;
76809 +}
76810 +
76811 +void
76812 +grsecurity_init(void)
76813 +{
76814 + return;
76815 +}
76816 +
76817 +umode_t gr_acl_umask(void)
76818 +{
76819 + return 0;
76820 +}
76821 +
76822 +__u32
76823 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76824 + const struct dentry * parent_dentry,
76825 + const struct vfsmount * parent_mnt,
76826 + const int mode)
76827 +{
76828 + return 1;
76829 +}
76830 +
76831 +__u32
76832 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76833 + const struct dentry * parent_dentry,
76834 + const struct vfsmount * parent_mnt)
76835 +{
76836 + return 1;
76837 +}
76838 +
76839 +__u32
76840 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76841 + const struct dentry * parent_dentry,
76842 + const struct vfsmount * parent_mnt, const struct filename *from)
76843 +{
76844 + return 1;
76845 +}
76846 +
76847 +__u32
76848 +gr_acl_handle_link(const struct dentry * new_dentry,
76849 + const struct dentry * parent_dentry,
76850 + const struct vfsmount * parent_mnt,
76851 + const struct dentry * old_dentry,
76852 + const struct vfsmount * old_mnt, const struct filename *to)
76853 +{
76854 + return 1;
76855 +}
76856 +
76857 +int
76858 +gr_acl_handle_rename(const struct dentry *new_dentry,
76859 + const struct dentry *parent_dentry,
76860 + const struct vfsmount *parent_mnt,
76861 + const struct dentry *old_dentry,
76862 + const struct inode *old_parent_inode,
76863 + const struct vfsmount *old_mnt, const struct filename *newname,
76864 + unsigned int flags)
76865 +{
76866 + return 0;
76867 +}
76868 +
76869 +int
76870 +gr_acl_handle_filldir(const struct file *file, const char *name,
76871 + const int namelen, const ino_t ino)
76872 +{
76873 + return 1;
76874 +}
76875 +
76876 +int
76877 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76878 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76879 +{
76880 + return 1;
76881 +}
76882 +
76883 +int
76884 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76885 +{
76886 + return 0;
76887 +}
76888 +
76889 +int
76890 +gr_search_accept(const struct socket *sock)
76891 +{
76892 + return 0;
76893 +}
76894 +
76895 +int
76896 +gr_search_listen(const struct socket *sock)
76897 +{
76898 + return 0;
76899 +}
76900 +
76901 +int
76902 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76903 +{
76904 + return 0;
76905 +}
76906 +
76907 +__u32
76908 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76909 +{
76910 + return 1;
76911 +}
76912 +
76913 +__u32
76914 +gr_acl_handle_creat(const struct dentry * dentry,
76915 + const struct dentry * p_dentry,
76916 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76917 + const int imode)
76918 +{
76919 + return 1;
76920 +}
76921 +
76922 +void
76923 +gr_acl_handle_exit(void)
76924 +{
76925 + return;
76926 +}
76927 +
76928 +int
76929 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76930 +{
76931 + return 1;
76932 +}
76933 +
76934 +void
76935 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76936 +{
76937 + return;
76938 +}
76939 +
76940 +int
76941 +gr_acl_handle_procpidmem(const struct task_struct *task)
76942 +{
76943 + return 0;
76944 +}
76945 +
76946 +int
76947 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76948 +{
76949 + return 0;
76950 +}
76951 +
76952 +int
76953 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76954 +{
76955 + return 0;
76956 +}
76957 +
76958 +int
76959 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76960 +{
76961 + return 0;
76962 +}
76963 +
76964 +int
76965 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76966 +{
76967 + return 0;
76968 +}
76969 +
76970 +int gr_acl_enable_at_secure(void)
76971 +{
76972 + return 0;
76973 +}
76974 +
76975 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76976 +{
76977 + return dentry->d_sb->s_dev;
76978 +}
76979 +
76980 +void gr_put_exec_file(struct task_struct *task)
76981 +{
76982 + return;
76983 +}
76984 +
76985 +#ifdef CONFIG_SECURITY
76986 +EXPORT_SYMBOL_GPL(gr_check_user_change);
76987 +EXPORT_SYMBOL_GPL(gr_check_group_change);
76988 +#endif
76989 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76990 new file mode 100644
76991 index 0000000..14638ff
76992 --- /dev/null
76993 +++ b/grsecurity/grsec_exec.c
76994 @@ -0,0 +1,188 @@
76995 +#include <linux/kernel.h>
76996 +#include <linux/sched.h>
76997 +#include <linux/file.h>
76998 +#include <linux/binfmts.h>
76999 +#include <linux/fs.h>
77000 +#include <linux/types.h>
77001 +#include <linux/grdefs.h>
77002 +#include <linux/grsecurity.h>
77003 +#include <linux/grinternal.h>
77004 +#include <linux/capability.h>
77005 +#include <linux/module.h>
77006 +#include <linux/compat.h>
77007 +
77008 +#include <asm/uaccess.h>
77009 +
77010 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77011 +static char gr_exec_arg_buf[132];
77012 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77013 +#endif
77014 +
77015 +struct user_arg_ptr {
77016 +#ifdef CONFIG_COMPAT
77017 + bool is_compat;
77018 +#endif
77019 + union {
77020 + const char __user *const __user *native;
77021 +#ifdef CONFIG_COMPAT
77022 + const compat_uptr_t __user *compat;
77023 +#endif
77024 + } ptr;
77025 +};
77026 +
77027 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77028 +
77029 +void
77030 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77031 +{
77032 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77033 + char *grarg = gr_exec_arg_buf;
77034 + unsigned int i, x, execlen = 0;
77035 + char c;
77036 +
77037 + if (!((grsec_enable_execlog && grsec_enable_group &&
77038 + in_group_p(grsec_audit_gid))
77039 + || (grsec_enable_execlog && !grsec_enable_group)))
77040 + return;
77041 +
77042 + mutex_lock(&gr_exec_arg_mutex);
77043 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77044 +
77045 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77046 + const char __user *p;
77047 + unsigned int len;
77048 +
77049 + p = get_user_arg_ptr(argv, i);
77050 + if (IS_ERR(p))
77051 + goto log;
77052 +
77053 + len = strnlen_user(p, 128 - execlen);
77054 + if (len > 128 - execlen)
77055 + len = 128 - execlen;
77056 + else if (len > 0)
77057 + len--;
77058 + if (copy_from_user(grarg + execlen, p, len))
77059 + goto log;
77060 +
77061 + /* rewrite unprintable characters */
77062 + for (x = 0; x < len; x++) {
77063 + c = *(grarg + execlen + x);
77064 + if (c < 32 || c > 126)
77065 + *(grarg + execlen + x) = ' ';
77066 + }
77067 +
77068 + execlen += len;
77069 + *(grarg + execlen) = ' ';
77070 + *(grarg + execlen + 1) = '\0';
77071 + execlen++;
77072 + }
77073 +
77074 + log:
77075 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77076 + bprm->file->f_path.mnt, grarg);
77077 + mutex_unlock(&gr_exec_arg_mutex);
77078 +#endif
77079 + return;
77080 +}
77081 +
77082 +#ifdef CONFIG_GRKERNSEC
77083 +extern int gr_acl_is_capable(const int cap);
77084 +extern int gr_acl_is_capable_nolog(const int cap);
77085 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77086 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77087 +extern int gr_chroot_is_capable(const int cap);
77088 +extern int gr_chroot_is_capable_nolog(const int cap);
77089 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77090 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77091 +#endif
77092 +
77093 +const char *captab_log[] = {
77094 + "CAP_CHOWN",
77095 + "CAP_DAC_OVERRIDE",
77096 + "CAP_DAC_READ_SEARCH",
77097 + "CAP_FOWNER",
77098 + "CAP_FSETID",
77099 + "CAP_KILL",
77100 + "CAP_SETGID",
77101 + "CAP_SETUID",
77102 + "CAP_SETPCAP",
77103 + "CAP_LINUX_IMMUTABLE",
77104 + "CAP_NET_BIND_SERVICE",
77105 + "CAP_NET_BROADCAST",
77106 + "CAP_NET_ADMIN",
77107 + "CAP_NET_RAW",
77108 + "CAP_IPC_LOCK",
77109 + "CAP_IPC_OWNER",
77110 + "CAP_SYS_MODULE",
77111 + "CAP_SYS_RAWIO",
77112 + "CAP_SYS_CHROOT",
77113 + "CAP_SYS_PTRACE",
77114 + "CAP_SYS_PACCT",
77115 + "CAP_SYS_ADMIN",
77116 + "CAP_SYS_BOOT",
77117 + "CAP_SYS_NICE",
77118 + "CAP_SYS_RESOURCE",
77119 + "CAP_SYS_TIME",
77120 + "CAP_SYS_TTY_CONFIG",
77121 + "CAP_MKNOD",
77122 + "CAP_LEASE",
77123 + "CAP_AUDIT_WRITE",
77124 + "CAP_AUDIT_CONTROL",
77125 + "CAP_SETFCAP",
77126 + "CAP_MAC_OVERRIDE",
77127 + "CAP_MAC_ADMIN",
77128 + "CAP_SYSLOG",
77129 + "CAP_WAKE_ALARM",
77130 + "CAP_BLOCK_SUSPEND"
77131 +};
77132 +
77133 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77134 +
77135 +int gr_is_capable(const int cap)
77136 +{
77137 +#ifdef CONFIG_GRKERNSEC
77138 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77139 + return 1;
77140 + return 0;
77141 +#else
77142 + return 1;
77143 +#endif
77144 +}
77145 +
77146 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77147 +{
77148 +#ifdef CONFIG_GRKERNSEC
77149 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77150 + return 1;
77151 + return 0;
77152 +#else
77153 + return 1;
77154 +#endif
77155 +}
77156 +
77157 +int gr_is_capable_nolog(const int cap)
77158 +{
77159 +#ifdef CONFIG_GRKERNSEC
77160 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77161 + return 1;
77162 + return 0;
77163 +#else
77164 + return 1;
77165 +#endif
77166 +}
77167 +
77168 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77169 +{
77170 +#ifdef CONFIG_GRKERNSEC
77171 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77172 + return 1;
77173 + return 0;
77174 +#else
77175 + return 1;
77176 +#endif
77177 +}
77178 +
77179 +EXPORT_SYMBOL_GPL(gr_is_capable);
77180 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77181 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77182 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77183 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77184 new file mode 100644
77185 index 0000000..06cc6ea
77186 --- /dev/null
77187 +++ b/grsecurity/grsec_fifo.c
77188 @@ -0,0 +1,24 @@
77189 +#include <linux/kernel.h>
77190 +#include <linux/sched.h>
77191 +#include <linux/fs.h>
77192 +#include <linux/file.h>
77193 +#include <linux/grinternal.h>
77194 +
77195 +int
77196 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77197 + const struct dentry *dir, const int flag, const int acc_mode)
77198 +{
77199 +#ifdef CONFIG_GRKERNSEC_FIFO
77200 + const struct cred *cred = current_cred();
77201 +
77202 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77203 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77204 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77205 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77206 + if (!inode_permission(dentry->d_inode, acc_mode))
77207 + 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));
77208 + return -EACCES;
77209 + }
77210 +#endif
77211 + return 0;
77212 +}
77213 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77214 new file mode 100644
77215 index 0000000..8ca18bf
77216 --- /dev/null
77217 +++ b/grsecurity/grsec_fork.c
77218 @@ -0,0 +1,23 @@
77219 +#include <linux/kernel.h>
77220 +#include <linux/sched.h>
77221 +#include <linux/grsecurity.h>
77222 +#include <linux/grinternal.h>
77223 +#include <linux/errno.h>
77224 +
77225 +void
77226 +gr_log_forkfail(const int retval)
77227 +{
77228 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77229 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77230 + switch (retval) {
77231 + case -EAGAIN:
77232 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77233 + break;
77234 + case -ENOMEM:
77235 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77236 + break;
77237 + }
77238 + }
77239 +#endif
77240 + return;
77241 +}
77242 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77243 new file mode 100644
77244 index 0000000..4ed9e7d
77245 --- /dev/null
77246 +++ b/grsecurity/grsec_init.c
77247 @@ -0,0 +1,290 @@
77248 +#include <linux/kernel.h>
77249 +#include <linux/sched.h>
77250 +#include <linux/mm.h>
77251 +#include <linux/gracl.h>
77252 +#include <linux/slab.h>
77253 +#include <linux/vmalloc.h>
77254 +#include <linux/percpu.h>
77255 +#include <linux/module.h>
77256 +
77257 +int grsec_enable_ptrace_readexec;
77258 +int grsec_enable_setxid;
77259 +int grsec_enable_symlinkown;
77260 +kgid_t grsec_symlinkown_gid;
77261 +int grsec_enable_brute;
77262 +int grsec_enable_link;
77263 +int grsec_enable_dmesg;
77264 +int grsec_enable_harden_ptrace;
77265 +int grsec_enable_harden_ipc;
77266 +int grsec_enable_fifo;
77267 +int grsec_enable_execlog;
77268 +int grsec_enable_signal;
77269 +int grsec_enable_forkfail;
77270 +int grsec_enable_audit_ptrace;
77271 +int grsec_enable_time;
77272 +int grsec_enable_group;
77273 +kgid_t grsec_audit_gid;
77274 +int grsec_enable_chdir;
77275 +int grsec_enable_mount;
77276 +int grsec_enable_rofs;
77277 +int grsec_deny_new_usb;
77278 +int grsec_enable_chroot_findtask;
77279 +int grsec_enable_chroot_mount;
77280 +int grsec_enable_chroot_shmat;
77281 +int grsec_enable_chroot_fchdir;
77282 +int grsec_enable_chroot_double;
77283 +int grsec_enable_chroot_pivot;
77284 +int grsec_enable_chroot_chdir;
77285 +int grsec_enable_chroot_chmod;
77286 +int grsec_enable_chroot_mknod;
77287 +int grsec_enable_chroot_nice;
77288 +int grsec_enable_chroot_execlog;
77289 +int grsec_enable_chroot_caps;
77290 +int grsec_enable_chroot_rename;
77291 +int grsec_enable_chroot_sysctl;
77292 +int grsec_enable_chroot_unix;
77293 +int grsec_enable_tpe;
77294 +kgid_t grsec_tpe_gid;
77295 +int grsec_enable_blackhole;
77296 +#ifdef CONFIG_IPV6_MODULE
77297 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77298 +#endif
77299 +int grsec_lastack_retries;
77300 +int grsec_enable_tpe_all;
77301 +int grsec_enable_tpe_invert;
77302 +int grsec_enable_socket_all;
77303 +kgid_t grsec_socket_all_gid;
77304 +int grsec_enable_socket_client;
77305 +kgid_t grsec_socket_client_gid;
77306 +int grsec_enable_socket_server;
77307 +kgid_t grsec_socket_server_gid;
77308 +int grsec_resource_logging;
77309 +int grsec_disable_privio;
77310 +int grsec_enable_log_rwxmaps;
77311 +int grsec_lock;
77312 +
77313 +DEFINE_SPINLOCK(grsec_alert_lock);
77314 +unsigned long grsec_alert_wtime = 0;
77315 +unsigned long grsec_alert_fyet = 0;
77316 +
77317 +DEFINE_SPINLOCK(grsec_audit_lock);
77318 +
77319 +DEFINE_RWLOCK(grsec_exec_file_lock);
77320 +
77321 +char *gr_shared_page[4];
77322 +
77323 +char *gr_alert_log_fmt;
77324 +char *gr_audit_log_fmt;
77325 +char *gr_alert_log_buf;
77326 +char *gr_audit_log_buf;
77327 +
77328 +extern struct gr_arg *gr_usermode;
77329 +extern unsigned char *gr_system_salt;
77330 +extern unsigned char *gr_system_sum;
77331 +
77332 +void __init
77333 +grsecurity_init(void)
77334 +{
77335 + int j;
77336 + /* create the per-cpu shared pages */
77337 +
77338 +#ifdef CONFIG_X86
77339 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77340 +#endif
77341 +
77342 + for (j = 0; j < 4; j++) {
77343 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77344 + if (gr_shared_page[j] == NULL) {
77345 + panic("Unable to allocate grsecurity shared page");
77346 + return;
77347 + }
77348 + }
77349 +
77350 + /* allocate log buffers */
77351 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77352 + if (!gr_alert_log_fmt) {
77353 + panic("Unable to allocate grsecurity alert log format buffer");
77354 + return;
77355 + }
77356 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77357 + if (!gr_audit_log_fmt) {
77358 + panic("Unable to allocate grsecurity audit log format buffer");
77359 + return;
77360 + }
77361 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77362 + if (!gr_alert_log_buf) {
77363 + panic("Unable to allocate grsecurity alert log buffer");
77364 + return;
77365 + }
77366 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77367 + if (!gr_audit_log_buf) {
77368 + panic("Unable to allocate grsecurity audit log buffer");
77369 + return;
77370 + }
77371 +
77372 + /* allocate memory for authentication structure */
77373 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77374 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77375 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77376 +
77377 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77378 + panic("Unable to allocate grsecurity authentication structure");
77379 + return;
77380 + }
77381 +
77382 +#ifdef CONFIG_GRKERNSEC_IO
77383 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77384 + grsec_disable_privio = 1;
77385 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77386 + grsec_disable_privio = 1;
77387 +#else
77388 + grsec_disable_privio = 0;
77389 +#endif
77390 +#endif
77391 +
77392 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77393 + /* for backward compatibility, tpe_invert always defaults to on if
77394 + enabled in the kernel
77395 + */
77396 + grsec_enable_tpe_invert = 1;
77397 +#endif
77398 +
77399 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77400 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77401 + grsec_lock = 1;
77402 +#endif
77403 +
77404 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77405 + grsec_enable_log_rwxmaps = 1;
77406 +#endif
77407 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77408 + grsec_enable_group = 1;
77409 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77410 +#endif
77411 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77412 + grsec_enable_ptrace_readexec = 1;
77413 +#endif
77414 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77415 + grsec_enable_chdir = 1;
77416 +#endif
77417 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77418 + grsec_enable_harden_ptrace = 1;
77419 +#endif
77420 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77421 + grsec_enable_harden_ipc = 1;
77422 +#endif
77423 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77424 + grsec_enable_mount = 1;
77425 +#endif
77426 +#ifdef CONFIG_GRKERNSEC_LINK
77427 + grsec_enable_link = 1;
77428 +#endif
77429 +#ifdef CONFIG_GRKERNSEC_BRUTE
77430 + grsec_enable_brute = 1;
77431 +#endif
77432 +#ifdef CONFIG_GRKERNSEC_DMESG
77433 + grsec_enable_dmesg = 1;
77434 +#endif
77435 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77436 + grsec_enable_blackhole = 1;
77437 + grsec_lastack_retries = 4;
77438 +#endif
77439 +#ifdef CONFIG_GRKERNSEC_FIFO
77440 + grsec_enable_fifo = 1;
77441 +#endif
77442 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77443 + grsec_enable_execlog = 1;
77444 +#endif
77445 +#ifdef CONFIG_GRKERNSEC_SETXID
77446 + grsec_enable_setxid = 1;
77447 +#endif
77448 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77449 + grsec_enable_signal = 1;
77450 +#endif
77451 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77452 + grsec_enable_forkfail = 1;
77453 +#endif
77454 +#ifdef CONFIG_GRKERNSEC_TIME
77455 + grsec_enable_time = 1;
77456 +#endif
77457 +#ifdef CONFIG_GRKERNSEC_RESLOG
77458 + grsec_resource_logging = 1;
77459 +#endif
77460 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77461 + grsec_enable_chroot_findtask = 1;
77462 +#endif
77463 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77464 + grsec_enable_chroot_unix = 1;
77465 +#endif
77466 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77467 + grsec_enable_chroot_mount = 1;
77468 +#endif
77469 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77470 + grsec_enable_chroot_fchdir = 1;
77471 +#endif
77472 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77473 + grsec_enable_chroot_shmat = 1;
77474 +#endif
77475 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77476 + grsec_enable_audit_ptrace = 1;
77477 +#endif
77478 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77479 + grsec_enable_chroot_double = 1;
77480 +#endif
77481 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77482 + grsec_enable_chroot_pivot = 1;
77483 +#endif
77484 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77485 + grsec_enable_chroot_chdir = 1;
77486 +#endif
77487 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77488 + grsec_enable_chroot_chmod = 1;
77489 +#endif
77490 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77491 + grsec_enable_chroot_mknod = 1;
77492 +#endif
77493 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77494 + grsec_enable_chroot_nice = 1;
77495 +#endif
77496 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77497 + grsec_enable_chroot_execlog = 1;
77498 +#endif
77499 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77500 + grsec_enable_chroot_caps = 1;
77501 +#endif
77502 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
77503 + grsec_enable_chroot_rename = 1;
77504 +#endif
77505 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77506 + grsec_enable_chroot_sysctl = 1;
77507 +#endif
77508 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77509 + grsec_enable_symlinkown = 1;
77510 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77511 +#endif
77512 +#ifdef CONFIG_GRKERNSEC_TPE
77513 + grsec_enable_tpe = 1;
77514 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77515 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77516 + grsec_enable_tpe_all = 1;
77517 +#endif
77518 +#endif
77519 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77520 + grsec_enable_socket_all = 1;
77521 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77522 +#endif
77523 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77524 + grsec_enable_socket_client = 1;
77525 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77526 +#endif
77527 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77528 + grsec_enable_socket_server = 1;
77529 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77530 +#endif
77531 +#endif
77532 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77533 + grsec_deny_new_usb = 1;
77534 +#endif
77535 +
77536 + return;
77537 +}
77538 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77539 new file mode 100644
77540 index 0000000..1773300
77541 --- /dev/null
77542 +++ b/grsecurity/grsec_ipc.c
77543 @@ -0,0 +1,48 @@
77544 +#include <linux/kernel.h>
77545 +#include <linux/mm.h>
77546 +#include <linux/sched.h>
77547 +#include <linux/file.h>
77548 +#include <linux/ipc.h>
77549 +#include <linux/ipc_namespace.h>
77550 +#include <linux/grsecurity.h>
77551 +#include <linux/grinternal.h>
77552 +
77553 +int
77554 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77555 +{
77556 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77557 + int write;
77558 + int orig_granted_mode;
77559 + kuid_t euid;
77560 + kgid_t egid;
77561 +
77562 + if (!grsec_enable_harden_ipc)
77563 + return 1;
77564 +
77565 + euid = current_euid();
77566 + egid = current_egid();
77567 +
77568 + write = requested_mode & 00002;
77569 + orig_granted_mode = ipcp->mode;
77570 +
77571 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77572 + orig_granted_mode >>= 6;
77573 + else {
77574 + /* if likely wrong permissions, lock to user */
77575 + if (orig_granted_mode & 0007)
77576 + orig_granted_mode = 0;
77577 + /* otherwise do a egid-only check */
77578 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77579 + orig_granted_mode >>= 3;
77580 + /* otherwise, no access */
77581 + else
77582 + orig_granted_mode = 0;
77583 + }
77584 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77585 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77586 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77587 + return 0;
77588 + }
77589 +#endif
77590 + return 1;
77591 +}
77592 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77593 new file mode 100644
77594 index 0000000..5e05e20
77595 --- /dev/null
77596 +++ b/grsecurity/grsec_link.c
77597 @@ -0,0 +1,58 @@
77598 +#include <linux/kernel.h>
77599 +#include <linux/sched.h>
77600 +#include <linux/fs.h>
77601 +#include <linux/file.h>
77602 +#include <linux/grinternal.h>
77603 +
77604 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77605 +{
77606 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77607 + const struct inode *link_inode = link->dentry->d_inode;
77608 +
77609 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77610 + /* ignore root-owned links, e.g. /proc/self */
77611 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77612 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77613 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77614 + return 1;
77615 + }
77616 +#endif
77617 + return 0;
77618 +}
77619 +
77620 +int
77621 +gr_handle_follow_link(const struct inode *parent,
77622 + const struct inode *inode,
77623 + const struct dentry *dentry, const struct vfsmount *mnt)
77624 +{
77625 +#ifdef CONFIG_GRKERNSEC_LINK
77626 + const struct cred *cred = current_cred();
77627 +
77628 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77629 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77630 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77631 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77632 + return -EACCES;
77633 + }
77634 +#endif
77635 + return 0;
77636 +}
77637 +
77638 +int
77639 +gr_handle_hardlink(const struct dentry *dentry,
77640 + const struct vfsmount *mnt,
77641 + struct inode *inode, const int mode, const struct filename *to)
77642 +{
77643 +#ifdef CONFIG_GRKERNSEC_LINK
77644 + const struct cred *cred = current_cred();
77645 +
77646 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77647 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77648 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77649 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77650 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77651 + return -EPERM;
77652 + }
77653 +#endif
77654 + return 0;
77655 +}
77656 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77657 new file mode 100644
77658 index 0000000..dbe0a6b
77659 --- /dev/null
77660 +++ b/grsecurity/grsec_log.c
77661 @@ -0,0 +1,341 @@
77662 +#include <linux/kernel.h>
77663 +#include <linux/sched.h>
77664 +#include <linux/file.h>
77665 +#include <linux/tty.h>
77666 +#include <linux/fs.h>
77667 +#include <linux/mm.h>
77668 +#include <linux/grinternal.h>
77669 +
77670 +#ifdef CONFIG_TREE_PREEMPT_RCU
77671 +#define DISABLE_PREEMPT() preempt_disable()
77672 +#define ENABLE_PREEMPT() preempt_enable()
77673 +#else
77674 +#define DISABLE_PREEMPT()
77675 +#define ENABLE_PREEMPT()
77676 +#endif
77677 +
77678 +#define BEGIN_LOCKS(x) \
77679 + DISABLE_PREEMPT(); \
77680 + rcu_read_lock(); \
77681 + read_lock(&tasklist_lock); \
77682 + read_lock(&grsec_exec_file_lock); \
77683 + if (x != GR_DO_AUDIT) \
77684 + spin_lock(&grsec_alert_lock); \
77685 + else \
77686 + spin_lock(&grsec_audit_lock)
77687 +
77688 +#define END_LOCKS(x) \
77689 + if (x != GR_DO_AUDIT) \
77690 + spin_unlock(&grsec_alert_lock); \
77691 + else \
77692 + spin_unlock(&grsec_audit_lock); \
77693 + read_unlock(&grsec_exec_file_lock); \
77694 + read_unlock(&tasklist_lock); \
77695 + rcu_read_unlock(); \
77696 + ENABLE_PREEMPT(); \
77697 + if (x == GR_DONT_AUDIT) \
77698 + gr_handle_alertkill(current)
77699 +
77700 +enum {
77701 + FLOODING,
77702 + NO_FLOODING
77703 +};
77704 +
77705 +extern char *gr_alert_log_fmt;
77706 +extern char *gr_audit_log_fmt;
77707 +extern char *gr_alert_log_buf;
77708 +extern char *gr_audit_log_buf;
77709 +
77710 +static int gr_log_start(int audit)
77711 +{
77712 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77713 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77714 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77715 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77716 + unsigned long curr_secs = get_seconds();
77717 +
77718 + if (audit == GR_DO_AUDIT)
77719 + goto set_fmt;
77720 +
77721 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77722 + grsec_alert_wtime = curr_secs;
77723 + grsec_alert_fyet = 0;
77724 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77725 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77726 + grsec_alert_fyet++;
77727 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77728 + grsec_alert_wtime = curr_secs;
77729 + grsec_alert_fyet++;
77730 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77731 + return FLOODING;
77732 + }
77733 + else return FLOODING;
77734 +
77735 +set_fmt:
77736 +#endif
77737 + memset(buf, 0, PAGE_SIZE);
77738 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77739 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77740 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77741 + } else if (current->signal->curr_ip) {
77742 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77743 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77744 + } else if (gr_acl_is_enabled()) {
77745 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77746 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77747 + } else {
77748 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77749 + strcpy(buf, fmt);
77750 + }
77751 +
77752 + return NO_FLOODING;
77753 +}
77754 +
77755 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77756 + __attribute__ ((format (printf, 2, 0)));
77757 +
77758 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77759 +{
77760 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77761 + unsigned int len = strlen(buf);
77762 +
77763 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77764 +
77765 + return;
77766 +}
77767 +
77768 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77769 + __attribute__ ((format (printf, 2, 3)));
77770 +
77771 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77772 +{
77773 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77774 + unsigned int len = strlen(buf);
77775 + va_list ap;
77776 +
77777 + va_start(ap, msg);
77778 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77779 + va_end(ap);
77780 +
77781 + return;
77782 +}
77783 +
77784 +static void gr_log_end(int audit, int append_default)
77785 +{
77786 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77787 + if (append_default) {
77788 + struct task_struct *task = current;
77789 + struct task_struct *parent = task->real_parent;
77790 + const struct cred *cred = __task_cred(task);
77791 + const struct cred *pcred = __task_cred(parent);
77792 + unsigned int len = strlen(buf);
77793 +
77794 + 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));
77795 + }
77796 +
77797 + printk("%s\n", buf);
77798 +
77799 + return;
77800 +}
77801 +
77802 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77803 +{
77804 + int logtype;
77805 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77806 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77807 + void *voidptr = NULL;
77808 + int num1 = 0, num2 = 0;
77809 + unsigned long ulong1 = 0, ulong2 = 0;
77810 + struct dentry *dentry = NULL;
77811 + struct vfsmount *mnt = NULL;
77812 + struct file *file = NULL;
77813 + struct task_struct *task = NULL;
77814 + struct vm_area_struct *vma = NULL;
77815 + const struct cred *cred, *pcred;
77816 + va_list ap;
77817 +
77818 + BEGIN_LOCKS(audit);
77819 + logtype = gr_log_start(audit);
77820 + if (logtype == FLOODING) {
77821 + END_LOCKS(audit);
77822 + return;
77823 + }
77824 + va_start(ap, argtypes);
77825 + switch (argtypes) {
77826 + case GR_TTYSNIFF:
77827 + task = va_arg(ap, struct task_struct *);
77828 + 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));
77829 + break;
77830 + case GR_SYSCTL_HIDDEN:
77831 + str1 = va_arg(ap, char *);
77832 + gr_log_middle_varargs(audit, msg, result, str1);
77833 + break;
77834 + case GR_RBAC:
77835 + dentry = va_arg(ap, struct dentry *);
77836 + mnt = va_arg(ap, struct vfsmount *);
77837 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77838 + break;
77839 + case GR_RBAC_STR:
77840 + dentry = va_arg(ap, struct dentry *);
77841 + mnt = va_arg(ap, struct vfsmount *);
77842 + str1 = va_arg(ap, char *);
77843 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77844 + break;
77845 + case GR_STR_RBAC:
77846 + str1 = va_arg(ap, char *);
77847 + dentry = va_arg(ap, struct dentry *);
77848 + mnt = va_arg(ap, struct vfsmount *);
77849 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77850 + break;
77851 + case GR_RBAC_MODE2:
77852 + dentry = va_arg(ap, struct dentry *);
77853 + mnt = va_arg(ap, struct vfsmount *);
77854 + str1 = va_arg(ap, char *);
77855 + str2 = va_arg(ap, char *);
77856 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77857 + break;
77858 + case GR_RBAC_MODE3:
77859 + dentry = va_arg(ap, struct dentry *);
77860 + mnt = va_arg(ap, struct vfsmount *);
77861 + str1 = va_arg(ap, char *);
77862 + str2 = va_arg(ap, char *);
77863 + str3 = va_arg(ap, char *);
77864 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77865 + break;
77866 + case GR_FILENAME:
77867 + dentry = va_arg(ap, struct dentry *);
77868 + mnt = va_arg(ap, struct vfsmount *);
77869 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77870 + break;
77871 + case GR_STR_FILENAME:
77872 + str1 = va_arg(ap, char *);
77873 + dentry = va_arg(ap, struct dentry *);
77874 + mnt = va_arg(ap, struct vfsmount *);
77875 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77876 + break;
77877 + case GR_FILENAME_STR:
77878 + dentry = va_arg(ap, struct dentry *);
77879 + mnt = va_arg(ap, struct vfsmount *);
77880 + str1 = va_arg(ap, char *);
77881 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77882 + break;
77883 + case GR_FILENAME_TWO_INT:
77884 + dentry = va_arg(ap, struct dentry *);
77885 + mnt = va_arg(ap, struct vfsmount *);
77886 + num1 = va_arg(ap, int);
77887 + num2 = va_arg(ap, int);
77888 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77889 + break;
77890 + case GR_FILENAME_TWO_INT_STR:
77891 + dentry = va_arg(ap, struct dentry *);
77892 + mnt = va_arg(ap, struct vfsmount *);
77893 + num1 = va_arg(ap, int);
77894 + num2 = va_arg(ap, int);
77895 + str1 = va_arg(ap, char *);
77896 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77897 + break;
77898 + case GR_TEXTREL:
77899 + file = va_arg(ap, struct file *);
77900 + ulong1 = va_arg(ap, unsigned long);
77901 + ulong2 = va_arg(ap, unsigned long);
77902 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77903 + break;
77904 + case GR_PTRACE:
77905 + task = va_arg(ap, struct task_struct *);
77906 + 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));
77907 + break;
77908 + case GR_RESOURCE:
77909 + task = va_arg(ap, struct task_struct *);
77910 + cred = __task_cred(task);
77911 + pcred = __task_cred(task->real_parent);
77912 + ulong1 = va_arg(ap, unsigned long);
77913 + str1 = va_arg(ap, char *);
77914 + ulong2 = va_arg(ap, unsigned long);
77915 + 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));
77916 + break;
77917 + case GR_CAP:
77918 + task = va_arg(ap, struct task_struct *);
77919 + cred = __task_cred(task);
77920 + pcred = __task_cred(task->real_parent);
77921 + str1 = va_arg(ap, char *);
77922 + 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));
77923 + break;
77924 + case GR_SIG:
77925 + str1 = va_arg(ap, char *);
77926 + voidptr = va_arg(ap, void *);
77927 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77928 + break;
77929 + case GR_SIG2:
77930 + task = va_arg(ap, struct task_struct *);
77931 + cred = __task_cred(task);
77932 + pcred = __task_cred(task->real_parent);
77933 + num1 = va_arg(ap, int);
77934 + 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));
77935 + break;
77936 + case GR_CRASH1:
77937 + task = va_arg(ap, struct task_struct *);
77938 + cred = __task_cred(task);
77939 + pcred = __task_cred(task->real_parent);
77940 + ulong1 = va_arg(ap, unsigned long);
77941 + 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);
77942 + break;
77943 + case GR_CRASH2:
77944 + task = va_arg(ap, struct task_struct *);
77945 + cred = __task_cred(task);
77946 + pcred = __task_cred(task->real_parent);
77947 + ulong1 = va_arg(ap, unsigned long);
77948 + 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);
77949 + break;
77950 + case GR_RWXMAP:
77951 + file = va_arg(ap, struct file *);
77952 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77953 + break;
77954 + case GR_RWXMAPVMA:
77955 + vma = va_arg(ap, struct vm_area_struct *);
77956 + if (vma->vm_file)
77957 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77958 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77959 + str1 = "<stack>";
77960 + else if (vma->vm_start <= current->mm->brk &&
77961 + vma->vm_end >= current->mm->start_brk)
77962 + str1 = "<heap>";
77963 + else
77964 + str1 = "<anonymous mapping>";
77965 + gr_log_middle_varargs(audit, msg, str1);
77966 + break;
77967 + case GR_PSACCT:
77968 + {
77969 + unsigned int wday, cday;
77970 + __u8 whr, chr;
77971 + __u8 wmin, cmin;
77972 + __u8 wsec, csec;
77973 + char cur_tty[64] = { 0 };
77974 + char parent_tty[64] = { 0 };
77975 +
77976 + task = va_arg(ap, struct task_struct *);
77977 + wday = va_arg(ap, unsigned int);
77978 + cday = va_arg(ap, unsigned int);
77979 + whr = va_arg(ap, int);
77980 + chr = va_arg(ap, int);
77981 + wmin = va_arg(ap, int);
77982 + cmin = va_arg(ap, int);
77983 + wsec = va_arg(ap, int);
77984 + csec = va_arg(ap, int);
77985 + ulong1 = va_arg(ap, unsigned long);
77986 + cred = __task_cred(task);
77987 + pcred = __task_cred(task->real_parent);
77988 +
77989 + 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));
77990 + }
77991 + break;
77992 + default:
77993 + gr_log_middle(audit, msg, ap);
77994 + }
77995 + va_end(ap);
77996 + // these don't need DEFAULTSECARGS printed on the end
77997 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77998 + gr_log_end(audit, 0);
77999 + else
78000 + gr_log_end(audit, 1);
78001 + END_LOCKS(audit);
78002 +}
78003 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78004 new file mode 100644
78005 index 0000000..0e39d8c
78006 --- /dev/null
78007 +++ b/grsecurity/grsec_mem.c
78008 @@ -0,0 +1,48 @@
78009 +#include <linux/kernel.h>
78010 +#include <linux/sched.h>
78011 +#include <linux/mm.h>
78012 +#include <linux/mman.h>
78013 +#include <linux/module.h>
78014 +#include <linux/grinternal.h>
78015 +
78016 +void gr_handle_msr_write(void)
78017 +{
78018 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78019 + return;
78020 +}
78021 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78022 +
78023 +void
78024 +gr_handle_ioperm(void)
78025 +{
78026 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78027 + return;
78028 +}
78029 +
78030 +void
78031 +gr_handle_iopl(void)
78032 +{
78033 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78034 + return;
78035 +}
78036 +
78037 +void
78038 +gr_handle_mem_readwrite(u64 from, u64 to)
78039 +{
78040 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78041 + return;
78042 +}
78043 +
78044 +void
78045 +gr_handle_vm86(void)
78046 +{
78047 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78048 + return;
78049 +}
78050 +
78051 +void
78052 +gr_log_badprocpid(const char *entry)
78053 +{
78054 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78055 + return;
78056 +}
78057 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78058 new file mode 100644
78059 index 0000000..6f9eb73
78060 --- /dev/null
78061 +++ b/grsecurity/grsec_mount.c
78062 @@ -0,0 +1,65 @@
78063 +#include <linux/kernel.h>
78064 +#include <linux/sched.h>
78065 +#include <linux/mount.h>
78066 +#include <linux/major.h>
78067 +#include <linux/grsecurity.h>
78068 +#include <linux/grinternal.h>
78069 +
78070 +void
78071 +gr_log_remount(const char *devname, const int retval)
78072 +{
78073 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78074 + if (grsec_enable_mount && (retval >= 0))
78075 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78076 +#endif
78077 + return;
78078 +}
78079 +
78080 +void
78081 +gr_log_unmount(const char *devname, const int retval)
78082 +{
78083 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78084 + if (grsec_enable_mount && (retval >= 0))
78085 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78086 +#endif
78087 + return;
78088 +}
78089 +
78090 +void
78091 +gr_log_mount(const char *from, struct path *to, const int retval)
78092 +{
78093 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78094 + if (grsec_enable_mount && (retval >= 0))
78095 + gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
78096 +#endif
78097 + return;
78098 +}
78099 +
78100 +int
78101 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78102 +{
78103 +#ifdef CONFIG_GRKERNSEC_ROFS
78104 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78105 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78106 + return -EPERM;
78107 + } else
78108 + return 0;
78109 +#endif
78110 + return 0;
78111 +}
78112 +
78113 +int
78114 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78115 +{
78116 +#ifdef CONFIG_GRKERNSEC_ROFS
78117 + struct inode *inode = dentry->d_inode;
78118 +
78119 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78120 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78121 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78122 + return -EPERM;
78123 + } else
78124 + return 0;
78125 +#endif
78126 + return 0;
78127 +}
78128 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78129 new file mode 100644
78130 index 0000000..6ee9d50
78131 --- /dev/null
78132 +++ b/grsecurity/grsec_pax.c
78133 @@ -0,0 +1,45 @@
78134 +#include <linux/kernel.h>
78135 +#include <linux/sched.h>
78136 +#include <linux/mm.h>
78137 +#include <linux/file.h>
78138 +#include <linux/grinternal.h>
78139 +#include <linux/grsecurity.h>
78140 +
78141 +void
78142 +gr_log_textrel(struct vm_area_struct * vma)
78143 +{
78144 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78145 + if (grsec_enable_log_rwxmaps)
78146 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78147 +#endif
78148 + return;
78149 +}
78150 +
78151 +void gr_log_ptgnustack(struct file *file)
78152 +{
78153 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78154 + if (grsec_enable_log_rwxmaps)
78155 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78156 +#endif
78157 + return;
78158 +}
78159 +
78160 +void
78161 +gr_log_rwxmmap(struct file *file)
78162 +{
78163 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78164 + if (grsec_enable_log_rwxmaps)
78165 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78166 +#endif
78167 + return;
78168 +}
78169 +
78170 +void
78171 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78172 +{
78173 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78174 + if (grsec_enable_log_rwxmaps)
78175 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78176 +#endif
78177 + return;
78178 +}
78179 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78180 new file mode 100644
78181 index 0000000..2005a3a
78182 --- /dev/null
78183 +++ b/grsecurity/grsec_proc.c
78184 @@ -0,0 +1,20 @@
78185 +#include <linux/kernel.h>
78186 +#include <linux/sched.h>
78187 +#include <linux/grsecurity.h>
78188 +#include <linux/grinternal.h>
78189 +
78190 +int gr_proc_is_restricted(void)
78191 +{
78192 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78193 + const struct cred *cred = current_cred();
78194 +#endif
78195 +
78196 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78197 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78198 + return -EACCES;
78199 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78200 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78201 + return -EACCES;
78202 +#endif
78203 + return 0;
78204 +}
78205 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78206 new file mode 100644
78207 index 0000000..f7f29aa
78208 --- /dev/null
78209 +++ b/grsecurity/grsec_ptrace.c
78210 @@ -0,0 +1,30 @@
78211 +#include <linux/kernel.h>
78212 +#include <linux/sched.h>
78213 +#include <linux/grinternal.h>
78214 +#include <linux/security.h>
78215 +
78216 +void
78217 +gr_audit_ptrace(struct task_struct *task)
78218 +{
78219 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78220 + if (grsec_enable_audit_ptrace)
78221 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78222 +#endif
78223 + return;
78224 +}
78225 +
78226 +int
78227 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78228 +{
78229 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78230 + const struct dentry *dentry = file->f_path.dentry;
78231 + const struct vfsmount *mnt = file->f_path.mnt;
78232 +
78233 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78234 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78235 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78236 + return -EACCES;
78237 + }
78238 +#endif
78239 + return 0;
78240 +}
78241 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78242 new file mode 100644
78243 index 0000000..3860c7e
78244 --- /dev/null
78245 +++ b/grsecurity/grsec_sig.c
78246 @@ -0,0 +1,236 @@
78247 +#include <linux/kernel.h>
78248 +#include <linux/sched.h>
78249 +#include <linux/fs.h>
78250 +#include <linux/delay.h>
78251 +#include <linux/grsecurity.h>
78252 +#include <linux/grinternal.h>
78253 +#include <linux/hardirq.h>
78254 +
78255 +char *signames[] = {
78256 + [SIGSEGV] = "Segmentation fault",
78257 + [SIGILL] = "Illegal instruction",
78258 + [SIGABRT] = "Abort",
78259 + [SIGBUS] = "Invalid alignment/Bus error"
78260 +};
78261 +
78262 +void
78263 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78264 +{
78265 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78266 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78267 + (sig == SIGABRT) || (sig == SIGBUS))) {
78268 + if (task_pid_nr(t) == task_pid_nr(current)) {
78269 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78270 + } else {
78271 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78272 + }
78273 + }
78274 +#endif
78275 + return;
78276 +}
78277 +
78278 +int
78279 +gr_handle_signal(const struct task_struct *p, const int sig)
78280 +{
78281 +#ifdef CONFIG_GRKERNSEC
78282 + /* ignore the 0 signal for protected task checks */
78283 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78284 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78285 + return -EPERM;
78286 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78287 + return -EPERM;
78288 + }
78289 +#endif
78290 + return 0;
78291 +}
78292 +
78293 +#ifdef CONFIG_GRKERNSEC
78294 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78295 +
78296 +int gr_fake_force_sig(int sig, struct task_struct *t)
78297 +{
78298 + unsigned long int flags;
78299 + int ret, blocked, ignored;
78300 + struct k_sigaction *action;
78301 +
78302 + spin_lock_irqsave(&t->sighand->siglock, flags);
78303 + action = &t->sighand->action[sig-1];
78304 + ignored = action->sa.sa_handler == SIG_IGN;
78305 + blocked = sigismember(&t->blocked, sig);
78306 + if (blocked || ignored) {
78307 + action->sa.sa_handler = SIG_DFL;
78308 + if (blocked) {
78309 + sigdelset(&t->blocked, sig);
78310 + recalc_sigpending_and_wake(t);
78311 + }
78312 + }
78313 + if (action->sa.sa_handler == SIG_DFL)
78314 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78315 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78316 +
78317 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78318 +
78319 + return ret;
78320 +}
78321 +#endif
78322 +
78323 +#define GR_USER_BAN_TIME (15 * 60)
78324 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78325 +
78326 +void gr_handle_brute_attach(int dumpable)
78327 +{
78328 +#ifdef CONFIG_GRKERNSEC_BRUTE
78329 + struct task_struct *p = current;
78330 + kuid_t uid = GLOBAL_ROOT_UID;
78331 + int daemon = 0;
78332 +
78333 + if (!grsec_enable_brute)
78334 + return;
78335 +
78336 + rcu_read_lock();
78337 + read_lock(&tasklist_lock);
78338 + read_lock(&grsec_exec_file_lock);
78339 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78340 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78341 + p->real_parent->brute = 1;
78342 + daemon = 1;
78343 + } else {
78344 + const struct cred *cred = __task_cred(p), *cred2;
78345 + struct task_struct *tsk, *tsk2;
78346 +
78347 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78348 + struct user_struct *user;
78349 +
78350 + uid = cred->uid;
78351 +
78352 + /* this is put upon execution past expiration */
78353 + user = find_user(uid);
78354 + if (user == NULL)
78355 + goto unlock;
78356 + user->suid_banned = 1;
78357 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78358 + if (user->suid_ban_expires == ~0UL)
78359 + user->suid_ban_expires--;
78360 +
78361 + /* only kill other threads of the same binary, from the same user */
78362 + do_each_thread(tsk2, tsk) {
78363 + cred2 = __task_cred(tsk);
78364 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78365 + gr_fake_force_sig(SIGKILL, tsk);
78366 + } while_each_thread(tsk2, tsk);
78367 + }
78368 + }
78369 +unlock:
78370 + read_unlock(&grsec_exec_file_lock);
78371 + read_unlock(&tasklist_lock);
78372 + rcu_read_unlock();
78373 +
78374 + if (gr_is_global_nonroot(uid))
78375 + 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);
78376 + else if (daemon)
78377 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78378 +
78379 +#endif
78380 + return;
78381 +}
78382 +
78383 +void gr_handle_brute_check(void)
78384 +{
78385 +#ifdef CONFIG_GRKERNSEC_BRUTE
78386 + struct task_struct *p = current;
78387 +
78388 + if (unlikely(p->brute)) {
78389 + if (!grsec_enable_brute)
78390 + p->brute = 0;
78391 + else if (time_before(get_seconds(), p->brute_expires))
78392 + msleep(30 * 1000);
78393 + }
78394 +#endif
78395 + return;
78396 +}
78397 +
78398 +void gr_handle_kernel_exploit(void)
78399 +{
78400 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78401 + const struct cred *cred;
78402 + struct task_struct *tsk, *tsk2;
78403 + struct user_struct *user;
78404 + kuid_t uid;
78405 +
78406 + if (in_irq() || in_serving_softirq() || in_nmi())
78407 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78408 +
78409 + uid = current_uid();
78410 +
78411 + if (gr_is_global_root(uid))
78412 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78413 + else {
78414 + /* kill all the processes of this user, hold a reference
78415 + to their creds struct, and prevent them from creating
78416 + another process until system reset
78417 + */
78418 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78419 + GR_GLOBAL_UID(uid));
78420 + /* we intentionally leak this ref */
78421 + user = get_uid(current->cred->user);
78422 + if (user)
78423 + user->kernel_banned = 1;
78424 +
78425 + /* kill all processes of this user */
78426 + read_lock(&tasklist_lock);
78427 + do_each_thread(tsk2, tsk) {
78428 + cred = __task_cred(tsk);
78429 + if (uid_eq(cred->uid, uid))
78430 + gr_fake_force_sig(SIGKILL, tsk);
78431 + } while_each_thread(tsk2, tsk);
78432 + read_unlock(&tasklist_lock);
78433 + }
78434 +#endif
78435 +}
78436 +
78437 +#ifdef CONFIG_GRKERNSEC_BRUTE
78438 +static bool suid_ban_expired(struct user_struct *user)
78439 +{
78440 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78441 + user->suid_banned = 0;
78442 + user->suid_ban_expires = 0;
78443 + free_uid(user);
78444 + return true;
78445 + }
78446 +
78447 + return false;
78448 +}
78449 +#endif
78450 +
78451 +int gr_process_kernel_exec_ban(void)
78452 +{
78453 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78454 + if (unlikely(current->cred->user->kernel_banned))
78455 + return -EPERM;
78456 +#endif
78457 + return 0;
78458 +}
78459 +
78460 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78461 +{
78462 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78463 + if (unlikely(user->kernel_banned))
78464 + gr_fake_force_sig(SIGKILL, current);
78465 +#endif
78466 + return 0;
78467 +}
78468 +
78469 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78470 +{
78471 +#ifdef CONFIG_GRKERNSEC_BRUTE
78472 + struct user_struct *user = current->cred->user;
78473 + if (unlikely(user->suid_banned)) {
78474 + if (suid_ban_expired(user))
78475 + return 0;
78476 + /* disallow execution of suid binaries only */
78477 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78478 + return -EPERM;
78479 + }
78480 +#endif
78481 + return 0;
78482 +}
78483 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78484 new file mode 100644
78485 index 0000000..e3650b6
78486 --- /dev/null
78487 +++ b/grsecurity/grsec_sock.c
78488 @@ -0,0 +1,244 @@
78489 +#include <linux/kernel.h>
78490 +#include <linux/module.h>
78491 +#include <linux/sched.h>
78492 +#include <linux/file.h>
78493 +#include <linux/net.h>
78494 +#include <linux/in.h>
78495 +#include <linux/ip.h>
78496 +#include <net/sock.h>
78497 +#include <net/inet_sock.h>
78498 +#include <linux/grsecurity.h>
78499 +#include <linux/grinternal.h>
78500 +#include <linux/gracl.h>
78501 +
78502 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78503 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78504 +
78505 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78506 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78507 +
78508 +#ifdef CONFIG_UNIX_MODULE
78509 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78510 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78511 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78512 +EXPORT_SYMBOL_GPL(gr_handle_create);
78513 +#endif
78514 +
78515 +#ifdef CONFIG_GRKERNSEC
78516 +#define gr_conn_table_size 32749
78517 +struct conn_table_entry {
78518 + struct conn_table_entry *next;
78519 + struct signal_struct *sig;
78520 +};
78521 +
78522 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78523 +DEFINE_SPINLOCK(gr_conn_table_lock);
78524 +
78525 +extern const char * gr_socktype_to_name(unsigned char type);
78526 +extern const char * gr_proto_to_name(unsigned char proto);
78527 +extern const char * gr_sockfamily_to_name(unsigned char family);
78528 +
78529 +static __inline__ int
78530 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78531 +{
78532 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78533 +}
78534 +
78535 +static __inline__ int
78536 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78537 + __u16 sport, __u16 dport)
78538 +{
78539 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78540 + sig->gr_sport == sport && sig->gr_dport == dport))
78541 + return 1;
78542 + else
78543 + return 0;
78544 +}
78545 +
78546 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78547 +{
78548 + struct conn_table_entry **match;
78549 + unsigned int index;
78550 +
78551 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78552 + sig->gr_sport, sig->gr_dport,
78553 + gr_conn_table_size);
78554 +
78555 + newent->sig = sig;
78556 +
78557 + match = &gr_conn_table[index];
78558 + newent->next = *match;
78559 + *match = newent;
78560 +
78561 + return;
78562 +}
78563 +
78564 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78565 +{
78566 + struct conn_table_entry *match, *last = NULL;
78567 + unsigned int index;
78568 +
78569 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78570 + sig->gr_sport, sig->gr_dport,
78571 + gr_conn_table_size);
78572 +
78573 + match = gr_conn_table[index];
78574 + while (match && !conn_match(match->sig,
78575 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78576 + sig->gr_dport)) {
78577 + last = match;
78578 + match = match->next;
78579 + }
78580 +
78581 + if (match) {
78582 + if (last)
78583 + last->next = match->next;
78584 + else
78585 + gr_conn_table[index] = NULL;
78586 + kfree(match);
78587 + }
78588 +
78589 + return;
78590 +}
78591 +
78592 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78593 + __u16 sport, __u16 dport)
78594 +{
78595 + struct conn_table_entry *match;
78596 + unsigned int index;
78597 +
78598 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78599 +
78600 + match = gr_conn_table[index];
78601 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78602 + match = match->next;
78603 +
78604 + if (match)
78605 + return match->sig;
78606 + else
78607 + return NULL;
78608 +}
78609 +
78610 +#endif
78611 +
78612 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78613 +{
78614 +#ifdef CONFIG_GRKERNSEC
78615 + struct signal_struct *sig = current->signal;
78616 + struct conn_table_entry *newent;
78617 +
78618 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78619 + if (newent == NULL)
78620 + return;
78621 + /* no bh lock needed since we are called with bh disabled */
78622 + spin_lock(&gr_conn_table_lock);
78623 + gr_del_task_from_ip_table_nolock(sig);
78624 + sig->gr_saddr = inet->inet_rcv_saddr;
78625 + sig->gr_daddr = inet->inet_daddr;
78626 + sig->gr_sport = inet->inet_sport;
78627 + sig->gr_dport = inet->inet_dport;
78628 + gr_add_to_task_ip_table_nolock(sig, newent);
78629 + spin_unlock(&gr_conn_table_lock);
78630 +#endif
78631 + return;
78632 +}
78633 +
78634 +void gr_del_task_from_ip_table(struct task_struct *task)
78635 +{
78636 +#ifdef CONFIG_GRKERNSEC
78637 + spin_lock_bh(&gr_conn_table_lock);
78638 + gr_del_task_from_ip_table_nolock(task->signal);
78639 + spin_unlock_bh(&gr_conn_table_lock);
78640 +#endif
78641 + return;
78642 +}
78643 +
78644 +void
78645 +gr_attach_curr_ip(const struct sock *sk)
78646 +{
78647 +#ifdef CONFIG_GRKERNSEC
78648 + struct signal_struct *p, *set;
78649 + const struct inet_sock *inet = inet_sk(sk);
78650 +
78651 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78652 + return;
78653 +
78654 + set = current->signal;
78655 +
78656 + spin_lock_bh(&gr_conn_table_lock);
78657 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78658 + inet->inet_dport, inet->inet_sport);
78659 + if (unlikely(p != NULL)) {
78660 + set->curr_ip = p->curr_ip;
78661 + set->used_accept = 1;
78662 + gr_del_task_from_ip_table_nolock(p);
78663 + spin_unlock_bh(&gr_conn_table_lock);
78664 + return;
78665 + }
78666 + spin_unlock_bh(&gr_conn_table_lock);
78667 +
78668 + set->curr_ip = inet->inet_daddr;
78669 + set->used_accept = 1;
78670 +#endif
78671 + return;
78672 +}
78673 +
78674 +int
78675 +gr_handle_sock_all(const int family, const int type, const int protocol)
78676 +{
78677 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78678 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78679 + (family != AF_UNIX)) {
78680 + if (family == AF_INET)
78681 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78682 + else
78683 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78684 + return -EACCES;
78685 + }
78686 +#endif
78687 + return 0;
78688 +}
78689 +
78690 +int
78691 +gr_handle_sock_server(const struct sockaddr *sck)
78692 +{
78693 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78694 + if (grsec_enable_socket_server &&
78695 + in_group_p(grsec_socket_server_gid) &&
78696 + sck && (sck->sa_family != AF_UNIX) &&
78697 + (sck->sa_family != AF_LOCAL)) {
78698 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78699 + return -EACCES;
78700 + }
78701 +#endif
78702 + return 0;
78703 +}
78704 +
78705 +int
78706 +gr_handle_sock_server_other(const struct sock *sck)
78707 +{
78708 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78709 + if (grsec_enable_socket_server &&
78710 + in_group_p(grsec_socket_server_gid) &&
78711 + sck && (sck->sk_family != AF_UNIX) &&
78712 + (sck->sk_family != AF_LOCAL)) {
78713 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78714 + return -EACCES;
78715 + }
78716 +#endif
78717 + return 0;
78718 +}
78719 +
78720 +int
78721 +gr_handle_sock_client(const struct sockaddr *sck)
78722 +{
78723 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78724 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78725 + sck && (sck->sa_family != AF_UNIX) &&
78726 + (sck->sa_family != AF_LOCAL)) {
78727 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78728 + return -EACCES;
78729 + }
78730 +#endif
78731 + return 0;
78732 +}
78733 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78734 new file mode 100644
78735 index 0000000..cce889e
78736 --- /dev/null
78737 +++ b/grsecurity/grsec_sysctl.c
78738 @@ -0,0 +1,488 @@
78739 +#include <linux/kernel.h>
78740 +#include <linux/sched.h>
78741 +#include <linux/sysctl.h>
78742 +#include <linux/grsecurity.h>
78743 +#include <linux/grinternal.h>
78744 +
78745 +int
78746 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78747 +{
78748 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78749 + if (dirname == NULL || name == NULL)
78750 + return 0;
78751 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78752 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78753 + return -EACCES;
78754 + }
78755 +#endif
78756 + return 0;
78757 +}
78758 +
78759 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78760 +static int __maybe_unused __read_only one = 1;
78761 +#endif
78762 +
78763 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78764 + defined(CONFIG_GRKERNSEC_DENYUSB)
78765 +struct ctl_table grsecurity_table[] = {
78766 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78767 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78768 +#ifdef CONFIG_GRKERNSEC_IO
78769 + {
78770 + .procname = "disable_priv_io",
78771 + .data = &grsec_disable_privio,
78772 + .maxlen = sizeof(int),
78773 + .mode = 0600,
78774 + .proc_handler = &proc_dointvec,
78775 + },
78776 +#endif
78777 +#endif
78778 +#ifdef CONFIG_GRKERNSEC_LINK
78779 + {
78780 + .procname = "linking_restrictions",
78781 + .data = &grsec_enable_link,
78782 + .maxlen = sizeof(int),
78783 + .mode = 0600,
78784 + .proc_handler = &proc_dointvec,
78785 + },
78786 +#endif
78787 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78788 + {
78789 + .procname = "enforce_symlinksifowner",
78790 + .data = &grsec_enable_symlinkown,
78791 + .maxlen = sizeof(int),
78792 + .mode = 0600,
78793 + .proc_handler = &proc_dointvec,
78794 + },
78795 + {
78796 + .procname = "symlinkown_gid",
78797 + .data = &grsec_symlinkown_gid,
78798 + .maxlen = sizeof(int),
78799 + .mode = 0600,
78800 + .proc_handler = &proc_dointvec,
78801 + },
78802 +#endif
78803 +#ifdef CONFIG_GRKERNSEC_BRUTE
78804 + {
78805 + .procname = "deter_bruteforce",
78806 + .data = &grsec_enable_brute,
78807 + .maxlen = sizeof(int),
78808 + .mode = 0600,
78809 + .proc_handler = &proc_dointvec,
78810 + },
78811 +#endif
78812 +#ifdef CONFIG_GRKERNSEC_FIFO
78813 + {
78814 + .procname = "fifo_restrictions",
78815 + .data = &grsec_enable_fifo,
78816 + .maxlen = sizeof(int),
78817 + .mode = 0600,
78818 + .proc_handler = &proc_dointvec,
78819 + },
78820 +#endif
78821 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78822 + {
78823 + .procname = "ptrace_readexec",
78824 + .data = &grsec_enable_ptrace_readexec,
78825 + .maxlen = sizeof(int),
78826 + .mode = 0600,
78827 + .proc_handler = &proc_dointvec,
78828 + },
78829 +#endif
78830 +#ifdef CONFIG_GRKERNSEC_SETXID
78831 + {
78832 + .procname = "consistent_setxid",
78833 + .data = &grsec_enable_setxid,
78834 + .maxlen = sizeof(int),
78835 + .mode = 0600,
78836 + .proc_handler = &proc_dointvec,
78837 + },
78838 +#endif
78839 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78840 + {
78841 + .procname = "ip_blackhole",
78842 + .data = &grsec_enable_blackhole,
78843 + .maxlen = sizeof(int),
78844 + .mode = 0600,
78845 + .proc_handler = &proc_dointvec,
78846 + },
78847 + {
78848 + .procname = "lastack_retries",
78849 + .data = &grsec_lastack_retries,
78850 + .maxlen = sizeof(int),
78851 + .mode = 0600,
78852 + .proc_handler = &proc_dointvec,
78853 + },
78854 +#endif
78855 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78856 + {
78857 + .procname = "exec_logging",
78858 + .data = &grsec_enable_execlog,
78859 + .maxlen = sizeof(int),
78860 + .mode = 0600,
78861 + .proc_handler = &proc_dointvec,
78862 + },
78863 +#endif
78864 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78865 + {
78866 + .procname = "rwxmap_logging",
78867 + .data = &grsec_enable_log_rwxmaps,
78868 + .maxlen = sizeof(int),
78869 + .mode = 0600,
78870 + .proc_handler = &proc_dointvec,
78871 + },
78872 +#endif
78873 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78874 + {
78875 + .procname = "signal_logging",
78876 + .data = &grsec_enable_signal,
78877 + .maxlen = sizeof(int),
78878 + .mode = 0600,
78879 + .proc_handler = &proc_dointvec,
78880 + },
78881 +#endif
78882 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78883 + {
78884 + .procname = "forkfail_logging",
78885 + .data = &grsec_enable_forkfail,
78886 + .maxlen = sizeof(int),
78887 + .mode = 0600,
78888 + .proc_handler = &proc_dointvec,
78889 + },
78890 +#endif
78891 +#ifdef CONFIG_GRKERNSEC_TIME
78892 + {
78893 + .procname = "timechange_logging",
78894 + .data = &grsec_enable_time,
78895 + .maxlen = sizeof(int),
78896 + .mode = 0600,
78897 + .proc_handler = &proc_dointvec,
78898 + },
78899 +#endif
78900 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78901 + {
78902 + .procname = "chroot_deny_shmat",
78903 + .data = &grsec_enable_chroot_shmat,
78904 + .maxlen = sizeof(int),
78905 + .mode = 0600,
78906 + .proc_handler = &proc_dointvec,
78907 + },
78908 +#endif
78909 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78910 + {
78911 + .procname = "chroot_deny_unix",
78912 + .data = &grsec_enable_chroot_unix,
78913 + .maxlen = sizeof(int),
78914 + .mode = 0600,
78915 + .proc_handler = &proc_dointvec,
78916 + },
78917 +#endif
78918 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78919 + {
78920 + .procname = "chroot_deny_mount",
78921 + .data = &grsec_enable_chroot_mount,
78922 + .maxlen = sizeof(int),
78923 + .mode = 0600,
78924 + .proc_handler = &proc_dointvec,
78925 + },
78926 +#endif
78927 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78928 + {
78929 + .procname = "chroot_deny_fchdir",
78930 + .data = &grsec_enable_chroot_fchdir,
78931 + .maxlen = sizeof(int),
78932 + .mode = 0600,
78933 + .proc_handler = &proc_dointvec,
78934 + },
78935 +#endif
78936 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78937 + {
78938 + .procname = "chroot_deny_chroot",
78939 + .data = &grsec_enable_chroot_double,
78940 + .maxlen = sizeof(int),
78941 + .mode = 0600,
78942 + .proc_handler = &proc_dointvec,
78943 + },
78944 +#endif
78945 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78946 + {
78947 + .procname = "chroot_deny_pivot",
78948 + .data = &grsec_enable_chroot_pivot,
78949 + .maxlen = sizeof(int),
78950 + .mode = 0600,
78951 + .proc_handler = &proc_dointvec,
78952 + },
78953 +#endif
78954 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78955 + {
78956 + .procname = "chroot_enforce_chdir",
78957 + .data = &grsec_enable_chroot_chdir,
78958 + .maxlen = sizeof(int),
78959 + .mode = 0600,
78960 + .proc_handler = &proc_dointvec,
78961 + },
78962 +#endif
78963 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78964 + {
78965 + .procname = "chroot_deny_chmod",
78966 + .data = &grsec_enable_chroot_chmod,
78967 + .maxlen = sizeof(int),
78968 + .mode = 0600,
78969 + .proc_handler = &proc_dointvec,
78970 + },
78971 +#endif
78972 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78973 + {
78974 + .procname = "chroot_deny_mknod",
78975 + .data = &grsec_enable_chroot_mknod,
78976 + .maxlen = sizeof(int),
78977 + .mode = 0600,
78978 + .proc_handler = &proc_dointvec,
78979 + },
78980 +#endif
78981 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78982 + {
78983 + .procname = "chroot_restrict_nice",
78984 + .data = &grsec_enable_chroot_nice,
78985 + .maxlen = sizeof(int),
78986 + .mode = 0600,
78987 + .proc_handler = &proc_dointvec,
78988 + },
78989 +#endif
78990 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78991 + {
78992 + .procname = "chroot_execlog",
78993 + .data = &grsec_enable_chroot_execlog,
78994 + .maxlen = sizeof(int),
78995 + .mode = 0600,
78996 + .proc_handler = &proc_dointvec,
78997 + },
78998 +#endif
78999 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79000 + {
79001 + .procname = "chroot_caps",
79002 + .data = &grsec_enable_chroot_caps,
79003 + .maxlen = sizeof(int),
79004 + .mode = 0600,
79005 + .proc_handler = &proc_dointvec,
79006 + },
79007 +#endif
79008 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
79009 + {
79010 + .procname = "chroot_deny_bad_rename",
79011 + .data = &grsec_enable_chroot_rename,
79012 + .maxlen = sizeof(int),
79013 + .mode = 0600,
79014 + .proc_handler = &proc_dointvec,
79015 + },
79016 +#endif
79017 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79018 + {
79019 + .procname = "chroot_deny_sysctl",
79020 + .data = &grsec_enable_chroot_sysctl,
79021 + .maxlen = sizeof(int),
79022 + .mode = 0600,
79023 + .proc_handler = &proc_dointvec,
79024 + },
79025 +#endif
79026 +#ifdef CONFIG_GRKERNSEC_TPE
79027 + {
79028 + .procname = "tpe",
79029 + .data = &grsec_enable_tpe,
79030 + .maxlen = sizeof(int),
79031 + .mode = 0600,
79032 + .proc_handler = &proc_dointvec,
79033 + },
79034 + {
79035 + .procname = "tpe_gid",
79036 + .data = &grsec_tpe_gid,
79037 + .maxlen = sizeof(int),
79038 + .mode = 0600,
79039 + .proc_handler = &proc_dointvec,
79040 + },
79041 +#endif
79042 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79043 + {
79044 + .procname = "tpe_invert",
79045 + .data = &grsec_enable_tpe_invert,
79046 + .maxlen = sizeof(int),
79047 + .mode = 0600,
79048 + .proc_handler = &proc_dointvec,
79049 + },
79050 +#endif
79051 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79052 + {
79053 + .procname = "tpe_restrict_all",
79054 + .data = &grsec_enable_tpe_all,
79055 + .maxlen = sizeof(int),
79056 + .mode = 0600,
79057 + .proc_handler = &proc_dointvec,
79058 + },
79059 +#endif
79060 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79061 + {
79062 + .procname = "socket_all",
79063 + .data = &grsec_enable_socket_all,
79064 + .maxlen = sizeof(int),
79065 + .mode = 0600,
79066 + .proc_handler = &proc_dointvec,
79067 + },
79068 + {
79069 + .procname = "socket_all_gid",
79070 + .data = &grsec_socket_all_gid,
79071 + .maxlen = sizeof(int),
79072 + .mode = 0600,
79073 + .proc_handler = &proc_dointvec,
79074 + },
79075 +#endif
79076 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79077 + {
79078 + .procname = "socket_client",
79079 + .data = &grsec_enable_socket_client,
79080 + .maxlen = sizeof(int),
79081 + .mode = 0600,
79082 + .proc_handler = &proc_dointvec,
79083 + },
79084 + {
79085 + .procname = "socket_client_gid",
79086 + .data = &grsec_socket_client_gid,
79087 + .maxlen = sizeof(int),
79088 + .mode = 0600,
79089 + .proc_handler = &proc_dointvec,
79090 + },
79091 +#endif
79092 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79093 + {
79094 + .procname = "socket_server",
79095 + .data = &grsec_enable_socket_server,
79096 + .maxlen = sizeof(int),
79097 + .mode = 0600,
79098 + .proc_handler = &proc_dointvec,
79099 + },
79100 + {
79101 + .procname = "socket_server_gid",
79102 + .data = &grsec_socket_server_gid,
79103 + .maxlen = sizeof(int),
79104 + .mode = 0600,
79105 + .proc_handler = &proc_dointvec,
79106 + },
79107 +#endif
79108 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79109 + {
79110 + .procname = "audit_group",
79111 + .data = &grsec_enable_group,
79112 + .maxlen = sizeof(int),
79113 + .mode = 0600,
79114 + .proc_handler = &proc_dointvec,
79115 + },
79116 + {
79117 + .procname = "audit_gid",
79118 + .data = &grsec_audit_gid,
79119 + .maxlen = sizeof(int),
79120 + .mode = 0600,
79121 + .proc_handler = &proc_dointvec,
79122 + },
79123 +#endif
79124 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79125 + {
79126 + .procname = "audit_chdir",
79127 + .data = &grsec_enable_chdir,
79128 + .maxlen = sizeof(int),
79129 + .mode = 0600,
79130 + .proc_handler = &proc_dointvec,
79131 + },
79132 +#endif
79133 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79134 + {
79135 + .procname = "audit_mount",
79136 + .data = &grsec_enable_mount,
79137 + .maxlen = sizeof(int),
79138 + .mode = 0600,
79139 + .proc_handler = &proc_dointvec,
79140 + },
79141 +#endif
79142 +#ifdef CONFIG_GRKERNSEC_DMESG
79143 + {
79144 + .procname = "dmesg",
79145 + .data = &grsec_enable_dmesg,
79146 + .maxlen = sizeof(int),
79147 + .mode = 0600,
79148 + .proc_handler = &proc_dointvec,
79149 + },
79150 +#endif
79151 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79152 + {
79153 + .procname = "chroot_findtask",
79154 + .data = &grsec_enable_chroot_findtask,
79155 + .maxlen = sizeof(int),
79156 + .mode = 0600,
79157 + .proc_handler = &proc_dointvec,
79158 + },
79159 +#endif
79160 +#ifdef CONFIG_GRKERNSEC_RESLOG
79161 + {
79162 + .procname = "resource_logging",
79163 + .data = &grsec_resource_logging,
79164 + .maxlen = sizeof(int),
79165 + .mode = 0600,
79166 + .proc_handler = &proc_dointvec,
79167 + },
79168 +#endif
79169 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79170 + {
79171 + .procname = "audit_ptrace",
79172 + .data = &grsec_enable_audit_ptrace,
79173 + .maxlen = sizeof(int),
79174 + .mode = 0600,
79175 + .proc_handler = &proc_dointvec,
79176 + },
79177 +#endif
79178 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79179 + {
79180 + .procname = "harden_ptrace",
79181 + .data = &grsec_enable_harden_ptrace,
79182 + .maxlen = sizeof(int),
79183 + .mode = 0600,
79184 + .proc_handler = &proc_dointvec,
79185 + },
79186 +#endif
79187 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79188 + {
79189 + .procname = "harden_ipc",
79190 + .data = &grsec_enable_harden_ipc,
79191 + .maxlen = sizeof(int),
79192 + .mode = 0600,
79193 + .proc_handler = &proc_dointvec,
79194 + },
79195 +#endif
79196 + {
79197 + .procname = "grsec_lock",
79198 + .data = &grsec_lock,
79199 + .maxlen = sizeof(int),
79200 + .mode = 0600,
79201 + .proc_handler = &proc_dointvec,
79202 + },
79203 +#endif
79204 +#ifdef CONFIG_GRKERNSEC_ROFS
79205 + {
79206 + .procname = "romount_protect",
79207 + .data = &grsec_enable_rofs,
79208 + .maxlen = sizeof(int),
79209 + .mode = 0600,
79210 + .proc_handler = &proc_dointvec_minmax,
79211 + .extra1 = &one,
79212 + .extra2 = &one,
79213 + },
79214 +#endif
79215 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79216 + {
79217 + .procname = "deny_new_usb",
79218 + .data = &grsec_deny_new_usb,
79219 + .maxlen = sizeof(int),
79220 + .mode = 0600,
79221 + .proc_handler = &proc_dointvec,
79222 + },
79223 +#endif
79224 + { }
79225 +};
79226 +#endif
79227 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79228 new file mode 100644
79229 index 0000000..61b514e
79230 --- /dev/null
79231 +++ b/grsecurity/grsec_time.c
79232 @@ -0,0 +1,16 @@
79233 +#include <linux/kernel.h>
79234 +#include <linux/sched.h>
79235 +#include <linux/grinternal.h>
79236 +#include <linux/module.h>
79237 +
79238 +void
79239 +gr_log_timechange(void)
79240 +{
79241 +#ifdef CONFIG_GRKERNSEC_TIME
79242 + if (grsec_enable_time)
79243 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79244 +#endif
79245 + return;
79246 +}
79247 +
79248 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79249 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79250 new file mode 100644
79251 index 0000000..d1953de
79252 --- /dev/null
79253 +++ b/grsecurity/grsec_tpe.c
79254 @@ -0,0 +1,78 @@
79255 +#include <linux/kernel.h>
79256 +#include <linux/sched.h>
79257 +#include <linux/file.h>
79258 +#include <linux/fs.h>
79259 +#include <linux/grinternal.h>
79260 +
79261 +extern int gr_acl_tpe_check(void);
79262 +
79263 +int
79264 +gr_tpe_allow(const struct file *file)
79265 +{
79266 +#ifdef CONFIG_GRKERNSEC
79267 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79268 + struct inode *file_inode = file->f_path.dentry->d_inode;
79269 + const struct cred *cred = current_cred();
79270 + char *msg = NULL;
79271 + char *msg2 = NULL;
79272 +
79273 + // never restrict root
79274 + if (gr_is_global_root(cred->uid))
79275 + return 1;
79276 +
79277 + if (grsec_enable_tpe) {
79278 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79279 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79280 + msg = "not being in trusted group";
79281 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79282 + msg = "being in untrusted group";
79283 +#else
79284 + if (in_group_p(grsec_tpe_gid))
79285 + msg = "being in untrusted group";
79286 +#endif
79287 + }
79288 + if (!msg && gr_acl_tpe_check())
79289 + msg = "being in untrusted role";
79290 +
79291 + // not in any affected group/role
79292 + if (!msg)
79293 + goto next_check;
79294 +
79295 + if (gr_is_global_nonroot(inode->i_uid))
79296 + msg2 = "file in non-root-owned directory";
79297 + else if (inode->i_mode & S_IWOTH)
79298 + msg2 = "file in world-writable directory";
79299 + else if (inode->i_mode & S_IWGRP)
79300 + msg2 = "file in group-writable directory";
79301 + else if (file_inode->i_mode & S_IWOTH)
79302 + msg2 = "file is world-writable";
79303 +
79304 + if (msg && msg2) {
79305 + char fullmsg[70] = {0};
79306 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79307 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79308 + return 0;
79309 + }
79310 + msg = NULL;
79311 +next_check:
79312 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79313 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79314 + return 1;
79315 +
79316 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79317 + msg = "directory not owned by user";
79318 + else if (inode->i_mode & S_IWOTH)
79319 + msg = "file in world-writable directory";
79320 + else if (inode->i_mode & S_IWGRP)
79321 + msg = "file in group-writable directory";
79322 + else if (file_inode->i_mode & S_IWOTH)
79323 + msg = "file is world-writable";
79324 +
79325 + if (msg) {
79326 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79327 + return 0;
79328 + }
79329 +#endif
79330 +#endif
79331 + return 1;
79332 +}
79333 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79334 new file mode 100644
79335 index 0000000..ae02d8e
79336 --- /dev/null
79337 +++ b/grsecurity/grsec_usb.c
79338 @@ -0,0 +1,15 @@
79339 +#include <linux/kernel.h>
79340 +#include <linux/grinternal.h>
79341 +#include <linux/module.h>
79342 +
79343 +int gr_handle_new_usb(void)
79344 +{
79345 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79346 + if (grsec_deny_new_usb) {
79347 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79348 + return 1;
79349 + }
79350 +#endif
79351 + return 0;
79352 +}
79353 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79354 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79355 new file mode 100644
79356 index 0000000..158b330
79357 --- /dev/null
79358 +++ b/grsecurity/grsum.c
79359 @@ -0,0 +1,64 @@
79360 +#include <linux/err.h>
79361 +#include <linux/kernel.h>
79362 +#include <linux/sched.h>
79363 +#include <linux/mm.h>
79364 +#include <linux/scatterlist.h>
79365 +#include <linux/crypto.h>
79366 +#include <linux/gracl.h>
79367 +
79368 +
79369 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79370 +#error "crypto and sha256 must be built into the kernel"
79371 +#endif
79372 +
79373 +int
79374 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79375 +{
79376 + struct crypto_hash *tfm;
79377 + struct hash_desc desc;
79378 + struct scatterlist sg[2];
79379 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79380 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79381 + unsigned long *sumptr = (unsigned long *)sum;
79382 + int cryptres;
79383 + int retval = 1;
79384 + volatile int mismatched = 0;
79385 + volatile int dummy = 0;
79386 + unsigned int i;
79387 +
79388 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79389 + if (IS_ERR(tfm)) {
79390 + /* should never happen, since sha256 should be built in */
79391 + memset(entry->pw, 0, GR_PW_LEN);
79392 + return 1;
79393 + }
79394 +
79395 + sg_init_table(sg, 2);
79396 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79397 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79398 +
79399 + desc.tfm = tfm;
79400 + desc.flags = 0;
79401 +
79402 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79403 + temp_sum);
79404 +
79405 + memset(entry->pw, 0, GR_PW_LEN);
79406 +
79407 + if (cryptres)
79408 + goto out;
79409 +
79410 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79411 + if (sumptr[i] != tmpsumptr[i])
79412 + mismatched = 1;
79413 + else
79414 + dummy = 1; // waste a cycle
79415 +
79416 + if (!mismatched)
79417 + retval = dummy - 1;
79418 +
79419 +out:
79420 + crypto_free_hash(tfm);
79421 +
79422 + return retval;
79423 +}
79424 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79425 index 77ff547..181834f 100644
79426 --- a/include/asm-generic/4level-fixup.h
79427 +++ b/include/asm-generic/4level-fixup.h
79428 @@ -13,8 +13,10 @@
79429 #define pmd_alloc(mm, pud, address) \
79430 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79431 NULL: pmd_offset(pud, address))
79432 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79433
79434 #define pud_alloc(mm, pgd, address) (pgd)
79435 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79436 #define pud_offset(pgd, start) (pgd)
79437 #define pud_none(pud) 0
79438 #define pud_bad(pud) 0
79439 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79440 index b7babf0..1e4b4f1 100644
79441 --- a/include/asm-generic/atomic-long.h
79442 +++ b/include/asm-generic/atomic-long.h
79443 @@ -22,6 +22,12 @@
79444
79445 typedef atomic64_t atomic_long_t;
79446
79447 +#ifdef CONFIG_PAX_REFCOUNT
79448 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79449 +#else
79450 +typedef atomic64_t atomic_long_unchecked_t;
79451 +#endif
79452 +
79453 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79454
79455 static inline long atomic_long_read(atomic_long_t *l)
79456 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79457 return (long)atomic64_read(v);
79458 }
79459
79460 +#ifdef CONFIG_PAX_REFCOUNT
79461 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79462 +{
79463 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79464 +
79465 + return (long)atomic64_read_unchecked(v);
79466 +}
79467 +#endif
79468 +
79469 static inline void atomic_long_set(atomic_long_t *l, long i)
79470 {
79471 atomic64_t *v = (atomic64_t *)l;
79472 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79473 atomic64_set(v, i);
79474 }
79475
79476 +#ifdef CONFIG_PAX_REFCOUNT
79477 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79478 +{
79479 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79480 +
79481 + atomic64_set_unchecked(v, i);
79482 +}
79483 +#endif
79484 +
79485 static inline void atomic_long_inc(atomic_long_t *l)
79486 {
79487 atomic64_t *v = (atomic64_t *)l;
79488 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79489 atomic64_inc(v);
79490 }
79491
79492 +#ifdef CONFIG_PAX_REFCOUNT
79493 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79494 +{
79495 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79496 +
79497 + atomic64_inc_unchecked(v);
79498 +}
79499 +#endif
79500 +
79501 static inline void atomic_long_dec(atomic_long_t *l)
79502 {
79503 atomic64_t *v = (atomic64_t *)l;
79504 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79505 atomic64_dec(v);
79506 }
79507
79508 +#ifdef CONFIG_PAX_REFCOUNT
79509 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79510 +{
79511 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79512 +
79513 + atomic64_dec_unchecked(v);
79514 +}
79515 +#endif
79516 +
79517 static inline void atomic_long_add(long i, atomic_long_t *l)
79518 {
79519 atomic64_t *v = (atomic64_t *)l;
79520 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79521 atomic64_add(i, v);
79522 }
79523
79524 +#ifdef CONFIG_PAX_REFCOUNT
79525 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79526 +{
79527 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79528 +
79529 + atomic64_add_unchecked(i, v);
79530 +}
79531 +#endif
79532 +
79533 static inline void atomic_long_sub(long i, atomic_long_t *l)
79534 {
79535 atomic64_t *v = (atomic64_t *)l;
79536 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79537 atomic64_sub(i, v);
79538 }
79539
79540 +#ifdef CONFIG_PAX_REFCOUNT
79541 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79542 +{
79543 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79544 +
79545 + atomic64_sub_unchecked(i, v);
79546 +}
79547 +#endif
79548 +
79549 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79550 {
79551 atomic64_t *v = (atomic64_t *)l;
79552 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79553 return atomic64_add_negative(i, v);
79554 }
79555
79556 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79557 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79558 {
79559 atomic64_t *v = (atomic64_t *)l;
79560
79561 return (long)atomic64_add_return(i, v);
79562 }
79563
79564 +#ifdef CONFIG_PAX_REFCOUNT
79565 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79566 +{
79567 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79568 +
79569 + return (long)atomic64_add_return_unchecked(i, v);
79570 +}
79571 +#endif
79572 +
79573 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79574 {
79575 atomic64_t *v = (atomic64_t *)l;
79576 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79577 return (long)atomic64_inc_return(v);
79578 }
79579
79580 +#ifdef CONFIG_PAX_REFCOUNT
79581 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79582 +{
79583 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79584 +
79585 + return (long)atomic64_inc_return_unchecked(v);
79586 +}
79587 +#endif
79588 +
79589 static inline long atomic_long_dec_return(atomic_long_t *l)
79590 {
79591 atomic64_t *v = (atomic64_t *)l;
79592 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79593
79594 typedef atomic_t atomic_long_t;
79595
79596 +#ifdef CONFIG_PAX_REFCOUNT
79597 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79598 +#else
79599 +typedef atomic_t atomic_long_unchecked_t;
79600 +#endif
79601 +
79602 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79603 static inline long atomic_long_read(atomic_long_t *l)
79604 {
79605 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79606 return (long)atomic_read(v);
79607 }
79608
79609 +#ifdef CONFIG_PAX_REFCOUNT
79610 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79611 +{
79612 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79613 +
79614 + return (long)atomic_read_unchecked(v);
79615 +}
79616 +#endif
79617 +
79618 static inline void atomic_long_set(atomic_long_t *l, long i)
79619 {
79620 atomic_t *v = (atomic_t *)l;
79621 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79622 atomic_set(v, i);
79623 }
79624
79625 +#ifdef CONFIG_PAX_REFCOUNT
79626 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79627 +{
79628 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79629 +
79630 + atomic_set_unchecked(v, i);
79631 +}
79632 +#endif
79633 +
79634 static inline void atomic_long_inc(atomic_long_t *l)
79635 {
79636 atomic_t *v = (atomic_t *)l;
79637 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79638 atomic_inc(v);
79639 }
79640
79641 +#ifdef CONFIG_PAX_REFCOUNT
79642 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79643 +{
79644 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79645 +
79646 + atomic_inc_unchecked(v);
79647 +}
79648 +#endif
79649 +
79650 static inline void atomic_long_dec(atomic_long_t *l)
79651 {
79652 atomic_t *v = (atomic_t *)l;
79653 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79654 atomic_dec(v);
79655 }
79656
79657 +#ifdef CONFIG_PAX_REFCOUNT
79658 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79659 +{
79660 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79661 +
79662 + atomic_dec_unchecked(v);
79663 +}
79664 +#endif
79665 +
79666 static inline void atomic_long_add(long i, atomic_long_t *l)
79667 {
79668 atomic_t *v = (atomic_t *)l;
79669 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79670 atomic_add(i, v);
79671 }
79672
79673 +#ifdef CONFIG_PAX_REFCOUNT
79674 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79675 +{
79676 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79677 +
79678 + atomic_add_unchecked(i, v);
79679 +}
79680 +#endif
79681 +
79682 static inline void atomic_long_sub(long i, atomic_long_t *l)
79683 {
79684 atomic_t *v = (atomic_t *)l;
79685 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79686 atomic_sub(i, v);
79687 }
79688
79689 +#ifdef CONFIG_PAX_REFCOUNT
79690 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79691 +{
79692 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79693 +
79694 + atomic_sub_unchecked(i, v);
79695 +}
79696 +#endif
79697 +
79698 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79699 {
79700 atomic_t *v = (atomic_t *)l;
79701 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79702 return atomic_add_negative(i, v);
79703 }
79704
79705 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79706 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79707 {
79708 atomic_t *v = (atomic_t *)l;
79709
79710 return (long)atomic_add_return(i, v);
79711 }
79712
79713 +#ifdef CONFIG_PAX_REFCOUNT
79714 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79715 +{
79716 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79717 +
79718 + return (long)atomic_add_return_unchecked(i, v);
79719 +}
79720 +
79721 +#endif
79722 +
79723 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79724 {
79725 atomic_t *v = (atomic_t *)l;
79726 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79727 return (long)atomic_inc_return(v);
79728 }
79729
79730 +#ifdef CONFIG_PAX_REFCOUNT
79731 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79732 +{
79733 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79734 +
79735 + return (long)atomic_inc_return_unchecked(v);
79736 +}
79737 +#endif
79738 +
79739 static inline long atomic_long_dec_return(atomic_long_t *l)
79740 {
79741 atomic_t *v = (atomic_t *)l;
79742 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79743
79744 #endif /* BITS_PER_LONG == 64 */
79745
79746 +#ifdef CONFIG_PAX_REFCOUNT
79747 +static inline void pax_refcount_needs_these_functions(void)
79748 +{
79749 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79750 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79751 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79752 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79753 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79754 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79755 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79756 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79757 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79758 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79759 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79760 +#ifdef CONFIG_X86
79761 + atomic_clear_mask_unchecked(0, NULL);
79762 + atomic_set_mask_unchecked(0, NULL);
79763 +#endif
79764 +
79765 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79766 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79767 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79768 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79769 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79770 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79771 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79772 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79773 +}
79774 +#else
79775 +#define atomic_read_unchecked(v) atomic_read(v)
79776 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79777 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79778 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79779 +#define atomic_inc_unchecked(v) atomic_inc(v)
79780 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79781 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79782 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79783 +#define atomic_dec_unchecked(v) atomic_dec(v)
79784 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79785 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79786 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79787 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79788 +
79789 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79790 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79791 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79792 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79793 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79794 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79795 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79796 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79797 +#endif
79798 +
79799 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79800 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79801 index 30ad9c8..c70c170 100644
79802 --- a/include/asm-generic/atomic64.h
79803 +++ b/include/asm-generic/atomic64.h
79804 @@ -16,6 +16,8 @@ typedef struct {
79805 long long counter;
79806 } atomic64_t;
79807
79808 +typedef atomic64_t atomic64_unchecked_t;
79809 +
79810 #define ATOMIC64_INIT(i) { (i) }
79811
79812 extern long long atomic64_read(const atomic64_t *v);
79813 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79814 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79815 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79816
79817 +#define atomic64_read_unchecked(v) atomic64_read(v)
79818 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79819 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79820 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79821 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79822 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79823 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79824 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79825 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79826 +
79827 #endif /* _ASM_GENERIC_ATOMIC64_H */
79828 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79829 index 1402fa8..025a736 100644
79830 --- a/include/asm-generic/barrier.h
79831 +++ b/include/asm-generic/barrier.h
79832 @@ -74,7 +74,7 @@
79833 do { \
79834 compiletime_assert_atomic_type(*p); \
79835 smp_mb(); \
79836 - ACCESS_ONCE(*p) = (v); \
79837 + ACCESS_ONCE_RW(*p) = (v); \
79838 } while (0)
79839
79840 #define smp_load_acquire(p) \
79841 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79842 index a60a7cc..0fe12f2 100644
79843 --- a/include/asm-generic/bitops/__fls.h
79844 +++ b/include/asm-generic/bitops/__fls.h
79845 @@ -9,7 +9,7 @@
79846 *
79847 * Undefined if no set bit exists, so code should check against 0 first.
79848 */
79849 -static __always_inline unsigned long __fls(unsigned long word)
79850 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79851 {
79852 int num = BITS_PER_LONG - 1;
79853
79854 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79855 index 0576d1f..dad6c71 100644
79856 --- a/include/asm-generic/bitops/fls.h
79857 +++ b/include/asm-generic/bitops/fls.h
79858 @@ -9,7 +9,7 @@
79859 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79860 */
79861
79862 -static __always_inline int fls(int x)
79863 +static __always_inline int __intentional_overflow(-1) fls(int x)
79864 {
79865 int r = 32;
79866
79867 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79868 index b097cf8..3d40e14 100644
79869 --- a/include/asm-generic/bitops/fls64.h
79870 +++ b/include/asm-generic/bitops/fls64.h
79871 @@ -15,7 +15,7 @@
79872 * at position 64.
79873 */
79874 #if BITS_PER_LONG == 32
79875 -static __always_inline int fls64(__u64 x)
79876 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79877 {
79878 __u32 h = x >> 32;
79879 if (h)
79880 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79881 return fls(x);
79882 }
79883 #elif BITS_PER_LONG == 64
79884 -static __always_inline int fls64(__u64 x)
79885 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79886 {
79887 if (x == 0)
79888 return 0;
79889 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79890 index 1bfcfe5..e04c5c9 100644
79891 --- a/include/asm-generic/cache.h
79892 +++ b/include/asm-generic/cache.h
79893 @@ -6,7 +6,7 @@
79894 * cache lines need to provide their own cache.h.
79895 */
79896
79897 -#define L1_CACHE_SHIFT 5
79898 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79899 +#define L1_CACHE_SHIFT 5UL
79900 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79901
79902 #endif /* __ASM_GENERIC_CACHE_H */
79903 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79904 index 0d68a1e..b74a761 100644
79905 --- a/include/asm-generic/emergency-restart.h
79906 +++ b/include/asm-generic/emergency-restart.h
79907 @@ -1,7 +1,7 @@
79908 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79909 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79910
79911 -static inline void machine_emergency_restart(void)
79912 +static inline __noreturn void machine_emergency_restart(void)
79913 {
79914 machine_restart(NULL);
79915 }
79916 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79917 index b8fdc57..c6d5a5c 100644
79918 --- a/include/asm-generic/io.h
79919 +++ b/include/asm-generic/io.h
79920 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79921 * These are pretty trivial
79922 */
79923 #ifndef virt_to_phys
79924 -static inline unsigned long virt_to_phys(volatile void *address)
79925 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79926 {
79927 return __pa((unsigned long)address);
79928 }
79929 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79930 index 90f99c7..00ce236 100644
79931 --- a/include/asm-generic/kmap_types.h
79932 +++ b/include/asm-generic/kmap_types.h
79933 @@ -2,9 +2,9 @@
79934 #define _ASM_GENERIC_KMAP_TYPES_H
79935
79936 #ifdef __WITH_KM_FENCE
79937 -# define KM_TYPE_NR 41
79938 +# define KM_TYPE_NR 42
79939 #else
79940 -# define KM_TYPE_NR 20
79941 +# define KM_TYPE_NR 21
79942 #endif
79943
79944 #endif
79945 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79946 index 9ceb03b..62b0b8f 100644
79947 --- a/include/asm-generic/local.h
79948 +++ b/include/asm-generic/local.h
79949 @@ -23,24 +23,37 @@ typedef struct
79950 atomic_long_t a;
79951 } local_t;
79952
79953 +typedef struct {
79954 + atomic_long_unchecked_t a;
79955 +} local_unchecked_t;
79956 +
79957 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79958
79959 #define local_read(l) atomic_long_read(&(l)->a)
79960 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79961 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79962 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79963 #define local_inc(l) atomic_long_inc(&(l)->a)
79964 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79965 #define local_dec(l) atomic_long_dec(&(l)->a)
79966 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79967 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79968 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79969 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79970 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79971
79972 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79973 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79974 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79975 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79976 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79977 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79978 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79979 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79980 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79981
79982 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79983 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79984 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79985 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79986 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79987 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79988 index 725612b..9cc513a 100644
79989 --- a/include/asm-generic/pgtable-nopmd.h
79990 +++ b/include/asm-generic/pgtable-nopmd.h
79991 @@ -1,14 +1,19 @@
79992 #ifndef _PGTABLE_NOPMD_H
79993 #define _PGTABLE_NOPMD_H
79994
79995 -#ifndef __ASSEMBLY__
79996 -
79997 #include <asm-generic/pgtable-nopud.h>
79998
79999 -struct mm_struct;
80000 -
80001 #define __PAGETABLE_PMD_FOLDED
80002
80003 +#define PMD_SHIFT PUD_SHIFT
80004 +#define PTRS_PER_PMD 1
80005 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80006 +#define PMD_MASK (~(PMD_SIZE-1))
80007 +
80008 +#ifndef __ASSEMBLY__
80009 +
80010 +struct mm_struct;
80011 +
80012 /*
80013 * Having the pmd type consist of a pud gets the size right, and allows
80014 * us to conceptually access the pud entry that this pmd is folded into
80015 @@ -16,11 +21,6 @@ struct mm_struct;
80016 */
80017 typedef struct { pud_t pud; } pmd_t;
80018
80019 -#define PMD_SHIFT PUD_SHIFT
80020 -#define PTRS_PER_PMD 1
80021 -#define PMD_SIZE (1UL << PMD_SHIFT)
80022 -#define PMD_MASK (~(PMD_SIZE-1))
80023 -
80024 /*
80025 * The "pud_xxx()" functions here are trivial for a folded two-level
80026 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80027 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80028 index 810431d..0ec4804f 100644
80029 --- a/include/asm-generic/pgtable-nopud.h
80030 +++ b/include/asm-generic/pgtable-nopud.h
80031 @@ -1,10 +1,15 @@
80032 #ifndef _PGTABLE_NOPUD_H
80033 #define _PGTABLE_NOPUD_H
80034
80035 -#ifndef __ASSEMBLY__
80036 -
80037 #define __PAGETABLE_PUD_FOLDED
80038
80039 +#define PUD_SHIFT PGDIR_SHIFT
80040 +#define PTRS_PER_PUD 1
80041 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80042 +#define PUD_MASK (~(PUD_SIZE-1))
80043 +
80044 +#ifndef __ASSEMBLY__
80045 +
80046 /*
80047 * Having the pud type consist of a pgd gets the size right, and allows
80048 * us to conceptually access the pgd entry that this pud is folded into
80049 @@ -12,11 +17,6 @@
80050 */
80051 typedef struct { pgd_t pgd; } pud_t;
80052
80053 -#define PUD_SHIFT PGDIR_SHIFT
80054 -#define PTRS_PER_PUD 1
80055 -#define PUD_SIZE (1UL << PUD_SHIFT)
80056 -#define PUD_MASK (~(PUD_SIZE-1))
80057 -
80058 /*
80059 * The "pgd_xxx()" functions here are trivial for a folded two-level
80060 * setup: the pud is never bad, and a pud always exists (as it's folded
80061 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80062 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80063
80064 #define pgd_populate(mm, pgd, pud) do { } while (0)
80065 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80066 /*
80067 * (puds are folded into pgds so this doesn't get actually called,
80068 * but the define is needed for a generic inline function.)
80069 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80070 index 752e30d..87f172d 100644
80071 --- a/include/asm-generic/pgtable.h
80072 +++ b/include/asm-generic/pgtable.h
80073 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80074 }
80075 #endif /* CONFIG_NUMA_BALANCING */
80076
80077 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80078 +#ifdef CONFIG_PAX_KERNEXEC
80079 +#error KERNEXEC requires pax_open_kernel
80080 +#else
80081 +static inline unsigned long pax_open_kernel(void) { return 0; }
80082 +#endif
80083 +#endif
80084 +
80085 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80086 +#ifdef CONFIG_PAX_KERNEXEC
80087 +#error KERNEXEC requires pax_close_kernel
80088 +#else
80089 +static inline unsigned long pax_close_kernel(void) { return 0; }
80090 +#endif
80091 +#endif
80092 +
80093 #endif /* CONFIG_MMU */
80094
80095 #endif /* !__ASSEMBLY__ */
80096 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80097 index 72d8803..cb9749c 100644
80098 --- a/include/asm-generic/uaccess.h
80099 +++ b/include/asm-generic/uaccess.h
80100 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80101 return __clear_user(to, n);
80102 }
80103
80104 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80106 +#error UDEREF requires pax_open_userland
80107 +#else
80108 +static inline unsigned long pax_open_userland(void) { return 0; }
80109 +#endif
80110 +#endif
80111 +
80112 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80113 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80114 +#error UDEREF requires pax_close_userland
80115 +#else
80116 +static inline unsigned long pax_close_userland(void) { return 0; }
80117 +#endif
80118 +#endif
80119 +
80120 #endif /* __ASM_GENERIC_UACCESS_H */
80121 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80122 index aa70cbd..fd72c7a 100644
80123 --- a/include/asm-generic/vmlinux.lds.h
80124 +++ b/include/asm-generic/vmlinux.lds.h
80125 @@ -233,6 +233,7 @@
80126 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80127 VMLINUX_SYMBOL(__start_rodata) = .; \
80128 *(.rodata) *(.rodata.*) \
80129 + *(.data..read_only) \
80130 *(__vermagic) /* Kernel version magic */ \
80131 . = ALIGN(8); \
80132 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80133 @@ -724,17 +725,18 @@
80134 * section in the linker script will go there too. @phdr should have
80135 * a leading colon.
80136 *
80137 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80138 + * Note that this macros defines per_cpu_load as an absolute symbol.
80139 * If there is no need to put the percpu section at a predetermined
80140 * address, use PERCPU_SECTION.
80141 */
80142 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80143 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80144 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80145 + per_cpu_load = .; \
80146 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80147 - LOAD_OFFSET) { \
80148 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80149 PERCPU_INPUT(cacheline) \
80150 } phdr \
80151 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80152 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80153
80154 /**
80155 * PERCPU_SECTION - define output section for percpu area, simple version
80156 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80157 index 623a59c..1e79ab9 100644
80158 --- a/include/crypto/algapi.h
80159 +++ b/include/crypto/algapi.h
80160 @@ -34,7 +34,7 @@ struct crypto_type {
80161 unsigned int maskclear;
80162 unsigned int maskset;
80163 unsigned int tfmsize;
80164 -};
80165 +} __do_const;
80166
80167 struct crypto_instance {
80168 struct crypto_alg alg;
80169 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80170 index 53ed876..5bb09be 100644
80171 --- a/include/drm/drmP.h
80172 +++ b/include/drm/drmP.h
80173 @@ -59,6 +59,7 @@
80174
80175 #include <asm/mman.h>
80176 #include <asm/pgalloc.h>
80177 +#include <asm/local.h>
80178 #include <asm/uaccess.h>
80179
80180 #include <uapi/drm/drm.h>
80181 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80182 * \param cmd command.
80183 * \param arg argument.
80184 */
80185 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80186 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80187 + struct drm_file *file_priv);
80188 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80189 struct drm_file *file_priv);
80190
80191 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80192 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80193 unsigned long arg);
80194
80195 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80196 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80197 struct drm_ioctl_desc {
80198 unsigned int cmd;
80199 int flags;
80200 - drm_ioctl_t *func;
80201 + drm_ioctl_t func;
80202 unsigned int cmd_drv;
80203 const char *name;
80204 -};
80205 +} __do_const;
80206
80207 /**
80208 * Creates a driver or general drm_ioctl_desc array entry for the given
80209 @@ -629,7 +632,8 @@ struct drm_info_list {
80210 int (*show)(struct seq_file*, void*); /** show callback */
80211 u32 driver_features; /**< Required driver features for this entry */
80212 void *data;
80213 -};
80214 +} __do_const;
80215 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80216
80217 /**
80218 * debugfs node structure. This structure represents a debugfs file.
80219 @@ -713,7 +717,7 @@ struct drm_device {
80220
80221 /** \name Usage Counters */
80222 /*@{ */
80223 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80224 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80225 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80226 int buf_use; /**< Buffers in use -- cannot alloc */
80227 atomic_t buf_alloc; /**< Buffer allocation in progress */
80228 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80229 index a3d75fe..6802f9c 100644
80230 --- a/include/drm/drm_crtc_helper.h
80231 +++ b/include/drm/drm_crtc_helper.h
80232 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80233 struct drm_connector *connector);
80234 /* disable encoder when not in use - more explicit than dpms off */
80235 void (*disable)(struct drm_encoder *encoder);
80236 -};
80237 +} __no_const;
80238
80239 /**
80240 * drm_connector_helper_funcs - helper operations for connectors
80241 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80242 index a70d456..6ea07cd 100644
80243 --- a/include/drm/i915_pciids.h
80244 +++ b/include/drm/i915_pciids.h
80245 @@ -37,7 +37,7 @@
80246 */
80247 #define INTEL_VGA_DEVICE(id, info) { \
80248 0x8086, id, \
80249 - ~0, ~0, \
80250 + PCI_ANY_ID, PCI_ANY_ID, \
80251 0x030000, 0xff0000, \
80252 (unsigned long) info }
80253
80254 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80255 index 72dcbe8..8db58d7 100644
80256 --- a/include/drm/ttm/ttm_memory.h
80257 +++ b/include/drm/ttm/ttm_memory.h
80258 @@ -48,7 +48,7 @@
80259
80260 struct ttm_mem_shrink {
80261 int (*do_shrink) (struct ttm_mem_shrink *);
80262 -};
80263 +} __no_const;
80264
80265 /**
80266 * struct ttm_mem_global - Global memory accounting structure.
80267 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80268 index 49a8284..9643967 100644
80269 --- a/include/drm/ttm/ttm_page_alloc.h
80270 +++ b/include/drm/ttm/ttm_page_alloc.h
80271 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80272 */
80273 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80274
80275 +struct device;
80276 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80277 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80278
80279 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80280 index 4b840e8..155d235 100644
80281 --- a/include/keys/asymmetric-subtype.h
80282 +++ b/include/keys/asymmetric-subtype.h
80283 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80284 /* Verify the signature on a key of this subtype (optional) */
80285 int (*verify_signature)(const struct key *key,
80286 const struct public_key_signature *sig);
80287 -};
80288 +} __do_const;
80289
80290 /**
80291 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80292 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80293 index c1da539..1dcec55 100644
80294 --- a/include/linux/atmdev.h
80295 +++ b/include/linux/atmdev.h
80296 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80297 #endif
80298
80299 struct k_atm_aal_stats {
80300 -#define __HANDLE_ITEM(i) atomic_t i
80301 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80302 __AAL_STAT_ITEMS
80303 #undef __HANDLE_ITEM
80304 };
80305 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80306 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80307 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80308 struct module *owner;
80309 -};
80310 +} __do_const ;
80311
80312 struct atmphy_ops {
80313 int (*start)(struct atm_dev *dev);
80314 diff --git a/include/linux/audit.h b/include/linux/audit.h
80315 index 10f155b..6c73ffe 100644
80316 --- a/include/linux/audit.h
80317 +++ b/include/linux/audit.h
80318 @@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
80319 extern unsigned int audit_serial(void);
80320 extern int auditsc_get_stamp(struct audit_context *ctx,
80321 struct timespec *t, unsigned int *serial);
80322 -extern int audit_set_loginuid(kuid_t loginuid);
80323 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80324
80325 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80326 {
80327 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80328 index 61f29e5..e67c658 100644
80329 --- a/include/linux/binfmts.h
80330 +++ b/include/linux/binfmts.h
80331 @@ -44,7 +44,7 @@ struct linux_binprm {
80332 unsigned interp_flags;
80333 unsigned interp_data;
80334 unsigned long loader, exec;
80335 -};
80336 +} __randomize_layout;
80337
80338 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80339 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80340 @@ -73,8 +73,10 @@ struct linux_binfmt {
80341 int (*load_binary)(struct linux_binprm *);
80342 int (*load_shlib)(struct file *);
80343 int (*core_dump)(struct coredump_params *cprm);
80344 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80345 + void (*handle_mmap)(struct file *);
80346 unsigned long min_coredump; /* minimal dump size */
80347 -};
80348 +} __do_const __randomize_layout;
80349
80350 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80351
80352 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80353 index 5d858e0..336c1d9 100644
80354 --- a/include/linux/bitops.h
80355 +++ b/include/linux/bitops.h
80356 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80357 * @word: value to rotate
80358 * @shift: bits to roll
80359 */
80360 -static inline __u32 rol32(__u32 word, unsigned int shift)
80361 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80362 {
80363 return (word << shift) | (word >> (32 - shift));
80364 }
80365 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80366 * @word: value to rotate
80367 * @shift: bits to roll
80368 */
80369 -static inline __u32 ror32(__u32 word, unsigned int shift)
80370 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80371 {
80372 return (word >> shift) | (word << (32 - shift));
80373 }
80374 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80375 return (__s32)(value << shift) >> shift;
80376 }
80377
80378 -static inline unsigned fls_long(unsigned long l)
80379 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80380 {
80381 if (sizeof(l) == 4)
80382 return fls(l);
80383 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80384 index aac0f9e..73c9869 100644
80385 --- a/include/linux/blkdev.h
80386 +++ b/include/linux/blkdev.h
80387 @@ -1615,7 +1615,7 @@ struct block_device_operations {
80388 /* this callback is with swap_lock and sometimes page table lock held */
80389 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80390 struct module *owner;
80391 -};
80392 +} __do_const;
80393
80394 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80395 unsigned long);
80396 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80397 index afc1343..9735539 100644
80398 --- a/include/linux/blktrace_api.h
80399 +++ b/include/linux/blktrace_api.h
80400 @@ -25,7 +25,7 @@ struct blk_trace {
80401 struct dentry *dropped_file;
80402 struct dentry *msg_file;
80403 struct list_head running_list;
80404 - atomic_t dropped;
80405 + atomic_unchecked_t dropped;
80406 };
80407
80408 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80409 diff --git a/include/linux/cache.h b/include/linux/cache.h
80410 index 17e7e82..1d7da26 100644
80411 --- a/include/linux/cache.h
80412 +++ b/include/linux/cache.h
80413 @@ -16,6 +16,14 @@
80414 #define __read_mostly
80415 #endif
80416
80417 +#ifndef __read_only
80418 +#ifdef CONFIG_PAX_KERNEXEC
80419 +#error KERNEXEC requires __read_only
80420 +#else
80421 +#define __read_only __read_mostly
80422 +#endif
80423 +#endif
80424 +
80425 #ifndef ____cacheline_aligned
80426 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80427 #endif
80428 diff --git a/include/linux/capability.h b/include/linux/capability.h
80429 index aa93e5e..985a1b0 100644
80430 --- a/include/linux/capability.h
80431 +++ b/include/linux/capability.h
80432 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80433 extern bool capable(int cap);
80434 extern bool ns_capable(struct user_namespace *ns, int cap);
80435 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80436 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80437 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80438 +extern bool capable_nolog(int cap);
80439 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80440
80441 /* audit system wants to get cap info from files as well */
80442 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80443
80444 +extern int is_privileged_binary(const struct dentry *dentry);
80445 +
80446 #endif /* !_LINUX_CAPABILITY_H */
80447 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80448 index 8609d57..86e4d79 100644
80449 --- a/include/linux/cdrom.h
80450 +++ b/include/linux/cdrom.h
80451 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80452
80453 /* driver specifications */
80454 const int capability; /* capability flags */
80455 - int n_minors; /* number of active minor devices */
80456 /* handle uniform packets for scsi type devices (scsi,atapi) */
80457 int (*generic_packet) (struct cdrom_device_info *,
80458 struct packet_command *);
80459 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80460 index 4ce9056..86caac6 100644
80461 --- a/include/linux/cleancache.h
80462 +++ b/include/linux/cleancache.h
80463 @@ -31,7 +31,7 @@ struct cleancache_ops {
80464 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80465 void (*invalidate_inode)(int, struct cleancache_filekey);
80466 void (*invalidate_fs)(int);
80467 -};
80468 +} __no_const;
80469
80470 extern struct cleancache_ops *
80471 cleancache_register_ops(struct cleancache_ops *ops);
80472 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80473 index 2839c63..5b06b6b 100644
80474 --- a/include/linux/clk-provider.h
80475 +++ b/include/linux/clk-provider.h
80476 @@ -191,6 +191,7 @@ struct clk_ops {
80477 void (*init)(struct clk_hw *hw);
80478 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80479 };
80480 +typedef struct clk_ops __no_const clk_ops_no_const;
80481
80482 /**
80483 * struct clk_init_data - holds init data that's common to all clocks and is
80484 diff --git a/include/linux/compat.h b/include/linux/compat.h
80485 index e649426..a74047b 100644
80486 --- a/include/linux/compat.h
80487 +++ b/include/linux/compat.h
80488 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80489 compat_size_t __user *len_ptr);
80490
80491 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80492 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80493 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80494 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80495 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80496 compat_ssize_t msgsz, int msgflg);
80497 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80498 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80499 compat_ulong_t addr, compat_ulong_t data);
80500 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80501 - compat_long_t addr, compat_long_t data);
80502 + compat_ulong_t addr, compat_ulong_t data);
80503
80504 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80505 /*
80506 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80507 index d1a5582..4424efa 100644
80508 --- a/include/linux/compiler-gcc4.h
80509 +++ b/include/linux/compiler-gcc4.h
80510 @@ -39,9 +39,34 @@
80511 # define __compiletime_warning(message) __attribute__((warning(message)))
80512 # define __compiletime_error(message) __attribute__((error(message)))
80513 #endif /* __CHECKER__ */
80514 +
80515 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80516 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80517 +#define __bos0(ptr) __bos((ptr), 0)
80518 +#define __bos1(ptr) __bos((ptr), 1)
80519 #endif /* GCC_VERSION >= 40300 */
80520
80521 #if GCC_VERSION >= 40500
80522 +
80523 +#ifdef RANDSTRUCT_PLUGIN
80524 +#define __randomize_layout __attribute__((randomize_layout))
80525 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80526 +#endif
80527 +
80528 +#ifdef CONSTIFY_PLUGIN
80529 +#define __no_const __attribute__((no_const))
80530 +#define __do_const __attribute__((do_const))
80531 +#endif
80532 +
80533 +#ifdef SIZE_OVERFLOW_PLUGIN
80534 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80535 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80536 +#endif
80537 +
80538 +#ifdef LATENT_ENTROPY_PLUGIN
80539 +#define __latent_entropy __attribute__((latent_entropy))
80540 +#endif
80541 +
80542 /*
80543 * Mark a position in code as unreachable. This can be used to
80544 * suppress control flow warnings after asm blocks that transfer
80545 diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h
80546 index c8c5659..d09f2ad 100644
80547 --- a/include/linux/compiler-gcc5.h
80548 +++ b/include/linux/compiler-gcc5.h
80549 @@ -28,6 +28,28 @@
80550 # define __compiletime_error(message) __attribute__((error(message)))
80551 #endif /* __CHECKER__ */
80552
80553 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80554 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80555 +#define __bos0(ptr) __bos((ptr), 0)
80556 +#define __bos1(ptr) __bos((ptr), 1)
80557 +
80558 +#ifdef CONSTIFY_PLUGIN
80559 +#error not yet
80560 +#define __no_const __attribute__((no_const))
80561 +#define __do_const __attribute__((do_const))
80562 +#endif
80563 +
80564 +#ifdef SIZE_OVERFLOW_PLUGIN
80565 +#error not yet
80566 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80567 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80568 +#endif
80569 +
80570 +#ifdef LATENT_ENTROPY_PLUGIN
80571 +#error not yet
80572 +#define __latent_entropy __attribute__((latent_entropy))
80573 +#endif
80574 +
80575 /*
80576 * Mark a position in code as unreachable. This can be used to
80577 * suppress control flow warnings after asm blocks that transfer
80578 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80579 index d5ad7b1..3b74638 100644
80580 --- a/include/linux/compiler.h
80581 +++ b/include/linux/compiler.h
80582 @@ -5,11 +5,14 @@
80583
80584 #ifdef __CHECKER__
80585 # define __user __attribute__((noderef, address_space(1)))
80586 +# define __force_user __force __user
80587 # define __kernel __attribute__((address_space(0)))
80588 +# define __force_kernel __force __kernel
80589 # define __safe __attribute__((safe))
80590 # define __force __attribute__((force))
80591 # define __nocast __attribute__((nocast))
80592 # define __iomem __attribute__((noderef, address_space(2)))
80593 +# define __force_iomem __force __iomem
80594 # define __must_hold(x) __attribute__((context(x,1,1)))
80595 # define __acquires(x) __attribute__((context(x,0,1)))
80596 # define __releases(x) __attribute__((context(x,1,0)))
80597 @@ -17,20 +20,37 @@
80598 # define __release(x) __context__(x,-1)
80599 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80600 # define __percpu __attribute__((noderef, address_space(3)))
80601 +# define __force_percpu __force __percpu
80602 #ifdef CONFIG_SPARSE_RCU_POINTER
80603 # define __rcu __attribute__((noderef, address_space(4)))
80604 +# define __force_rcu __force __rcu
80605 #else
80606 # define __rcu
80607 +# define __force_rcu
80608 #endif
80609 extern void __chk_user_ptr(const volatile void __user *);
80610 extern void __chk_io_ptr(const volatile void __iomem *);
80611 #else
80612 -# define __user
80613 -# define __kernel
80614 +# ifdef CHECKER_PLUGIN
80615 +//# define __user
80616 +//# define __force_user
80617 +//# define __kernel
80618 +//# define __force_kernel
80619 +# else
80620 +# ifdef STRUCTLEAK_PLUGIN
80621 +# define __user __attribute__((user))
80622 +# else
80623 +# define __user
80624 +# endif
80625 +# define __force_user
80626 +# define __kernel
80627 +# define __force_kernel
80628 +# endif
80629 # define __safe
80630 # define __force
80631 # define __nocast
80632 # define __iomem
80633 +# define __force_iomem
80634 # define __chk_user_ptr(x) (void)0
80635 # define __chk_io_ptr(x) (void)0
80636 # define __builtin_warning(x, y...) (1)
80637 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80638 # define __release(x) (void)0
80639 # define __cond_lock(x,c) (c)
80640 # define __percpu
80641 +# define __force_percpu
80642 # define __rcu
80643 +# define __force_rcu
80644 #endif
80645
80646 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80647 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80648 # define __attribute_const__ /* unimplemented */
80649 #endif
80650
80651 +#ifndef __randomize_layout
80652 +# define __randomize_layout
80653 +#endif
80654 +
80655 +#ifndef __no_randomize_layout
80656 +# define __no_randomize_layout
80657 +#endif
80658 +
80659 +#ifndef __no_const
80660 +# define __no_const
80661 +#endif
80662 +
80663 +#ifndef __do_const
80664 +# define __do_const
80665 +#endif
80666 +
80667 +#ifndef __size_overflow
80668 +# define __size_overflow(...)
80669 +#endif
80670 +
80671 +#ifndef __intentional_overflow
80672 +# define __intentional_overflow(...)
80673 +#endif
80674 +
80675 +#ifndef __latent_entropy
80676 +# define __latent_entropy
80677 +#endif
80678 +
80679 /*
80680 * Tell gcc if a function is cold. The compiler will assume any path
80681 * directly leading to the call is unlikely.
80682 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80683 #define __cold
80684 #endif
80685
80686 +#ifndef __alloc_size
80687 +#define __alloc_size(...)
80688 +#endif
80689 +
80690 +#ifndef __bos
80691 +#define __bos(ptr, arg)
80692 +#endif
80693 +
80694 +#ifndef __bos0
80695 +#define __bos0(ptr)
80696 +#endif
80697 +
80698 +#ifndef __bos1
80699 +#define __bos1(ptr)
80700 +#endif
80701 +
80702 /* Simple shorthand for a section definition */
80703 #ifndef __section
80704 # define __section(S) __attribute__ ((__section__(#S)))
80705 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80706 * use is to mediate communication between process-level code and irq/NMI
80707 * handlers, all running on the same CPU.
80708 */
80709 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80710 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80711 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80712
80713 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80714 #ifdef CONFIG_KPROBES
80715 diff --git a/include/linux/completion.h b/include/linux/completion.h
80716 index 5d5aaae..0ea9b84 100644
80717 --- a/include/linux/completion.h
80718 +++ b/include/linux/completion.h
80719 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80720
80721 extern void wait_for_completion(struct completion *);
80722 extern void wait_for_completion_io(struct completion *);
80723 -extern int wait_for_completion_interruptible(struct completion *x);
80724 -extern int wait_for_completion_killable(struct completion *x);
80725 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80726 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80727 extern unsigned long wait_for_completion_timeout(struct completion *x,
80728 - unsigned long timeout);
80729 + unsigned long timeout) __intentional_overflow(-1);
80730 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80731 - unsigned long timeout);
80732 + unsigned long timeout) __intentional_overflow(-1);
80733 extern long wait_for_completion_interruptible_timeout(
80734 - struct completion *x, unsigned long timeout);
80735 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80736 extern long wait_for_completion_killable_timeout(
80737 - struct completion *x, unsigned long timeout);
80738 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80739 extern bool try_wait_for_completion(struct completion *x);
80740 extern bool completion_done(struct completion *x);
80741
80742 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80743 index 34025df..d94bbbc 100644
80744 --- a/include/linux/configfs.h
80745 +++ b/include/linux/configfs.h
80746 @@ -125,7 +125,7 @@ struct configfs_attribute {
80747 const char *ca_name;
80748 struct module *ca_owner;
80749 umode_t ca_mode;
80750 -};
80751 +} __do_const;
80752
80753 /*
80754 * Users often need to create attribute structures for their configurable
80755 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80756 index 503b085b..1638c9e 100644
80757 --- a/include/linux/cpufreq.h
80758 +++ b/include/linux/cpufreq.h
80759 @@ -206,6 +206,7 @@ struct global_attr {
80760 ssize_t (*store)(struct kobject *a, struct attribute *b,
80761 const char *c, size_t count);
80762 };
80763 +typedef struct global_attr __no_const global_attr_no_const;
80764
80765 #define define_one_global_ro(_name) \
80766 static struct global_attr _name = \
80767 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80768 bool boost_supported;
80769 bool boost_enabled;
80770 int (*set_boost) (int state);
80771 -};
80772 +} __do_const;
80773
80774 /* flags */
80775 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80776 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80777 index 25e0df6..952dffd 100644
80778 --- a/include/linux/cpuidle.h
80779 +++ b/include/linux/cpuidle.h
80780 @@ -50,7 +50,8 @@ struct cpuidle_state {
80781 int index);
80782
80783 int (*enter_dead) (struct cpuidle_device *dev, int index);
80784 -};
80785 +} __do_const;
80786 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80787
80788 /* Idle State Flags */
80789 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80790 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80791 void (*reflect) (struct cpuidle_device *dev, int index);
80792
80793 struct module *owner;
80794 -};
80795 +} __do_const;
80796
80797 #ifdef CONFIG_CPU_IDLE
80798 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80799 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80800 index 0a9a6da..ea597ca 100644
80801 --- a/include/linux/cpumask.h
80802 +++ b/include/linux/cpumask.h
80803 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80804 }
80805
80806 /* Valid inputs for n are -1 and 0. */
80807 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80808 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80809 {
80810 return n+1;
80811 }
80812
80813 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80814 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80815 {
80816 return n+1;
80817 }
80818
80819 -static inline unsigned int cpumask_next_and(int n,
80820 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80821 const struct cpumask *srcp,
80822 const struct cpumask *andp)
80823 {
80824 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80825 *
80826 * Returns >= nr_cpu_ids if no further cpus set.
80827 */
80828 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80829 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80830 {
80831 /* -1 is a legal arg here. */
80832 if (n != -1)
80833 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80834 *
80835 * Returns >= nr_cpu_ids if no further cpus unset.
80836 */
80837 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80838 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80839 {
80840 /* -1 is a legal arg here. */
80841 if (n != -1)
80842 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80843 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80844 }
80845
80846 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80847 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80848 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80849 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80850
80851 diff --git a/include/linux/cred.h b/include/linux/cred.h
80852 index 2fb2ca2..d6a3340 100644
80853 --- a/include/linux/cred.h
80854 +++ b/include/linux/cred.h
80855 @@ -35,7 +35,7 @@ struct group_info {
80856 int nblocks;
80857 kgid_t small_block[NGROUPS_SMALL];
80858 kgid_t *blocks[0];
80859 -};
80860 +} __randomize_layout;
80861
80862 /**
80863 * get_group_info - Get a reference to a group info structure
80864 @@ -137,7 +137,7 @@ struct cred {
80865 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80866 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80867 struct rcu_head rcu; /* RCU deletion hook */
80868 -};
80869 +} __randomize_layout;
80870
80871 extern void __put_cred(struct cred *);
80872 extern void exit_creds(struct task_struct *);
80873 @@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80874 static inline void validate_process_creds(void)
80875 {
80876 }
80877 +static inline void validate_task_creds(struct task_struct *task)
80878 +{
80879 +}
80880 #endif
80881
80882 /**
80883 @@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
80884
80885 #define task_uid(task) (task_cred_xxx((task), uid))
80886 #define task_euid(task) (task_cred_xxx((task), euid))
80887 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80888
80889 #define current_cred_xxx(xxx) \
80890 ({ \
80891 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80892 index dc34dfc..bdf9b5d 100644
80893 --- a/include/linux/crypto.h
80894 +++ b/include/linux/crypto.h
80895 @@ -386,7 +386,7 @@ struct cipher_tfm {
80896 const u8 *key, unsigned int keylen);
80897 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80898 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80899 -};
80900 +} __no_const;
80901
80902 struct hash_tfm {
80903 int (*init)(struct hash_desc *desc);
80904 @@ -407,13 +407,13 @@ struct compress_tfm {
80905 int (*cot_decompress)(struct crypto_tfm *tfm,
80906 const u8 *src, unsigned int slen,
80907 u8 *dst, unsigned int *dlen);
80908 -};
80909 +} __no_const;
80910
80911 struct rng_tfm {
80912 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80913 unsigned int dlen);
80914 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80915 -};
80916 +} __no_const;
80917
80918 #define crt_ablkcipher crt_u.ablkcipher
80919 #define crt_aead crt_u.aead
80920 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80921 index 653589e..4ef254a 100644
80922 --- a/include/linux/ctype.h
80923 +++ b/include/linux/ctype.h
80924 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80925 * Fast implementation of tolower() for internal usage. Do not use in your
80926 * code.
80927 */
80928 -static inline char _tolower(const char c)
80929 +static inline unsigned char _tolower(const unsigned char c)
80930 {
80931 return c | 0x20;
80932 }
80933 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80934 index 1c2f1b8..7b9f50c 100644
80935 --- a/include/linux/dcache.h
80936 +++ b/include/linux/dcache.h
80937 @@ -123,6 +123,9 @@ struct dentry {
80938 unsigned long d_time; /* used by d_revalidate */
80939 void *d_fsdata; /* fs-specific data */
80940
80941 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
80942 + atomic_t chroot_refcnt; /* tracks use of directory in chroot */
80943 +#endif
80944 struct list_head d_lru; /* LRU list */
80945 struct list_head d_child; /* child of parent list */
80946 struct list_head d_subdirs; /* our children */
80947 @@ -133,7 +136,7 @@ struct dentry {
80948 struct hlist_node d_alias; /* inode alias list */
80949 struct rcu_head d_rcu;
80950 } d_u;
80951 -};
80952 +} __randomize_layout;
80953
80954 /*
80955 * dentry->d_lock spinlock nesting subclasses:
80956 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80957 index 7925bf0..d5143d2 100644
80958 --- a/include/linux/decompress/mm.h
80959 +++ b/include/linux/decompress/mm.h
80960 @@ -77,7 +77,7 @@ static void free(void *where)
80961 * warnings when not needed (indeed large_malloc / large_free are not
80962 * needed by inflate */
80963
80964 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80965 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80966 #define free(a) kfree(a)
80967
80968 #define large_malloc(a) vmalloc(a)
80969 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80970 index f1863dc..5c26074 100644
80971 --- a/include/linux/devfreq.h
80972 +++ b/include/linux/devfreq.h
80973 @@ -114,7 +114,7 @@ struct devfreq_governor {
80974 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80975 int (*event_handler)(struct devfreq *devfreq,
80976 unsigned int event, void *data);
80977 -};
80978 +} __do_const;
80979
80980 /**
80981 * struct devfreq - Device devfreq structure
80982 diff --git a/include/linux/device.h b/include/linux/device.h
80983 index ce1f2160..189bc33 100644
80984 --- a/include/linux/device.h
80985 +++ b/include/linux/device.h
80986 @@ -311,7 +311,7 @@ struct subsys_interface {
80987 struct list_head node;
80988 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80989 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80990 -};
80991 +} __do_const;
80992
80993 int subsys_interface_register(struct subsys_interface *sif);
80994 void subsys_interface_unregister(struct subsys_interface *sif);
80995 @@ -507,7 +507,7 @@ struct device_type {
80996 void (*release)(struct device *dev);
80997
80998 const struct dev_pm_ops *pm;
80999 -};
81000 +} __do_const;
81001
81002 /* interface for exporting device attributes */
81003 struct device_attribute {
81004 @@ -517,11 +517,12 @@ struct device_attribute {
81005 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81006 const char *buf, size_t count);
81007 };
81008 +typedef struct device_attribute __no_const device_attribute_no_const;
81009
81010 struct dev_ext_attribute {
81011 struct device_attribute attr;
81012 void *var;
81013 -};
81014 +} __do_const;
81015
81016 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81017 char *buf);
81018 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81019 index d5d3881..7ed54af 100644
81020 --- a/include/linux/dma-mapping.h
81021 +++ b/include/linux/dma-mapping.h
81022 @@ -60,7 +60,7 @@ struct dma_map_ops {
81023 u64 (*get_required_mask)(struct device *dev);
81024 #endif
81025 int is_phys;
81026 -};
81027 +} __do_const;
81028
81029 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81030
81031 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81032 index 653a1fd..9133cd1 100644
81033 --- a/include/linux/dmaengine.h
81034 +++ b/include/linux/dmaengine.h
81035 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
81036 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81037 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81038
81039 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81040 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81041 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81042 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81043 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81044 struct dma_pinned_list *pinned_list, struct page *page,
81045 unsigned int offset, size_t len);
81046
81047 diff --git a/include/linux/efi.h b/include/linux/efi.h
81048 index 0949f9c..04cb9a5 100644
81049 --- a/include/linux/efi.h
81050 +++ b/include/linux/efi.h
81051 @@ -1050,6 +1050,7 @@ struct efivar_operations {
81052 efi_set_variable_nonblocking_t *set_variable_nonblocking;
81053 efi_query_variable_store_t *query_variable_store;
81054 };
81055 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81056
81057 struct efivars {
81058 /*
81059 diff --git a/include/linux/elf.h b/include/linux/elf.h
81060 index 67a5fa7..b817372 100644
81061 --- a/include/linux/elf.h
81062 +++ b/include/linux/elf.h
81063 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81064 #define elf_note elf32_note
81065 #define elf_addr_t Elf32_Off
81066 #define Elf_Half Elf32_Half
81067 +#define elf_dyn Elf32_Dyn
81068
81069 #else
81070
81071 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81072 #define elf_note elf64_note
81073 #define elf_addr_t Elf64_Off
81074 #define Elf_Half Elf64_Half
81075 +#define elf_dyn Elf64_Dyn
81076
81077 #endif
81078
81079 diff --git a/include/linux/err.h b/include/linux/err.h
81080 index a729120..6ede2c9 100644
81081 --- a/include/linux/err.h
81082 +++ b/include/linux/err.h
81083 @@ -20,12 +20,12 @@
81084
81085 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81086
81087 -static inline void * __must_check ERR_PTR(long error)
81088 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81089 {
81090 return (void *) error;
81091 }
81092
81093 -static inline long __must_check PTR_ERR(__force const void *ptr)
81094 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81095 {
81096 return (long) ptr;
81097 }
81098 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81099 index 36f49c4..a2a1f4c 100644
81100 --- a/include/linux/extcon.h
81101 +++ b/include/linux/extcon.h
81102 @@ -135,7 +135,7 @@ struct extcon_dev {
81103 /* /sys/class/extcon/.../mutually_exclusive/... */
81104 struct attribute_group attr_g_muex;
81105 struct attribute **attrs_muex;
81106 - struct device_attribute *d_attrs_muex;
81107 + device_attribute_no_const *d_attrs_muex;
81108 };
81109
81110 /**
81111 diff --git a/include/linux/fb.h b/include/linux/fb.h
81112 index 09bb7a1..d98870a 100644
81113 --- a/include/linux/fb.h
81114 +++ b/include/linux/fb.h
81115 @@ -305,7 +305,7 @@ struct fb_ops {
81116 /* called at KDB enter and leave time to prepare the console */
81117 int (*fb_debug_enter)(struct fb_info *info);
81118 int (*fb_debug_leave)(struct fb_info *info);
81119 -};
81120 +} __do_const;
81121
81122 #ifdef CONFIG_FB_TILEBLITTING
81123 #define FB_TILE_CURSOR_NONE 0
81124 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81125 index 230f87b..1fd0485 100644
81126 --- a/include/linux/fdtable.h
81127 +++ b/include/linux/fdtable.h
81128 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81129 void put_files_struct(struct files_struct *fs);
81130 void reset_files_struct(struct files_struct *);
81131 int unshare_files(struct files_struct **);
81132 -struct files_struct *dup_fd(struct files_struct *, int *);
81133 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81134 void do_close_on_exec(struct files_struct *);
81135 int iterate_fd(struct files_struct *, unsigned,
81136 int (*)(const void *, struct file *, unsigned),
81137 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81138 index 8293262..2b3b8bd 100644
81139 --- a/include/linux/frontswap.h
81140 +++ b/include/linux/frontswap.h
81141 @@ -11,7 +11,7 @@ struct frontswap_ops {
81142 int (*load)(unsigned, pgoff_t, struct page *);
81143 void (*invalidate_page)(unsigned, pgoff_t);
81144 void (*invalidate_area)(unsigned);
81145 -};
81146 +} __no_const;
81147
81148 extern bool frontswap_enabled;
81149 extern struct frontswap_ops *
81150 diff --git a/include/linux/fs.h b/include/linux/fs.h
81151 index 9ab779e..0c636f2 100644
81152 --- a/include/linux/fs.h
81153 +++ b/include/linux/fs.h
81154 @@ -412,7 +412,7 @@ struct address_space {
81155 spinlock_t private_lock; /* for use by the address_space */
81156 struct list_head private_list; /* ditto */
81157 void *private_data; /* ditto */
81158 -} __attribute__((aligned(sizeof(long))));
81159 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81160 /*
81161 * On most architectures that alignment is already the case; but
81162 * must be enforced here for CRIS, to let the least significant bit
81163 @@ -455,7 +455,7 @@ struct block_device {
81164 int bd_fsfreeze_count;
81165 /* Mutex for freeze */
81166 struct mutex bd_fsfreeze_mutex;
81167 -};
81168 +} __randomize_layout;
81169
81170 /*
81171 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81172 @@ -624,7 +624,7 @@ struct inode {
81173 #endif
81174
81175 void *i_private; /* fs or device private pointer */
81176 -};
81177 +} __randomize_layout;
81178
81179 static inline int inode_unhashed(struct inode *inode)
81180 {
81181 @@ -820,7 +820,7 @@ struct file {
81182 struct list_head f_tfile_llink;
81183 #endif /* #ifdef CONFIG_EPOLL */
81184 struct address_space *f_mapping;
81185 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81186 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81187
81188 struct file_handle {
81189 __u32 handle_bytes;
81190 @@ -945,7 +945,7 @@ struct file_lock {
81191 int state; /* state of grant or error if -ve */
81192 } afs;
81193 } fl_u;
81194 -};
81195 +} __randomize_layout;
81196
81197 /* The following constant reflects the upper bound of the file/locking space */
81198 #ifndef OFFSET_MAX
81199 @@ -1287,7 +1287,7 @@ struct super_block {
81200 * Indicates how deep in a filesystem stack this SB is
81201 */
81202 int s_stack_depth;
81203 -};
81204 +} __randomize_layout;
81205
81206 extern struct timespec current_fs_time(struct super_block *sb);
81207
81208 @@ -1514,7 +1514,8 @@ struct file_operations {
81209 long (*fallocate)(struct file *file, int mode, loff_t offset,
81210 loff_t len);
81211 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81212 -};
81213 +} __do_const __randomize_layout;
81214 +typedef struct file_operations __no_const file_operations_no_const;
81215
81216 struct inode_operations {
81217 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81218 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81219 return !IS_DEADDIR(inode);
81220 }
81221
81222 +static inline bool is_sidechannel_device(const struct inode *inode)
81223 +{
81224 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81225 + umode_t mode = inode->i_mode;
81226 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81227 +#else
81228 + return false;
81229 +#endif
81230 +}
81231 +
81232 #endif /* _LINUX_FS_H */
81233 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81234 index 0efc3e6..fd23610 100644
81235 --- a/include/linux/fs_struct.h
81236 +++ b/include/linux/fs_struct.h
81237 @@ -6,13 +6,13 @@
81238 #include <linux/seqlock.h>
81239
81240 struct fs_struct {
81241 - int users;
81242 + atomic_t users;
81243 spinlock_t lock;
81244 seqcount_t seq;
81245 int umask;
81246 int in_exec;
81247 struct path root, pwd;
81248 -};
81249 +} __randomize_layout;
81250
81251 extern struct kmem_cache *fs_cachep;
81252
81253 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81254 index 7714849..a4a5c7a 100644
81255 --- a/include/linux/fscache-cache.h
81256 +++ b/include/linux/fscache-cache.h
81257 @@ -113,7 +113,7 @@ struct fscache_operation {
81258 fscache_operation_release_t release;
81259 };
81260
81261 -extern atomic_t fscache_op_debug_id;
81262 +extern atomic_unchecked_t fscache_op_debug_id;
81263 extern void fscache_op_work_func(struct work_struct *work);
81264
81265 extern void fscache_enqueue_operation(struct fscache_operation *);
81266 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81267 INIT_WORK(&op->work, fscache_op_work_func);
81268 atomic_set(&op->usage, 1);
81269 op->state = FSCACHE_OP_ST_INITIALISED;
81270 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81271 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81272 op->processor = processor;
81273 op->release = release;
81274 INIT_LIST_HEAD(&op->pend_link);
81275 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81276 index 115bb81..e7b812b 100644
81277 --- a/include/linux/fscache.h
81278 +++ b/include/linux/fscache.h
81279 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81280 * - this is mandatory for any object that may have data
81281 */
81282 void (*now_uncached)(void *cookie_netfs_data);
81283 -};
81284 +} __do_const;
81285
81286 /*
81287 * fscache cached network filesystem type
81288 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81289 index 1c804b0..1432c2b 100644
81290 --- a/include/linux/fsnotify.h
81291 +++ b/include/linux/fsnotify.h
81292 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81293 struct inode *inode = file_inode(file);
81294 __u32 mask = FS_ACCESS;
81295
81296 + if (is_sidechannel_device(inode))
81297 + return;
81298 +
81299 if (S_ISDIR(inode->i_mode))
81300 mask |= FS_ISDIR;
81301
81302 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81303 struct inode *inode = file_inode(file);
81304 __u32 mask = FS_MODIFY;
81305
81306 + if (is_sidechannel_device(inode))
81307 + return;
81308 +
81309 if (S_ISDIR(inode->i_mode))
81310 mask |= FS_ISDIR;
81311
81312 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81313 */
81314 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81315 {
81316 - return kstrdup(name, GFP_KERNEL);
81317 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81318 }
81319
81320 /*
81321 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81322 index ec274e0..e678159 100644
81323 --- a/include/linux/genhd.h
81324 +++ b/include/linux/genhd.h
81325 @@ -194,7 +194,7 @@ struct gendisk {
81326 struct kobject *slave_dir;
81327
81328 struct timer_rand_state *random;
81329 - atomic_t sync_io; /* RAID */
81330 + atomic_unchecked_t sync_io; /* RAID */
81331 struct disk_events *ev;
81332 #ifdef CONFIG_BLK_DEV_INTEGRITY
81333 struct blk_integrity *integrity;
81334 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81335 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81336
81337 /* drivers/char/random.c */
81338 -extern void add_disk_randomness(struct gendisk *disk);
81339 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81340 extern void rand_initialize_disk(struct gendisk *disk);
81341
81342 static inline sector_t get_start_sect(struct block_device *bdev)
81343 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81344 index 667c311..abac2a7 100644
81345 --- a/include/linux/genl_magic_func.h
81346 +++ b/include/linux/genl_magic_func.h
81347 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81348 },
81349
81350 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81351 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81352 +static struct genl_ops ZZZ_genl_ops[] = {
81353 #include GENL_MAGIC_INCLUDE_FILE
81354 };
81355
81356 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81357 index 41b30fd..a3718cf 100644
81358 --- a/include/linux/gfp.h
81359 +++ b/include/linux/gfp.h
81360 @@ -34,6 +34,13 @@ struct vm_area_struct;
81361 #define ___GFP_NO_KSWAPD 0x400000u
81362 #define ___GFP_OTHER_NODE 0x800000u
81363 #define ___GFP_WRITE 0x1000000u
81364 +
81365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81366 +#define ___GFP_USERCOPY 0x2000000u
81367 +#else
81368 +#define ___GFP_USERCOPY 0
81369 +#endif
81370 +
81371 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81372
81373 /*
81374 @@ -90,6 +97,7 @@ struct vm_area_struct;
81375 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81376 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81377 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81378 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81379
81380 /*
81381 * This may seem redundant, but it's a way of annotating false positives vs.
81382 @@ -97,7 +105,7 @@ struct vm_area_struct;
81383 */
81384 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81385
81386 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81387 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81388 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81389
81390 /* This equals 0, but use constants in case they ever change */
81391 @@ -155,6 +163,8 @@ struct vm_area_struct;
81392 /* 4GB DMA on some platforms */
81393 #define GFP_DMA32 __GFP_DMA32
81394
81395 +#define GFP_USERCOPY __GFP_USERCOPY
81396 +
81397 /* Convert GFP flags to their corresponding migrate type */
81398 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81399 {
81400 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81401 new file mode 100644
81402 index 0000000..edb2cb6
81403 --- /dev/null
81404 +++ b/include/linux/gracl.h
81405 @@ -0,0 +1,340 @@
81406 +#ifndef GR_ACL_H
81407 +#define GR_ACL_H
81408 +
81409 +#include <linux/grdefs.h>
81410 +#include <linux/resource.h>
81411 +#include <linux/capability.h>
81412 +#include <linux/dcache.h>
81413 +#include <asm/resource.h>
81414 +
81415 +/* Major status information */
81416 +
81417 +#define GR_VERSION "grsecurity 3.0"
81418 +#define GRSECURITY_VERSION 0x3000
81419 +
81420 +enum {
81421 + GR_SHUTDOWN = 0,
81422 + GR_ENABLE = 1,
81423 + GR_SPROLE = 2,
81424 + GR_OLDRELOAD = 3,
81425 + GR_SEGVMOD = 4,
81426 + GR_STATUS = 5,
81427 + GR_UNSPROLE = 6,
81428 + GR_PASSSET = 7,
81429 + GR_SPROLEPAM = 8,
81430 + GR_RELOAD = 9,
81431 +};
81432 +
81433 +/* Password setup definitions
81434 + * kernel/grhash.c */
81435 +enum {
81436 + GR_PW_LEN = 128,
81437 + GR_SALT_LEN = 16,
81438 + GR_SHA_LEN = 32,
81439 +};
81440 +
81441 +enum {
81442 + GR_SPROLE_LEN = 64,
81443 +};
81444 +
81445 +enum {
81446 + GR_NO_GLOB = 0,
81447 + GR_REG_GLOB,
81448 + GR_CREATE_GLOB
81449 +};
81450 +
81451 +#define GR_NLIMITS 32
81452 +
81453 +/* Begin Data Structures */
81454 +
81455 +struct sprole_pw {
81456 + unsigned char *rolename;
81457 + unsigned char salt[GR_SALT_LEN];
81458 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81459 +};
81460 +
81461 +struct name_entry {
81462 + __u32 key;
81463 + ino_t inode;
81464 + dev_t device;
81465 + char *name;
81466 + __u16 len;
81467 + __u8 deleted;
81468 + struct name_entry *prev;
81469 + struct name_entry *next;
81470 +};
81471 +
81472 +struct inodev_entry {
81473 + struct name_entry *nentry;
81474 + struct inodev_entry *prev;
81475 + struct inodev_entry *next;
81476 +};
81477 +
81478 +struct acl_role_db {
81479 + struct acl_role_label **r_hash;
81480 + __u32 r_size;
81481 +};
81482 +
81483 +struct inodev_db {
81484 + struct inodev_entry **i_hash;
81485 + __u32 i_size;
81486 +};
81487 +
81488 +struct name_db {
81489 + struct name_entry **n_hash;
81490 + __u32 n_size;
81491 +};
81492 +
81493 +struct crash_uid {
81494 + uid_t uid;
81495 + unsigned long expires;
81496 +};
81497 +
81498 +struct gr_hash_struct {
81499 + void **table;
81500 + void **nametable;
81501 + void *first;
81502 + __u32 table_size;
81503 + __u32 used_size;
81504 + int type;
81505 +};
81506 +
81507 +/* Userspace Grsecurity ACL data structures */
81508 +
81509 +struct acl_subject_label {
81510 + char *filename;
81511 + ino_t inode;
81512 + dev_t device;
81513 + __u32 mode;
81514 + kernel_cap_t cap_mask;
81515 + kernel_cap_t cap_lower;
81516 + kernel_cap_t cap_invert_audit;
81517 +
81518 + struct rlimit res[GR_NLIMITS];
81519 + __u32 resmask;
81520 +
81521 + __u8 user_trans_type;
81522 + __u8 group_trans_type;
81523 + uid_t *user_transitions;
81524 + gid_t *group_transitions;
81525 + __u16 user_trans_num;
81526 + __u16 group_trans_num;
81527 +
81528 + __u32 sock_families[2];
81529 + __u32 ip_proto[8];
81530 + __u32 ip_type;
81531 + struct acl_ip_label **ips;
81532 + __u32 ip_num;
81533 + __u32 inaddr_any_override;
81534 +
81535 + __u32 crashes;
81536 + unsigned long expires;
81537 +
81538 + struct acl_subject_label *parent_subject;
81539 + struct gr_hash_struct *hash;
81540 + struct acl_subject_label *prev;
81541 + struct acl_subject_label *next;
81542 +
81543 + struct acl_object_label **obj_hash;
81544 + __u32 obj_hash_size;
81545 + __u16 pax_flags;
81546 +};
81547 +
81548 +struct role_allowed_ip {
81549 + __u32 addr;
81550 + __u32 netmask;
81551 +
81552 + struct role_allowed_ip *prev;
81553 + struct role_allowed_ip *next;
81554 +};
81555 +
81556 +struct role_transition {
81557 + char *rolename;
81558 +
81559 + struct role_transition *prev;
81560 + struct role_transition *next;
81561 +};
81562 +
81563 +struct acl_role_label {
81564 + char *rolename;
81565 + uid_t uidgid;
81566 + __u16 roletype;
81567 +
81568 + __u16 auth_attempts;
81569 + unsigned long expires;
81570 +
81571 + struct acl_subject_label *root_label;
81572 + struct gr_hash_struct *hash;
81573 +
81574 + struct acl_role_label *prev;
81575 + struct acl_role_label *next;
81576 +
81577 + struct role_transition *transitions;
81578 + struct role_allowed_ip *allowed_ips;
81579 + uid_t *domain_children;
81580 + __u16 domain_child_num;
81581 +
81582 + umode_t umask;
81583 +
81584 + struct acl_subject_label **subj_hash;
81585 + __u32 subj_hash_size;
81586 +};
81587 +
81588 +struct user_acl_role_db {
81589 + struct acl_role_label **r_table;
81590 + __u32 num_pointers; /* Number of allocations to track */
81591 + __u32 num_roles; /* Number of roles */
81592 + __u32 num_domain_children; /* Number of domain children */
81593 + __u32 num_subjects; /* Number of subjects */
81594 + __u32 num_objects; /* Number of objects */
81595 +};
81596 +
81597 +struct acl_object_label {
81598 + char *filename;
81599 + ino_t inode;
81600 + dev_t device;
81601 + __u32 mode;
81602 +
81603 + struct acl_subject_label *nested;
81604 + struct acl_object_label *globbed;
81605 +
81606 + /* next two structures not used */
81607 +
81608 + struct acl_object_label *prev;
81609 + struct acl_object_label *next;
81610 +};
81611 +
81612 +struct acl_ip_label {
81613 + char *iface;
81614 + __u32 addr;
81615 + __u32 netmask;
81616 + __u16 low, high;
81617 + __u8 mode;
81618 + __u32 type;
81619 + __u32 proto[8];
81620 +
81621 + /* next two structures not used */
81622 +
81623 + struct acl_ip_label *prev;
81624 + struct acl_ip_label *next;
81625 +};
81626 +
81627 +struct gr_arg {
81628 + struct user_acl_role_db role_db;
81629 + unsigned char pw[GR_PW_LEN];
81630 + unsigned char salt[GR_SALT_LEN];
81631 + unsigned char sum[GR_SHA_LEN];
81632 + unsigned char sp_role[GR_SPROLE_LEN];
81633 + struct sprole_pw *sprole_pws;
81634 + dev_t segv_device;
81635 + ino_t segv_inode;
81636 + uid_t segv_uid;
81637 + __u16 num_sprole_pws;
81638 + __u16 mode;
81639 +};
81640 +
81641 +struct gr_arg_wrapper {
81642 + struct gr_arg *arg;
81643 + __u32 version;
81644 + __u32 size;
81645 +};
81646 +
81647 +struct subject_map {
81648 + struct acl_subject_label *user;
81649 + struct acl_subject_label *kernel;
81650 + struct subject_map *prev;
81651 + struct subject_map *next;
81652 +};
81653 +
81654 +struct acl_subj_map_db {
81655 + struct subject_map **s_hash;
81656 + __u32 s_size;
81657 +};
81658 +
81659 +struct gr_policy_state {
81660 + struct sprole_pw **acl_special_roles;
81661 + __u16 num_sprole_pws;
81662 + struct acl_role_label *kernel_role;
81663 + struct acl_role_label *role_list;
81664 + struct acl_role_label *default_role;
81665 + struct acl_role_db acl_role_set;
81666 + struct acl_subj_map_db subj_map_set;
81667 + struct name_db name_set;
81668 + struct inodev_db inodev_set;
81669 +};
81670 +
81671 +struct gr_alloc_state {
81672 + unsigned long alloc_stack_next;
81673 + unsigned long alloc_stack_size;
81674 + void **alloc_stack;
81675 +};
81676 +
81677 +struct gr_reload_state {
81678 + struct gr_policy_state oldpolicy;
81679 + struct gr_alloc_state oldalloc;
81680 + struct gr_policy_state newpolicy;
81681 + struct gr_alloc_state newalloc;
81682 + struct gr_policy_state *oldpolicy_ptr;
81683 + struct gr_alloc_state *oldalloc_ptr;
81684 + unsigned char oldmode;
81685 +};
81686 +
81687 +/* End Data Structures Section */
81688 +
81689 +/* Hash functions generated by empirical testing by Brad Spengler
81690 + Makes good use of the low bits of the inode. Generally 0-1 times
81691 + in loop for successful match. 0-3 for unsuccessful match.
81692 + Shift/add algorithm with modulus of table size and an XOR*/
81693 +
81694 +static __inline__ unsigned int
81695 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81696 +{
81697 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81698 +}
81699 +
81700 + static __inline__ unsigned int
81701 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81702 +{
81703 + return ((const unsigned long)userp % sz);
81704 +}
81705 +
81706 +static __inline__ unsigned int
81707 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81708 +{
81709 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81710 +}
81711 +
81712 +static __inline__ unsigned int
81713 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81714 +{
81715 + return full_name_hash((const unsigned char *)name, len) % sz;
81716 +}
81717 +
81718 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81719 + subj = NULL; \
81720 + iter = 0; \
81721 + while (iter < role->subj_hash_size) { \
81722 + if (subj == NULL) \
81723 + subj = role->subj_hash[iter]; \
81724 + if (subj == NULL) { \
81725 + iter++; \
81726 + continue; \
81727 + }
81728 +
81729 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81730 + subj = subj->next; \
81731 + if (subj == NULL) \
81732 + iter++; \
81733 + }
81734 +
81735 +
81736 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81737 + subj = role->hash->first; \
81738 + while (subj != NULL) {
81739 +
81740 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81741 + subj = subj->next; \
81742 + }
81743 +
81744 +#endif
81745 +
81746 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81747 new file mode 100644
81748 index 0000000..33ebd1f
81749 --- /dev/null
81750 +++ b/include/linux/gracl_compat.h
81751 @@ -0,0 +1,156 @@
81752 +#ifndef GR_ACL_COMPAT_H
81753 +#define GR_ACL_COMPAT_H
81754 +
81755 +#include <linux/resource.h>
81756 +#include <asm/resource.h>
81757 +
81758 +struct sprole_pw_compat {
81759 + compat_uptr_t rolename;
81760 + unsigned char salt[GR_SALT_LEN];
81761 + unsigned char sum[GR_SHA_LEN];
81762 +};
81763 +
81764 +struct gr_hash_struct_compat {
81765 + compat_uptr_t table;
81766 + compat_uptr_t nametable;
81767 + compat_uptr_t first;
81768 + __u32 table_size;
81769 + __u32 used_size;
81770 + int type;
81771 +};
81772 +
81773 +struct acl_subject_label_compat {
81774 + compat_uptr_t filename;
81775 + compat_ino_t inode;
81776 + __u32 device;
81777 + __u32 mode;
81778 + kernel_cap_t cap_mask;
81779 + kernel_cap_t cap_lower;
81780 + kernel_cap_t cap_invert_audit;
81781 +
81782 + struct compat_rlimit res[GR_NLIMITS];
81783 + __u32 resmask;
81784 +
81785 + __u8 user_trans_type;
81786 + __u8 group_trans_type;
81787 + compat_uptr_t user_transitions;
81788 + compat_uptr_t group_transitions;
81789 + __u16 user_trans_num;
81790 + __u16 group_trans_num;
81791 +
81792 + __u32 sock_families[2];
81793 + __u32 ip_proto[8];
81794 + __u32 ip_type;
81795 + compat_uptr_t ips;
81796 + __u32 ip_num;
81797 + __u32 inaddr_any_override;
81798 +
81799 + __u32 crashes;
81800 + compat_ulong_t expires;
81801 +
81802 + compat_uptr_t parent_subject;
81803 + compat_uptr_t hash;
81804 + compat_uptr_t prev;
81805 + compat_uptr_t next;
81806 +
81807 + compat_uptr_t obj_hash;
81808 + __u32 obj_hash_size;
81809 + __u16 pax_flags;
81810 +};
81811 +
81812 +struct role_allowed_ip_compat {
81813 + __u32 addr;
81814 + __u32 netmask;
81815 +
81816 + compat_uptr_t prev;
81817 + compat_uptr_t next;
81818 +};
81819 +
81820 +struct role_transition_compat {
81821 + compat_uptr_t rolename;
81822 +
81823 + compat_uptr_t prev;
81824 + compat_uptr_t next;
81825 +};
81826 +
81827 +struct acl_role_label_compat {
81828 + compat_uptr_t rolename;
81829 + uid_t uidgid;
81830 + __u16 roletype;
81831 +
81832 + __u16 auth_attempts;
81833 + compat_ulong_t expires;
81834 +
81835 + compat_uptr_t root_label;
81836 + compat_uptr_t hash;
81837 +
81838 + compat_uptr_t prev;
81839 + compat_uptr_t next;
81840 +
81841 + compat_uptr_t transitions;
81842 + compat_uptr_t allowed_ips;
81843 + compat_uptr_t domain_children;
81844 + __u16 domain_child_num;
81845 +
81846 + umode_t umask;
81847 +
81848 + compat_uptr_t subj_hash;
81849 + __u32 subj_hash_size;
81850 +};
81851 +
81852 +struct user_acl_role_db_compat {
81853 + compat_uptr_t r_table;
81854 + __u32 num_pointers;
81855 + __u32 num_roles;
81856 + __u32 num_domain_children;
81857 + __u32 num_subjects;
81858 + __u32 num_objects;
81859 +};
81860 +
81861 +struct acl_object_label_compat {
81862 + compat_uptr_t filename;
81863 + compat_ino_t inode;
81864 + __u32 device;
81865 + __u32 mode;
81866 +
81867 + compat_uptr_t nested;
81868 + compat_uptr_t globbed;
81869 +
81870 + compat_uptr_t prev;
81871 + compat_uptr_t next;
81872 +};
81873 +
81874 +struct acl_ip_label_compat {
81875 + compat_uptr_t iface;
81876 + __u32 addr;
81877 + __u32 netmask;
81878 + __u16 low, high;
81879 + __u8 mode;
81880 + __u32 type;
81881 + __u32 proto[8];
81882 +
81883 + compat_uptr_t prev;
81884 + compat_uptr_t next;
81885 +};
81886 +
81887 +struct gr_arg_compat {
81888 + struct user_acl_role_db_compat role_db;
81889 + unsigned char pw[GR_PW_LEN];
81890 + unsigned char salt[GR_SALT_LEN];
81891 + unsigned char sum[GR_SHA_LEN];
81892 + unsigned char sp_role[GR_SPROLE_LEN];
81893 + compat_uptr_t sprole_pws;
81894 + __u32 segv_device;
81895 + compat_ino_t segv_inode;
81896 + uid_t segv_uid;
81897 + __u16 num_sprole_pws;
81898 + __u16 mode;
81899 +};
81900 +
81901 +struct gr_arg_wrapper_compat {
81902 + compat_uptr_t arg;
81903 + __u32 version;
81904 + __u32 size;
81905 +};
81906 +
81907 +#endif
81908 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81909 new file mode 100644
81910 index 0000000..323ecf2
81911 --- /dev/null
81912 +++ b/include/linux/gralloc.h
81913 @@ -0,0 +1,9 @@
81914 +#ifndef __GRALLOC_H
81915 +#define __GRALLOC_H
81916 +
81917 +void acl_free_all(void);
81918 +int acl_alloc_stack_init(unsigned long size);
81919 +void *acl_alloc(unsigned long len);
81920 +void *acl_alloc_num(unsigned long num, unsigned long len);
81921 +
81922 +#endif
81923 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81924 new file mode 100644
81925 index 0000000..be66033
81926 --- /dev/null
81927 +++ b/include/linux/grdefs.h
81928 @@ -0,0 +1,140 @@
81929 +#ifndef GRDEFS_H
81930 +#define GRDEFS_H
81931 +
81932 +/* Begin grsecurity status declarations */
81933 +
81934 +enum {
81935 + GR_READY = 0x01,
81936 + GR_STATUS_INIT = 0x00 // disabled state
81937 +};
81938 +
81939 +/* Begin ACL declarations */
81940 +
81941 +/* Role flags */
81942 +
81943 +enum {
81944 + GR_ROLE_USER = 0x0001,
81945 + GR_ROLE_GROUP = 0x0002,
81946 + GR_ROLE_DEFAULT = 0x0004,
81947 + GR_ROLE_SPECIAL = 0x0008,
81948 + GR_ROLE_AUTH = 0x0010,
81949 + GR_ROLE_NOPW = 0x0020,
81950 + GR_ROLE_GOD = 0x0040,
81951 + GR_ROLE_LEARN = 0x0080,
81952 + GR_ROLE_TPE = 0x0100,
81953 + GR_ROLE_DOMAIN = 0x0200,
81954 + GR_ROLE_PAM = 0x0400,
81955 + GR_ROLE_PERSIST = 0x0800
81956 +};
81957 +
81958 +/* ACL Subject and Object mode flags */
81959 +enum {
81960 + GR_DELETED = 0x80000000
81961 +};
81962 +
81963 +/* ACL Object-only mode flags */
81964 +enum {
81965 + GR_READ = 0x00000001,
81966 + GR_APPEND = 0x00000002,
81967 + GR_WRITE = 0x00000004,
81968 + GR_EXEC = 0x00000008,
81969 + GR_FIND = 0x00000010,
81970 + GR_INHERIT = 0x00000020,
81971 + GR_SETID = 0x00000040,
81972 + GR_CREATE = 0x00000080,
81973 + GR_DELETE = 0x00000100,
81974 + GR_LINK = 0x00000200,
81975 + GR_AUDIT_READ = 0x00000400,
81976 + GR_AUDIT_APPEND = 0x00000800,
81977 + GR_AUDIT_WRITE = 0x00001000,
81978 + GR_AUDIT_EXEC = 0x00002000,
81979 + GR_AUDIT_FIND = 0x00004000,
81980 + GR_AUDIT_INHERIT= 0x00008000,
81981 + GR_AUDIT_SETID = 0x00010000,
81982 + GR_AUDIT_CREATE = 0x00020000,
81983 + GR_AUDIT_DELETE = 0x00040000,
81984 + GR_AUDIT_LINK = 0x00080000,
81985 + GR_PTRACERD = 0x00100000,
81986 + GR_NOPTRACE = 0x00200000,
81987 + GR_SUPPRESS = 0x00400000,
81988 + GR_NOLEARN = 0x00800000,
81989 + GR_INIT_TRANSFER= 0x01000000
81990 +};
81991 +
81992 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81993 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81994 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81995 +
81996 +/* ACL subject-only mode flags */
81997 +enum {
81998 + GR_KILL = 0x00000001,
81999 + GR_VIEW = 0x00000002,
82000 + GR_PROTECTED = 0x00000004,
82001 + GR_LEARN = 0x00000008,
82002 + GR_OVERRIDE = 0x00000010,
82003 + /* just a placeholder, this mode is only used in userspace */
82004 + GR_DUMMY = 0x00000020,
82005 + GR_PROTSHM = 0x00000040,
82006 + GR_KILLPROC = 0x00000080,
82007 + GR_KILLIPPROC = 0x00000100,
82008 + /* just a placeholder, this mode is only used in userspace */
82009 + GR_NOTROJAN = 0x00000200,
82010 + GR_PROTPROCFD = 0x00000400,
82011 + GR_PROCACCT = 0x00000800,
82012 + GR_RELAXPTRACE = 0x00001000,
82013 + //GR_NESTED = 0x00002000,
82014 + GR_INHERITLEARN = 0x00004000,
82015 + GR_PROCFIND = 0x00008000,
82016 + GR_POVERRIDE = 0x00010000,
82017 + GR_KERNELAUTH = 0x00020000,
82018 + GR_ATSECURE = 0x00040000,
82019 + GR_SHMEXEC = 0x00080000
82020 +};
82021 +
82022 +enum {
82023 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82024 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82025 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82026 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82027 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82028 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82029 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82030 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82031 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82032 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82033 +};
82034 +
82035 +enum {
82036 + GR_ID_USER = 0x01,
82037 + GR_ID_GROUP = 0x02,
82038 +};
82039 +
82040 +enum {
82041 + GR_ID_ALLOW = 0x01,
82042 + GR_ID_DENY = 0x02,
82043 +};
82044 +
82045 +#define GR_CRASH_RES 31
82046 +#define GR_UIDTABLE_MAX 500
82047 +
82048 +/* begin resource learning section */
82049 +enum {
82050 + GR_RLIM_CPU_BUMP = 60,
82051 + GR_RLIM_FSIZE_BUMP = 50000,
82052 + GR_RLIM_DATA_BUMP = 10000,
82053 + GR_RLIM_STACK_BUMP = 1000,
82054 + GR_RLIM_CORE_BUMP = 10000,
82055 + GR_RLIM_RSS_BUMP = 500000,
82056 + GR_RLIM_NPROC_BUMP = 1,
82057 + GR_RLIM_NOFILE_BUMP = 5,
82058 + GR_RLIM_MEMLOCK_BUMP = 50000,
82059 + GR_RLIM_AS_BUMP = 500000,
82060 + GR_RLIM_LOCKS_BUMP = 2,
82061 + GR_RLIM_SIGPENDING_BUMP = 5,
82062 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82063 + GR_RLIM_NICE_BUMP = 1,
82064 + GR_RLIM_RTPRIO_BUMP = 1,
82065 + GR_RLIM_RTTIME_BUMP = 1000000
82066 +};
82067 +
82068 +#endif
82069 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82070 new file mode 100644
82071 index 0000000..fb1de5d
82072 --- /dev/null
82073 +++ b/include/linux/grinternal.h
82074 @@ -0,0 +1,230 @@
82075 +#ifndef __GRINTERNAL_H
82076 +#define __GRINTERNAL_H
82077 +
82078 +#ifdef CONFIG_GRKERNSEC
82079 +
82080 +#include <linux/fs.h>
82081 +#include <linux/mnt_namespace.h>
82082 +#include <linux/nsproxy.h>
82083 +#include <linux/gracl.h>
82084 +#include <linux/grdefs.h>
82085 +#include <linux/grmsg.h>
82086 +
82087 +void gr_add_learn_entry(const char *fmt, ...)
82088 + __attribute__ ((format (printf, 1, 2)));
82089 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82090 + const struct vfsmount *mnt);
82091 +__u32 gr_check_create(const struct dentry *new_dentry,
82092 + const struct dentry *parent,
82093 + const struct vfsmount *mnt, const __u32 mode);
82094 +int gr_check_protected_task(const struct task_struct *task);
82095 +__u32 to_gr_audit(const __u32 reqmode);
82096 +int gr_set_acls(const int type);
82097 +int gr_acl_is_enabled(void);
82098 +char gr_roletype_to_char(void);
82099 +
82100 +void gr_handle_alertkill(struct task_struct *task);
82101 +char *gr_to_filename(const struct dentry *dentry,
82102 + const struct vfsmount *mnt);
82103 +char *gr_to_filename1(const struct dentry *dentry,
82104 + const struct vfsmount *mnt);
82105 +char *gr_to_filename2(const struct dentry *dentry,
82106 + const struct vfsmount *mnt);
82107 +char *gr_to_filename3(const struct dentry *dentry,
82108 + const struct vfsmount *mnt);
82109 +
82110 +extern int grsec_enable_ptrace_readexec;
82111 +extern int grsec_enable_harden_ptrace;
82112 +extern int grsec_enable_link;
82113 +extern int grsec_enable_fifo;
82114 +extern int grsec_enable_execve;
82115 +extern int grsec_enable_shm;
82116 +extern int grsec_enable_execlog;
82117 +extern int grsec_enable_signal;
82118 +extern int grsec_enable_audit_ptrace;
82119 +extern int grsec_enable_forkfail;
82120 +extern int grsec_enable_time;
82121 +extern int grsec_enable_rofs;
82122 +extern int grsec_deny_new_usb;
82123 +extern int grsec_enable_chroot_shmat;
82124 +extern int grsec_enable_chroot_mount;
82125 +extern int grsec_enable_chroot_double;
82126 +extern int grsec_enable_chroot_pivot;
82127 +extern int grsec_enable_chroot_chdir;
82128 +extern int grsec_enable_chroot_chmod;
82129 +extern int grsec_enable_chroot_mknod;
82130 +extern int grsec_enable_chroot_fchdir;
82131 +extern int grsec_enable_chroot_nice;
82132 +extern int grsec_enable_chroot_execlog;
82133 +extern int grsec_enable_chroot_caps;
82134 +extern int grsec_enable_chroot_rename;
82135 +extern int grsec_enable_chroot_sysctl;
82136 +extern int grsec_enable_chroot_unix;
82137 +extern int grsec_enable_symlinkown;
82138 +extern kgid_t grsec_symlinkown_gid;
82139 +extern int grsec_enable_tpe;
82140 +extern kgid_t grsec_tpe_gid;
82141 +extern int grsec_enable_tpe_all;
82142 +extern int grsec_enable_tpe_invert;
82143 +extern int grsec_enable_socket_all;
82144 +extern kgid_t grsec_socket_all_gid;
82145 +extern int grsec_enable_socket_client;
82146 +extern kgid_t grsec_socket_client_gid;
82147 +extern int grsec_enable_socket_server;
82148 +extern kgid_t grsec_socket_server_gid;
82149 +extern kgid_t grsec_audit_gid;
82150 +extern int grsec_enable_group;
82151 +extern int grsec_enable_log_rwxmaps;
82152 +extern int grsec_enable_mount;
82153 +extern int grsec_enable_chdir;
82154 +extern int grsec_resource_logging;
82155 +extern int grsec_enable_blackhole;
82156 +extern int grsec_lastack_retries;
82157 +extern int grsec_enable_brute;
82158 +extern int grsec_enable_harden_ipc;
82159 +extern int grsec_lock;
82160 +
82161 +extern spinlock_t grsec_alert_lock;
82162 +extern unsigned long grsec_alert_wtime;
82163 +extern unsigned long grsec_alert_fyet;
82164 +
82165 +extern spinlock_t grsec_audit_lock;
82166 +
82167 +extern rwlock_t grsec_exec_file_lock;
82168 +
82169 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82170 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82171 + (tsk)->exec_file->f_path.mnt) : "/")
82172 +
82173 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82174 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82175 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82176 +
82177 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82178 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82179 + (tsk)->exec_file->f_path.mnt) : "/")
82180 +
82181 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82182 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82183 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82184 +
82185 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82186 +
82187 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82188 +
82189 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82190 +{
82191 + if (file1 && file2) {
82192 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82193 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82194 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82195 + return true;
82196 + }
82197 +
82198 + return false;
82199 +}
82200 +
82201 +#define GR_CHROOT_CAPS {{ \
82202 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82203 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82204 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82205 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82206 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82207 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82208 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82209 +
82210 +#define security_learn(normal_msg,args...) \
82211 +({ \
82212 + read_lock(&grsec_exec_file_lock); \
82213 + gr_add_learn_entry(normal_msg "\n", ## args); \
82214 + read_unlock(&grsec_exec_file_lock); \
82215 +})
82216 +
82217 +enum {
82218 + GR_DO_AUDIT,
82219 + GR_DONT_AUDIT,
82220 + /* used for non-audit messages that we shouldn't kill the task on */
82221 + GR_DONT_AUDIT_GOOD
82222 +};
82223 +
82224 +enum {
82225 + GR_TTYSNIFF,
82226 + GR_RBAC,
82227 + GR_RBAC_STR,
82228 + GR_STR_RBAC,
82229 + GR_RBAC_MODE2,
82230 + GR_RBAC_MODE3,
82231 + GR_FILENAME,
82232 + GR_SYSCTL_HIDDEN,
82233 + GR_NOARGS,
82234 + GR_ONE_INT,
82235 + GR_ONE_INT_TWO_STR,
82236 + GR_ONE_STR,
82237 + GR_STR_INT,
82238 + GR_TWO_STR_INT,
82239 + GR_TWO_INT,
82240 + GR_TWO_U64,
82241 + GR_THREE_INT,
82242 + GR_FIVE_INT_TWO_STR,
82243 + GR_TWO_STR,
82244 + GR_THREE_STR,
82245 + GR_FOUR_STR,
82246 + GR_STR_FILENAME,
82247 + GR_FILENAME_STR,
82248 + GR_FILENAME_TWO_INT,
82249 + GR_FILENAME_TWO_INT_STR,
82250 + GR_TEXTREL,
82251 + GR_PTRACE,
82252 + GR_RESOURCE,
82253 + GR_CAP,
82254 + GR_SIG,
82255 + GR_SIG2,
82256 + GR_CRASH1,
82257 + GR_CRASH2,
82258 + GR_PSACCT,
82259 + GR_RWXMAP,
82260 + GR_RWXMAPVMA
82261 +};
82262 +
82263 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82264 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82265 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82266 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82267 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82268 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82269 +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
82270 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82271 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82272 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82273 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82274 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82275 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82276 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82277 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82278 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82279 +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
82280 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82281 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82282 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82283 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82284 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82285 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82286 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82287 +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
82288 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82289 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82290 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82291 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82292 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82293 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82294 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82295 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82296 +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
82297 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82298 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82299 +
82300 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82301 +
82302 +#endif
82303 +
82304 +#endif
82305 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82306 new file mode 100644
82307 index 0000000..26ef560
82308 --- /dev/null
82309 +++ b/include/linux/grmsg.h
82310 @@ -0,0 +1,118 @@
82311 +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
82312 +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
82313 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82314 +#define GR_STOPMOD_MSG "denied modification of module state by "
82315 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82316 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82317 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82318 +#define GR_IOPL_MSG "denied use of iopl() by "
82319 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82320 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82321 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82322 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82323 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82324 +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
82325 +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
82326 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82327 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82328 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82329 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82330 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82331 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82332 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82333 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82334 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82335 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82336 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82337 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82338 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82339 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82340 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82341 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82342 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82343 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82344 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82345 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82346 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82347 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82348 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82349 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82350 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82351 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82352 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82353 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82354 +#define GR_CHROOT_RENAME_MSG "denied bad rename of %.950s out of a chroot by "
82355 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82356 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82357 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82358 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82359 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82360 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82361 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82362 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82363 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82364 +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
82365 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82366 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82367 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82368 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82369 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82370 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82371 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82372 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82373 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82374 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82375 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82376 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82377 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82378 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82379 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82380 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82381 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82382 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82383 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82384 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82385 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82386 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82387 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82388 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82389 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82390 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82391 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82392 +#define GR_TIME_MSG "time set by "
82393 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82394 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82395 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82396 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82397 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82398 +#define GR_BIND_MSG "denied bind() by "
82399 +#define GR_CONNECT_MSG "denied connect() by "
82400 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82401 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82402 +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
82403 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82404 +#define GR_CAP_ACL_MSG "use of %s denied for "
82405 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82406 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82407 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82408 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82409 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82410 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82411 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82412 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82413 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82414 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82415 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82416 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82417 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82418 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82419 +#define GR_VM86_MSG "denied use of vm86 by "
82420 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82421 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82422 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82423 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82424 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82425 +#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
82426 +#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
82427 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82428 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82429 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82430 new file mode 100644
82431 index 0000000..6c76fcb
82432 --- /dev/null
82433 +++ b/include/linux/grsecurity.h
82434 @@ -0,0 +1,249 @@
82435 +#ifndef GR_SECURITY_H
82436 +#define GR_SECURITY_H
82437 +#include <linux/fs.h>
82438 +#include <linux/fs_struct.h>
82439 +#include <linux/binfmts.h>
82440 +#include <linux/gracl.h>
82441 +
82442 +/* notify of brain-dead configs */
82443 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82444 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82445 +#endif
82446 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82447 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82448 +#endif
82449 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82450 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82451 +#endif
82452 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82453 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82454 +#endif
82455 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82456 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82457 +#endif
82458 +
82459 +int gr_handle_new_usb(void);
82460 +
82461 +void gr_handle_brute_attach(int dumpable);
82462 +void gr_handle_brute_check(void);
82463 +void gr_handle_kernel_exploit(void);
82464 +
82465 +char gr_roletype_to_char(void);
82466 +
82467 +int gr_proc_is_restricted(void);
82468 +
82469 +int gr_acl_enable_at_secure(void);
82470 +
82471 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82472 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82473 +
82474 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82475 +
82476 +void gr_del_task_from_ip_table(struct task_struct *p);
82477 +
82478 +int gr_pid_is_chrooted(struct task_struct *p);
82479 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82480 +int gr_handle_chroot_nice(void);
82481 +int gr_handle_chroot_sysctl(const int op);
82482 +int gr_handle_chroot_setpriority(struct task_struct *p,
82483 + const int niceval);
82484 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82485 +int gr_chroot_fhandle(void);
82486 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82487 + const struct vfsmount *mnt);
82488 +void gr_handle_chroot_chdir(const struct path *path);
82489 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82490 + const struct vfsmount *mnt, const int mode);
82491 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82492 + const struct vfsmount *mnt, const int mode);
82493 +int gr_handle_chroot_mount(const struct dentry *dentry,
82494 + const struct vfsmount *mnt,
82495 + const char *dev_name);
82496 +int gr_handle_chroot_pivot(void);
82497 +int gr_handle_chroot_unix(const pid_t pid);
82498 +
82499 +int gr_handle_rawio(const struct inode *inode);
82500 +
82501 +void gr_handle_ioperm(void);
82502 +void gr_handle_iopl(void);
82503 +void gr_handle_msr_write(void);
82504 +
82505 +umode_t gr_acl_umask(void);
82506 +
82507 +int gr_tpe_allow(const struct file *file);
82508 +
82509 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82510 +void gr_clear_chroot_entries(struct task_struct *task);
82511 +
82512 +void gr_log_forkfail(const int retval);
82513 +void gr_log_timechange(void);
82514 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82515 +void gr_log_chdir(const struct dentry *dentry,
82516 + const struct vfsmount *mnt);
82517 +void gr_log_chroot_exec(const struct dentry *dentry,
82518 + const struct vfsmount *mnt);
82519 +void gr_log_remount(const char *devname, const int retval);
82520 +void gr_log_unmount(const char *devname, const int retval);
82521 +void gr_log_mount(const char *from, struct path *to, const int retval);
82522 +void gr_log_textrel(struct vm_area_struct *vma);
82523 +void gr_log_ptgnustack(struct file *file);
82524 +void gr_log_rwxmmap(struct file *file);
82525 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82526 +
82527 +int gr_handle_follow_link(const struct inode *parent,
82528 + const struct inode *inode,
82529 + const struct dentry *dentry,
82530 + const struct vfsmount *mnt);
82531 +int gr_handle_fifo(const struct dentry *dentry,
82532 + const struct vfsmount *mnt,
82533 + const struct dentry *dir, const int flag,
82534 + const int acc_mode);
82535 +int gr_handle_hardlink(const struct dentry *dentry,
82536 + const struct vfsmount *mnt,
82537 + struct inode *inode,
82538 + const int mode, const struct filename *to);
82539 +
82540 +int gr_is_capable(const int cap);
82541 +int gr_is_capable_nolog(const int cap);
82542 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82543 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82544 +
82545 +void gr_copy_label(struct task_struct *tsk);
82546 +void gr_handle_crash(struct task_struct *task, const int sig);
82547 +int gr_handle_signal(const struct task_struct *p, const int sig);
82548 +int gr_check_crash_uid(const kuid_t uid);
82549 +int gr_check_protected_task(const struct task_struct *task);
82550 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82551 +int gr_acl_handle_mmap(const struct file *file,
82552 + const unsigned long prot);
82553 +int gr_acl_handle_mprotect(const struct file *file,
82554 + const unsigned long prot);
82555 +int gr_check_hidden_task(const struct task_struct *tsk);
82556 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82557 + const struct vfsmount *mnt);
82558 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82559 + const struct vfsmount *mnt);
82560 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82561 + const struct vfsmount *mnt, const int fmode);
82562 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82563 + const struct vfsmount *mnt, umode_t *mode);
82564 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82565 + const struct vfsmount *mnt);
82566 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82567 + const struct vfsmount *mnt);
82568 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82569 + const struct vfsmount *mnt);
82570 +int gr_handle_ptrace(struct task_struct *task, const long request);
82571 +int gr_handle_proc_ptrace(struct task_struct *task);
82572 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82573 + const struct vfsmount *mnt);
82574 +int gr_check_crash_exec(const struct file *filp);
82575 +int gr_acl_is_enabled(void);
82576 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82577 + const kgid_t gid);
82578 +int gr_set_proc_label(const struct dentry *dentry,
82579 + const struct vfsmount *mnt,
82580 + const int unsafe_flags);
82581 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82582 + const struct vfsmount *mnt);
82583 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82584 + const struct vfsmount *mnt, int acc_mode);
82585 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82586 + const struct dentry *p_dentry,
82587 + const struct vfsmount *p_mnt,
82588 + int open_flags, int acc_mode, const int imode);
82589 +void gr_handle_create(const struct dentry *dentry,
82590 + const struct vfsmount *mnt);
82591 +void gr_handle_proc_create(const struct dentry *dentry,
82592 + const struct inode *inode);
82593 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82594 + const struct dentry *parent_dentry,
82595 + const struct vfsmount *parent_mnt,
82596 + const int mode);
82597 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82598 + const struct dentry *parent_dentry,
82599 + const struct vfsmount *parent_mnt);
82600 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82601 + const struct vfsmount *mnt);
82602 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82603 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82604 + const struct vfsmount *mnt);
82605 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82606 + const struct dentry *parent_dentry,
82607 + const struct vfsmount *parent_mnt,
82608 + const struct filename *from);
82609 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82610 + const struct dentry *parent_dentry,
82611 + const struct vfsmount *parent_mnt,
82612 + const struct dentry *old_dentry,
82613 + const struct vfsmount *old_mnt, const struct filename *to);
82614 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82615 +int gr_acl_handle_rename(struct dentry *new_dentry,
82616 + struct dentry *parent_dentry,
82617 + const struct vfsmount *parent_mnt,
82618 + struct dentry *old_dentry,
82619 + struct inode *old_parent_inode,
82620 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82621 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82622 + struct dentry *old_dentry,
82623 + struct dentry *new_dentry,
82624 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82625 +__u32 gr_check_link(const struct dentry *new_dentry,
82626 + const struct dentry *parent_dentry,
82627 + const struct vfsmount *parent_mnt,
82628 + const struct dentry *old_dentry,
82629 + const struct vfsmount *old_mnt);
82630 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82631 + const unsigned int namelen, const ino_t ino);
82632 +
82633 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82634 + const struct vfsmount *mnt);
82635 +void gr_acl_handle_exit(void);
82636 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82637 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82638 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82639 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82640 +void gr_audit_ptrace(struct task_struct *task);
82641 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82642 +void gr_put_exec_file(struct task_struct *task);
82643 +
82644 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82645 +
82646 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82647 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82648 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
82649 + struct dentry *newdentry, struct vfsmount *newmnt);
82650 +
82651 +#ifdef CONFIG_GRKERNSEC_RESLOG
82652 +extern void gr_log_resource(const struct task_struct *task, const int res,
82653 + const unsigned long wanted, const int gt);
82654 +#else
82655 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82656 + const unsigned long wanted, const int gt)
82657 +{
82658 +}
82659 +#endif
82660 +
82661 +#ifdef CONFIG_GRKERNSEC
82662 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82663 +void gr_handle_vm86(void);
82664 +void gr_handle_mem_readwrite(u64 from, u64 to);
82665 +
82666 +void gr_log_badprocpid(const char *entry);
82667 +
82668 +extern int grsec_enable_dmesg;
82669 +extern int grsec_disable_privio;
82670 +
82671 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82672 +extern kgid_t grsec_proc_gid;
82673 +#endif
82674 +
82675 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82676 +extern int grsec_enable_chroot_findtask;
82677 +#endif
82678 +#ifdef CONFIG_GRKERNSEC_SETXID
82679 +extern int grsec_enable_setxid;
82680 +#endif
82681 +#endif
82682 +
82683 +#endif
82684 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82685 new file mode 100644
82686 index 0000000..e7ffaaf
82687 --- /dev/null
82688 +++ b/include/linux/grsock.h
82689 @@ -0,0 +1,19 @@
82690 +#ifndef __GRSOCK_H
82691 +#define __GRSOCK_H
82692 +
82693 +extern void gr_attach_curr_ip(const struct sock *sk);
82694 +extern int gr_handle_sock_all(const int family, const int type,
82695 + const int protocol);
82696 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82697 +extern int gr_handle_sock_server_other(const struct sock *sck);
82698 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82699 +extern int gr_search_connect(struct socket * sock,
82700 + struct sockaddr_in * addr);
82701 +extern int gr_search_bind(struct socket * sock,
82702 + struct sockaddr_in * addr);
82703 +extern int gr_search_listen(struct socket * sock);
82704 +extern int gr_search_accept(struct socket * sock);
82705 +extern int gr_search_socket(const int domain, const int type,
82706 + const int protocol);
82707 +
82708 +#endif
82709 diff --git a/include/linux/hash.h b/include/linux/hash.h
82710 index d0494c3..69b7715 100644
82711 --- a/include/linux/hash.h
82712 +++ b/include/linux/hash.h
82713 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82714 struct fast_hash_ops {
82715 u32 (*hash)(const void *data, u32 len, u32 seed);
82716 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82717 -};
82718 +} __no_const;
82719
82720 /**
82721 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82722 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82723 index 9286a46..373f27f 100644
82724 --- a/include/linux/highmem.h
82725 +++ b/include/linux/highmem.h
82726 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82727 kunmap_atomic(kaddr);
82728 }
82729
82730 +static inline void sanitize_highpage(struct page *page)
82731 +{
82732 + void *kaddr;
82733 + unsigned long flags;
82734 +
82735 + local_irq_save(flags);
82736 + kaddr = kmap_atomic(page);
82737 + clear_page(kaddr);
82738 + kunmap_atomic(kaddr);
82739 + local_irq_restore(flags);
82740 +}
82741 +
82742 static inline void zero_user_segments(struct page *page,
82743 unsigned start1, unsigned end1,
82744 unsigned start2, unsigned end2)
82745 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82746 index 1c7b89a..7dda400 100644
82747 --- a/include/linux/hwmon-sysfs.h
82748 +++ b/include/linux/hwmon-sysfs.h
82749 @@ -25,7 +25,8 @@
82750 struct sensor_device_attribute{
82751 struct device_attribute dev_attr;
82752 int index;
82753 -};
82754 +} __do_const;
82755 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82756 #define to_sensor_dev_attr(_dev_attr) \
82757 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82758
82759 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82760 struct device_attribute dev_attr;
82761 u8 index;
82762 u8 nr;
82763 -};
82764 +} __do_const;
82765 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82766 #define to_sensor_dev_attr_2(_dev_attr) \
82767 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82768
82769 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82770 index b556e0a..c10a515 100644
82771 --- a/include/linux/i2c.h
82772 +++ b/include/linux/i2c.h
82773 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82774 /* To determine what the adapter supports */
82775 u32 (*functionality) (struct i2c_adapter *);
82776 };
82777 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82778
82779 /**
82780 * struct i2c_bus_recovery_info - I2C bus recovery information
82781 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82782 index d23c3c2..eb63c81 100644
82783 --- a/include/linux/i2o.h
82784 +++ b/include/linux/i2o.h
82785 @@ -565,7 +565,7 @@ struct i2o_controller {
82786 struct i2o_device *exec; /* Executive */
82787 #if BITS_PER_LONG == 64
82788 spinlock_t context_list_lock; /* lock for context_list */
82789 - atomic_t context_list_counter; /* needed for unique contexts */
82790 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82791 struct list_head context_list; /* list of context id's
82792 and pointers */
82793 #endif
82794 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82795 index aff7ad8..3942bbd 100644
82796 --- a/include/linux/if_pppox.h
82797 +++ b/include/linux/if_pppox.h
82798 @@ -76,7 +76,7 @@ struct pppox_proto {
82799 int (*ioctl)(struct socket *sock, unsigned int cmd,
82800 unsigned long arg);
82801 struct module *owner;
82802 -};
82803 +} __do_const;
82804
82805 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82806 extern void unregister_pppox_proto(int proto_num);
82807 diff --git a/include/linux/init.h b/include/linux/init.h
82808 index 2df8e8d..3e1280d 100644
82809 --- a/include/linux/init.h
82810 +++ b/include/linux/init.h
82811 @@ -37,9 +37,17 @@
82812 * section.
82813 */
82814
82815 +#define add_init_latent_entropy __latent_entropy
82816 +
82817 +#ifdef CONFIG_MEMORY_HOTPLUG
82818 +#define add_meminit_latent_entropy
82819 +#else
82820 +#define add_meminit_latent_entropy __latent_entropy
82821 +#endif
82822 +
82823 /* These are for everybody (although not all archs will actually
82824 discard it in modules) */
82825 -#define __init __section(.init.text) __cold notrace
82826 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82827 #define __initdata __section(.init.data)
82828 #define __initconst __constsection(.init.rodata)
82829 #define __exitdata __section(.exit.data)
82830 @@ -100,7 +108,7 @@
82831 #define __cpuexitconst
82832
82833 /* Used for MEMORY_HOTPLUG */
82834 -#define __meminit __section(.meminit.text) __cold notrace
82835 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82836 #define __meminitdata __section(.meminit.data)
82837 #define __meminitconst __constsection(.meminit.rodata)
82838 #define __memexit __section(.memexit.text) __exitused __cold notrace
82839 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82840 index 77fc43f..73caf92 100644
82841 --- a/include/linux/init_task.h
82842 +++ b/include/linux/init_task.h
82843 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82844
82845 #define INIT_TASK_COMM "swapper"
82846
82847 +#ifdef CONFIG_X86
82848 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82849 +#else
82850 +#define INIT_TASK_THREAD_INFO
82851 +#endif
82852 +
82853 #ifdef CONFIG_RT_MUTEXES
82854 # define INIT_RT_MUTEXES(tsk) \
82855 .pi_waiters = RB_ROOT, \
82856 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82857 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82858 .comm = INIT_TASK_COMM, \
82859 .thread = INIT_THREAD, \
82860 + INIT_TASK_THREAD_INFO \
82861 .fs = &init_fs, \
82862 .files = &init_files, \
82863 .signal = &init_signals, \
82864 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82865 index 69517a2..6b12d37 100644
82866 --- a/include/linux/interrupt.h
82867 +++ b/include/linux/interrupt.h
82868 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82869
82870 struct softirq_action
82871 {
82872 - void (*action)(struct softirq_action *);
82873 -};
82874 + void (*action)(void);
82875 +} __no_const;
82876
82877 asmlinkage void do_softirq(void);
82878 asmlinkage void __do_softirq(void);
82879 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82880 }
82881 #endif
82882
82883 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82884 +extern void open_softirq(int nr, void (*action)(void));
82885 extern void softirq_init(void);
82886 extern void __raise_softirq_irqoff(unsigned int nr);
82887
82888 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82889 index e6a7c9f..5804745 100644
82890 --- a/include/linux/iommu.h
82891 +++ b/include/linux/iommu.h
82892 @@ -133,7 +133,7 @@ struct iommu_ops {
82893 u32 (*domain_get_windows)(struct iommu_domain *domain);
82894
82895 unsigned long pgsize_bitmap;
82896 -};
82897 +} __do_const;
82898
82899 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82900 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82901 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82902 index 2c525022..345b106 100644
82903 --- a/include/linux/ioport.h
82904 +++ b/include/linux/ioport.h
82905 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82906 int adjust_resource(struct resource *res, resource_size_t start,
82907 resource_size_t size);
82908 resource_size_t resource_alignment(struct resource *res);
82909 -static inline resource_size_t resource_size(const struct resource *res)
82910 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82911 {
82912 return res->end - res->start + 1;
82913 }
82914 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82915 index 35e7eca..6afb7ad 100644
82916 --- a/include/linux/ipc_namespace.h
82917 +++ b/include/linux/ipc_namespace.h
82918 @@ -69,7 +69,7 @@ struct ipc_namespace {
82919 struct user_namespace *user_ns;
82920
82921 unsigned int proc_inum;
82922 -};
82923 +} __randomize_layout;
82924
82925 extern struct ipc_namespace init_ipc_ns;
82926 extern atomic_t nr_ipc_ns;
82927 diff --git a/include/linux/irq.h b/include/linux/irq.h
82928 index 03f48d9..e86af0c 100644
82929 --- a/include/linux/irq.h
82930 +++ b/include/linux/irq.h
82931 @@ -352,7 +352,8 @@ struct irq_chip {
82932 void (*irq_release_resources)(struct irq_data *data);
82933
82934 unsigned long flags;
82935 -};
82936 +} __do_const;
82937 +typedef struct irq_chip __no_const irq_chip_no_const;
82938
82939 /*
82940 * irq_chip specific flags
82941 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82942 index 13eed92..3261c86 100644
82943 --- a/include/linux/irqchip/arm-gic.h
82944 +++ b/include/linux/irqchip/arm-gic.h
82945 @@ -91,9 +91,11 @@
82946
82947 #ifndef __ASSEMBLY__
82948
82949 +#include <linux/irq.h>
82950 +
82951 struct device_node;
82952
82953 -extern struct irq_chip gic_arch_extn;
82954 +extern irq_chip_no_const gic_arch_extn;
82955
82956 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82957 u32 offset, struct device_node *);
82958 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82959 index c367cbd..c9b79e6 100644
82960 --- a/include/linux/jiffies.h
82961 +++ b/include/linux/jiffies.h
82962 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82963 /*
82964 * Convert various time units to each other:
82965 */
82966 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82967 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82968 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82969 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82970
82971 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82972 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82973 {
82974 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82975 }
82976
82977 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82978 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82979 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82980 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82981 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82982 extern void jiffies_to_timespec(const unsigned long jiffies,
82983 - struct timespec *value);
82984 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82985 + struct timespec *value) __intentional_overflow(-1);
82986 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82987 extern void jiffies_to_timeval(const unsigned long jiffies,
82988 struct timeval *value);
82989
82990 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82991 index 6883e19..e854fcb 100644
82992 --- a/include/linux/kallsyms.h
82993 +++ b/include/linux/kallsyms.h
82994 @@ -15,7 +15,8 @@
82995
82996 struct module;
82997
82998 -#ifdef CONFIG_KALLSYMS
82999 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83000 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83001 /* Lookup the address for a symbol. Returns 0 if not found. */
83002 unsigned long kallsyms_lookup_name(const char *name);
83003
83004 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83005 /* Stupid that this does nothing, but I didn't create this mess. */
83006 #define __print_symbol(fmt, addr)
83007 #endif /*CONFIG_KALLSYMS*/
83008 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83009 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83010 +extern unsigned long kallsyms_lookup_name(const char *name);
83011 +extern void __print_symbol(const char *fmt, unsigned long address);
83012 +extern int sprint_backtrace(char *buffer, unsigned long address);
83013 +extern int sprint_symbol(char *buffer, unsigned long address);
83014 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83015 +const char *kallsyms_lookup(unsigned long addr,
83016 + unsigned long *symbolsize,
83017 + unsigned long *offset,
83018 + char **modname, char *namebuf);
83019 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83020 + unsigned long *symbolsize,
83021 + unsigned long *offset);
83022 +#endif
83023
83024 /* This macro allows us to keep printk typechecking */
83025 static __printf(1, 2)
83026 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83027 index ff9f1d3..6712be5 100644
83028 --- a/include/linux/key-type.h
83029 +++ b/include/linux/key-type.h
83030 @@ -152,7 +152,7 @@ struct key_type {
83031 /* internal fields */
83032 struct list_head link; /* link in types list */
83033 struct lock_class_key lock_class; /* key->sem lock class */
83034 -};
83035 +} __do_const;
83036
83037 extern struct key_type key_type_keyring;
83038
83039 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83040 index e465bb1..19f605fd 100644
83041 --- a/include/linux/kgdb.h
83042 +++ b/include/linux/kgdb.h
83043 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83044 extern int kgdb_io_module_registered;
83045
83046 extern atomic_t kgdb_setting_breakpoint;
83047 -extern atomic_t kgdb_cpu_doing_single_step;
83048 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83049
83050 extern struct task_struct *kgdb_usethread;
83051 extern struct task_struct *kgdb_contthread;
83052 @@ -254,7 +254,7 @@ struct kgdb_arch {
83053 void (*correct_hw_break)(void);
83054
83055 void (*enable_nmi)(bool on);
83056 -};
83057 +} __do_const;
83058
83059 /**
83060 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83061 @@ -279,7 +279,7 @@ struct kgdb_io {
83062 void (*pre_exception) (void);
83063 void (*post_exception) (void);
83064 int is_console;
83065 -};
83066 +} __do_const;
83067
83068 extern struct kgdb_arch arch_kgdb_ops;
83069
83070 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83071 index 0555cc6..40116ce 100644
83072 --- a/include/linux/kmod.h
83073 +++ b/include/linux/kmod.h
83074 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83075 * usually useless though. */
83076 extern __printf(2, 3)
83077 int __request_module(bool wait, const char *name, ...);
83078 +extern __printf(3, 4)
83079 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83080 #define request_module(mod...) __request_module(true, mod)
83081 #define request_module_nowait(mod...) __request_module(false, mod)
83082 #define try_then_request_module(x, mod...) \
83083 @@ -57,6 +59,9 @@ struct subprocess_info {
83084 struct work_struct work;
83085 struct completion *complete;
83086 char *path;
83087 +#ifdef CONFIG_GRKERNSEC
83088 + char *origpath;
83089 +#endif
83090 char **argv;
83091 char **envp;
83092 int wait;
83093 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83094 index 2d61b90..a1d0a13 100644
83095 --- a/include/linux/kobject.h
83096 +++ b/include/linux/kobject.h
83097 @@ -118,7 +118,7 @@ struct kobj_type {
83098 struct attribute **default_attrs;
83099 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83100 const void *(*namespace)(struct kobject *kobj);
83101 -};
83102 +} __do_const;
83103
83104 struct kobj_uevent_env {
83105 char *argv[3];
83106 @@ -142,6 +142,7 @@ struct kobj_attribute {
83107 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83108 const char *buf, size_t count);
83109 };
83110 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83111
83112 extern const struct sysfs_ops kobj_sysfs_ops;
83113
83114 @@ -169,7 +170,7 @@ struct kset {
83115 spinlock_t list_lock;
83116 struct kobject kobj;
83117 const struct kset_uevent_ops *uevent_ops;
83118 -};
83119 +} __randomize_layout;
83120
83121 extern void kset_init(struct kset *kset);
83122 extern int __must_check kset_register(struct kset *kset);
83123 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83124 index df32d25..fb52e27 100644
83125 --- a/include/linux/kobject_ns.h
83126 +++ b/include/linux/kobject_ns.h
83127 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83128 const void *(*netlink_ns)(struct sock *sk);
83129 const void *(*initial_ns)(void);
83130 void (*drop_ns)(void *);
83131 -};
83132 +} __do_const;
83133
83134 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83135 int kobj_ns_type_registered(enum kobj_ns_type type);
83136 diff --git a/include/linux/kref.h b/include/linux/kref.h
83137 index 484604d..0f6c5b6 100644
83138 --- a/include/linux/kref.h
83139 +++ b/include/linux/kref.h
83140 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83141 static inline int kref_sub(struct kref *kref, unsigned int count,
83142 void (*release)(struct kref *kref))
83143 {
83144 - WARN_ON(release == NULL);
83145 + BUG_ON(release == NULL);
83146
83147 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83148 release(kref);
83149 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83150 index a6059bd..8126d5c 100644
83151 --- a/include/linux/kvm_host.h
83152 +++ b/include/linux/kvm_host.h
83153 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
83154 {
83155 }
83156 #endif
83157 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83158 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83159 struct module *module);
83160 void kvm_exit(void);
83161
83162 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83163 struct kvm_guest_debug *dbg);
83164 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83165
83166 -int kvm_arch_init(void *opaque);
83167 +int kvm_arch_init(const void *opaque);
83168 void kvm_arch_exit(void);
83169
83170 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83171 diff --git a/include/linux/libata.h b/include/linux/libata.h
83172 index fe0bf8d..c511ca6 100644
83173 --- a/include/linux/libata.h
83174 +++ b/include/linux/libata.h
83175 @@ -977,7 +977,7 @@ struct ata_port_operations {
83176 * fields must be pointers.
83177 */
83178 const struct ata_port_operations *inherits;
83179 -};
83180 +} __do_const;
83181
83182 struct ata_port_info {
83183 unsigned long flags;
83184 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83185 index a6a42dd..6c5ebce 100644
83186 --- a/include/linux/linkage.h
83187 +++ b/include/linux/linkage.h
83188 @@ -36,6 +36,7 @@
83189 #endif
83190
83191 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83192 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83193 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83194
83195 /*
83196 diff --git a/include/linux/list.h b/include/linux/list.h
83197 index f33f831..1ffe5e2 100644
83198 --- a/include/linux/list.h
83199 +++ b/include/linux/list.h
83200 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83201 extern void list_del(struct list_head *entry);
83202 #endif
83203
83204 +extern void __pax_list_add(struct list_head *new,
83205 + struct list_head *prev,
83206 + struct list_head *next);
83207 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83208 +{
83209 + __pax_list_add(new, head, head->next);
83210 +}
83211 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83212 +{
83213 + __pax_list_add(new, head->prev, head);
83214 +}
83215 +extern void pax_list_del(struct list_head *entry);
83216 +
83217 /**
83218 * list_replace - replace old entry by new one
83219 * @old : the element to be replaced
83220 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83221 INIT_LIST_HEAD(entry);
83222 }
83223
83224 +extern void pax_list_del_init(struct list_head *entry);
83225 +
83226 /**
83227 * list_move - delete from one list and add as another's head
83228 * @list: the entry to move
83229 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83230 index 4bfde0e..d6e2e09 100644
83231 --- a/include/linux/lockref.h
83232 +++ b/include/linux/lockref.h
83233 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83234 return ((int)l->count < 0);
83235 }
83236
83237 +static inline unsigned int __lockref_read(struct lockref *lockref)
83238 +{
83239 + return lockref->count;
83240 +}
83241 +
83242 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83243 +{
83244 + lockref->count = count;
83245 +}
83246 +
83247 +static inline void __lockref_inc(struct lockref *lockref)
83248 +{
83249 +
83250 +#ifdef CONFIG_PAX_REFCOUNT
83251 + atomic_inc((atomic_t *)&lockref->count);
83252 +#else
83253 + lockref->count++;
83254 +#endif
83255 +
83256 +}
83257 +
83258 +static inline void __lockref_dec(struct lockref *lockref)
83259 +{
83260 +
83261 +#ifdef CONFIG_PAX_REFCOUNT
83262 + atomic_dec((atomic_t *)&lockref->count);
83263 +#else
83264 + lockref->count--;
83265 +#endif
83266 +
83267 +}
83268 +
83269 #endif /* __LINUX_LOCKREF_H */
83270 diff --git a/include/linux/math64.h b/include/linux/math64.h
83271 index c45c089..298841c 100644
83272 --- a/include/linux/math64.h
83273 +++ b/include/linux/math64.h
83274 @@ -15,7 +15,7 @@
83275 * This is commonly provided by 32bit archs to provide an optimized 64bit
83276 * divide.
83277 */
83278 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83279 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83280 {
83281 *remainder = dividend % divisor;
83282 return dividend / divisor;
83283 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83284 /**
83285 * div64_u64 - unsigned 64bit divide with 64bit divisor
83286 */
83287 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83288 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83289 {
83290 return dividend / divisor;
83291 }
83292 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83293 #define div64_ul(x, y) div_u64((x), (y))
83294
83295 #ifndef div_u64_rem
83296 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83297 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83298 {
83299 *remainder = do_div(dividend, divisor);
83300 return dividend;
83301 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83302 #endif
83303
83304 #ifndef div64_u64
83305 -extern u64 div64_u64(u64 dividend, u64 divisor);
83306 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83307 #endif
83308
83309 #ifndef div64_s64
83310 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83311 * divide.
83312 */
83313 #ifndef div_u64
83314 -static inline u64 div_u64(u64 dividend, u32 divisor)
83315 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83316 {
83317 u32 remainder;
83318 return div_u64_rem(dividend, divisor, &remainder);
83319 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83320 index 3d385c8..deacb6a 100644
83321 --- a/include/linux/mempolicy.h
83322 +++ b/include/linux/mempolicy.h
83323 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83324 }
83325
83326 #define vma_policy(vma) ((vma)->vm_policy)
83327 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83328 +{
83329 + vma->vm_policy = pol;
83330 +}
83331
83332 static inline void mpol_get(struct mempolicy *pol)
83333 {
83334 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83335 }
83336
83337 #define vma_policy(vma) NULL
83338 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83339 +{
83340 +}
83341
83342 static inline int
83343 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83344 diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
83345 index 37e4404..26ebbd0 100644
83346 --- a/include/linux/mlx4/device.h
83347 +++ b/include/linux/mlx4/device.h
83348 @@ -97,7 +97,7 @@ enum {
83349 MLX4_MAX_NUM_PF = 16,
83350 MLX4_MAX_NUM_VF = 64,
83351 MLX4_MAX_NUM_VF_P_PORT = 64,
83352 - MLX4_MFUNC_MAX = 80,
83353 + MLX4_MFUNC_MAX = 128,
83354 MLX4_MAX_EQ_NUM = 1024,
83355 MLX4_MFUNC_EQ_NUM = 4,
83356 MLX4_MFUNC_MAX_EQES = 8,
83357 diff --git a/include/linux/mm.h b/include/linux/mm.h
83358 index 86a977b..8122960 100644
83359 --- a/include/linux/mm.h
83360 +++ b/include/linux/mm.h
83361 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83362 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83363 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83364 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83365 +
83366 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83367 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83368 +#endif
83369 +
83370 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83371
83372 #ifdef CONFIG_MEM_SOFT_DIRTY
83373 @@ -238,8 +243,8 @@ struct vm_operations_struct {
83374 /* called by access_process_vm when get_user_pages() fails, typically
83375 * for use by special VMAs that can switch between memory and hardware
83376 */
83377 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83378 - void *buf, int len, int write);
83379 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83380 + void *buf, size_t len, int write);
83381
83382 /* Called by the /proc/PID/maps code to ask the vma whether it
83383 * has a special name. Returning non-NULL will also cause this
83384 @@ -275,6 +280,7 @@ struct vm_operations_struct {
83385 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83386 unsigned long size, pgoff_t pgoff);
83387 };
83388 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83389
83390 struct mmu_gather;
83391 struct inode;
83392 @@ -1167,8 +1173,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83393 unsigned long *pfn);
83394 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83395 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83396 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83397 - void *buf, int len, int write);
83398 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83399 + void *buf, size_t len, int write);
83400
83401 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83402 loff_t const holebegin, loff_t const holelen)
83403 @@ -1208,9 +1214,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83404 }
83405 #endif
83406
83407 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83408 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83409 - void *buf, int len, int write);
83410 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83411 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83412 + void *buf, size_t len, int write);
83413
83414 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83415 unsigned long start, unsigned long nr_pages,
83416 @@ -1242,34 +1248,6 @@ int set_page_dirty_lock(struct page *page);
83417 int clear_page_dirty_for_io(struct page *page);
83418 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83419
83420 -/* Is the vma a continuation of the stack vma above it? */
83421 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83422 -{
83423 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83424 -}
83425 -
83426 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83427 - unsigned long addr)
83428 -{
83429 - return (vma->vm_flags & VM_GROWSDOWN) &&
83430 - (vma->vm_start == addr) &&
83431 - !vma_growsdown(vma->vm_prev, addr);
83432 -}
83433 -
83434 -/* Is the vma a continuation of the stack vma below it? */
83435 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83436 -{
83437 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83438 -}
83439 -
83440 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83441 - unsigned long addr)
83442 -{
83443 - return (vma->vm_flags & VM_GROWSUP) &&
83444 - (vma->vm_end == addr) &&
83445 - !vma_growsup(vma->vm_next, addr);
83446 -}
83447 -
83448 extern struct task_struct *task_of_stack(struct task_struct *task,
83449 struct vm_area_struct *vma, bool in_group);
83450
83451 @@ -1387,8 +1365,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83452 {
83453 return 0;
83454 }
83455 +
83456 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83457 + unsigned long address)
83458 +{
83459 + return 0;
83460 +}
83461 #else
83462 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83463 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83464 #endif
83465
83466 #ifdef __PAGETABLE_PMD_FOLDED
83467 @@ -1397,8 +1382,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83468 {
83469 return 0;
83470 }
83471 +
83472 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83473 + unsigned long address)
83474 +{
83475 + return 0;
83476 +}
83477 #else
83478 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83479 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83480 #endif
83481
83482 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83483 @@ -1416,11 +1408,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83484 NULL: pud_offset(pgd, address);
83485 }
83486
83487 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83488 +{
83489 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83490 + NULL: pud_offset(pgd, address);
83491 +}
83492 +
83493 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83494 {
83495 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83496 NULL: pmd_offset(pud, address);
83497 }
83498 +
83499 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83500 +{
83501 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83502 + NULL: pmd_offset(pud, address);
83503 +}
83504 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83505
83506 #if USE_SPLIT_PTE_PTLOCKS
83507 @@ -1803,12 +1807,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83508 bool *need_rmap_locks);
83509 extern void exit_mmap(struct mm_struct *);
83510
83511 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83512 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83513 + const unsigned long wanted, const int gt);
83514 +#else
83515 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83516 + const unsigned long wanted, const int gt)
83517 +{
83518 +}
83519 +#endif
83520 +
83521 static inline int check_data_rlimit(unsigned long rlim,
83522 unsigned long new,
83523 unsigned long start,
83524 unsigned long end_data,
83525 unsigned long start_data)
83526 {
83527 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83528 if (rlim < RLIM_INFINITY) {
83529 if (((new - start) + (end_data - start_data)) > rlim)
83530 return -ENOSPC;
83531 @@ -1833,7 +1848,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83532 unsigned long addr, unsigned long len,
83533 unsigned long flags, struct page **pages);
83534
83535 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83536 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83537
83538 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83539 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83540 @@ -1841,6 +1856,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83541 unsigned long len, unsigned long prot, unsigned long flags,
83542 unsigned long pgoff, unsigned long *populate);
83543 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83544 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83545
83546 #ifdef CONFIG_MMU
83547 extern int __mm_populate(unsigned long addr, unsigned long len,
83548 @@ -1869,10 +1885,11 @@ struct vm_unmapped_area_info {
83549 unsigned long high_limit;
83550 unsigned long align_mask;
83551 unsigned long align_offset;
83552 + unsigned long threadstack_offset;
83553 };
83554
83555 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83556 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83557 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83558 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83559
83560 /*
83561 * Search for an unmapped address range.
83562 @@ -1884,7 +1901,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83563 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83564 */
83565 static inline unsigned long
83566 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83567 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83568 {
83569 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83570 return unmapped_area(info);
83571 @@ -1946,6 +1963,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83572 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83573 struct vm_area_struct **pprev);
83574
83575 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83576 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83577 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83578 +
83579 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83580 NULL if none. Assume start_addr < end_addr. */
83581 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83582 @@ -1975,10 +1996,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83583 }
83584
83585 #ifdef CONFIG_MMU
83586 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83587 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83588 void vma_set_page_prot(struct vm_area_struct *vma);
83589 #else
83590 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83591 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83592 {
83593 return __pgprot(0);
83594 }
83595 @@ -2040,6 +2061,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83596 static inline void vm_stat_account(struct mm_struct *mm,
83597 unsigned long flags, struct file *file, long pages)
83598 {
83599 +
83600 +#ifdef CONFIG_PAX_RANDMMAP
83601 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83602 +#endif
83603 +
83604 mm->total_vm += pages;
83605 }
83606 #endif /* CONFIG_PROC_FS */
83607 @@ -2128,7 +2154,7 @@ extern int unpoison_memory(unsigned long pfn);
83608 extern int sysctl_memory_failure_early_kill;
83609 extern int sysctl_memory_failure_recovery;
83610 extern void shake_page(struct page *p, int access);
83611 -extern atomic_long_t num_poisoned_pages;
83612 +extern atomic_long_unchecked_t num_poisoned_pages;
83613 extern int soft_offline_page(struct page *page, int flags);
83614
83615 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83616 @@ -2163,5 +2189,11 @@ void __init setup_nr_node_ids(void);
83617 static inline void setup_nr_node_ids(void) {}
83618 #endif
83619
83620 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83621 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83622 +#else
83623 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83624 +#endif
83625 +
83626 #endif /* __KERNEL__ */
83627 #endif /* _LINUX_MM_H */
83628 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83629 index 6e0b286..90d9c0d 100644
83630 --- a/include/linux/mm_types.h
83631 +++ b/include/linux/mm_types.h
83632 @@ -308,7 +308,9 @@ struct vm_area_struct {
83633 #ifdef CONFIG_NUMA
83634 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83635 #endif
83636 -};
83637 +
83638 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83639 +} __randomize_layout;
83640
83641 struct core_thread {
83642 struct task_struct *task;
83643 @@ -454,7 +456,25 @@ struct mm_struct {
83644 bool tlb_flush_pending;
83645 #endif
83646 struct uprobes_state uprobes_state;
83647 -};
83648 +
83649 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83650 + unsigned long pax_flags;
83651 +#endif
83652 +
83653 +#ifdef CONFIG_PAX_DLRESOLVE
83654 + unsigned long call_dl_resolve;
83655 +#endif
83656 +
83657 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83658 + unsigned long call_syscall;
83659 +#endif
83660 +
83661 +#ifdef CONFIG_PAX_ASLR
83662 + unsigned long delta_mmap; /* randomized offset */
83663 + unsigned long delta_stack; /* randomized offset */
83664 +#endif
83665 +
83666 +} __randomize_layout;
83667
83668 static inline void mm_init_cpumask(struct mm_struct *mm)
83669 {
83670 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83671 index c5d5278..f0b68c8 100644
83672 --- a/include/linux/mmiotrace.h
83673 +++ b/include/linux/mmiotrace.h
83674 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83675 /* Called from ioremap.c */
83676 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83677 void __iomem *addr);
83678 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83679 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83680
83681 /* For anyone to insert markers. Remember trailing newline. */
83682 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83683 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83684 {
83685 }
83686
83687 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83688 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83689 {
83690 }
83691
83692 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83693 index ffe66e3..b310722 100644
83694 --- a/include/linux/mmzone.h
83695 +++ b/include/linux/mmzone.h
83696 @@ -527,7 +527,7 @@ struct zone {
83697
83698 ZONE_PADDING(_pad3_)
83699 /* Zone statistics */
83700 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83701 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83702 } ____cacheline_internodealigned_in_smp;
83703
83704 enum zone_flags {
83705 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83706 index 44eeef0..a92d3f9 100644
83707 --- a/include/linux/mod_devicetable.h
83708 +++ b/include/linux/mod_devicetable.h
83709 @@ -139,7 +139,7 @@ struct usb_device_id {
83710 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83711 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83712
83713 -#define HID_ANY_ID (~0)
83714 +#define HID_ANY_ID (~0U)
83715 #define HID_BUS_ANY 0xffff
83716 #define HID_GROUP_ANY 0x0000
83717
83718 @@ -475,7 +475,7 @@ struct dmi_system_id {
83719 const char *ident;
83720 struct dmi_strmatch matches[4];
83721 void *driver_data;
83722 -};
83723 +} __do_const;
83724 /*
83725 * struct dmi_device_id appears during expansion of
83726 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83727 diff --git a/include/linux/module.h b/include/linux/module.h
83728 index 71f282a..b2387e2 100644
83729 --- a/include/linux/module.h
83730 +++ b/include/linux/module.h
83731 @@ -17,9 +17,11 @@
83732 #include <linux/moduleparam.h>
83733 #include <linux/jump_label.h>
83734 #include <linux/export.h>
83735 +#include <linux/fs.h>
83736
83737 #include <linux/percpu.h>
83738 #include <asm/module.h>
83739 +#include <asm/pgtable.h>
83740
83741 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83742 #define MODULE_SIG_STRING "~Module signature appended~\n"
83743 @@ -42,7 +44,7 @@ struct module_kobject {
83744 struct kobject *drivers_dir;
83745 struct module_param_attrs *mp;
83746 struct completion *kobj_completion;
83747 -};
83748 +} __randomize_layout;
83749
83750 struct module_attribute {
83751 struct attribute attr;
83752 @@ -54,12 +56,13 @@ struct module_attribute {
83753 int (*test)(struct module *);
83754 void (*free)(struct module *);
83755 };
83756 +typedef struct module_attribute __no_const module_attribute_no_const;
83757
83758 struct module_version_attribute {
83759 struct module_attribute mattr;
83760 const char *module_name;
83761 const char *version;
83762 -} __attribute__ ((__aligned__(sizeof(void *))));
83763 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83764
83765 extern ssize_t __modver_version_show(struct module_attribute *,
83766 struct module_kobject *, char *);
83767 @@ -235,7 +238,7 @@ struct module {
83768
83769 /* Sysfs stuff. */
83770 struct module_kobject mkobj;
83771 - struct module_attribute *modinfo_attrs;
83772 + module_attribute_no_const *modinfo_attrs;
83773 const char *version;
83774 const char *srcversion;
83775 struct kobject *holders_dir;
83776 @@ -284,19 +287,16 @@ struct module {
83777 int (*init)(void);
83778
83779 /* If this is non-NULL, vfree after init() returns */
83780 - void *module_init;
83781 + void *module_init_rx, *module_init_rw;
83782
83783 /* Here is the actual code + data, vfree'd on unload. */
83784 - void *module_core;
83785 + void *module_core_rx, *module_core_rw;
83786
83787 /* Here are the sizes of the init and core sections */
83788 - unsigned int init_size, core_size;
83789 + unsigned int init_size_rw, core_size_rw;
83790
83791 /* The size of the executable code in each section. */
83792 - unsigned int init_text_size, core_text_size;
83793 -
83794 - /* Size of RO sections of the module (text+rodata) */
83795 - unsigned int init_ro_size, core_ro_size;
83796 + unsigned int init_size_rx, core_size_rx;
83797
83798 /* Arch-specific module values */
83799 struct mod_arch_specific arch;
83800 @@ -352,6 +352,10 @@ struct module {
83801 #ifdef CONFIG_EVENT_TRACING
83802 struct ftrace_event_call **trace_events;
83803 unsigned int num_trace_events;
83804 + struct file_operations trace_id;
83805 + struct file_operations trace_enable;
83806 + struct file_operations trace_format;
83807 + struct file_operations trace_filter;
83808 #endif
83809 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83810 unsigned int num_ftrace_callsites;
83811 @@ -375,7 +379,7 @@ struct module {
83812 ctor_fn_t *ctors;
83813 unsigned int num_ctors;
83814 #endif
83815 -};
83816 +} __randomize_layout;
83817 #ifndef MODULE_ARCH_INIT
83818 #define MODULE_ARCH_INIT {}
83819 #endif
83820 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83821 bool is_module_percpu_address(unsigned long addr);
83822 bool is_module_text_address(unsigned long addr);
83823
83824 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83825 +{
83826 +
83827 +#ifdef CONFIG_PAX_KERNEXEC
83828 + if (ktla_ktva(addr) >= (unsigned long)start &&
83829 + ktla_ktva(addr) < (unsigned long)start + size)
83830 + return 1;
83831 +#endif
83832 +
83833 + return ((void *)addr >= start && (void *)addr < start + size);
83834 +}
83835 +
83836 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83837 +{
83838 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83839 +}
83840 +
83841 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83842 +{
83843 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83844 +}
83845 +
83846 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83847 +{
83848 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83849 +}
83850 +
83851 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83852 +{
83853 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83854 +}
83855 +
83856 static inline bool within_module_core(unsigned long addr,
83857 const struct module *mod)
83858 {
83859 - return (unsigned long)mod->module_core <= addr &&
83860 - addr < (unsigned long)mod->module_core + mod->core_size;
83861 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83862 }
83863
83864 static inline bool within_module_init(unsigned long addr,
83865 const struct module *mod)
83866 {
83867 - return (unsigned long)mod->module_init <= addr &&
83868 - addr < (unsigned long)mod->module_init + mod->init_size;
83869 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83870 }
83871
83872 static inline bool within_module(unsigned long addr, const struct module *mod)
83873 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83874 index 7eeb9bb..68f37e0 100644
83875 --- a/include/linux/moduleloader.h
83876 +++ b/include/linux/moduleloader.h
83877 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83878 sections. Returns NULL on failure. */
83879 void *module_alloc(unsigned long size);
83880
83881 +#ifdef CONFIG_PAX_KERNEXEC
83882 +void *module_alloc_exec(unsigned long size);
83883 +#else
83884 +#define module_alloc_exec(x) module_alloc(x)
83885 +#endif
83886 +
83887 /* Free memory returned from module_alloc. */
83888 void module_free(struct module *mod, void *module_region);
83889
83890 +#ifdef CONFIG_PAX_KERNEXEC
83891 +void module_free_exec(struct module *mod, void *module_region);
83892 +#else
83893 +#define module_free_exec(x, y) module_free((x), (y))
83894 +#endif
83895 +
83896 /*
83897 * Apply the given relocation to the (simplified) ELF. Return -error
83898 * or 0.
83899 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83900 unsigned int relsec,
83901 struct module *me)
83902 {
83903 +#ifdef CONFIG_MODULES
83904 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83905 module_name(me));
83906 +#endif
83907 return -ENOEXEC;
83908 }
83909 #endif
83910 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83911 unsigned int relsec,
83912 struct module *me)
83913 {
83914 +#ifdef CONFIG_MODULES
83915 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83916 module_name(me));
83917 +#endif
83918 return -ENOEXEC;
83919 }
83920 #endif
83921 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83922 index 1c9effa..1160bdd 100644
83923 --- a/include/linux/moduleparam.h
83924 +++ b/include/linux/moduleparam.h
83925 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83926 * @len is usually just sizeof(string).
83927 */
83928 #define module_param_string(name, string, len, perm) \
83929 - static const struct kparam_string __param_string_##name \
83930 + static const struct kparam_string __param_string_##name __used \
83931 = { len, string }; \
83932 __module_param_call(MODULE_PARAM_PREFIX, name, \
83933 &param_ops_string, \
83934 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83935 */
83936 #define module_param_array_named(name, array, type, nump, perm) \
83937 param_check_##type(name, &(array)[0]); \
83938 - static const struct kparam_array __param_arr_##name \
83939 + static const struct kparam_array __param_arr_##name __used \
83940 = { .max = ARRAY_SIZE(array), .num = nump, \
83941 .ops = &param_ops_##type, \
83942 .elemsize = sizeof(array[0]), .elem = array }; \
83943 diff --git a/include/linux/mount.h b/include/linux/mount.h
83944 index c2c561d..a5f2a8c 100644
83945 --- a/include/linux/mount.h
83946 +++ b/include/linux/mount.h
83947 @@ -66,7 +66,7 @@ struct vfsmount {
83948 struct dentry *mnt_root; /* root of the mounted tree */
83949 struct super_block *mnt_sb; /* pointer to superblock */
83950 int mnt_flags;
83951 -};
83952 +} __randomize_layout;
83953
83954 struct file; /* forward dec */
83955 struct path;
83956 diff --git a/include/linux/namei.h b/include/linux/namei.h
83957 index 492de72..1bddcd4 100644
83958 --- a/include/linux/namei.h
83959 +++ b/include/linux/namei.h
83960 @@ -19,7 +19,7 @@ struct nameidata {
83961 unsigned seq, m_seq;
83962 int last_type;
83963 unsigned depth;
83964 - char *saved_names[MAX_NESTED_LINKS + 1];
83965 + const char *saved_names[MAX_NESTED_LINKS + 1];
83966 };
83967
83968 /*
83969 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83970
83971 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83972
83973 -static inline void nd_set_link(struct nameidata *nd, char *path)
83974 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83975 {
83976 nd->saved_names[nd->depth] = path;
83977 }
83978
83979 -static inline char *nd_get_link(struct nameidata *nd)
83980 +static inline const char *nd_get_link(const struct nameidata *nd)
83981 {
83982 return nd->saved_names[nd->depth];
83983 }
83984 diff --git a/include/linux/net.h b/include/linux/net.h
83985 index 17d8339..81656c0 100644
83986 --- a/include/linux/net.h
83987 +++ b/include/linux/net.h
83988 @@ -192,7 +192,7 @@ struct net_proto_family {
83989 int (*create)(struct net *net, struct socket *sock,
83990 int protocol, int kern);
83991 struct module *owner;
83992 -};
83993 +} __do_const;
83994
83995 struct iovec;
83996 struct kvec;
83997 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83998 index 22339b4..4b4d5b3 100644
83999 --- a/include/linux/netdevice.h
84000 +++ b/include/linux/netdevice.h
84001 @@ -1160,6 +1160,7 @@ struct net_device_ops {
84002 struct net_device *dev,
84003 netdev_features_t features);
84004 };
84005 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84006
84007 /**
84008 * enum net_device_priv_flags - &struct net_device priv_flags
84009 @@ -1502,10 +1503,10 @@ struct net_device {
84010
84011 struct net_device_stats stats;
84012
84013 - atomic_long_t rx_dropped;
84014 - atomic_long_t tx_dropped;
84015 + atomic_long_unchecked_t rx_dropped;
84016 + atomic_long_unchecked_t tx_dropped;
84017
84018 - atomic_t carrier_changes;
84019 + atomic_unchecked_t carrier_changes;
84020
84021 #ifdef CONFIG_WIRELESS_EXT
84022 const struct iw_handler_def * wireless_handlers;
84023 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84024 index 2517ece..0bbfcfb 100644
84025 --- a/include/linux/netfilter.h
84026 +++ b/include/linux/netfilter.h
84027 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84028 #endif
84029 /* Use the module struct to lock set/get code in place */
84030 struct module *owner;
84031 -};
84032 +} __do_const;
84033
84034 /* Function to register/unregister hook points. */
84035 int nf_register_hook(struct nf_hook_ops *reg);
84036 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84037 index e955d47..04a5338 100644
84038 --- a/include/linux/netfilter/nfnetlink.h
84039 +++ b/include/linux/netfilter/nfnetlink.h
84040 @@ -19,7 +19,7 @@ struct nfnl_callback {
84041 const struct nlattr * const cda[]);
84042 const struct nla_policy *policy; /* netlink attribute policy */
84043 const u_int16_t attr_count; /* number of nlattr's */
84044 -};
84045 +} __do_const;
84046
84047 struct nfnetlink_subsystem {
84048 const char *name;
84049 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84050 new file mode 100644
84051 index 0000000..33f4af8
84052 --- /dev/null
84053 +++ b/include/linux/netfilter/xt_gradm.h
84054 @@ -0,0 +1,9 @@
84055 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84056 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84057 +
84058 +struct xt_gradm_mtinfo {
84059 + __u16 flags;
84060 + __u16 invflags;
84061 +};
84062 +
84063 +#endif
84064 diff --git a/include/linux/nls.h b/include/linux/nls.h
84065 index 520681b..2b7fabb 100644
84066 --- a/include/linux/nls.h
84067 +++ b/include/linux/nls.h
84068 @@ -31,7 +31,7 @@ struct nls_table {
84069 const unsigned char *charset2upper;
84070 struct module *owner;
84071 struct nls_table *next;
84072 -};
84073 +} __do_const;
84074
84075 /* this value hold the maximum octet of charset */
84076 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84077 @@ -46,7 +46,7 @@ enum utf16_endian {
84078 /* nls_base.c */
84079 extern int __register_nls(struct nls_table *, struct module *);
84080 extern int unregister_nls(struct nls_table *);
84081 -extern struct nls_table *load_nls(char *);
84082 +extern struct nls_table *load_nls(const char *);
84083 extern void unload_nls(struct nls_table *);
84084 extern struct nls_table *load_nls_default(void);
84085 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84086 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84087 index d14a4c3..a078786 100644
84088 --- a/include/linux/notifier.h
84089 +++ b/include/linux/notifier.h
84090 @@ -54,7 +54,8 @@ struct notifier_block {
84091 notifier_fn_t notifier_call;
84092 struct notifier_block __rcu *next;
84093 int priority;
84094 -};
84095 +} __do_const;
84096 +typedef struct notifier_block __no_const notifier_block_no_const;
84097
84098 struct atomic_notifier_head {
84099 spinlock_t lock;
84100 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84101 index b2a0f15..4d7da32 100644
84102 --- a/include/linux/oprofile.h
84103 +++ b/include/linux/oprofile.h
84104 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84105 int oprofilefs_create_ro_ulong(struct dentry * root,
84106 char const * name, ulong * val);
84107
84108 -/** Create a file for read-only access to an atomic_t. */
84109 +/** Create a file for read-only access to an atomic_unchecked_t. */
84110 int oprofilefs_create_ro_atomic(struct dentry * root,
84111 - char const * name, atomic_t * val);
84112 + char const * name, atomic_unchecked_t * val);
84113
84114 /** create a directory */
84115 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84116 diff --git a/include/linux/padata.h b/include/linux/padata.h
84117 index 4386946..f50c615 100644
84118 --- a/include/linux/padata.h
84119 +++ b/include/linux/padata.h
84120 @@ -129,7 +129,7 @@ struct parallel_data {
84121 struct padata_serial_queue __percpu *squeue;
84122 atomic_t reorder_objects;
84123 atomic_t refcnt;
84124 - atomic_t seq_nr;
84125 + atomic_unchecked_t seq_nr;
84126 struct padata_cpumask cpumask;
84127 spinlock_t lock ____cacheline_aligned;
84128 unsigned int processed;
84129 diff --git a/include/linux/path.h b/include/linux/path.h
84130 index d137218..be0c176 100644
84131 --- a/include/linux/path.h
84132 +++ b/include/linux/path.h
84133 @@ -1,13 +1,15 @@
84134 #ifndef _LINUX_PATH_H
84135 #define _LINUX_PATH_H
84136
84137 +#include <linux/compiler.h>
84138 +
84139 struct dentry;
84140 struct vfsmount;
84141
84142 struct path {
84143 struct vfsmount *mnt;
84144 struct dentry *dentry;
84145 -};
84146 +} __randomize_layout;
84147
84148 extern void path_get(const struct path *);
84149 extern void path_put(const struct path *);
84150 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84151 index 2706ee9..e691f7c 100644
84152 --- a/include/linux/pci_hotplug.h
84153 +++ b/include/linux/pci_hotplug.h
84154 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84155 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84156 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84157 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84158 -};
84159 +} __do_const;
84160 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84161
84162 /**
84163 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84164 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84165 index 893a0d0..d5f996e 100644
84166 --- a/include/linux/perf_event.h
84167 +++ b/include/linux/perf_event.h
84168 @@ -341,8 +341,8 @@ struct perf_event {
84169
84170 enum perf_event_active_state state;
84171 unsigned int attach_state;
84172 - local64_t count;
84173 - atomic64_t child_count;
84174 + local64_t count; /* PaX: fix it one day */
84175 + atomic64_unchecked_t child_count;
84176
84177 /*
84178 * These are the total time in nanoseconds that the event
84179 @@ -393,8 +393,8 @@ struct perf_event {
84180 * These accumulate total time (in nanoseconds) that children
84181 * events have been enabled and running, respectively.
84182 */
84183 - atomic64_t child_total_time_enabled;
84184 - atomic64_t child_total_time_running;
84185 + atomic64_unchecked_t child_total_time_enabled;
84186 + atomic64_unchecked_t child_total_time_running;
84187
84188 /*
84189 * Protect attach/detach and child_list:
84190 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84191 entry->ip[entry->nr++] = ip;
84192 }
84193
84194 -extern int sysctl_perf_event_paranoid;
84195 +extern int sysctl_perf_event_legitimately_concerned;
84196 extern int sysctl_perf_event_mlock;
84197 extern int sysctl_perf_event_sample_rate;
84198 extern int sysctl_perf_cpu_time_max_percent;
84199 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84200 loff_t *ppos);
84201
84202
84203 +static inline bool perf_paranoid_any(void)
84204 +{
84205 + return sysctl_perf_event_legitimately_concerned > 2;
84206 +}
84207 +
84208 static inline bool perf_paranoid_tracepoint_raw(void)
84209 {
84210 - return sysctl_perf_event_paranoid > -1;
84211 + return sysctl_perf_event_legitimately_concerned > -1;
84212 }
84213
84214 static inline bool perf_paranoid_cpu(void)
84215 {
84216 - return sysctl_perf_event_paranoid > 0;
84217 + return sysctl_perf_event_legitimately_concerned > 0;
84218 }
84219
84220 static inline bool perf_paranoid_kernel(void)
84221 {
84222 - return sysctl_perf_event_paranoid > 1;
84223 + return sysctl_perf_event_legitimately_concerned > 1;
84224 }
84225
84226 extern void perf_event_init(void);
84227 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84228 struct device_attribute attr;
84229 u64 id;
84230 const char *event_str;
84231 -};
84232 +} __do_const;
84233
84234 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84235 static struct perf_pmu_events_attr _var = { \
84236 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84237 index 1997ffc..4f1f44d 100644
84238 --- a/include/linux/pid_namespace.h
84239 +++ b/include/linux/pid_namespace.h
84240 @@ -44,7 +44,7 @@ struct pid_namespace {
84241 int hide_pid;
84242 int reboot; /* group exit code if this pidns was rebooted */
84243 unsigned int proc_inum;
84244 -};
84245 +} __randomize_layout;
84246
84247 extern struct pid_namespace init_pid_ns;
84248
84249 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84250 index eb8b8ac..62649e1 100644
84251 --- a/include/linux/pipe_fs_i.h
84252 +++ b/include/linux/pipe_fs_i.h
84253 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84254 struct mutex mutex;
84255 wait_queue_head_t wait;
84256 unsigned int nrbufs, curbuf, buffers;
84257 - unsigned int readers;
84258 - unsigned int writers;
84259 - unsigned int files;
84260 - unsigned int waiting_writers;
84261 + atomic_t readers;
84262 + atomic_t writers;
84263 + atomic_t files;
84264 + atomic_t waiting_writers;
84265 unsigned int r_counter;
84266 unsigned int w_counter;
84267 struct page *tmp_page;
84268 diff --git a/include/linux/pm.h b/include/linux/pm.h
84269 index 383fd68..7a11504 100644
84270 --- a/include/linux/pm.h
84271 +++ b/include/linux/pm.h
84272 @@ -621,6 +621,7 @@ struct dev_pm_domain {
84273 struct dev_pm_ops ops;
84274 void (*detach)(struct device *dev, bool power_off);
84275 };
84276 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84277
84278 /*
84279 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84280 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84281 index 2e0e06d..824cc9b 100644
84282 --- a/include/linux/pm_domain.h
84283 +++ b/include/linux/pm_domain.h
84284 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
84285 int (*save_state)(struct device *dev);
84286 int (*restore_state)(struct device *dev);
84287 bool (*active_wakeup)(struct device *dev);
84288 -};
84289 +} __no_const;
84290
84291 struct gpd_cpuidle_data {
84292 unsigned int saved_exit_latency;
84293 - struct cpuidle_state *idle_state;
84294 + cpuidle_state_no_const *idle_state;
84295 };
84296
84297 struct generic_pm_domain {
84298 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84299 index 367f49b..d2f5a14 100644
84300 --- a/include/linux/pm_runtime.h
84301 +++ b/include/linux/pm_runtime.h
84302 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84303
84304 static inline void pm_runtime_mark_last_busy(struct device *dev)
84305 {
84306 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84307 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84308 }
84309
84310 #else /* !CONFIG_PM_RUNTIME */
84311 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84312 index 195aafc..49a7bc2 100644
84313 --- a/include/linux/pnp.h
84314 +++ b/include/linux/pnp.h
84315 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84316 struct pnp_fixup {
84317 char id[7];
84318 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84319 -};
84320 +} __do_const;
84321
84322 /* config parameters */
84323 #define PNP_CONFIG_NORMAL 0x0001
84324 diff --git a/include/linux/poison.h b/include/linux/poison.h
84325 index 2110a81..13a11bb 100644
84326 --- a/include/linux/poison.h
84327 +++ b/include/linux/poison.h
84328 @@ -19,8 +19,8 @@
84329 * under normal circumstances, used to verify that nobody uses
84330 * non-initialized list entries.
84331 */
84332 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84333 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84334 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84335 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84336
84337 /********** include/linux/timer.h **********/
84338 /*
84339 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84340 index d8b187c3..9a9257a 100644
84341 --- a/include/linux/power/smartreflex.h
84342 +++ b/include/linux/power/smartreflex.h
84343 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84344 int (*notify)(struct omap_sr *sr, u32 status);
84345 u8 notify_flags;
84346 u8 class_type;
84347 -};
84348 +} __do_const;
84349
84350 /**
84351 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84352 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84353 index 4ea1d37..80f4b33 100644
84354 --- a/include/linux/ppp-comp.h
84355 +++ b/include/linux/ppp-comp.h
84356 @@ -84,7 +84,7 @@ struct compressor {
84357 struct module *owner;
84358 /* Extra skb space needed by the compressor algorithm */
84359 unsigned int comp_extra;
84360 -};
84361 +} __do_const;
84362
84363 /*
84364 * The return value from decompress routine is the length of the
84365 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84366 index de83b4e..c4b997d 100644
84367 --- a/include/linux/preempt.h
84368 +++ b/include/linux/preempt.h
84369 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84370 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84371 #endif
84372
84373 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84374 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84375 +
84376 #define __preempt_count_inc() __preempt_count_add(1)
84377 #define __preempt_count_dec() __preempt_count_sub(1)
84378
84379 #define preempt_count_inc() preempt_count_add(1)
84380 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84381 #define preempt_count_dec() preempt_count_sub(1)
84382 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84383
84384 #ifdef CONFIG_PREEMPT_COUNT
84385
84386 @@ -41,6 +46,12 @@ do { \
84387 barrier(); \
84388 } while (0)
84389
84390 +#define raw_preempt_disable() \
84391 +do { \
84392 + raw_preempt_count_inc(); \
84393 + barrier(); \
84394 +} while (0)
84395 +
84396 #define sched_preempt_enable_no_resched() \
84397 do { \
84398 barrier(); \
84399 @@ -49,6 +60,12 @@ do { \
84400
84401 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84402
84403 +#define raw_preempt_enable_no_resched() \
84404 +do { \
84405 + barrier(); \
84406 + raw_preempt_count_dec(); \
84407 +} while (0)
84408 +
84409 #ifdef CONFIG_PREEMPT
84410 #define preempt_enable() \
84411 do { \
84412 @@ -113,8 +130,10 @@ do { \
84413 * region.
84414 */
84415 #define preempt_disable() barrier()
84416 +#define raw_preempt_disable() barrier()
84417 #define sched_preempt_enable_no_resched() barrier()
84418 #define preempt_enable_no_resched() barrier()
84419 +#define raw_preempt_enable_no_resched() barrier()
84420 #define preempt_enable() barrier()
84421 #define preempt_check_resched() do { } while (0)
84422
84423 @@ -128,11 +147,13 @@ do { \
84424 /*
84425 * Modules have no business playing preemption tricks.
84426 */
84427 +#ifndef CONFIG_PAX_KERNEXEC
84428 #undef sched_preempt_enable_no_resched
84429 #undef preempt_enable_no_resched
84430 #undef preempt_enable_no_resched_notrace
84431 #undef preempt_check_resched
84432 #endif
84433 +#endif
84434
84435 #define preempt_set_need_resched() \
84436 do { \
84437 diff --git a/include/linux/printk.h b/include/linux/printk.h
84438 index d78125f..7f36596 100644
84439 --- a/include/linux/printk.h
84440 +++ b/include/linux/printk.h
84441 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84442 void early_printk(const char *s, ...) { }
84443 #endif
84444
84445 +extern int kptr_restrict;
84446 +
84447 #ifdef CONFIG_PRINTK
84448 asmlinkage __printf(5, 0)
84449 int vprintk_emit(int facility, int level,
84450 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84451
84452 extern int printk_delay_msec;
84453 extern int dmesg_restrict;
84454 -extern int kptr_restrict;
84455
84456 extern void wake_up_klogd(void);
84457
84458 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84459 index b97bf2e..f14c92d4 100644
84460 --- a/include/linux/proc_fs.h
84461 +++ b/include/linux/proc_fs.h
84462 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84463 extern struct proc_dir_entry *proc_symlink(const char *,
84464 struct proc_dir_entry *, const char *);
84465 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84466 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84467 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84468 struct proc_dir_entry *, void *);
84469 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84470 + struct proc_dir_entry *, void *);
84471 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84472 struct proc_dir_entry *);
84473
84474 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84475 return proc_create_data(name, mode, parent, proc_fops, NULL);
84476 }
84477
84478 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84479 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84480 +{
84481 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84482 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84483 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84484 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84485 +#else
84486 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84487 +#endif
84488 +}
84489 +
84490 +
84491 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84492 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84493 extern void *PDE_DATA(const struct inode *);
84494 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84495 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84496 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84497 struct proc_dir_entry *parent) {return NULL;}
84498 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84499 + struct proc_dir_entry *parent) { return NULL; }
84500 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84501 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84502 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84503 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84504 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84505 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84506 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84507 @@ -79,7 +99,7 @@ struct net;
84508 static inline struct proc_dir_entry *proc_net_mkdir(
84509 struct net *net, const char *name, struct proc_dir_entry *parent)
84510 {
84511 - return proc_mkdir_data(name, 0, parent, net);
84512 + return proc_mkdir_data_restrict(name, 0, parent, net);
84513 }
84514
84515 #endif /* _LINUX_PROC_FS_H */
84516 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84517 index 34a1e10..70f6bde 100644
84518 --- a/include/linux/proc_ns.h
84519 +++ b/include/linux/proc_ns.h
84520 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84521 void (*put)(void *ns);
84522 int (*install)(struct nsproxy *nsproxy, void *ns);
84523 unsigned int (*inum)(void *ns);
84524 -};
84525 +} __do_const __randomize_layout;
84526
84527 struct proc_ns {
84528 void *ns;
84529 diff --git a/include/linux/quota.h b/include/linux/quota.h
84530 index 224fb81..9d85c41 100644
84531 --- a/include/linux/quota.h
84532 +++ b/include/linux/quota.h
84533 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84534
84535 extern bool qid_eq(struct kqid left, struct kqid right);
84536 extern bool qid_lt(struct kqid left, struct kqid right);
84537 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84538 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84539 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84540 extern bool qid_valid(struct kqid qid);
84541
84542 diff --git a/include/linux/random.h b/include/linux/random.h
84543 index b05856e..0a9f14e 100644
84544 --- a/include/linux/random.h
84545 +++ b/include/linux/random.h
84546 @@ -9,9 +9,19 @@
84547 #include <uapi/linux/random.h>
84548
84549 extern void add_device_randomness(const void *, unsigned int);
84550 +
84551 +static inline void add_latent_entropy(void)
84552 +{
84553 +
84554 +#ifdef LATENT_ENTROPY_PLUGIN
84555 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84556 +#endif
84557 +
84558 +}
84559 +
84560 extern void add_input_randomness(unsigned int type, unsigned int code,
84561 - unsigned int value);
84562 -extern void add_interrupt_randomness(int irq, int irq_flags);
84563 + unsigned int value) __latent_entropy;
84564 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84565
84566 extern void get_random_bytes(void *buf, int nbytes);
84567 extern void get_random_bytes_arch(void *buf, int nbytes);
84568 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84569 extern const struct file_operations random_fops, urandom_fops;
84570 #endif
84571
84572 -unsigned int get_random_int(void);
84573 +unsigned int __intentional_overflow(-1) get_random_int(void);
84574 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84575
84576 -u32 prandom_u32(void);
84577 +u32 prandom_u32(void) __intentional_overflow(-1);
84578 void prandom_bytes(void *buf, size_t nbytes);
84579 void prandom_seed(u32 seed);
84580 void prandom_reseed_late(void);
84581 @@ -37,6 +47,11 @@ struct rnd_state {
84582 u32 prandom_u32_state(struct rnd_state *state);
84583 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84584
84585 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84586 +{
84587 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84588 +}
84589 +
84590 /**
84591 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84592 * @ep_ro: right open interval endpoint
84593 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84594 *
84595 * Returns: pseudo-random number in interval [0, ep_ro)
84596 */
84597 -static inline u32 prandom_u32_max(u32 ep_ro)
84598 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84599 {
84600 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84601 }
84602 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84603 index 378c5ee..aa84a47 100644
84604 --- a/include/linux/rbtree_augmented.h
84605 +++ b/include/linux/rbtree_augmented.h
84606 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84607 old->rbaugmented = rbcompute(old); \
84608 } \
84609 rbstatic const struct rb_augment_callbacks rbname = { \
84610 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84611 + .propagate = rbname ## _propagate, \
84612 + .copy = rbname ## _copy, \
84613 + .rotate = rbname ## _rotate \
84614 };
84615
84616
84617 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84618 index 372ad5e..d4373f8 100644
84619 --- a/include/linux/rculist.h
84620 +++ b/include/linux/rculist.h
84621 @@ -29,8 +29,8 @@
84622 */
84623 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84624 {
84625 - ACCESS_ONCE(list->next) = list;
84626 - ACCESS_ONCE(list->prev) = list;
84627 + ACCESS_ONCE_RW(list->next) = list;
84628 + ACCESS_ONCE_RW(list->prev) = list;
84629 }
84630
84631 /*
84632 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84633 struct list_head *prev, struct list_head *next);
84634 #endif
84635
84636 +void __pax_list_add_rcu(struct list_head *new,
84637 + struct list_head *prev, struct list_head *next);
84638 +
84639 /**
84640 * list_add_rcu - add a new entry to rcu-protected list
84641 * @new: new entry to be added
84642 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84643 __list_add_rcu(new, head, head->next);
84644 }
84645
84646 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84647 +{
84648 + __pax_list_add_rcu(new, head, head->next);
84649 +}
84650 +
84651 /**
84652 * list_add_tail_rcu - add a new entry to rcu-protected list
84653 * @new: new entry to be added
84654 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84655 __list_add_rcu(new, head->prev, head);
84656 }
84657
84658 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84659 + struct list_head *head)
84660 +{
84661 + __pax_list_add_rcu(new, head->prev, head);
84662 +}
84663 +
84664 /**
84665 * list_del_rcu - deletes entry from list without re-initialization
84666 * @entry: the element to delete from the list.
84667 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84668 entry->prev = LIST_POISON2;
84669 }
84670
84671 +extern void pax_list_del_rcu(struct list_head *entry);
84672 +
84673 /**
84674 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84675 * @n: the element to delete from the hash list.
84676 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84677 index 53ff1a7..c40f0ab 100644
84678 --- a/include/linux/rcupdate.h
84679 +++ b/include/linux/rcupdate.h
84680 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84681 #define rcu_note_voluntary_context_switch(t) \
84682 do { \
84683 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84684 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84685 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84686 } while (0)
84687 #else /* #ifdef CONFIG_TASKS_RCU */
84688 #define TASKS_RCU(x) do { } while (0)
84689 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84690 index 67fc8fc..a90f7d8 100644
84691 --- a/include/linux/reboot.h
84692 +++ b/include/linux/reboot.h
84693 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84694 */
84695
84696 extern void migrate_to_reboot_cpu(void);
84697 -extern void machine_restart(char *cmd);
84698 -extern void machine_halt(void);
84699 -extern void machine_power_off(void);
84700 +extern void machine_restart(char *cmd) __noreturn;
84701 +extern void machine_halt(void) __noreturn;
84702 +extern void machine_power_off(void) __noreturn;
84703
84704 extern void machine_shutdown(void);
84705 struct pt_regs;
84706 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84707 */
84708
84709 extern void kernel_restart_prepare(char *cmd);
84710 -extern void kernel_restart(char *cmd);
84711 -extern void kernel_halt(void);
84712 -extern void kernel_power_off(void);
84713 +extern void kernel_restart(char *cmd) __noreturn;
84714 +extern void kernel_halt(void) __noreturn;
84715 +extern void kernel_power_off(void) __noreturn;
84716
84717 extern int C_A_D; /* for sysctl */
84718 void ctrl_alt_del(void);
84719 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84720 * Emergency restart, callable from an interrupt handler.
84721 */
84722
84723 -extern void emergency_restart(void);
84724 +extern void emergency_restart(void) __noreturn;
84725 #include <asm/emergency-restart.h>
84726
84727 #endif /* _LINUX_REBOOT_H */
84728 diff --git a/include/linux/regset.h b/include/linux/regset.h
84729 index 8e0c9fe..ac4d221 100644
84730 --- a/include/linux/regset.h
84731 +++ b/include/linux/regset.h
84732 @@ -161,7 +161,8 @@ struct user_regset {
84733 unsigned int align;
84734 unsigned int bias;
84735 unsigned int core_note_type;
84736 -};
84737 +} __do_const;
84738 +typedef struct user_regset __no_const user_regset_no_const;
84739
84740 /**
84741 * struct user_regset_view - available regsets
84742 diff --git a/include/linux/relay.h b/include/linux/relay.h
84743 index d7c8359..818daf5 100644
84744 --- a/include/linux/relay.h
84745 +++ b/include/linux/relay.h
84746 @@ -157,7 +157,7 @@ struct rchan_callbacks
84747 * The callback should return 0 if successful, negative if not.
84748 */
84749 int (*remove_buf_file)(struct dentry *dentry);
84750 -};
84751 +} __no_const;
84752
84753 /*
84754 * CONFIG_RELAY kernel API, kernel/relay.c
84755 diff --git a/include/linux/rio.h b/include/linux/rio.h
84756 index 6bda06f..bf39a9b 100644
84757 --- a/include/linux/rio.h
84758 +++ b/include/linux/rio.h
84759 @@ -358,7 +358,7 @@ struct rio_ops {
84760 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84761 u64 rstart, u32 size, u32 flags);
84762 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84763 -};
84764 +} __no_const;
84765
84766 #define RIO_RESOURCE_MEM 0x00000100
84767 #define RIO_RESOURCE_DOORBELL 0x00000200
84768 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84769 index c0c2bce..4813524 100644
84770 --- a/include/linux/rmap.h
84771 +++ b/include/linux/rmap.h
84772 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84773 void anon_vma_init(void); /* create anon_vma_cachep */
84774 int anon_vma_prepare(struct vm_area_struct *);
84775 void unlink_anon_vmas(struct vm_area_struct *);
84776 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84777 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84778 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84779 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84780
84781 static inline void anon_vma_merge(struct vm_area_struct *vma,
84782 struct vm_area_struct *next)
84783 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84784 index ed8f9e7..999bc96 100644
84785 --- a/include/linux/scatterlist.h
84786 +++ b/include/linux/scatterlist.h
84787 @@ -1,6 +1,7 @@
84788 #ifndef _LINUX_SCATTERLIST_H
84789 #define _LINUX_SCATTERLIST_H
84790
84791 +#include <linux/sched.h>
84792 #include <linux/string.h>
84793 #include <linux/bug.h>
84794 #include <linux/mm.h>
84795 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84796 #ifdef CONFIG_DEBUG_SG
84797 BUG_ON(!virt_addr_valid(buf));
84798 #endif
84799 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84800 + if (object_starts_on_stack(buf)) {
84801 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84802 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84803 + } else
84804 +#endif
84805 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84806 }
84807
84808 diff --git a/include/linux/sched.h b/include/linux/sched.h
84809 index 5e344bb..0743255 100644
84810 --- a/include/linux/sched.h
84811 +++ b/include/linux/sched.h
84812 @@ -133,6 +133,7 @@ struct fs_struct;
84813 struct perf_event_context;
84814 struct blk_plug;
84815 struct filename;
84816 +struct linux_binprm;
84817
84818 #define VMACACHE_BITS 2
84819 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84820 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84821 extern int in_sched_functions(unsigned long addr);
84822
84823 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84824 -extern signed long schedule_timeout(signed long timeout);
84825 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84826 extern signed long schedule_timeout_interruptible(signed long timeout);
84827 extern signed long schedule_timeout_killable(signed long timeout);
84828 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84829 @@ -387,6 +388,19 @@ struct nsproxy;
84830 struct user_namespace;
84831
84832 #ifdef CONFIG_MMU
84833 +
84834 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84835 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84836 +#else
84837 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84838 +{
84839 + return 0;
84840 +}
84841 +#endif
84842 +
84843 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84844 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84845 +
84846 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84847 extern unsigned long
84848 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84849 @@ -685,6 +699,17 @@ struct signal_struct {
84850 #ifdef CONFIG_TASKSTATS
84851 struct taskstats *stats;
84852 #endif
84853 +
84854 +#ifdef CONFIG_GRKERNSEC
84855 + u32 curr_ip;
84856 + u32 saved_ip;
84857 + u32 gr_saddr;
84858 + u32 gr_daddr;
84859 + u16 gr_sport;
84860 + u16 gr_dport;
84861 + u8 used_accept:1;
84862 +#endif
84863 +
84864 #ifdef CONFIG_AUDIT
84865 unsigned audit_tty;
84866 unsigned audit_tty_log_passwd;
84867 @@ -711,7 +736,7 @@ struct signal_struct {
84868 struct mutex cred_guard_mutex; /* guard against foreign influences on
84869 * credential calculations
84870 * (notably. ptrace) */
84871 -};
84872 +} __randomize_layout;
84873
84874 /*
84875 * Bits in flags field of signal_struct.
84876 @@ -764,6 +789,14 @@ struct user_struct {
84877 struct key *session_keyring; /* UID's default session keyring */
84878 #endif
84879
84880 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84881 + unsigned char kernel_banned;
84882 +#endif
84883 +#ifdef CONFIG_GRKERNSEC_BRUTE
84884 + unsigned char suid_banned;
84885 + unsigned long suid_ban_expires;
84886 +#endif
84887 +
84888 /* Hash table maintenance information */
84889 struct hlist_node uidhash_node;
84890 kuid_t uid;
84891 @@ -771,7 +804,7 @@ struct user_struct {
84892 #ifdef CONFIG_PERF_EVENTS
84893 atomic_long_t locked_vm;
84894 #endif
84895 -};
84896 +} __randomize_layout;
84897
84898 extern int uids_sysfs_init(void);
84899
84900 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84901 struct task_struct {
84902 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84903 void *stack;
84904 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84905 + void *lowmem_stack;
84906 +#endif
84907 atomic_t usage;
84908 unsigned int flags; /* per process flags, defined below */
84909 unsigned int ptrace;
84910 @@ -1362,8 +1398,8 @@ struct task_struct {
84911 struct list_head thread_node;
84912
84913 struct completion *vfork_done; /* for vfork() */
84914 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84915 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84916 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84917 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84918
84919 cputime_t utime, stime, utimescaled, stimescaled;
84920 cputime_t gtime;
84921 @@ -1388,11 +1424,6 @@ struct task_struct {
84922 struct task_cputime cputime_expires;
84923 struct list_head cpu_timers[3];
84924
84925 -/* process credentials */
84926 - const struct cred __rcu *real_cred; /* objective and real subjective task
84927 - * credentials (COW) */
84928 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84929 - * credentials (COW) */
84930 char comm[TASK_COMM_LEN]; /* executable name excluding path
84931 - access with [gs]et_task_comm (which lock
84932 it with task_lock())
84933 @@ -1410,6 +1441,10 @@ struct task_struct {
84934 #endif
84935 /* CPU-specific state of this task */
84936 struct thread_struct thread;
84937 +/* thread_info moved to task_struct */
84938 +#ifdef CONFIG_X86
84939 + struct thread_info tinfo;
84940 +#endif
84941 /* filesystem information */
84942 struct fs_struct *fs;
84943 /* open file information */
84944 @@ -1484,6 +1519,10 @@ struct task_struct {
84945 gfp_t lockdep_reclaim_gfp;
84946 #endif
84947
84948 +/* process credentials */
84949 + const struct cred __rcu *real_cred; /* objective and real subjective task
84950 + * credentials (COW) */
84951 +
84952 /* journalling filesystem info */
84953 void *journal_info;
84954
84955 @@ -1522,6 +1561,10 @@ struct task_struct {
84956 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84957 struct list_head cg_list;
84958 #endif
84959 +
84960 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84961 + * credentials (COW) */
84962 +
84963 #ifdef CONFIG_FUTEX
84964 struct robust_list_head __user *robust_list;
84965 #ifdef CONFIG_COMPAT
84966 @@ -1635,7 +1678,7 @@ struct task_struct {
84967 * Number of functions that haven't been traced
84968 * because of depth overrun.
84969 */
84970 - atomic_t trace_overrun;
84971 + atomic_unchecked_t trace_overrun;
84972 /* Pause for the tracing */
84973 atomic_t tracing_graph_pause;
84974 #endif
84975 @@ -1661,7 +1704,78 @@ struct task_struct {
84976 unsigned int sequential_io;
84977 unsigned int sequential_io_avg;
84978 #endif
84979 -};
84980 +
84981 +#ifdef CONFIG_GRKERNSEC
84982 + /* grsecurity */
84983 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84984 + u64 exec_id;
84985 +#endif
84986 +#ifdef CONFIG_GRKERNSEC_SETXID
84987 + const struct cred *delayed_cred;
84988 +#endif
84989 + struct dentry *gr_chroot_dentry;
84990 + struct acl_subject_label *acl;
84991 + struct acl_subject_label *tmpacl;
84992 + struct acl_role_label *role;
84993 + struct file *exec_file;
84994 + unsigned long brute_expires;
84995 + u16 acl_role_id;
84996 + u8 inherited;
84997 + /* is this the task that authenticated to the special role */
84998 + u8 acl_sp_role;
84999 + u8 is_writable;
85000 + u8 brute;
85001 + u8 gr_is_chrooted;
85002 +#endif
85003 +
85004 +} __randomize_layout;
85005 +
85006 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85007 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85008 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85009 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85010 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85011 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85012 +
85013 +#ifdef CONFIG_PAX_SOFTMODE
85014 +extern int pax_softmode;
85015 +#endif
85016 +
85017 +extern int pax_check_flags(unsigned long *);
85018 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85019 +
85020 +/* if tsk != current then task_lock must be held on it */
85021 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85022 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85023 +{
85024 + if (likely(tsk->mm))
85025 + return tsk->mm->pax_flags;
85026 + else
85027 + return 0UL;
85028 +}
85029 +
85030 +/* if tsk != current then task_lock must be held on it */
85031 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85032 +{
85033 + if (likely(tsk->mm)) {
85034 + tsk->mm->pax_flags = flags;
85035 + return 0;
85036 + }
85037 + return -EINVAL;
85038 +}
85039 +#endif
85040 +
85041 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85042 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85043 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85044 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85045 +#endif
85046 +
85047 +struct path;
85048 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85049 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85050 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85051 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85052
85053 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85054 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85055 @@ -1743,7 +1857,7 @@ struct pid_namespace;
85056 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85057 struct pid_namespace *ns);
85058
85059 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85060 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85061 {
85062 return tsk->pid;
85063 }
85064 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
85065
85066 extern void sched_clock_init(void);
85067
85068 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85069 +static inline void populate_stack(void)
85070 +{
85071 + struct task_struct *curtask = current;
85072 + int c;
85073 + int *ptr = curtask->stack;
85074 + int *end = curtask->stack + THREAD_SIZE;
85075 +
85076 + while (ptr < end) {
85077 + c = *(volatile int *)ptr;
85078 + ptr += PAGE_SIZE/sizeof(int);
85079 + }
85080 +}
85081 +#else
85082 +static inline void populate_stack(void)
85083 +{
85084 +}
85085 +#endif
85086 +
85087 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85088 static inline void sched_clock_tick(void)
85089 {
85090 @@ -2239,7 +2372,9 @@ void yield(void);
85091 extern struct exec_domain default_exec_domain;
85092
85093 union thread_union {
85094 +#ifndef CONFIG_X86
85095 struct thread_info thread_info;
85096 +#endif
85097 unsigned long stack[THREAD_SIZE/sizeof(long)];
85098 };
85099
85100 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
85101 */
85102
85103 extern struct task_struct *find_task_by_vpid(pid_t nr);
85104 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85105 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85106 struct pid_namespace *ns);
85107
85108 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85109 extern void exit_itimers(struct signal_struct *);
85110 extern void flush_itimer_signals(void);
85111
85112 -extern void do_group_exit(int);
85113 +extern __noreturn void do_group_exit(int);
85114
85115 extern int do_execve(struct filename *,
85116 const char __user * const __user *,
85117 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85118 #define task_stack_end_corrupted(task) \
85119 (*(end_of_stack(task)) != STACK_END_MAGIC)
85120
85121 -static inline int object_is_on_stack(void *obj)
85122 +static inline int object_starts_on_stack(const void *obj)
85123 {
85124 - void *stack = task_stack_page(current);
85125 + const void *stack = task_stack_page(current);
85126
85127 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85128 }
85129 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85130 index 596a0e0..bea77ec 100644
85131 --- a/include/linux/sched/sysctl.h
85132 +++ b/include/linux/sched/sysctl.h
85133 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85134 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85135
85136 extern int sysctl_max_map_count;
85137 +extern unsigned long sysctl_heap_stack_gap;
85138
85139 extern unsigned int sysctl_sched_latency;
85140 extern unsigned int sysctl_sched_min_granularity;
85141 diff --git a/include/linux/security.h b/include/linux/security.h
85142 index ba96471..74fb3f6 100644
85143 --- a/include/linux/security.h
85144 +++ b/include/linux/security.h
85145 @@ -27,6 +27,7 @@
85146 #include <linux/slab.h>
85147 #include <linux/err.h>
85148 #include <linux/string.h>
85149 +#include <linux/grsecurity.h>
85150
85151 struct linux_binprm;
85152 struct cred;
85153 @@ -116,8 +117,6 @@ struct seq_file;
85154
85155 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85156
85157 -void reset_security_ops(void);
85158 -
85159 #ifdef CONFIG_MMU
85160 extern unsigned long mmap_min_addr;
85161 extern unsigned long dac_mmap_min_addr;
85162 @@ -1729,7 +1728,7 @@ struct security_operations {
85163 struct audit_context *actx);
85164 void (*audit_rule_free) (void *lsmrule);
85165 #endif /* CONFIG_AUDIT */
85166 -};
85167 +} __randomize_layout;
85168
85169 /* prototypes */
85170 extern int security_init(void);
85171 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85172 index dc368b8..e895209 100644
85173 --- a/include/linux/semaphore.h
85174 +++ b/include/linux/semaphore.h
85175 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85176 }
85177
85178 extern void down(struct semaphore *sem);
85179 -extern int __must_check down_interruptible(struct semaphore *sem);
85180 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85181 extern int __must_check down_killable(struct semaphore *sem);
85182 extern int __must_check down_trylock(struct semaphore *sem);
85183 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85184 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85185 index 52e0097..383f21d 100644
85186 --- a/include/linux/seq_file.h
85187 +++ b/include/linux/seq_file.h
85188 @@ -27,6 +27,9 @@ struct seq_file {
85189 struct mutex lock;
85190 const struct seq_operations *op;
85191 int poll_event;
85192 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85193 + u64 exec_id;
85194 +#endif
85195 #ifdef CONFIG_USER_NS
85196 struct user_namespace *user_ns;
85197 #endif
85198 @@ -39,6 +42,7 @@ struct seq_operations {
85199 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85200 int (*show) (struct seq_file *m, void *v);
85201 };
85202 +typedef struct seq_operations __no_const seq_operations_no_const;
85203
85204 #define SEQ_SKIP 1
85205
85206 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85207
85208 char *mangle_path(char *s, const char *p, const char *esc);
85209 int seq_open(struct file *, const struct seq_operations *);
85210 +int seq_open_restrict(struct file *, const struct seq_operations *);
85211 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85212 loff_t seq_lseek(struct file *, loff_t, int);
85213 int seq_release(struct inode *, struct file *);
85214 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85215 }
85216
85217 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85218 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85219 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85220 int single_release(struct inode *, struct file *);
85221 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85222 diff --git a/include/linux/shm.h b/include/linux/shm.h
85223 index 6fb8016..ab4465e 100644
85224 --- a/include/linux/shm.h
85225 +++ b/include/linux/shm.h
85226 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85227 /* The task created the shm object. NULL if the task is dead. */
85228 struct task_struct *shm_creator;
85229 struct list_head shm_clist; /* list by creator */
85230 +#ifdef CONFIG_GRKERNSEC
85231 + u64 shm_createtime;
85232 + pid_t shm_lapid;
85233 +#endif
85234 };
85235
85236 /* shm_mode upper byte flags */
85237 diff --git a/include/linux/signal.h b/include/linux/signal.h
85238 index ab1e039..ad4229e 100644
85239 --- a/include/linux/signal.h
85240 +++ b/include/linux/signal.h
85241 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85242 * know it'll be handled, so that they don't get converted to
85243 * SIGKILL or just silently dropped.
85244 */
85245 - kernel_sigaction(sig, (__force __sighandler_t)2);
85246 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85247 }
85248
85249 static inline void disallow_signal(int sig)
85250 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85251 index 6c8b6f6..5a0f4bd 100644
85252 --- a/include/linux/skbuff.h
85253 +++ b/include/linux/skbuff.h
85254 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85255 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85256 int node);
85257 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85258 -static inline struct sk_buff *alloc_skb(unsigned int size,
85259 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85260 gfp_t priority)
85261 {
85262 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85263 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85264 return skb->inner_transport_header - skb->inner_network_header;
85265 }
85266
85267 -static inline int skb_network_offset(const struct sk_buff *skb)
85268 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85269 {
85270 return skb_network_header(skb) - skb->data;
85271 }
85272 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85273 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85274 */
85275 #ifndef NET_SKB_PAD
85276 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85277 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85278 #endif
85279
85280 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85281 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85282 int *err);
85283 unsigned int datagram_poll(struct file *file, struct socket *sock,
85284 struct poll_table_struct *wait);
85285 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85286 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85287 struct iovec *to, int size);
85288 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85289 struct iovec *iov);
85290 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85291 nf_bridge_put(skb->nf_bridge);
85292 skb->nf_bridge = NULL;
85293 #endif
85294 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85295 + skb->nf_trace = 0;
85296 +#endif
85297 }
85298
85299 static inline void nf_reset_trace(struct sk_buff *skb)
85300 diff --git a/include/linux/slab.h b/include/linux/slab.h
85301 index c265bec..4867d28 100644
85302 --- a/include/linux/slab.h
85303 +++ b/include/linux/slab.h
85304 @@ -14,15 +14,29 @@
85305 #include <linux/gfp.h>
85306 #include <linux/types.h>
85307 #include <linux/workqueue.h>
85308 -
85309 +#include <linux/err.h>
85310
85311 /*
85312 * Flags to pass to kmem_cache_create().
85313 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85314 */
85315 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85316 +
85317 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85318 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85319 +#else
85320 +#define SLAB_USERCOPY 0x00000000UL
85321 +#endif
85322 +
85323 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85324 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85325 +
85326 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85327 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85328 +#else
85329 +#define SLAB_NO_SANITIZE 0x00000000UL
85330 +#endif
85331 +
85332 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85333 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85334 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85335 @@ -98,10 +112,13 @@
85336 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85337 * Both make kfree a no-op.
85338 */
85339 -#define ZERO_SIZE_PTR ((void *)16)
85340 +#define ZERO_SIZE_PTR \
85341 +({ \
85342 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85343 + (void *)(-MAX_ERRNO-1L); \
85344 +})
85345
85346 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85347 - (unsigned long)ZERO_SIZE_PTR)
85348 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85349
85350 #include <linux/kmemleak.h>
85351
85352 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85353 void kfree(const void *);
85354 void kzfree(const void *);
85355 size_t ksize(const void *);
85356 +const char *check_heap_object(const void *ptr, unsigned long n);
85357 +bool is_usercopy_object(const void *ptr);
85358
85359 /*
85360 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85361 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85362 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85363 #endif
85364
85365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85366 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85367 +#endif
85368 +
85369 /*
85370 * Figure out which kmalloc slab an allocation of a certain size
85371 * belongs to.
85372 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85373 * 2 = 120 .. 192 bytes
85374 * n = 2^(n-1) .. 2^n -1
85375 */
85376 -static __always_inline int kmalloc_index(size_t size)
85377 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85378 {
85379 if (!size)
85380 return 0;
85381 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85382 }
85383 #endif /* !CONFIG_SLOB */
85384
85385 -void *__kmalloc(size_t size, gfp_t flags);
85386 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85387 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85388
85389 #ifdef CONFIG_NUMA
85390 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85391 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85392 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85393 #else
85394 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85395 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85396 index b869d16..1453c73 100644
85397 --- a/include/linux/slab_def.h
85398 +++ b/include/linux/slab_def.h
85399 @@ -40,7 +40,7 @@ struct kmem_cache {
85400 /* 4) cache creation/removal */
85401 const char *name;
85402 struct list_head list;
85403 - int refcount;
85404 + atomic_t refcount;
85405 int object_size;
85406 int align;
85407
85408 @@ -56,10 +56,14 @@ struct kmem_cache {
85409 unsigned long node_allocs;
85410 unsigned long node_frees;
85411 unsigned long node_overflow;
85412 - atomic_t allochit;
85413 - atomic_t allocmiss;
85414 - atomic_t freehit;
85415 - atomic_t freemiss;
85416 + atomic_unchecked_t allochit;
85417 + atomic_unchecked_t allocmiss;
85418 + atomic_unchecked_t freehit;
85419 + atomic_unchecked_t freemiss;
85420 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85421 + atomic_unchecked_t sanitized;
85422 + atomic_unchecked_t not_sanitized;
85423 +#endif
85424
85425 /*
85426 * If debugging is enabled, then the allocator can add additional
85427 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85428 index d82abd4..408c3a0 100644
85429 --- a/include/linux/slub_def.h
85430 +++ b/include/linux/slub_def.h
85431 @@ -74,7 +74,7 @@ struct kmem_cache {
85432 struct kmem_cache_order_objects max;
85433 struct kmem_cache_order_objects min;
85434 gfp_t allocflags; /* gfp flags to use on each alloc */
85435 - int refcount; /* Refcount for slab cache destroy */
85436 + atomic_t refcount; /* Refcount for slab cache destroy */
85437 void (*ctor)(void *);
85438 int inuse; /* Offset to metadata */
85439 int align; /* Alignment */
85440 diff --git a/include/linux/smp.h b/include/linux/smp.h
85441 index 93dff5f..933c561 100644
85442 --- a/include/linux/smp.h
85443 +++ b/include/linux/smp.h
85444 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85445 #endif
85446
85447 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85448 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85449 #define put_cpu() preempt_enable()
85450 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85451
85452 /*
85453 * Callback to arch code if there's nosmp or maxcpus=0 on the
85454 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85455 index 46cca4c..3323536 100644
85456 --- a/include/linux/sock_diag.h
85457 +++ b/include/linux/sock_diag.h
85458 @@ -11,7 +11,7 @@ struct sock;
85459 struct sock_diag_handler {
85460 __u8 family;
85461 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85462 -};
85463 +} __do_const;
85464
85465 int sock_diag_register(const struct sock_diag_handler *h);
85466 void sock_diag_unregister(const struct sock_diag_handler *h);
85467 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85468 index 680f9a3..f13aeb0 100644
85469 --- a/include/linux/sonet.h
85470 +++ b/include/linux/sonet.h
85471 @@ -7,7 +7,7 @@
85472 #include <uapi/linux/sonet.h>
85473
85474 struct k_sonet_stats {
85475 -#define __HANDLE_ITEM(i) atomic_t i
85476 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85477 __SONET_ITEMS
85478 #undef __HANDLE_ITEM
85479 };
85480 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85481 index 07d8e53..dc934c9 100644
85482 --- a/include/linux/sunrpc/addr.h
85483 +++ b/include/linux/sunrpc/addr.h
85484 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85485 {
85486 switch (sap->sa_family) {
85487 case AF_INET:
85488 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85489 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85490 case AF_INET6:
85491 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85492 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85493 }
85494 return 0;
85495 }
85496 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85497 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85498 const struct sockaddr *src)
85499 {
85500 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85501 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85502 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85503
85504 dsin->sin_family = ssin->sin_family;
85505 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85506 if (sa->sa_family != AF_INET6)
85507 return 0;
85508
85509 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85510 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85511 }
85512
85513 #endif /* _LINUX_SUNRPC_ADDR_H */
85514 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85515 index 70736b9..37f33db 100644
85516 --- a/include/linux/sunrpc/clnt.h
85517 +++ b/include/linux/sunrpc/clnt.h
85518 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85519 unsigned int p_timer; /* Which RTT timer to use */
85520 u32 p_statidx; /* Which procedure to account */
85521 const char * p_name; /* name of procedure */
85522 -};
85523 +} __do_const;
85524
85525 #ifdef __KERNEL__
85526
85527 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85528 index 2167846..0648fc3 100644
85529 --- a/include/linux/sunrpc/svc.h
85530 +++ b/include/linux/sunrpc/svc.h
85531 @@ -416,7 +416,7 @@ struct svc_procedure {
85532 unsigned int pc_count; /* call count */
85533 unsigned int pc_cachetype; /* cache info (NFS) */
85534 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85535 -};
85536 +} __do_const;
85537
85538 /*
85539 * Function prototypes.
85540 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85541 index 975da75..318c083 100644
85542 --- a/include/linux/sunrpc/svc_rdma.h
85543 +++ b/include/linux/sunrpc/svc_rdma.h
85544 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85545 extern unsigned int svcrdma_max_requests;
85546 extern unsigned int svcrdma_max_req_size;
85547
85548 -extern atomic_t rdma_stat_recv;
85549 -extern atomic_t rdma_stat_read;
85550 -extern atomic_t rdma_stat_write;
85551 -extern atomic_t rdma_stat_sq_starve;
85552 -extern atomic_t rdma_stat_rq_starve;
85553 -extern atomic_t rdma_stat_rq_poll;
85554 -extern atomic_t rdma_stat_rq_prod;
85555 -extern atomic_t rdma_stat_sq_poll;
85556 -extern atomic_t rdma_stat_sq_prod;
85557 +extern atomic_unchecked_t rdma_stat_recv;
85558 +extern atomic_unchecked_t rdma_stat_read;
85559 +extern atomic_unchecked_t rdma_stat_write;
85560 +extern atomic_unchecked_t rdma_stat_sq_starve;
85561 +extern atomic_unchecked_t rdma_stat_rq_starve;
85562 +extern atomic_unchecked_t rdma_stat_rq_poll;
85563 +extern atomic_unchecked_t rdma_stat_rq_prod;
85564 +extern atomic_unchecked_t rdma_stat_sq_poll;
85565 +extern atomic_unchecked_t rdma_stat_sq_prod;
85566
85567 #define RPCRDMA_VERSION 1
85568
85569 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85570 index 8d71d65..f79586e 100644
85571 --- a/include/linux/sunrpc/svcauth.h
85572 +++ b/include/linux/sunrpc/svcauth.h
85573 @@ -120,7 +120,7 @@ struct auth_ops {
85574 int (*release)(struct svc_rqst *rq);
85575 void (*domain_release)(struct auth_domain *);
85576 int (*set_client)(struct svc_rqst *rq);
85577 -};
85578 +} __do_const;
85579
85580 #define SVC_GARBAGE 1
85581 #define SVC_SYSERR 2
85582 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85583 index e7a018e..49f8b17 100644
85584 --- a/include/linux/swiotlb.h
85585 +++ b/include/linux/swiotlb.h
85586 @@ -60,7 +60,8 @@ extern void
85587
85588 extern void
85589 swiotlb_free_coherent(struct device *hwdev, size_t size,
85590 - void *vaddr, dma_addr_t dma_handle);
85591 + void *vaddr, dma_addr_t dma_handle,
85592 + struct dma_attrs *attrs);
85593
85594 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85595 unsigned long offset, size_t size,
85596 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85597 index bda9b81..629e06e 100644
85598 --- a/include/linux/syscalls.h
85599 +++ b/include/linux/syscalls.h
85600 @@ -99,10 +99,16 @@ union bpf_attr;
85601 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85602
85603 #define __SC_DECL(t, a) t a
85604 +#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
85605 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85606 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85607 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85608 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85609 +#define __SC_LONG(t, a) __typeof( \
85610 + __builtin_choose_expr( \
85611 + sizeof(t) > sizeof(int), \
85612 + (t) 0, \
85613 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85614 + )) a
85615 #define __SC_CAST(t, a) (t) a
85616 #define __SC_ARGS(t, a) a
85617 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85618 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85619 asmlinkage long sys_fsync(unsigned int fd);
85620 asmlinkage long sys_fdatasync(unsigned int fd);
85621 asmlinkage long sys_bdflush(int func, long data);
85622 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85623 - char __user *type, unsigned long flags,
85624 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85625 + const char __user *type, unsigned long flags,
85626 void __user *data);
85627 -asmlinkage long sys_umount(char __user *name, int flags);
85628 -asmlinkage long sys_oldumount(char __user *name);
85629 +asmlinkage long sys_umount(const char __user *name, int flags);
85630 +asmlinkage long sys_oldumount(const char __user *name);
85631 asmlinkage long sys_truncate(const char __user *path, long length);
85632 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85633 asmlinkage long sys_stat(const char __user *filename,
85634 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85635 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85636 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85637 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85638 - struct sockaddr __user *, int);
85639 + struct sockaddr __user *, int) __intentional_overflow(0);
85640 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85641 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85642 unsigned int vlen, unsigned flags);
85643 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85644 index 27b3b0b..e093dd9 100644
85645 --- a/include/linux/syscore_ops.h
85646 +++ b/include/linux/syscore_ops.h
85647 @@ -16,7 +16,7 @@ struct syscore_ops {
85648 int (*suspend)(void);
85649 void (*resume)(void);
85650 void (*shutdown)(void);
85651 -};
85652 +} __do_const;
85653
85654 extern void register_syscore_ops(struct syscore_ops *ops);
85655 extern void unregister_syscore_ops(struct syscore_ops *ops);
85656 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85657 index b7361f8..341a15a 100644
85658 --- a/include/linux/sysctl.h
85659 +++ b/include/linux/sysctl.h
85660 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85661
85662 extern int proc_dostring(struct ctl_table *, int,
85663 void __user *, size_t *, loff_t *);
85664 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85665 + void __user *, size_t *, loff_t *);
85666 extern int proc_dointvec(struct ctl_table *, int,
85667 void __user *, size_t *, loff_t *);
85668 extern int proc_dointvec_minmax(struct ctl_table *, int,
85669 @@ -113,7 +115,8 @@ struct ctl_table
85670 struct ctl_table_poll *poll;
85671 void *extra1;
85672 void *extra2;
85673 -};
85674 +} __do_const __randomize_layout;
85675 +typedef struct ctl_table __no_const ctl_table_no_const;
85676
85677 struct ctl_node {
85678 struct rb_node node;
85679 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85680 index f97d0db..c1187dc 100644
85681 --- a/include/linux/sysfs.h
85682 +++ b/include/linux/sysfs.h
85683 @@ -34,7 +34,8 @@ struct attribute {
85684 struct lock_class_key *key;
85685 struct lock_class_key skey;
85686 #endif
85687 -};
85688 +} __do_const;
85689 +typedef struct attribute __no_const attribute_no_const;
85690
85691 /**
85692 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85693 @@ -63,7 +64,8 @@ struct attribute_group {
85694 struct attribute *, int);
85695 struct attribute **attrs;
85696 struct bin_attribute **bin_attrs;
85697 -};
85698 +} __do_const;
85699 +typedef struct attribute_group __no_const attribute_group_no_const;
85700
85701 /**
85702 * Use these macros to make defining attributes easier. See include/linux/device.h
85703 @@ -128,7 +130,8 @@ struct bin_attribute {
85704 char *, loff_t, size_t);
85705 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85706 struct vm_area_struct *vma);
85707 -};
85708 +} __do_const;
85709 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85710
85711 /**
85712 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85713 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85714 index 387fa7d..3fcde6b 100644
85715 --- a/include/linux/sysrq.h
85716 +++ b/include/linux/sysrq.h
85717 @@ -16,6 +16,7 @@
85718
85719 #include <linux/errno.h>
85720 #include <linux/types.h>
85721 +#include <linux/compiler.h>
85722
85723 /* Possible values of bitmask for enabling sysrq functions */
85724 /* 0x0001 is reserved for enable everything */
85725 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85726 char *help_msg;
85727 char *action_msg;
85728 int enable_mask;
85729 -};
85730 +} __do_const;
85731
85732 #ifdef CONFIG_MAGIC_SYSRQ
85733
85734 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85735 index ff307b5..f1a4468 100644
85736 --- a/include/linux/thread_info.h
85737 +++ b/include/linux/thread_info.h
85738 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85739 #error "no set_restore_sigmask() provided and default one won't work"
85740 #endif
85741
85742 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85743 +
85744 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85745 +{
85746 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85747 +}
85748 +
85749 #endif /* __KERNEL__ */
85750
85751 #endif /* _LINUX_THREAD_INFO_H */
85752 diff --git a/include/linux/tty.h b/include/linux/tty.h
85753 index 5171ef8..1048d83e 100644
85754 --- a/include/linux/tty.h
85755 +++ b/include/linux/tty.h
85756 @@ -202,7 +202,7 @@ struct tty_port {
85757 const struct tty_port_operations *ops; /* Port operations */
85758 spinlock_t lock; /* Lock protecting tty field */
85759 int blocked_open; /* Waiting to open */
85760 - int count; /* Usage count */
85761 + atomic_t count; /* Usage count */
85762 wait_queue_head_t open_wait; /* Open waiters */
85763 wait_queue_head_t close_wait; /* Close waiters */
85764 wait_queue_head_t delta_msr_wait; /* Modem status change */
85765 @@ -290,7 +290,7 @@ struct tty_struct {
85766 /* If the tty has a pending do_SAK, queue it here - akpm */
85767 struct work_struct SAK_work;
85768 struct tty_port *port;
85769 -};
85770 +} __randomize_layout;
85771
85772 /* Each of a tty's open files has private_data pointing to tty_file_private */
85773 struct tty_file_private {
85774 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85775 struct tty_struct *tty, struct file *filp);
85776 static inline int tty_port_users(struct tty_port *port)
85777 {
85778 - return port->count + port->blocked_open;
85779 + return atomic_read(&port->count) + port->blocked_open;
85780 }
85781
85782 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85783 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85784 index 92e337c..f46757b 100644
85785 --- a/include/linux/tty_driver.h
85786 +++ b/include/linux/tty_driver.h
85787 @@ -291,7 +291,7 @@ struct tty_operations {
85788 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85789 #endif
85790 const struct file_operations *proc_fops;
85791 -};
85792 +} __do_const __randomize_layout;
85793
85794 struct tty_driver {
85795 int magic; /* magic number for this structure */
85796 @@ -325,7 +325,7 @@ struct tty_driver {
85797
85798 const struct tty_operations *ops;
85799 struct list_head tty_drivers;
85800 -};
85801 +} __randomize_layout;
85802
85803 extern struct list_head tty_drivers;
85804
85805 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85806 index 00c9d68..bc0188b 100644
85807 --- a/include/linux/tty_ldisc.h
85808 +++ b/include/linux/tty_ldisc.h
85809 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85810
85811 struct module *owner;
85812
85813 - int refcount;
85814 + atomic_t refcount;
85815 };
85816
85817 struct tty_ldisc {
85818 diff --git a/include/linux/types.h b/include/linux/types.h
85819 index a0bb704..f511c77 100644
85820 --- a/include/linux/types.h
85821 +++ b/include/linux/types.h
85822 @@ -177,10 +177,26 @@ typedef struct {
85823 int counter;
85824 } atomic_t;
85825
85826 +#ifdef CONFIG_PAX_REFCOUNT
85827 +typedef struct {
85828 + int counter;
85829 +} atomic_unchecked_t;
85830 +#else
85831 +typedef atomic_t atomic_unchecked_t;
85832 +#endif
85833 +
85834 #ifdef CONFIG_64BIT
85835 typedef struct {
85836 long counter;
85837 } atomic64_t;
85838 +
85839 +#ifdef CONFIG_PAX_REFCOUNT
85840 +typedef struct {
85841 + long counter;
85842 +} atomic64_unchecked_t;
85843 +#else
85844 +typedef atomic64_t atomic64_unchecked_t;
85845 +#endif
85846 #endif
85847
85848 struct list_head {
85849 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85850 index ecd3319..8a36ded 100644
85851 --- a/include/linux/uaccess.h
85852 +++ b/include/linux/uaccess.h
85853 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85854 long ret; \
85855 mm_segment_t old_fs = get_fs(); \
85856 \
85857 - set_fs(KERNEL_DS); \
85858 pagefault_disable(); \
85859 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85860 - pagefault_enable(); \
85861 + set_fs(KERNEL_DS); \
85862 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85863 set_fs(old_fs); \
85864 + pagefault_enable(); \
85865 ret; \
85866 })
85867
85868 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85869 index 2d1f9b6..d7a9fce 100644
85870 --- a/include/linux/uidgid.h
85871 +++ b/include/linux/uidgid.h
85872 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85873
85874 #endif /* CONFIG_USER_NS */
85875
85876 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85877 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85878 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85879 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85880 +
85881 #endif /* _LINUX_UIDGID_H */
85882 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85883 index baa8171..9ca98ba 100644
85884 --- a/include/linux/uio_driver.h
85885 +++ b/include/linux/uio_driver.h
85886 @@ -67,7 +67,7 @@ struct uio_device {
85887 struct module *owner;
85888 struct device *dev;
85889 int minor;
85890 - atomic_t event;
85891 + atomic_unchecked_t event;
85892 struct fasync_struct *async_queue;
85893 wait_queue_head_t wait;
85894 struct uio_info *info;
85895 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85896 index 99c1b4d..562e6f3 100644
85897 --- a/include/linux/unaligned/access_ok.h
85898 +++ b/include/linux/unaligned/access_ok.h
85899 @@ -4,34 +4,34 @@
85900 #include <linux/kernel.h>
85901 #include <asm/byteorder.h>
85902
85903 -static inline u16 get_unaligned_le16(const void *p)
85904 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85905 {
85906 - return le16_to_cpup((__le16 *)p);
85907 + return le16_to_cpup((const __le16 *)p);
85908 }
85909
85910 -static inline u32 get_unaligned_le32(const void *p)
85911 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85912 {
85913 - return le32_to_cpup((__le32 *)p);
85914 + return le32_to_cpup((const __le32 *)p);
85915 }
85916
85917 -static inline u64 get_unaligned_le64(const void *p)
85918 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85919 {
85920 - return le64_to_cpup((__le64 *)p);
85921 + return le64_to_cpup((const __le64 *)p);
85922 }
85923
85924 -static inline u16 get_unaligned_be16(const void *p)
85925 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85926 {
85927 - return be16_to_cpup((__be16 *)p);
85928 + return be16_to_cpup((const __be16 *)p);
85929 }
85930
85931 -static inline u32 get_unaligned_be32(const void *p)
85932 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85933 {
85934 - return be32_to_cpup((__be32 *)p);
85935 + return be32_to_cpup((const __be32 *)p);
85936 }
85937
85938 -static inline u64 get_unaligned_be64(const void *p)
85939 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85940 {
85941 - return be64_to_cpup((__be64 *)p);
85942 + return be64_to_cpup((const __be64 *)p);
85943 }
85944
85945 static inline void put_unaligned_le16(u16 val, void *p)
85946 diff --git a/include/linux/usb.h b/include/linux/usb.h
85947 index 447a7e2..9cea7e9 100644
85948 --- a/include/linux/usb.h
85949 +++ b/include/linux/usb.h
85950 @@ -571,7 +571,7 @@ struct usb_device {
85951 int maxchild;
85952
85953 u32 quirks;
85954 - atomic_t urbnum;
85955 + atomic_unchecked_t urbnum;
85956
85957 unsigned long active_duration;
85958
85959 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85960
85961 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85962 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85963 - void *data, __u16 size, int timeout);
85964 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85965 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85966 void *data, int len, int *actual_length, int timeout);
85967 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85968 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85969 index d5952bb..9a626d4 100644
85970 --- a/include/linux/usb/renesas_usbhs.h
85971 +++ b/include/linux/usb/renesas_usbhs.h
85972 @@ -39,7 +39,7 @@ enum {
85973 */
85974 struct renesas_usbhs_driver_callback {
85975 int (*notify_hotplug)(struct platform_device *pdev);
85976 -};
85977 +} __no_const;
85978
85979 /*
85980 * callback functions for platform
85981 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85982 index 9f3579f..3b2afa5 100644
85983 --- a/include/linux/user_namespace.h
85984 +++ b/include/linux/user_namespace.h
85985 @@ -38,7 +38,7 @@ struct user_namespace {
85986 struct key *persistent_keyring_register;
85987 struct rw_semaphore persistent_keyring_register_sem;
85988 #endif
85989 -};
85990 +} __randomize_layout;
85991
85992 extern struct user_namespace init_user_ns;
85993
85994 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85995 index 239e277..22a5cf5 100644
85996 --- a/include/linux/utsname.h
85997 +++ b/include/linux/utsname.h
85998 @@ -24,7 +24,7 @@ struct uts_namespace {
85999 struct new_utsname name;
86000 struct user_namespace *user_ns;
86001 unsigned int proc_inum;
86002 -};
86003 +} __randomize_layout;
86004 extern struct uts_namespace init_uts_ns;
86005
86006 #ifdef CONFIG_UTS_NS
86007 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86008 index 6f8fbcf..4efc177 100644
86009 --- a/include/linux/vermagic.h
86010 +++ b/include/linux/vermagic.h
86011 @@ -25,9 +25,42 @@
86012 #define MODULE_ARCH_VERMAGIC ""
86013 #endif
86014
86015 +#ifdef CONFIG_PAX_REFCOUNT
86016 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86017 +#else
86018 +#define MODULE_PAX_REFCOUNT ""
86019 +#endif
86020 +
86021 +#ifdef CONSTIFY_PLUGIN
86022 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86023 +#else
86024 +#define MODULE_CONSTIFY_PLUGIN ""
86025 +#endif
86026 +
86027 +#ifdef STACKLEAK_PLUGIN
86028 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86029 +#else
86030 +#define MODULE_STACKLEAK_PLUGIN ""
86031 +#endif
86032 +
86033 +#ifdef RANDSTRUCT_PLUGIN
86034 +#include <generated/randomize_layout_hash.h>
86035 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86036 +#else
86037 +#define MODULE_RANDSTRUCT_PLUGIN
86038 +#endif
86039 +
86040 +#ifdef CONFIG_GRKERNSEC
86041 +#define MODULE_GRSEC "GRSEC "
86042 +#else
86043 +#define MODULE_GRSEC ""
86044 +#endif
86045 +
86046 #define VERMAGIC_STRING \
86047 UTS_RELEASE " " \
86048 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86049 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86050 - MODULE_ARCH_VERMAGIC
86051 + MODULE_ARCH_VERMAGIC \
86052 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86053 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86054
86055 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86056 index b483abd..af305ad 100644
86057 --- a/include/linux/vga_switcheroo.h
86058 +++ b/include/linux/vga_switcheroo.h
86059 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86060
86061 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86062
86063 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86064 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86065 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86066 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86067 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86068 #else
86069
86070 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86071 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86072
86073 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86074
86075 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86076 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86077 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86078 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86079 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86080
86081 #endif
86082 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86083 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86084 index b87696f..1d11de7 100644
86085 --- a/include/linux/vmalloc.h
86086 +++ b/include/linux/vmalloc.h
86087 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86088 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86089 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86090 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86091 +
86092 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86093 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86094 +#endif
86095 +
86096 /* bits [20..32] reserved for arch specific ioremap internals */
86097
86098 /*
86099 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86100 unsigned long flags, pgprot_t prot);
86101 extern void vunmap(const void *addr);
86102
86103 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86104 +extern void unmap_process_stacks(struct task_struct *task);
86105 +#endif
86106 +
86107 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86108 unsigned long uaddr, void *kaddr,
86109 unsigned long size);
86110 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86111
86112 /* for /dev/kmem */
86113 extern long vread(char *buf, char *addr, unsigned long count);
86114 -extern long vwrite(char *buf, char *addr, unsigned long count);
86115 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86116
86117 /*
86118 * Internals. Dont't use..
86119 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86120 index 82e7db7..f8ce3d0 100644
86121 --- a/include/linux/vmstat.h
86122 +++ b/include/linux/vmstat.h
86123 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86124 /*
86125 * Zone based page accounting with per cpu differentials.
86126 */
86127 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86128 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86129
86130 static inline void zone_page_state_add(long x, struct zone *zone,
86131 enum zone_stat_item item)
86132 {
86133 - atomic_long_add(x, &zone->vm_stat[item]);
86134 - atomic_long_add(x, &vm_stat[item]);
86135 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86136 + atomic_long_add_unchecked(x, &vm_stat[item]);
86137 }
86138
86139 -static inline unsigned long global_page_state(enum zone_stat_item item)
86140 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86141 {
86142 - long x = atomic_long_read(&vm_stat[item]);
86143 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86144 #ifdef CONFIG_SMP
86145 if (x < 0)
86146 x = 0;
86147 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86148 return x;
86149 }
86150
86151 -static inline unsigned long zone_page_state(struct zone *zone,
86152 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86153 enum zone_stat_item item)
86154 {
86155 - long x = atomic_long_read(&zone->vm_stat[item]);
86156 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86157 #ifdef CONFIG_SMP
86158 if (x < 0)
86159 x = 0;
86160 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86161 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86162 enum zone_stat_item item)
86163 {
86164 - long x = atomic_long_read(&zone->vm_stat[item]);
86165 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86166
86167 #ifdef CONFIG_SMP
86168 int cpu;
86169 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86170
86171 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86172 {
86173 - atomic_long_inc(&zone->vm_stat[item]);
86174 - atomic_long_inc(&vm_stat[item]);
86175 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86176 + atomic_long_inc_unchecked(&vm_stat[item]);
86177 }
86178
86179 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86180 {
86181 - atomic_long_dec(&zone->vm_stat[item]);
86182 - atomic_long_dec(&vm_stat[item]);
86183 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86184 + atomic_long_dec_unchecked(&vm_stat[item]);
86185 }
86186
86187 static inline void __inc_zone_page_state(struct page *page,
86188 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86189 index 91b0a68..0e9adf6 100644
86190 --- a/include/linux/xattr.h
86191 +++ b/include/linux/xattr.h
86192 @@ -28,7 +28,7 @@ struct xattr_handler {
86193 size_t size, int handler_flags);
86194 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86195 size_t size, int flags, int handler_flags);
86196 -};
86197 +} __do_const;
86198
86199 struct xattr {
86200 const char *name;
86201 @@ -37,6 +37,9 @@ struct xattr {
86202 };
86203
86204 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86205 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86206 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86207 +#endif
86208 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86209 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86210 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86211 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86212 index 92dbbd3..13ab0b3 100644
86213 --- a/include/linux/zlib.h
86214 +++ b/include/linux/zlib.h
86215 @@ -31,6 +31,7 @@
86216 #define _ZLIB_H
86217
86218 #include <linux/zconf.h>
86219 +#include <linux/compiler.h>
86220
86221 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86222 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86223 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86224
86225 /* basic functions */
86226
86227 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86228 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86229 /*
86230 Returns the number of bytes that needs to be allocated for a per-
86231 stream workspace with the specified parameters. A pointer to this
86232 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86233 index eb76cfd..9fd0e7c 100644
86234 --- a/include/media/v4l2-dev.h
86235 +++ b/include/media/v4l2-dev.h
86236 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86237 int (*mmap) (struct file *, struct vm_area_struct *);
86238 int (*open) (struct file *);
86239 int (*release) (struct file *);
86240 -};
86241 +} __do_const;
86242
86243 /*
86244 * Newer version of video_device, handled by videodev2.c
86245 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86246 index ffb69da..040393e 100644
86247 --- a/include/media/v4l2-device.h
86248 +++ b/include/media/v4l2-device.h
86249 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86250 this function returns 0. If the name ends with a digit (e.g. cx18),
86251 then the name will be set to cx18-0 since cx180 looks really odd. */
86252 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86253 - atomic_t *instance);
86254 + atomic_unchecked_t *instance);
86255
86256 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86257 Since the parent disappears this ensures that v4l2_dev doesn't have an
86258 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86259 index 2a25dec..bf6dd8a 100644
86260 --- a/include/net/9p/transport.h
86261 +++ b/include/net/9p/transport.h
86262 @@ -62,7 +62,7 @@ struct p9_trans_module {
86263 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86264 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86265 char *, char *, int , int, int, int);
86266 -};
86267 +} __do_const;
86268
86269 void v9fs_register_trans(struct p9_trans_module *m);
86270 void v9fs_unregister_trans(struct p9_trans_module *m);
86271 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86272 index a175ba4..196eb8242 100644
86273 --- a/include/net/af_unix.h
86274 +++ b/include/net/af_unix.h
86275 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86276 u32 secid; /* Security ID */
86277 #endif
86278 u32 consumed;
86279 -};
86280 +} __randomize_layout;
86281
86282 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86283 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86284 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86285 index ead99f0..6263c4b 100644
86286 --- a/include/net/bluetooth/l2cap.h
86287 +++ b/include/net/bluetooth/l2cap.h
86288 @@ -608,7 +608,7 @@ struct l2cap_ops {
86289 unsigned char *kdata,
86290 struct iovec *iov,
86291 int len);
86292 -};
86293 +} __do_const;
86294
86295 struct l2cap_conn {
86296 struct hci_conn *hcon;
86297 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86298 index f2ae33d..c457cf0 100644
86299 --- a/include/net/caif/cfctrl.h
86300 +++ b/include/net/caif/cfctrl.h
86301 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86302 void (*radioset_rsp)(void);
86303 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86304 struct cflayer *client_layer);
86305 -};
86306 +} __no_const;
86307
86308 /* Link Setup Parameters for CAIF-Links. */
86309 struct cfctrl_link_param {
86310 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86311 struct cfctrl {
86312 struct cfsrvl serv;
86313 struct cfctrl_rsp res;
86314 - atomic_t req_seq_no;
86315 - atomic_t rsp_seq_no;
86316 + atomic_unchecked_t req_seq_no;
86317 + atomic_unchecked_t rsp_seq_no;
86318 struct list_head list;
86319 /* Protects from simultaneous access to first_req list */
86320 spinlock_t info_list_lock;
86321 diff --git a/include/net/flow.h b/include/net/flow.h
86322 index 8109a15..504466d 100644
86323 --- a/include/net/flow.h
86324 +++ b/include/net/flow.h
86325 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86326
86327 void flow_cache_flush(struct net *net);
86328 void flow_cache_flush_deferred(struct net *net);
86329 -extern atomic_t flow_cache_genid;
86330 +extern atomic_unchecked_t flow_cache_genid;
86331
86332 #endif
86333 diff --git a/include/net/flow_keys.h b/include/net/flow_keys.h
86334 index 7ee2df0..dc8fd81 100644
86335 --- a/include/net/flow_keys.h
86336 +++ b/include/net/flow_keys.h
86337 @@ -22,9 +22,9 @@ struct flow_keys {
86338 __be32 ports;
86339 __be16 port16[2];
86340 };
86341 - u16 thoff;
86342 - u16 n_proto;
86343 - u8 ip_proto;
86344 + u16 thoff;
86345 + __be16 n_proto;
86346 + u8 ip_proto;
86347 };
86348
86349 bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
86350 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86351 index af10c2c..a431cc5 100644
86352 --- a/include/net/genetlink.h
86353 +++ b/include/net/genetlink.h
86354 @@ -120,7 +120,7 @@ struct genl_ops {
86355 u8 cmd;
86356 u8 internal_flags;
86357 u8 flags;
86358 -};
86359 +} __do_const;
86360
86361 int __genl_register_family(struct genl_family *family);
86362
86363 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86364 index 734d9b5..48a9a4b 100644
86365 --- a/include/net/gro_cells.h
86366 +++ b/include/net/gro_cells.h
86367 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86368 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86369
86370 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86371 - atomic_long_inc(&dev->rx_dropped);
86372 + atomic_long_inc_unchecked(&dev->rx_dropped);
86373 kfree_skb(skb);
86374 return;
86375 }
86376 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86377 index 848e85c..051c7de 100644
86378 --- a/include/net/inet_connection_sock.h
86379 +++ b/include/net/inet_connection_sock.h
86380 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86381 int (*bind_conflict)(const struct sock *sk,
86382 const struct inet_bind_bucket *tb, bool relax);
86383 void (*mtu_reduced)(struct sock *sk);
86384 -};
86385 +} __do_const;
86386
86387 /** inet_connection_sock - INET connection oriented sock
86388 *
86389 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86390 index 80479ab..0c3f647 100644
86391 --- a/include/net/inetpeer.h
86392 +++ b/include/net/inetpeer.h
86393 @@ -47,7 +47,7 @@ struct inet_peer {
86394 */
86395 union {
86396 struct {
86397 - atomic_t rid; /* Frag reception counter */
86398 + atomic_unchecked_t rid; /* Frag reception counter */
86399 };
86400 struct rcu_head rcu;
86401 struct inet_peer *gc_next;
86402 diff --git a/include/net/ip.h b/include/net/ip.h
86403 index 0bb6207..1f38247 100644
86404 --- a/include/net/ip.h
86405 +++ b/include/net/ip.h
86406 @@ -39,11 +39,12 @@ struct inet_skb_parm {
86407 struct ip_options opt; /* Compiled IP options */
86408 unsigned char flags;
86409
86410 -#define IPSKB_FORWARDED 1
86411 -#define IPSKB_XFRM_TUNNEL_SIZE 2
86412 -#define IPSKB_XFRM_TRANSFORMED 4
86413 -#define IPSKB_FRAG_COMPLETE 8
86414 -#define IPSKB_REROUTED 16
86415 +#define IPSKB_FORWARDED BIT(0)
86416 +#define IPSKB_XFRM_TUNNEL_SIZE BIT(1)
86417 +#define IPSKB_XFRM_TRANSFORMED BIT(2)
86418 +#define IPSKB_FRAG_COMPLETE BIT(3)
86419 +#define IPSKB_REROUTED BIT(4)
86420 +#define IPSKB_DOREDIRECT BIT(5)
86421
86422 u16 frag_max_size;
86423 };
86424 @@ -316,7 +317,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86425 }
86426 }
86427
86428 -u32 ip_idents_reserve(u32 hash, int segs);
86429 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86430 void __ip_select_ident(struct iphdr *iph, int segs);
86431
86432 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86433 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86434 index dc9d2a2..d985691 100644
86435 --- a/include/net/ip_fib.h
86436 +++ b/include/net/ip_fib.h
86437 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86438
86439 #define FIB_RES_SADDR(net, res) \
86440 ((FIB_RES_NH(res).nh_saddr_genid == \
86441 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86442 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86443 FIB_RES_NH(res).nh_saddr : \
86444 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86445 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86446 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86447 index 615b20b..fd4cbd8 100644
86448 --- a/include/net/ip_vs.h
86449 +++ b/include/net/ip_vs.h
86450 @@ -534,7 +534,7 @@ struct ip_vs_conn {
86451 struct ip_vs_conn *control; /* Master control connection */
86452 atomic_t n_control; /* Number of controlled ones */
86453 struct ip_vs_dest *dest; /* real server */
86454 - atomic_t in_pkts; /* incoming packet counter */
86455 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86456
86457 /* Packet transmitter for different forwarding methods. If it
86458 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86459 @@ -682,7 +682,7 @@ struct ip_vs_dest {
86460 __be16 port; /* port number of the server */
86461 union nf_inet_addr addr; /* IP address of the server */
86462 volatile unsigned int flags; /* dest status flags */
86463 - atomic_t conn_flags; /* flags to copy to conn */
86464 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86465 atomic_t weight; /* server weight */
86466
86467 atomic_t refcnt; /* reference counter */
86468 @@ -928,11 +928,11 @@ struct netns_ipvs {
86469 /* ip_vs_lblc */
86470 int sysctl_lblc_expiration;
86471 struct ctl_table_header *lblc_ctl_header;
86472 - struct ctl_table *lblc_ctl_table;
86473 + ctl_table_no_const *lblc_ctl_table;
86474 /* ip_vs_lblcr */
86475 int sysctl_lblcr_expiration;
86476 struct ctl_table_header *lblcr_ctl_header;
86477 - struct ctl_table *lblcr_ctl_table;
86478 + ctl_table_no_const *lblcr_ctl_table;
86479 /* ip_vs_est */
86480 struct list_head est_list; /* estimator list */
86481 spinlock_t est_lock;
86482 diff --git a/include/net/ipv6.h b/include/net/ipv6.h
86483 index 4292929..7e21d2e 100644
86484 --- a/include/net/ipv6.h
86485 +++ b/include/net/ipv6.h
86486 @@ -708,7 +708,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86487 __be32 flowlabel, bool autolabel)
86488 {
86489 if (!flowlabel && (autolabel || net->ipv6.sysctl.auto_flowlabels)) {
86490 - __be32 hash;
86491 + u32 hash;
86492
86493 hash = skb_get_hash(skb);
86494
86495 @@ -718,7 +718,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86496 */
86497 hash ^= hash >> 12;
86498
86499 - flowlabel = hash & IPV6_FLOWLABEL_MASK;
86500 + flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
86501 }
86502
86503 return flowlabel;
86504 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86505 index 8d4f588..2e37ad2 100644
86506 --- a/include/net/irda/ircomm_tty.h
86507 +++ b/include/net/irda/ircomm_tty.h
86508 @@ -33,6 +33,7 @@
86509 #include <linux/termios.h>
86510 #include <linux/timer.h>
86511 #include <linux/tty.h> /* struct tty_struct */
86512 +#include <asm/local.h>
86513
86514 #include <net/irda/irias_object.h>
86515 #include <net/irda/ircomm_core.h>
86516 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86517 index 714cc9a..ea05f3e 100644
86518 --- a/include/net/iucv/af_iucv.h
86519 +++ b/include/net/iucv/af_iucv.h
86520 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86521 struct iucv_sock_list {
86522 struct hlist_head head;
86523 rwlock_t lock;
86524 - atomic_t autobind_name;
86525 + atomic_unchecked_t autobind_name;
86526 };
86527
86528 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86529 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86530 index f3be818..bf46196 100644
86531 --- a/include/net/llc_c_ac.h
86532 +++ b/include/net/llc_c_ac.h
86533 @@ -87,7 +87,7 @@
86534 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86535 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86536
86537 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86538 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86539
86540 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86541 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86542 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86543 index 3948cf1..83b28c4 100644
86544 --- a/include/net/llc_c_ev.h
86545 +++ b/include/net/llc_c_ev.h
86546 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86547 return (struct llc_conn_state_ev *)skb->cb;
86548 }
86549
86550 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86551 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86552 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86553 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86554
86555 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86556 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86557 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86558 index 0e79cfb..f46db31 100644
86559 --- a/include/net/llc_c_st.h
86560 +++ b/include/net/llc_c_st.h
86561 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86562 u8 next_state;
86563 llc_conn_ev_qfyr_t *ev_qualifiers;
86564 llc_conn_action_t *ev_actions;
86565 -};
86566 +} __do_const;
86567
86568 struct llc_conn_state {
86569 u8 current_state;
86570 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86571 index a61b98c..aade1eb 100644
86572 --- a/include/net/llc_s_ac.h
86573 +++ b/include/net/llc_s_ac.h
86574 @@ -23,7 +23,7 @@
86575 #define SAP_ACT_TEST_IND 9
86576
86577 /* All action functions must look like this */
86578 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86579 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86580
86581 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86582 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86583 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86584 index 567c681..cd73ac02 100644
86585 --- a/include/net/llc_s_st.h
86586 +++ b/include/net/llc_s_st.h
86587 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86588 llc_sap_ev_t ev;
86589 u8 next_state;
86590 llc_sap_action_t *ev_actions;
86591 -};
86592 +} __do_const;
86593
86594 struct llc_sap_state {
86595 u8 curr_state;
86596 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86597 index a9de1da..df72057 100644
86598 --- a/include/net/mac80211.h
86599 +++ b/include/net/mac80211.h
86600 @@ -4645,7 +4645,7 @@ struct rate_control_ops {
86601 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86602
86603 u32 (*get_expected_throughput)(void *priv_sta);
86604 -};
86605 +} __do_const;
86606
86607 static inline int rate_supported(struct ieee80211_sta *sta,
86608 enum ieee80211_band band,
86609 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86610 index f60558d..e5ed9bd 100644
86611 --- a/include/net/neighbour.h
86612 +++ b/include/net/neighbour.h
86613 @@ -163,7 +163,7 @@ struct neigh_ops {
86614 void (*error_report)(struct neighbour *, struct sk_buff *);
86615 int (*output)(struct neighbour *, struct sk_buff *);
86616 int (*connected_output)(struct neighbour *, struct sk_buff *);
86617 -};
86618 +} __do_const;
86619
86620 struct pneigh_entry {
86621 struct pneigh_entry *next;
86622 @@ -217,7 +217,7 @@ struct neigh_table {
86623 struct neigh_statistics __percpu *stats;
86624 struct neigh_hash_table __rcu *nht;
86625 struct pneigh_entry **phash_buckets;
86626 -};
86627 +} __randomize_layout;
86628
86629 static inline int neigh_parms_family(struct neigh_parms *p)
86630 {
86631 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86632 index e0d6466..e2f3003 100644
86633 --- a/include/net/net_namespace.h
86634 +++ b/include/net/net_namespace.h
86635 @@ -129,8 +129,8 @@ struct net {
86636 struct netns_ipvs *ipvs;
86637 #endif
86638 struct sock *diag_nlsk;
86639 - atomic_t fnhe_genid;
86640 -};
86641 + atomic_unchecked_t fnhe_genid;
86642 +} __randomize_layout;
86643
86644 #include <linux/seq_file_net.h>
86645
86646 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86647 #define __net_init __init
86648 #define __net_exit __exit_refok
86649 #define __net_initdata __initdata
86650 +#ifdef CONSTIFY_PLUGIN
86651 #define __net_initconst __initconst
86652 +#else
86653 +#define __net_initconst __initdata
86654 +#endif
86655 #endif
86656
86657 struct pernet_operations {
86658 @@ -296,7 +300,7 @@ struct pernet_operations {
86659 void (*exit_batch)(struct list_head *net_exit_list);
86660 int *id;
86661 size_t size;
86662 -};
86663 +} __do_const;
86664
86665 /*
86666 * Use these carefully. If you implement a network device and it
86667 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86668
86669 static inline int rt_genid_ipv4(struct net *net)
86670 {
86671 - return atomic_read(&net->ipv4.rt_genid);
86672 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86673 }
86674
86675 static inline void rt_genid_bump_ipv4(struct net *net)
86676 {
86677 - atomic_inc(&net->ipv4.rt_genid);
86678 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86679 }
86680
86681 extern void (*__fib6_flush_trees)(struct net *net);
86682 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86683
86684 static inline int fnhe_genid(struct net *net)
86685 {
86686 - return atomic_read(&net->fnhe_genid);
86687 + return atomic_read_unchecked(&net->fnhe_genid);
86688 }
86689
86690 static inline void fnhe_genid_bump(struct net *net)
86691 {
86692 - atomic_inc(&net->fnhe_genid);
86693 + atomic_inc_unchecked(&net->fnhe_genid);
86694 }
86695
86696 #endif /* __NET_NET_NAMESPACE_H */
86697 diff --git a/include/net/netlink.h b/include/net/netlink.h
86698 index 7b903e1..ad9ca4b 100644
86699 --- a/include/net/netlink.h
86700 +++ b/include/net/netlink.h
86701 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86702 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86703 {
86704 if (mark)
86705 - skb_trim(skb, (unsigned char *) mark - skb->data);
86706 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86707 }
86708
86709 /**
86710 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86711 index 29d6a94..235d3d84 100644
86712 --- a/include/net/netns/conntrack.h
86713 +++ b/include/net/netns/conntrack.h
86714 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86715 struct nf_proto_net {
86716 #ifdef CONFIG_SYSCTL
86717 struct ctl_table_header *ctl_table_header;
86718 - struct ctl_table *ctl_table;
86719 + ctl_table_no_const *ctl_table;
86720 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86721 struct ctl_table_header *ctl_compat_header;
86722 - struct ctl_table *ctl_compat_table;
86723 + ctl_table_no_const *ctl_compat_table;
86724 #endif
86725 #endif
86726 unsigned int users;
86727 @@ -60,7 +60,7 @@ struct nf_ip_net {
86728 struct nf_icmp_net icmpv6;
86729 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86730 struct ctl_table_header *ctl_table_header;
86731 - struct ctl_table *ctl_table;
86732 + ctl_table_no_const *ctl_table;
86733 #endif
86734 };
86735
86736 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86737 index 24945ce..f19e42f 100644
86738 --- a/include/net/netns/ipv4.h
86739 +++ b/include/net/netns/ipv4.h
86740 @@ -83,7 +83,7 @@ struct netns_ipv4 {
86741
86742 struct ping_group_range ping_group_range;
86743
86744 - atomic_t dev_addr_genid;
86745 + atomic_unchecked_t dev_addr_genid;
86746
86747 #ifdef CONFIG_SYSCTL
86748 unsigned long *sysctl_local_reserved_ports;
86749 @@ -97,6 +97,6 @@ struct netns_ipv4 {
86750 struct fib_rules_ops *mr_rules_ops;
86751 #endif
86752 #endif
86753 - atomic_t rt_genid;
86754 + atomic_unchecked_t rt_genid;
86755 };
86756 #endif
86757 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86758 index 69ae41f..4f94868 100644
86759 --- a/include/net/netns/ipv6.h
86760 +++ b/include/net/netns/ipv6.h
86761 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86762 struct fib_rules_ops *mr6_rules_ops;
86763 #endif
86764 #endif
86765 - atomic_t dev_addr_genid;
86766 - atomic_t fib6_sernum;
86767 + atomic_unchecked_t dev_addr_genid;
86768 + atomic_unchecked_t fib6_sernum;
86769 };
86770
86771 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86772 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86773 index 9da7982..099321b9 100644
86774 --- a/include/net/netns/xfrm.h
86775 +++ b/include/net/netns/xfrm.h
86776 @@ -78,7 +78,7 @@ struct netns_xfrm {
86777
86778 /* flow cache part */
86779 struct flow_cache flow_cache_global;
86780 - atomic_t flow_cache_genid;
86781 + atomic_unchecked_t flow_cache_genid;
86782 struct list_head flow_cache_gc_list;
86783 spinlock_t flow_cache_gc_lock;
86784 struct work_struct flow_cache_gc_work;
86785 diff --git a/include/net/ping.h b/include/net/ping.h
86786 index 026479b..d9b2829 100644
86787 --- a/include/net/ping.h
86788 +++ b/include/net/ping.h
86789 @@ -54,7 +54,7 @@ struct ping_iter_state {
86790
86791 extern struct proto ping_prot;
86792 #if IS_ENABLED(CONFIG_IPV6)
86793 -extern struct pingv6_ops pingv6_ops;
86794 +extern struct pingv6_ops *pingv6_ops;
86795 #endif
86796
86797 struct pingfakehdr {
86798 diff --git a/include/net/protocol.h b/include/net/protocol.h
86799 index d6fcc1f..ca277058 100644
86800 --- a/include/net/protocol.h
86801 +++ b/include/net/protocol.h
86802 @@ -49,7 +49,7 @@ struct net_protocol {
86803 * socket lookup?
86804 */
86805 icmp_strict_tag_validation:1;
86806 -};
86807 +} __do_const;
86808
86809 #if IS_ENABLED(CONFIG_IPV6)
86810 struct inet6_protocol {
86811 @@ -62,7 +62,7 @@ struct inet6_protocol {
86812 u8 type, u8 code, int offset,
86813 __be32 info);
86814 unsigned int flags; /* INET6_PROTO_xxx */
86815 -};
86816 +} __do_const;
86817
86818 #define INET6_PROTO_NOPOLICY 0x1
86819 #define INET6_PROTO_FINAL 0x2
86820 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86821 index e21b9f9..0191ef0 100644
86822 --- a/include/net/rtnetlink.h
86823 +++ b/include/net/rtnetlink.h
86824 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86825 int (*fill_slave_info)(struct sk_buff *skb,
86826 const struct net_device *dev,
86827 const struct net_device *slave_dev);
86828 -};
86829 +} __do_const;
86830
86831 int __rtnl_link_register(struct rtnl_link_ops *ops);
86832 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86833 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86834 index 4a5b9a3..ca27d73 100644
86835 --- a/include/net/sctp/checksum.h
86836 +++ b/include/net/sctp/checksum.h
86837 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86838 unsigned int offset)
86839 {
86840 struct sctphdr *sh = sctp_hdr(skb);
86841 - __le32 ret, old = sh->checksum;
86842 - const struct skb_checksum_ops ops = {
86843 + __le32 ret, old = sh->checksum;
86844 + static const struct skb_checksum_ops ops = {
86845 .update = sctp_csum_update,
86846 .combine = sctp_csum_combine,
86847 };
86848 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86849 index 72a31db..aaa63d9 100644
86850 --- a/include/net/sctp/sm.h
86851 +++ b/include/net/sctp/sm.h
86852 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86853 typedef struct {
86854 sctp_state_fn_t *fn;
86855 const char *name;
86856 -} sctp_sm_table_entry_t;
86857 +} __do_const sctp_sm_table_entry_t;
86858
86859 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86860 * currently in use.
86861 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86862 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86863
86864 /* Extern declarations for major data structures. */
86865 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86866 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86867
86868
86869 /* Get the size of a DATA chunk payload. */
86870 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86871 index 4ff3f67..89ae38e 100644
86872 --- a/include/net/sctp/structs.h
86873 +++ b/include/net/sctp/structs.h
86874 @@ -509,7 +509,7 @@ struct sctp_pf {
86875 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86876 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86877 struct sctp_af *af;
86878 -};
86879 +} __do_const;
86880
86881
86882 /* Structure to track chunk fragments that have been acked, but peer
86883 diff --git a/include/net/sock.h b/include/net/sock.h
86884 index 7db3db1..a915cca 100644
86885 --- a/include/net/sock.h
86886 +++ b/include/net/sock.h
86887 @@ -355,7 +355,7 @@ struct sock {
86888 unsigned int sk_napi_id;
86889 unsigned int sk_ll_usec;
86890 #endif
86891 - atomic_t sk_drops;
86892 + atomic_unchecked_t sk_drops;
86893 int sk_rcvbuf;
86894
86895 struct sk_filter __rcu *sk_filter;
86896 @@ -1048,7 +1048,7 @@ struct proto {
86897 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86898 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86899 #endif
86900 -};
86901 +} __randomize_layout;
86902
86903 /*
86904 * Bits in struct cg_proto.flags
86905 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86906 return ret >> PAGE_SHIFT;
86907 }
86908
86909 -static inline long
86910 +static inline long __intentional_overflow(-1)
86911 sk_memory_allocated(const struct sock *sk)
86912 {
86913 struct proto *prot = sk->sk_prot;
86914 @@ -1380,7 +1380,7 @@ struct sock_iocb {
86915 struct scm_cookie *scm;
86916 struct msghdr *msg, async_msg;
86917 struct kiocb *kiocb;
86918 -};
86919 +} __randomize_layout;
86920
86921 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86922 {
86923 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86924 }
86925
86926 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86927 - char __user *from, char *to,
86928 + char __user *from, unsigned char *to,
86929 int copy, int offset)
86930 {
86931 if (skb->ip_summed == CHECKSUM_NONE) {
86932 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86933 }
86934 }
86935
86936 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86937 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86938
86939 /**
86940 * sk_page_frag - return an appropriate page_frag
86941 diff --git a/include/net/tcp.h b/include/net/tcp.h
86942 index 4062b4f..9ff45e7 100644
86943 --- a/include/net/tcp.h
86944 +++ b/include/net/tcp.h
86945 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86946 void tcp_xmit_retransmit_queue(struct sock *);
86947 void tcp_simple_retransmit(struct sock *);
86948 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86949 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86950 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86951
86952 void tcp_send_probe0(struct sock *);
86953 void tcp_send_partial(struct sock *);
86954 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86955 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86956 */
86957 struct tcp_skb_cb {
86958 - __u32 seq; /* Starting sequence number */
86959 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86960 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86961 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86962 union {
86963 /* Note : tcp_tw_isn is used in input path only
86964 * (isn chosen by tcp_timewait_state_process())
86965 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
86966
86967 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86968 /* 1 byte hole */
86969 - __u32 ack_seq; /* Sequence number ACK'd */
86970 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86971 union {
86972 struct inet_skb_parm h4;
86973 #if IS_ENABLED(CONFIG_IPV6)
86974 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86975 index dc4865e..152ee4c 100644
86976 --- a/include/net/xfrm.h
86977 +++ b/include/net/xfrm.h
86978 @@ -285,7 +285,6 @@ struct xfrm_dst;
86979 struct xfrm_policy_afinfo {
86980 unsigned short family;
86981 struct dst_ops *dst_ops;
86982 - void (*garbage_collect)(struct net *net);
86983 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86984 const xfrm_address_t *saddr,
86985 const xfrm_address_t *daddr);
86986 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86987 struct net_device *dev,
86988 const struct flowi *fl);
86989 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86990 -};
86991 +} __do_const;
86992
86993 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86994 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86995 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86996 int (*transport_finish)(struct sk_buff *skb,
86997 int async);
86998 void (*local_error)(struct sk_buff *skb, u32 mtu);
86999 -};
87000 +} __do_const;
87001
87002 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87003 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87004 @@ -437,7 +436,7 @@ struct xfrm_mode {
87005 struct module *owner;
87006 unsigned int encap;
87007 int flags;
87008 -};
87009 +} __do_const;
87010
87011 /* Flags for xfrm_mode. */
87012 enum {
87013 @@ -534,7 +533,7 @@ struct xfrm_policy {
87014 struct timer_list timer;
87015
87016 struct flow_cache_object flo;
87017 - atomic_t genid;
87018 + atomic_unchecked_t genid;
87019 u32 priority;
87020 u32 index;
87021 struct xfrm_mark mark;
87022 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87023 }
87024
87025 void xfrm_garbage_collect(struct net *net);
87026 +void xfrm_garbage_collect_deferred(struct net *net);
87027
87028 #else
87029
87030 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87031 static inline void xfrm_garbage_collect(struct net *net)
87032 {
87033 }
87034 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87035 +{
87036 +}
87037 #endif
87038
87039 static __inline__
87040 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87041 index 1017e0b..227aa4d 100644
87042 --- a/include/rdma/iw_cm.h
87043 +++ b/include/rdma/iw_cm.h
87044 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87045 int backlog);
87046
87047 int (*destroy_listen)(struct iw_cm_id *cm_id);
87048 -};
87049 +} __no_const;
87050
87051 /**
87052 * iw_create_cm_id - Create an IW CM identifier.
87053 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87054 index 52beadf..598734c 100644
87055 --- a/include/scsi/libfc.h
87056 +++ b/include/scsi/libfc.h
87057 @@ -771,6 +771,7 @@ struct libfc_function_template {
87058 */
87059 void (*disc_stop_final) (struct fc_lport *);
87060 };
87061 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87062
87063 /**
87064 * struct fc_disc - Discovery context
87065 @@ -875,7 +876,7 @@ struct fc_lport {
87066 struct fc_vport *vport;
87067
87068 /* Operational Information */
87069 - struct libfc_function_template tt;
87070 + libfc_function_template_no_const tt;
87071 u8 link_up;
87072 u8 qfull;
87073 enum fc_lport_state state;
87074 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87075 index 27ecee7..5f42632 100644
87076 --- a/include/scsi/scsi_device.h
87077 +++ b/include/scsi/scsi_device.h
87078 @@ -186,9 +186,9 @@ struct scsi_device {
87079 unsigned int max_device_blocked; /* what device_blocked counts down from */
87080 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87081
87082 - atomic_t iorequest_cnt;
87083 - atomic_t iodone_cnt;
87084 - atomic_t ioerr_cnt;
87085 + atomic_unchecked_t iorequest_cnt;
87086 + atomic_unchecked_t iodone_cnt;
87087 + atomic_unchecked_t ioerr_cnt;
87088
87089 struct device sdev_gendev,
87090 sdev_dev;
87091 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87092 index 007a0bc..7188db8 100644
87093 --- a/include/scsi/scsi_transport_fc.h
87094 +++ b/include/scsi/scsi_transport_fc.h
87095 @@ -756,7 +756,8 @@ struct fc_function_template {
87096 unsigned long show_host_system_hostname:1;
87097
87098 unsigned long disable_target_scan:1;
87099 -};
87100 +} __do_const;
87101 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87102
87103
87104 /**
87105 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87106 index ae6c3b8..fd748ac 100644
87107 --- a/include/sound/compress_driver.h
87108 +++ b/include/sound/compress_driver.h
87109 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87110 struct snd_compr_caps *caps);
87111 int (*get_codec_caps) (struct snd_compr_stream *stream,
87112 struct snd_compr_codec_caps *codec);
87113 -};
87114 +} __no_const;
87115
87116 /**
87117 * struct snd_compr: Compressed device
87118 diff --git a/include/sound/soc.h b/include/sound/soc.h
87119 index 7ba7130..d46594d 100644
87120 --- a/include/sound/soc.h
87121 +++ b/include/sound/soc.h
87122 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
87123 enum snd_soc_dapm_type, int);
87124
87125 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
87126 -};
87127 +} __do_const;
87128
87129 /* SoC platform interface */
87130 struct snd_soc_platform_driver {
87131 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
87132 const struct snd_compr_ops *compr_ops;
87133
87134 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87135 -};
87136 +} __do_const;
87137
87138 struct snd_soc_dai_link_component {
87139 const char *name;
87140 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87141 index 23c518a..d6ef510 100644
87142 --- a/include/target/target_core_base.h
87143 +++ b/include/target/target_core_base.h
87144 @@ -764,7 +764,7 @@ struct se_device {
87145 atomic_long_t write_bytes;
87146 /* Active commands on this virtual SE device */
87147 atomic_t simple_cmds;
87148 - atomic_t dev_ordered_id;
87149 + atomic_unchecked_t dev_ordered_id;
87150 atomic_t dev_ordered_sync;
87151 atomic_t dev_qf_count;
87152 int export_count;
87153 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87154 new file mode 100644
87155 index 0000000..fb634b7
87156 --- /dev/null
87157 +++ b/include/trace/events/fs.h
87158 @@ -0,0 +1,53 @@
87159 +#undef TRACE_SYSTEM
87160 +#define TRACE_SYSTEM fs
87161 +
87162 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87163 +#define _TRACE_FS_H
87164 +
87165 +#include <linux/fs.h>
87166 +#include <linux/tracepoint.h>
87167 +
87168 +TRACE_EVENT(do_sys_open,
87169 +
87170 + TP_PROTO(const char *filename, int flags, int mode),
87171 +
87172 + TP_ARGS(filename, flags, mode),
87173 +
87174 + TP_STRUCT__entry(
87175 + __string( filename, filename )
87176 + __field( int, flags )
87177 + __field( int, mode )
87178 + ),
87179 +
87180 + TP_fast_assign(
87181 + __assign_str(filename, filename);
87182 + __entry->flags = flags;
87183 + __entry->mode = mode;
87184 + ),
87185 +
87186 + TP_printk("\"%s\" %x %o",
87187 + __get_str(filename), __entry->flags, __entry->mode)
87188 +);
87189 +
87190 +TRACE_EVENT(open_exec,
87191 +
87192 + TP_PROTO(const char *filename),
87193 +
87194 + TP_ARGS(filename),
87195 +
87196 + TP_STRUCT__entry(
87197 + __string( filename, filename )
87198 + ),
87199 +
87200 + TP_fast_assign(
87201 + __assign_str(filename, filename);
87202 + ),
87203 +
87204 + TP_printk("\"%s\"",
87205 + __get_str(filename))
87206 +);
87207 +
87208 +#endif /* _TRACE_FS_H */
87209 +
87210 +/* This part must be outside protection */
87211 +#include <trace/define_trace.h>
87212 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87213 index 3608beb..df39d8a 100644
87214 --- a/include/trace/events/irq.h
87215 +++ b/include/trace/events/irq.h
87216 @@ -36,7 +36,7 @@ struct softirq_action;
87217 */
87218 TRACE_EVENT(irq_handler_entry,
87219
87220 - TP_PROTO(int irq, struct irqaction *action),
87221 + TP_PROTO(int irq, const struct irqaction *action),
87222
87223 TP_ARGS(irq, action),
87224
87225 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87226 */
87227 TRACE_EVENT(irq_handler_exit,
87228
87229 - TP_PROTO(int irq, struct irqaction *action, int ret),
87230 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87231
87232 TP_ARGS(irq, action, ret),
87233
87234 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87235 index 7caf44c..23c6f27 100644
87236 --- a/include/uapi/linux/a.out.h
87237 +++ b/include/uapi/linux/a.out.h
87238 @@ -39,6 +39,14 @@ enum machine_type {
87239 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87240 };
87241
87242 +/* Constants for the N_FLAGS field */
87243 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87244 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87245 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87246 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87247 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87248 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87249 +
87250 #if !defined (N_MAGIC)
87251 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87252 #endif
87253 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87254 index 22b6ad3..aeba37e 100644
87255 --- a/include/uapi/linux/bcache.h
87256 +++ b/include/uapi/linux/bcache.h
87257 @@ -5,6 +5,7 @@
87258 * Bcache on disk data structures
87259 */
87260
87261 +#include <linux/compiler.h>
87262 #include <asm/types.h>
87263
87264 #define BITMASK(name, type, field, offset, size) \
87265 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87266 /* Btree keys - all units are in sectors */
87267
87268 struct bkey {
87269 - __u64 high;
87270 - __u64 low;
87271 + __u64 high __intentional_overflow(-1);
87272 + __u64 low __intentional_overflow(-1);
87273 __u64 ptr[];
87274 };
87275
87276 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87277 index d876736..ccce5c0 100644
87278 --- a/include/uapi/linux/byteorder/little_endian.h
87279 +++ b/include/uapi/linux/byteorder/little_endian.h
87280 @@ -42,51 +42,51 @@
87281
87282 static inline __le64 __cpu_to_le64p(const __u64 *p)
87283 {
87284 - return (__force __le64)*p;
87285 + return (__force const __le64)*p;
87286 }
87287 -static inline __u64 __le64_to_cpup(const __le64 *p)
87288 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87289 {
87290 - return (__force __u64)*p;
87291 + return (__force const __u64)*p;
87292 }
87293 static inline __le32 __cpu_to_le32p(const __u32 *p)
87294 {
87295 - return (__force __le32)*p;
87296 + return (__force const __le32)*p;
87297 }
87298 static inline __u32 __le32_to_cpup(const __le32 *p)
87299 {
87300 - return (__force __u32)*p;
87301 + return (__force const __u32)*p;
87302 }
87303 static inline __le16 __cpu_to_le16p(const __u16 *p)
87304 {
87305 - return (__force __le16)*p;
87306 + return (__force const __le16)*p;
87307 }
87308 static inline __u16 __le16_to_cpup(const __le16 *p)
87309 {
87310 - return (__force __u16)*p;
87311 + return (__force const __u16)*p;
87312 }
87313 static inline __be64 __cpu_to_be64p(const __u64 *p)
87314 {
87315 - return (__force __be64)__swab64p(p);
87316 + return (__force const __be64)__swab64p(p);
87317 }
87318 static inline __u64 __be64_to_cpup(const __be64 *p)
87319 {
87320 - return __swab64p((__u64 *)p);
87321 + return __swab64p((const __u64 *)p);
87322 }
87323 static inline __be32 __cpu_to_be32p(const __u32 *p)
87324 {
87325 - return (__force __be32)__swab32p(p);
87326 + return (__force const __be32)__swab32p(p);
87327 }
87328 -static inline __u32 __be32_to_cpup(const __be32 *p)
87329 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87330 {
87331 - return __swab32p((__u32 *)p);
87332 + return __swab32p((const __u32 *)p);
87333 }
87334 static inline __be16 __cpu_to_be16p(const __u16 *p)
87335 {
87336 - return (__force __be16)__swab16p(p);
87337 + return (__force const __be16)__swab16p(p);
87338 }
87339 static inline __u16 __be16_to_cpup(const __be16 *p)
87340 {
87341 - return __swab16p((__u16 *)p);
87342 + return __swab16p((const __u16 *)p);
87343 }
87344 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87345 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87346 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87347 index ea9bf25..5140c61 100644
87348 --- a/include/uapi/linux/elf.h
87349 +++ b/include/uapi/linux/elf.h
87350 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87351 #define PT_GNU_EH_FRAME 0x6474e550
87352
87353 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87354 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87355 +
87356 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87357 +
87358 +/* Constants for the e_flags field */
87359 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87360 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87361 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87362 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87363 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87364 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87365
87366 /*
87367 * Extended Numbering
87368 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87369 #define DT_DEBUG 21
87370 #define DT_TEXTREL 22
87371 #define DT_JMPREL 23
87372 +#define DT_FLAGS 30
87373 + #define DF_TEXTREL 0x00000004
87374 #define DT_ENCODING 32
87375 #define OLD_DT_LOOS 0x60000000
87376 #define DT_LOOS 0x6000000d
87377 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87378 #define PF_W 0x2
87379 #define PF_X 0x1
87380
87381 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87382 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87383 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87384 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87385 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87386 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87387 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87388 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87389 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87390 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87391 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87392 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87393 +
87394 typedef struct elf32_phdr{
87395 Elf32_Word p_type;
87396 Elf32_Off p_offset;
87397 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87398 #define EI_OSABI 7
87399 #define EI_PAD 8
87400
87401 +#define EI_PAX 14
87402 +
87403 #define ELFMAG0 0x7f /* EI_MAG */
87404 #define ELFMAG1 'E'
87405 #define ELFMAG2 'L'
87406 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87407 index aa169c4..6a2771d 100644
87408 --- a/include/uapi/linux/personality.h
87409 +++ b/include/uapi/linux/personality.h
87410 @@ -30,6 +30,7 @@ enum {
87411 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87412 ADDR_NO_RANDOMIZE | \
87413 ADDR_COMPAT_LAYOUT | \
87414 + ADDR_LIMIT_3GB | \
87415 MMAP_PAGE_ZERO)
87416
87417 /*
87418 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87419 index 7530e74..e714828 100644
87420 --- a/include/uapi/linux/screen_info.h
87421 +++ b/include/uapi/linux/screen_info.h
87422 @@ -43,7 +43,8 @@ struct screen_info {
87423 __u16 pages; /* 0x32 */
87424 __u16 vesa_attributes; /* 0x34 */
87425 __u32 capabilities; /* 0x36 */
87426 - __u8 _reserved[6]; /* 0x3a */
87427 + __u16 vesapm_size; /* 0x3a */
87428 + __u8 _reserved[4]; /* 0x3c */
87429 } __attribute__((packed));
87430
87431 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87432 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87433 index 0e011eb..82681b1 100644
87434 --- a/include/uapi/linux/swab.h
87435 +++ b/include/uapi/linux/swab.h
87436 @@ -43,7 +43,7 @@
87437 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87438 */
87439
87440 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87441 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87442 {
87443 #ifdef __HAVE_BUILTIN_BSWAP16__
87444 return __builtin_bswap16(val);
87445 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87446 #endif
87447 }
87448
87449 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87450 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87451 {
87452 #ifdef __HAVE_BUILTIN_BSWAP32__
87453 return __builtin_bswap32(val);
87454 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87455 #endif
87456 }
87457
87458 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87459 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87460 {
87461 #ifdef __HAVE_BUILTIN_BSWAP64__
87462 return __builtin_bswap64(val);
87463 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87464 index 43aaba1..1c30b48 100644
87465 --- a/include/uapi/linux/sysctl.h
87466 +++ b/include/uapi/linux/sysctl.h
87467 @@ -155,8 +155,6 @@ enum
87468 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87469 };
87470
87471 -
87472 -
87473 /* CTL_VM names: */
87474 enum
87475 {
87476 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87477 index 1590c49..5eab462 100644
87478 --- a/include/uapi/linux/xattr.h
87479 +++ b/include/uapi/linux/xattr.h
87480 @@ -73,5 +73,9 @@
87481 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87482 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87483
87484 +/* User namespace */
87485 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87486 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87487 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87488
87489 #endif /* _UAPI_LINUX_XATTR_H */
87490 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87491 index f9466fa..f4e2b81 100644
87492 --- a/include/video/udlfb.h
87493 +++ b/include/video/udlfb.h
87494 @@ -53,10 +53,10 @@ struct dlfb_data {
87495 u32 pseudo_palette[256];
87496 int blank_mode; /*one of FB_BLANK_ */
87497 /* blit-only rendering path metrics, exposed through sysfs */
87498 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87499 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87500 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87501 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87502 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87503 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87504 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87505 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87506 };
87507
87508 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87509 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87510 index 30f5362..8ed8ac9 100644
87511 --- a/include/video/uvesafb.h
87512 +++ b/include/video/uvesafb.h
87513 @@ -122,6 +122,7 @@ struct uvesafb_par {
87514 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87515 u8 pmi_setpal; /* PMI for palette changes */
87516 u16 *pmi_base; /* protected mode interface location */
87517 + u8 *pmi_code; /* protected mode code location */
87518 void *pmi_start;
87519 void *pmi_pal;
87520 u8 *vbe_state_orig; /*
87521 diff --git a/init/Kconfig b/init/Kconfig
87522 index 2081a4d..98d1149 100644
87523 --- a/init/Kconfig
87524 +++ b/init/Kconfig
87525 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87526
87527 config CHECKPOINT_RESTORE
87528 bool "Checkpoint/restore support" if EXPERT
87529 + depends on !GRKERNSEC
87530 default n
87531 help
87532 Enables additional kernel features in a sake of checkpoint/restore.
87533 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87534
87535 config COMPAT_BRK
87536 bool "Disable heap randomization"
87537 - default y
87538 + default n
87539 help
87540 Randomizing heap placement makes heap exploits harder, but it
87541 also breaks ancient binaries (including anything libc5 based).
87542 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87543 config STOP_MACHINE
87544 bool
87545 default y
87546 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87547 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87548 help
87549 Need stop_machine() primitive.
87550
87551 diff --git a/init/Makefile b/init/Makefile
87552 index 7bc47ee..6da2dc7 100644
87553 --- a/init/Makefile
87554 +++ b/init/Makefile
87555 @@ -2,6 +2,9 @@
87556 # Makefile for the linux kernel.
87557 #
87558
87559 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87560 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87561 +
87562 obj-y := main.o version.o mounts.o
87563 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87564 obj-y += noinitramfs.o
87565 diff --git a/init/do_mounts.c b/init/do_mounts.c
87566 index 9b3565c..3f90cf9 100644
87567 --- a/init/do_mounts.c
87568 +++ b/init/do_mounts.c
87569 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87570 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87571 {
87572 struct super_block *s;
87573 - int err = sys_mount(name, "/root", fs, flags, data);
87574 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87575 if (err)
87576 return err;
87577
87578 - sys_chdir("/root");
87579 + sys_chdir((const char __force_user *)"/root");
87580 s = current->fs->pwd.dentry->d_sb;
87581 ROOT_DEV = s->s_dev;
87582 printk(KERN_INFO
87583 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87584 va_start(args, fmt);
87585 vsprintf(buf, fmt, args);
87586 va_end(args);
87587 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87588 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87589 if (fd >= 0) {
87590 sys_ioctl(fd, FDEJECT, 0);
87591 sys_close(fd);
87592 }
87593 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87594 - fd = sys_open("/dev/console", O_RDWR, 0);
87595 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87596 if (fd >= 0) {
87597 sys_ioctl(fd, TCGETS, (long)&termios);
87598 termios.c_lflag &= ~ICANON;
87599 sys_ioctl(fd, TCSETSF, (long)&termios);
87600 - sys_read(fd, &c, 1);
87601 + sys_read(fd, (char __user *)&c, 1);
87602 termios.c_lflag |= ICANON;
87603 sys_ioctl(fd, TCSETSF, (long)&termios);
87604 sys_close(fd);
87605 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87606 mount_root();
87607 out:
87608 devtmpfs_mount("dev");
87609 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87610 - sys_chroot(".");
87611 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87612 + sys_chroot((const char __force_user *)".");
87613 }
87614
87615 static bool is_tmpfs;
87616 diff --git a/init/do_mounts.h b/init/do_mounts.h
87617 index f5b978a..69dbfe8 100644
87618 --- a/init/do_mounts.h
87619 +++ b/init/do_mounts.h
87620 @@ -15,15 +15,15 @@ extern int root_mountflags;
87621
87622 static inline int create_dev(char *name, dev_t dev)
87623 {
87624 - sys_unlink(name);
87625 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87626 + sys_unlink((char __force_user *)name);
87627 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87628 }
87629
87630 #if BITS_PER_LONG == 32
87631 static inline u32 bstat(char *name)
87632 {
87633 struct stat64 stat;
87634 - if (sys_stat64(name, &stat) != 0)
87635 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87636 return 0;
87637 if (!S_ISBLK(stat.st_mode))
87638 return 0;
87639 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87640 static inline u32 bstat(char *name)
87641 {
87642 struct stat stat;
87643 - if (sys_newstat(name, &stat) != 0)
87644 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87645 return 0;
87646 if (!S_ISBLK(stat.st_mode))
87647 return 0;
87648 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87649 index 3e0878e..8a9d7a0 100644
87650 --- a/init/do_mounts_initrd.c
87651 +++ b/init/do_mounts_initrd.c
87652 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87653 {
87654 sys_unshare(CLONE_FS | CLONE_FILES);
87655 /* stdin/stdout/stderr for /linuxrc */
87656 - sys_open("/dev/console", O_RDWR, 0);
87657 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87658 sys_dup(0);
87659 sys_dup(0);
87660 /* move initrd over / and chdir/chroot in initrd root */
87661 - sys_chdir("/root");
87662 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87663 - sys_chroot(".");
87664 + sys_chdir((const char __force_user *)"/root");
87665 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87666 + sys_chroot((const char __force_user *)".");
87667 sys_setsid();
87668 return 0;
87669 }
87670 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87671 create_dev("/dev/root.old", Root_RAM0);
87672 /* mount initrd on rootfs' /root */
87673 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87674 - sys_mkdir("/old", 0700);
87675 - sys_chdir("/old");
87676 + sys_mkdir((const char __force_user *)"/old", 0700);
87677 + sys_chdir((const char __force_user *)"/old");
87678
87679 /* try loading default modules from initrd */
87680 load_default_modules();
87681 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87682 current->flags &= ~PF_FREEZER_SKIP;
87683
87684 /* move initrd to rootfs' /old */
87685 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87686 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87687 /* switch root and cwd back to / of rootfs */
87688 - sys_chroot("..");
87689 + sys_chroot((const char __force_user *)"..");
87690
87691 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87692 - sys_chdir("/old");
87693 + sys_chdir((const char __force_user *)"/old");
87694 return;
87695 }
87696
87697 - sys_chdir("/");
87698 + sys_chdir((const char __force_user *)"/");
87699 ROOT_DEV = new_decode_dev(real_root_dev);
87700 mount_root();
87701
87702 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87703 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87704 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87705 if (!error)
87706 printk("okay\n");
87707 else {
87708 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87709 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87710 if (error == -ENOENT)
87711 printk("/initrd does not exist. Ignored.\n");
87712 else
87713 printk("failed\n");
87714 printk(KERN_NOTICE "Unmounting old root\n");
87715 - sys_umount("/old", MNT_DETACH);
87716 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87717 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87718 if (fd < 0) {
87719 error = fd;
87720 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87721 * mounted in the normal path.
87722 */
87723 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87724 - sys_unlink("/initrd.image");
87725 + sys_unlink((const char __force_user *)"/initrd.image");
87726 handle_initrd();
87727 return 1;
87728 }
87729 }
87730 - sys_unlink("/initrd.image");
87731 + sys_unlink((const char __force_user *)"/initrd.image");
87732 return 0;
87733 }
87734 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87735 index 8cb6db5..d729f50 100644
87736 --- a/init/do_mounts_md.c
87737 +++ b/init/do_mounts_md.c
87738 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87739 partitioned ? "_d" : "", minor,
87740 md_setup_args[ent].device_names);
87741
87742 - fd = sys_open(name, 0, 0);
87743 + fd = sys_open((char __force_user *)name, 0, 0);
87744 if (fd < 0) {
87745 printk(KERN_ERR "md: open failed - cannot start "
87746 "array %s\n", name);
87747 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87748 * array without it
87749 */
87750 sys_close(fd);
87751 - fd = sys_open(name, 0, 0);
87752 + fd = sys_open((char __force_user *)name, 0, 0);
87753 sys_ioctl(fd, BLKRRPART, 0);
87754 }
87755 sys_close(fd);
87756 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87757
87758 wait_for_device_probe();
87759
87760 - fd = sys_open("/dev/md0", 0, 0);
87761 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87762 if (fd >= 0) {
87763 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87764 sys_close(fd);
87765 diff --git a/init/init_task.c b/init/init_task.c
87766 index ba0a7f36..2bcf1d5 100644
87767 --- a/init/init_task.c
87768 +++ b/init/init_task.c
87769 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87770 * Initial thread structure. Alignment of this is handled by a special
87771 * linker map entry.
87772 */
87773 +#ifdef CONFIG_X86
87774 +union thread_union init_thread_union __init_task_data;
87775 +#else
87776 union thread_union init_thread_union __init_task_data =
87777 { INIT_THREAD_INFO(init_task) };
87778 +#endif
87779 diff --git a/init/initramfs.c b/init/initramfs.c
87780 index ad1bd77..dca2c1b 100644
87781 --- a/init/initramfs.c
87782 +++ b/init/initramfs.c
87783 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87784
87785 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87786 while (count) {
87787 - ssize_t rv = sys_write(fd, p, count);
87788 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87789
87790 if (rv < 0) {
87791 if (rv == -EINTR || rv == -EAGAIN)
87792 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87793 }
87794 }
87795
87796 -static long __init do_utime(char *filename, time_t mtime)
87797 +static long __init do_utime(char __force_user *filename, time_t mtime)
87798 {
87799 struct timespec t[2];
87800
87801 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87802 struct dir_entry *de, *tmp;
87803 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87804 list_del(&de->list);
87805 - do_utime(de->name, de->mtime);
87806 + do_utime((char __force_user *)de->name, de->mtime);
87807 kfree(de->name);
87808 kfree(de);
87809 }
87810 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87811 if (nlink >= 2) {
87812 char *old = find_link(major, minor, ino, mode, collected);
87813 if (old)
87814 - return (sys_link(old, collected) < 0) ? -1 : 1;
87815 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87816 }
87817 return 0;
87818 }
87819 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87820 {
87821 struct stat st;
87822
87823 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87824 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87825 if (S_ISDIR(st.st_mode))
87826 - sys_rmdir(path);
87827 + sys_rmdir((char __force_user *)path);
87828 else
87829 - sys_unlink(path);
87830 + sys_unlink((char __force_user *)path);
87831 }
87832 }
87833
87834 @@ -338,7 +338,7 @@ static int __init do_name(void)
87835 int openflags = O_WRONLY|O_CREAT;
87836 if (ml != 1)
87837 openflags |= O_TRUNC;
87838 - wfd = sys_open(collected, openflags, mode);
87839 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87840
87841 if (wfd >= 0) {
87842 sys_fchown(wfd, uid, gid);
87843 @@ -350,17 +350,17 @@ static int __init do_name(void)
87844 }
87845 }
87846 } else if (S_ISDIR(mode)) {
87847 - sys_mkdir(collected, mode);
87848 - sys_chown(collected, uid, gid);
87849 - sys_chmod(collected, mode);
87850 + sys_mkdir((char __force_user *)collected, mode);
87851 + sys_chown((char __force_user *)collected, uid, gid);
87852 + sys_chmod((char __force_user *)collected, mode);
87853 dir_add(collected, mtime);
87854 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87855 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87856 if (maybe_link() == 0) {
87857 - sys_mknod(collected, mode, rdev);
87858 - sys_chown(collected, uid, gid);
87859 - sys_chmod(collected, mode);
87860 - do_utime(collected, mtime);
87861 + sys_mknod((char __force_user *)collected, mode, rdev);
87862 + sys_chown((char __force_user *)collected, uid, gid);
87863 + sys_chmod((char __force_user *)collected, mode);
87864 + do_utime((char __force_user *)collected, mtime);
87865 }
87866 }
87867 return 0;
87868 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87869 if (xwrite(wfd, victim, body_len) != body_len)
87870 error("write error");
87871 sys_close(wfd);
87872 - do_utime(vcollected, mtime);
87873 + do_utime((char __force_user *)vcollected, mtime);
87874 kfree(vcollected);
87875 eat(body_len);
87876 state = SkipIt;
87877 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87878 {
87879 collected[N_ALIGN(name_len) + body_len] = '\0';
87880 clean_path(collected, 0);
87881 - sys_symlink(collected + N_ALIGN(name_len), collected);
87882 - sys_lchown(collected, uid, gid);
87883 - do_utime(collected, mtime);
87884 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87885 + sys_lchown((char __force_user *)collected, uid, gid);
87886 + do_utime((char __force_user *)collected, mtime);
87887 state = SkipIt;
87888 next_state = Reset;
87889 return 0;
87890 diff --git a/init/main.c b/init/main.c
87891 index 321d0ce..91b53e5 100644
87892 --- a/init/main.c
87893 +++ b/init/main.c
87894 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87895 static inline void mark_rodata_ro(void) { }
87896 #endif
87897
87898 +extern void grsecurity_init(void);
87899 +
87900 /*
87901 * Debug helper: via this flag we know that we are in 'early bootup code'
87902 * where only the boot processor is running with IRQ disabled. This means
87903 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87904
87905 __setup("reset_devices", set_reset_devices);
87906
87907 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87908 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87909 +static int __init setup_grsec_proc_gid(char *str)
87910 +{
87911 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87912 + return 1;
87913 +}
87914 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87915 +#endif
87916 +
87917 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87918 +unsigned long pax_user_shadow_base __read_only;
87919 +EXPORT_SYMBOL(pax_user_shadow_base);
87920 +extern char pax_enter_kernel_user[];
87921 +extern char pax_exit_kernel_user[];
87922 +#endif
87923 +
87924 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87925 +static int __init setup_pax_nouderef(char *str)
87926 +{
87927 +#ifdef CONFIG_X86_32
87928 + unsigned int cpu;
87929 + struct desc_struct *gdt;
87930 +
87931 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87932 + gdt = get_cpu_gdt_table(cpu);
87933 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87934 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87935 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87936 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87937 + }
87938 + loadsegment(ds, __KERNEL_DS);
87939 + loadsegment(es, __KERNEL_DS);
87940 + loadsegment(ss, __KERNEL_DS);
87941 +#else
87942 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87943 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87944 + clone_pgd_mask = ~(pgdval_t)0UL;
87945 + pax_user_shadow_base = 0UL;
87946 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87947 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87948 +#endif
87949 +
87950 + return 0;
87951 +}
87952 +early_param("pax_nouderef", setup_pax_nouderef);
87953 +
87954 +#ifdef CONFIG_X86_64
87955 +static int __init setup_pax_weakuderef(char *str)
87956 +{
87957 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87958 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87959 + return 1;
87960 +}
87961 +__setup("pax_weakuderef", setup_pax_weakuderef);
87962 +#endif
87963 +#endif
87964 +
87965 +#ifdef CONFIG_PAX_SOFTMODE
87966 +int pax_softmode;
87967 +
87968 +static int __init setup_pax_softmode(char *str)
87969 +{
87970 + get_option(&str, &pax_softmode);
87971 + return 1;
87972 +}
87973 +__setup("pax_softmode=", setup_pax_softmode);
87974 +#endif
87975 +
87976 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87977 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87978 static const char *panic_later, *panic_param;
87979 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87980 struct blacklist_entry *entry;
87981 char *fn_name;
87982
87983 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87984 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87985 if (!fn_name)
87986 return false;
87987
87988 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87989 {
87990 int count = preempt_count();
87991 int ret;
87992 - char msgbuf[64];
87993 + const char *msg1 = "", *msg2 = "";
87994
87995 if (initcall_blacklisted(fn))
87996 return -EPERM;
87997 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87998 else
87999 ret = fn();
88000
88001 - msgbuf[0] = 0;
88002 -
88003 if (preempt_count() != count) {
88004 - sprintf(msgbuf, "preemption imbalance ");
88005 + msg1 = " preemption imbalance";
88006 preempt_count_set(count);
88007 }
88008 if (irqs_disabled()) {
88009 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88010 + msg2 = " disabled interrupts";
88011 local_irq_enable();
88012 }
88013 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88014 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88015
88016 + add_latent_entropy();
88017 return ret;
88018 }
88019
88020 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
88021 {
88022 argv_init[0] = init_filename;
88023 return do_execve(getname_kernel(init_filename),
88024 - (const char __user *const __user *)argv_init,
88025 - (const char __user *const __user *)envp_init);
88026 + (const char __user *const __force_user *)argv_init,
88027 + (const char __user *const __force_user *)envp_init);
88028 }
88029
88030 static int try_to_run_init_process(const char *init_filename)
88031 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
88032 return ret;
88033 }
88034
88035 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88036 +extern int gr_init_ran;
88037 +#endif
88038 +
88039 static noinline void __init kernel_init_freeable(void);
88040
88041 static int __ref kernel_init(void *unused)
88042 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
88043 ramdisk_execute_command, ret);
88044 }
88045
88046 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88047 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88048 + gr_init_ran = 1;
88049 +#endif
88050 +
88051 /*
88052 * We try each of these until one succeeds.
88053 *
88054 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
88055 do_basic_setup();
88056
88057 /* Open the /dev/console on the rootfs, this should never fail */
88058 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88059 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88060 pr_err("Warning: unable to open an initial console.\n");
88061
88062 (void) sys_dup(0);
88063 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
88064 if (!ramdisk_execute_command)
88065 ramdisk_execute_command = "/init";
88066
88067 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88068 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88069 ramdisk_execute_command = NULL;
88070 prepare_namespace();
88071 }
88072
88073 + grsecurity_init();
88074 +
88075 /*
88076 * Ok, we have completed the initial bootup, and
88077 * we're essentially up and running. Get rid of the
88078 diff --git a/ipc/compat.c b/ipc/compat.c
88079 index 9b3c85f..1c4d897 100644
88080 --- a/ipc/compat.c
88081 +++ b/ipc/compat.c
88082 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88083 COMPAT_SHMLBA);
88084 if (err < 0)
88085 return err;
88086 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88087 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88088 }
88089 case SHMDT:
88090 return sys_shmdt(compat_ptr(ptr));
88091 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88092 index e8075b2..76f2c6a 100644
88093 --- a/ipc/ipc_sysctl.c
88094 +++ b/ipc/ipc_sysctl.c
88095 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88096 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88097 void __user *buffer, size_t *lenp, loff_t *ppos)
88098 {
88099 - struct ctl_table ipc_table;
88100 + ctl_table_no_const ipc_table;
88101
88102 memcpy(&ipc_table, table, sizeof(ipc_table));
88103 ipc_table.data = get_ipc(table);
88104 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88105 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88106 void __user *buffer, size_t *lenp, loff_t *ppos)
88107 {
88108 - struct ctl_table ipc_table;
88109 + ctl_table_no_const ipc_table;
88110
88111 memcpy(&ipc_table, table, sizeof(ipc_table));
88112 ipc_table.data = get_ipc(table);
88113 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88114 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88115 void __user *buffer, size_t *lenp, loff_t *ppos)
88116 {
88117 - struct ctl_table ipc_table;
88118 + ctl_table_no_const ipc_table;
88119 size_t lenp_bef = *lenp;
88120 int rc;
88121
88122 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88123 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88124 void __user *buffer, size_t *lenp, loff_t *ppos)
88125 {
88126 - struct ctl_table ipc_table;
88127 + ctl_table_no_const ipc_table;
88128 memcpy(&ipc_table, table, sizeof(ipc_table));
88129 ipc_table.data = get_ipc(table);
88130
88131 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88132 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88133 void __user *buffer, size_t *lenp, loff_t *ppos)
88134 {
88135 - struct ctl_table ipc_table;
88136 + ctl_table_no_const ipc_table;
88137 int oldval;
88138 int rc;
88139
88140 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88141 index 68d4e95..1477ded 100644
88142 --- a/ipc/mq_sysctl.c
88143 +++ b/ipc/mq_sysctl.c
88144 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88145 static int proc_mq_dointvec(struct ctl_table *table, int write,
88146 void __user *buffer, size_t *lenp, loff_t *ppos)
88147 {
88148 - struct ctl_table mq_table;
88149 + ctl_table_no_const mq_table;
88150 memcpy(&mq_table, table, sizeof(mq_table));
88151 mq_table.data = get_mq(table);
88152
88153 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88154 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88155 void __user *buffer, size_t *lenp, loff_t *ppos)
88156 {
88157 - struct ctl_table mq_table;
88158 + ctl_table_no_const mq_table;
88159 memcpy(&mq_table, table, sizeof(mq_table));
88160 mq_table.data = get_mq(table);
88161
88162 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88163 index 4fcf39a..d3cc2ec 100644
88164 --- a/ipc/mqueue.c
88165 +++ b/ipc/mqueue.c
88166 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88167 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88168 info->attr.mq_msgsize);
88169
88170 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88171 spin_lock(&mq_lock);
88172 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88173 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88174 diff --git a/ipc/shm.c b/ipc/shm.c
88175 index 0145479..3d27947 100644
88176 --- a/ipc/shm.c
88177 +++ b/ipc/shm.c
88178 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88179 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88180 #endif
88181
88182 +#ifdef CONFIG_GRKERNSEC
88183 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88184 + const u64 shm_createtime, const kuid_t cuid,
88185 + const int shmid);
88186 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88187 + const u64 shm_createtime);
88188 +#endif
88189 +
88190 void shm_init_ns(struct ipc_namespace *ns)
88191 {
88192 ns->shm_ctlmax = SHMMAX;
88193 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88194 shp->shm_lprid = 0;
88195 shp->shm_atim = shp->shm_dtim = 0;
88196 shp->shm_ctim = get_seconds();
88197 +#ifdef CONFIG_GRKERNSEC
88198 + shp->shm_createtime = ktime_get_ns();
88199 +#endif
88200 shp->shm_segsz = size;
88201 shp->shm_nattch = 0;
88202 shp->shm_file = file;
88203 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88204 f_mode = FMODE_READ | FMODE_WRITE;
88205 }
88206 if (shmflg & SHM_EXEC) {
88207 +
88208 +#ifdef CONFIG_PAX_MPROTECT
88209 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88210 + goto out;
88211 +#endif
88212 +
88213 prot |= PROT_EXEC;
88214 acc_mode |= S_IXUGO;
88215 }
88216 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88217 if (err)
88218 goto out_unlock;
88219
88220 +#ifdef CONFIG_GRKERNSEC
88221 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88222 + shp->shm_perm.cuid, shmid) ||
88223 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88224 + err = -EACCES;
88225 + goto out_unlock;
88226 + }
88227 +#endif
88228 +
88229 ipc_lock_object(&shp->shm_perm);
88230
88231 /* check if shm_destroy() is tearing down shp */
88232 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88233 path = shp->shm_file->f_path;
88234 path_get(&path);
88235 shp->shm_nattch++;
88236 +#ifdef CONFIG_GRKERNSEC
88237 + shp->shm_lapid = current->pid;
88238 +#endif
88239 size = i_size_read(path.dentry->d_inode);
88240 ipc_unlock_object(&shp->shm_perm);
88241 rcu_read_unlock();
88242 diff --git a/ipc/util.c b/ipc/util.c
88243 index 88adc32..3867c68 100644
88244 --- a/ipc/util.c
88245 +++ b/ipc/util.c
88246 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88247 int (*show)(struct seq_file *, void *);
88248 };
88249
88250 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88251 +
88252 static void ipc_memory_notifier(struct work_struct *work)
88253 {
88254 ipcns_notify(IPCNS_MEMCHANGED);
88255 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88256 granted_mode >>= 6;
88257 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88258 granted_mode >>= 3;
88259 +
88260 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88261 + return -1;
88262 +
88263 /* is there some bit set in requested_mode but not in granted_mode? */
88264 if ((requested_mode & ~granted_mode & 0007) &&
88265 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88266 diff --git a/kernel/audit.c b/kernel/audit.c
88267 index c6df990..fde80b4 100644
88268 --- a/kernel/audit.c
88269 +++ b/kernel/audit.c
88270 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88271 3) suppressed due to audit_rate_limit
88272 4) suppressed due to audit_backlog_limit
88273 */
88274 -static atomic_t audit_lost = ATOMIC_INIT(0);
88275 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88276
88277 /* The netlink socket. */
88278 static struct sock *audit_sock;
88279 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88280 unsigned long now;
88281 int print;
88282
88283 - atomic_inc(&audit_lost);
88284 + atomic_inc_unchecked(&audit_lost);
88285
88286 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88287
88288 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88289 if (print) {
88290 if (printk_ratelimit())
88291 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88292 - atomic_read(&audit_lost),
88293 + atomic_read_unchecked(&audit_lost),
88294 audit_rate_limit,
88295 audit_backlog_limit);
88296 audit_panic(message);
88297 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88298 s.pid = audit_pid;
88299 s.rate_limit = audit_rate_limit;
88300 s.backlog_limit = audit_backlog_limit;
88301 - s.lost = atomic_read(&audit_lost);
88302 + s.lost = atomic_read_unchecked(&audit_lost);
88303 s.backlog = skb_queue_len(&audit_skb_queue);
88304 s.version = AUDIT_VERSION_LATEST;
88305 s.backlog_wait_time = audit_backlog_wait_time;
88306 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88307 index e420a0c..38137fa 100644
88308 --- a/kernel/auditsc.c
88309 +++ b/kernel/auditsc.c
88310 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88311 }
88312
88313 /* global counter which is incremented every time something logs in */
88314 -static atomic_t session_id = ATOMIC_INIT(0);
88315 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88316
88317 static int audit_set_loginuid_perm(kuid_t loginuid)
88318 {
88319 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88320
88321 /* are we setting or clearing? */
88322 if (uid_valid(loginuid))
88323 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88324 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88325
88326 task->sessionid = sessionid;
88327 task->loginuid = loginuid;
88328 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88329 index d6594e4..597264b 100644
88330 --- a/kernel/bpf/core.c
88331 +++ b/kernel/bpf/core.c
88332 @@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88333 * random section of illegal instructions.
88334 */
88335 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88336 - hdr = module_alloc(size);
88337 + hdr = module_alloc_exec(size);
88338 if (hdr == NULL)
88339 return NULL;
88340
88341 /* Fill space with illegal/arch-dep instructions. */
88342 bpf_fill_ill_insns(hdr, size);
88343
88344 + pax_open_kernel();
88345 hdr->pages = size / PAGE_SIZE;
88346 + pax_close_kernel();
88347 +
88348 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88349 PAGE_SIZE - sizeof(*hdr));
88350 start = (prandom_u32() % hole) & ~(alignment - 1);
88351 @@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88352
88353 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88354 {
88355 - module_free(NULL, hdr);
88356 + module_free_exec(NULL, hdr);
88357 }
88358 #endif /* CONFIG_BPF_JIT */
88359
88360 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88361 index ba61c8c..c60c486 100644
88362 --- a/kernel/bpf/syscall.c
88363 +++ b/kernel/bpf/syscall.c
88364 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88365 int err;
88366
88367 /* the syscall is limited to root temporarily. This restriction will be
88368 - * lifted when security audit is clean. Note that eBPF+tracing must have
88369 - * this restriction, since it may pass kernel data to user space
88370 + * lifted by upstream when a half-assed security audit is clean. Note
88371 + * that eBPF+tracing must have this restriction, since it may pass
88372 + * kernel data to user space
88373 */
88374 if (!capable(CAP_SYS_ADMIN))
88375 return -EPERM;
88376 +#ifdef CONFIG_GRKERNSEC
88377 + return -EPERM;
88378 +#endif
88379
88380 if (!access_ok(VERIFY_READ, uattr, 1))
88381 return -EFAULT;
88382 diff --git a/kernel/capability.c b/kernel/capability.c
88383 index 989f5bf..d317ca0 100644
88384 --- a/kernel/capability.c
88385 +++ b/kernel/capability.c
88386 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88387 * before modification is attempted and the application
88388 * fails.
88389 */
88390 + if (tocopy > ARRAY_SIZE(kdata))
88391 + return -EFAULT;
88392 +
88393 if (copy_to_user(dataptr, kdata, tocopy
88394 * sizeof(struct __user_cap_data_struct))) {
88395 return -EFAULT;
88396 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88397 int ret;
88398
88399 rcu_read_lock();
88400 - ret = security_capable(__task_cred(t), ns, cap);
88401 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88402 + gr_task_is_capable(t, __task_cred(t), cap);
88403 rcu_read_unlock();
88404
88405 - return (ret == 0);
88406 + return ret;
88407 }
88408
88409 /**
88410 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88411 int ret;
88412
88413 rcu_read_lock();
88414 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88415 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88416 rcu_read_unlock();
88417
88418 - return (ret == 0);
88419 + return ret;
88420 }
88421
88422 /**
88423 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88424 BUG();
88425 }
88426
88427 - if (security_capable(current_cred(), ns, cap) == 0) {
88428 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88429 current->flags |= PF_SUPERPRIV;
88430 return true;
88431 }
88432 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88433 }
88434 EXPORT_SYMBOL(ns_capable);
88435
88436 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88437 +{
88438 + if (unlikely(!cap_valid(cap))) {
88439 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88440 + BUG();
88441 + }
88442 +
88443 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88444 + current->flags |= PF_SUPERPRIV;
88445 + return true;
88446 + }
88447 + return false;
88448 +}
88449 +EXPORT_SYMBOL(ns_capable_nolog);
88450 +
88451 /**
88452 * file_ns_capable - Determine if the file's opener had a capability in effect
88453 * @file: The file we want to check
88454 @@ -427,6 +446,12 @@ bool capable(int cap)
88455 }
88456 EXPORT_SYMBOL(capable);
88457
88458 +bool capable_nolog(int cap)
88459 +{
88460 + return ns_capable_nolog(&init_user_ns, cap);
88461 +}
88462 +EXPORT_SYMBOL(capable_nolog);
88463 +
88464 /**
88465 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88466 * @inode: The inode in question
88467 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88468 kgid_has_mapping(ns, inode->i_gid);
88469 }
88470 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88471 +
88472 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88473 +{
88474 + struct user_namespace *ns = current_user_ns();
88475 +
88476 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88477 + kgid_has_mapping(ns, inode->i_gid);
88478 +}
88479 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88480 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88481 index 136ecea..45157a6 100644
88482 --- a/kernel/cgroup.c
88483 +++ b/kernel/cgroup.c
88484 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88485 if (!pathbuf || !agentbuf)
88486 goto out;
88487
88488 + if (agentbuf[0] == '\0')
88489 + goto out;
88490 +
88491 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88492 if (!path)
88493 goto out;
88494 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88495 struct task_struct *task;
88496 int count = 0;
88497
88498 - seq_printf(seq, "css_set %p\n", cset);
88499 + seq_printf(seq, "css_set %pK\n", cset);
88500
88501 list_for_each_entry(task, &cset->tasks, cg_list) {
88502 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88503 diff --git a/kernel/compat.c b/kernel/compat.c
88504 index ebb3c36..1df606e 100644
88505 --- a/kernel/compat.c
88506 +++ b/kernel/compat.c
88507 @@ -13,6 +13,7 @@
88508
88509 #include <linux/linkage.h>
88510 #include <linux/compat.h>
88511 +#include <linux/module.h>
88512 #include <linux/errno.h>
88513 #include <linux/time.h>
88514 #include <linux/signal.h>
88515 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88516 mm_segment_t oldfs;
88517 long ret;
88518
88519 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88520 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88521 oldfs = get_fs();
88522 set_fs(KERNEL_DS);
88523 ret = hrtimer_nanosleep_restart(restart);
88524 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88525 oldfs = get_fs();
88526 set_fs(KERNEL_DS);
88527 ret = hrtimer_nanosleep(&tu,
88528 - rmtp ? (struct timespec __user *)&rmt : NULL,
88529 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88530 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88531 set_fs(oldfs);
88532
88533 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88534 mm_segment_t old_fs = get_fs();
88535
88536 set_fs(KERNEL_DS);
88537 - ret = sys_sigpending((old_sigset_t __user *) &s);
88538 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88539 set_fs(old_fs);
88540 if (ret == 0)
88541 ret = put_user(s, set);
88542 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88543 mm_segment_t old_fs = get_fs();
88544
88545 set_fs(KERNEL_DS);
88546 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88547 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88548 set_fs(old_fs);
88549
88550 if (!ret) {
88551 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88552 set_fs (KERNEL_DS);
88553 ret = sys_wait4(pid,
88554 (stat_addr ?
88555 - (unsigned int __user *) &status : NULL),
88556 - options, (struct rusage __user *) &r);
88557 + (unsigned int __force_user *) &status : NULL),
88558 + options, (struct rusage __force_user *) &r);
88559 set_fs (old_fs);
88560
88561 if (ret > 0) {
88562 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88563 memset(&info, 0, sizeof(info));
88564
88565 set_fs(KERNEL_DS);
88566 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88567 - uru ? (struct rusage __user *)&ru : NULL);
88568 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88569 + uru ? (struct rusage __force_user *)&ru : NULL);
88570 set_fs(old_fs);
88571
88572 if ((ret < 0) || (info.si_signo == 0))
88573 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88574 oldfs = get_fs();
88575 set_fs(KERNEL_DS);
88576 err = sys_timer_settime(timer_id, flags,
88577 - (struct itimerspec __user *) &newts,
88578 - (struct itimerspec __user *) &oldts);
88579 + (struct itimerspec __force_user *) &newts,
88580 + (struct itimerspec __force_user *) &oldts);
88581 set_fs(oldfs);
88582 if (!err && old && put_compat_itimerspec(old, &oldts))
88583 return -EFAULT;
88584 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88585 oldfs = get_fs();
88586 set_fs(KERNEL_DS);
88587 err = sys_timer_gettime(timer_id,
88588 - (struct itimerspec __user *) &ts);
88589 + (struct itimerspec __force_user *) &ts);
88590 set_fs(oldfs);
88591 if (!err && put_compat_itimerspec(setting, &ts))
88592 return -EFAULT;
88593 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88594 oldfs = get_fs();
88595 set_fs(KERNEL_DS);
88596 err = sys_clock_settime(which_clock,
88597 - (struct timespec __user *) &ts);
88598 + (struct timespec __force_user *) &ts);
88599 set_fs(oldfs);
88600 return err;
88601 }
88602 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88603 oldfs = get_fs();
88604 set_fs(KERNEL_DS);
88605 err = sys_clock_gettime(which_clock,
88606 - (struct timespec __user *) &ts);
88607 + (struct timespec __force_user *) &ts);
88608 set_fs(oldfs);
88609 if (!err && compat_put_timespec(&ts, tp))
88610 return -EFAULT;
88611 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88612
88613 oldfs = get_fs();
88614 set_fs(KERNEL_DS);
88615 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88616 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88617 set_fs(oldfs);
88618
88619 err = compat_put_timex(utp, &txc);
88620 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88621 oldfs = get_fs();
88622 set_fs(KERNEL_DS);
88623 err = sys_clock_getres(which_clock,
88624 - (struct timespec __user *) &ts);
88625 + (struct timespec __force_user *) &ts);
88626 set_fs(oldfs);
88627 if (!err && tp && compat_put_timespec(&ts, tp))
88628 return -EFAULT;
88629 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88630 struct timespec tu;
88631 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88632
88633 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88634 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88635 oldfs = get_fs();
88636 set_fs(KERNEL_DS);
88637 err = clock_nanosleep_restart(restart);
88638 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88639 oldfs = get_fs();
88640 set_fs(KERNEL_DS);
88641 err = sys_clock_nanosleep(which_clock, flags,
88642 - (struct timespec __user *) &in,
88643 - (struct timespec __user *) &out);
88644 + (struct timespec __force_user *) &in,
88645 + (struct timespec __force_user *) &out);
88646 set_fs(oldfs);
88647
88648 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88649 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88650 mm_segment_t old_fs = get_fs();
88651
88652 set_fs(KERNEL_DS);
88653 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88654 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88655 set_fs(old_fs);
88656 if (compat_put_timespec(&t, interval))
88657 return -EFAULT;
88658 diff --git a/kernel/configs.c b/kernel/configs.c
88659 index c18b1f1..b9a0132 100644
88660 --- a/kernel/configs.c
88661 +++ b/kernel/configs.c
88662 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88663 struct proc_dir_entry *entry;
88664
88665 /* create the current config file */
88666 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88667 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88668 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88669 + &ikconfig_file_ops);
88670 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88671 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88672 + &ikconfig_file_ops);
88673 +#endif
88674 +#else
88675 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88676 &ikconfig_file_ops);
88677 +#endif
88678 +
88679 if (!entry)
88680 return -ENOMEM;
88681
88682 diff --git a/kernel/cred.c b/kernel/cred.c
88683 index e0573a4..26c0fd3 100644
88684 --- a/kernel/cred.c
88685 +++ b/kernel/cred.c
88686 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88687 validate_creds(cred);
88688 alter_cred_subscribers(cred, -1);
88689 put_cred(cred);
88690 +
88691 +#ifdef CONFIG_GRKERNSEC_SETXID
88692 + cred = (struct cred *) tsk->delayed_cred;
88693 + if (cred != NULL) {
88694 + tsk->delayed_cred = NULL;
88695 + validate_creds(cred);
88696 + alter_cred_subscribers(cred, -1);
88697 + put_cred(cred);
88698 + }
88699 +#endif
88700 }
88701
88702 /**
88703 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88704 * Always returns 0 thus allowing this function to be tail-called at the end
88705 * of, say, sys_setgid().
88706 */
88707 -int commit_creds(struct cred *new)
88708 +static int __commit_creds(struct cred *new)
88709 {
88710 struct task_struct *task = current;
88711 const struct cred *old = task->real_cred;
88712 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88713
88714 get_cred(new); /* we will require a ref for the subj creds too */
88715
88716 + gr_set_role_label(task, new->uid, new->gid);
88717 +
88718 /* dumpability changes */
88719 if (!uid_eq(old->euid, new->euid) ||
88720 !gid_eq(old->egid, new->egid) ||
88721 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88722 put_cred(old);
88723 return 0;
88724 }
88725 +#ifdef CONFIG_GRKERNSEC_SETXID
88726 +extern int set_user(struct cred *new);
88727 +
88728 +void gr_delayed_cred_worker(void)
88729 +{
88730 + const struct cred *new = current->delayed_cred;
88731 + struct cred *ncred;
88732 +
88733 + current->delayed_cred = NULL;
88734 +
88735 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88736 + // from doing get_cred on it when queueing this
88737 + put_cred(new);
88738 + return;
88739 + } else if (new == NULL)
88740 + return;
88741 +
88742 + ncred = prepare_creds();
88743 + if (!ncred)
88744 + goto die;
88745 + // uids
88746 + ncred->uid = new->uid;
88747 + ncred->euid = new->euid;
88748 + ncred->suid = new->suid;
88749 + ncred->fsuid = new->fsuid;
88750 + // gids
88751 + ncred->gid = new->gid;
88752 + ncred->egid = new->egid;
88753 + ncred->sgid = new->sgid;
88754 + ncred->fsgid = new->fsgid;
88755 + // groups
88756 + set_groups(ncred, new->group_info);
88757 + // caps
88758 + ncred->securebits = new->securebits;
88759 + ncred->cap_inheritable = new->cap_inheritable;
88760 + ncred->cap_permitted = new->cap_permitted;
88761 + ncred->cap_effective = new->cap_effective;
88762 + ncred->cap_bset = new->cap_bset;
88763 +
88764 + if (set_user(ncred)) {
88765 + abort_creds(ncred);
88766 + goto die;
88767 + }
88768 +
88769 + // from doing get_cred on it when queueing this
88770 + put_cred(new);
88771 +
88772 + __commit_creds(ncred);
88773 + return;
88774 +die:
88775 + // from doing get_cred on it when queueing this
88776 + put_cred(new);
88777 + do_group_exit(SIGKILL);
88778 +}
88779 +#endif
88780 +
88781 +int commit_creds(struct cred *new)
88782 +{
88783 +#ifdef CONFIG_GRKERNSEC_SETXID
88784 + int ret;
88785 + int schedule_it = 0;
88786 + struct task_struct *t;
88787 + unsigned oldsecurebits = current_cred()->securebits;
88788 +
88789 + /* we won't get called with tasklist_lock held for writing
88790 + and interrupts disabled as the cred struct in that case is
88791 + init_cred
88792 + */
88793 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88794 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88795 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88796 + schedule_it = 1;
88797 + }
88798 + ret = __commit_creds(new);
88799 + if (schedule_it) {
88800 + rcu_read_lock();
88801 + read_lock(&tasklist_lock);
88802 + for (t = next_thread(current); t != current;
88803 + t = next_thread(t)) {
88804 + /* we'll check if the thread has uid 0 in
88805 + * the delayed worker routine
88806 + */
88807 + if (task_securebits(t) == oldsecurebits &&
88808 + t->delayed_cred == NULL) {
88809 + t->delayed_cred = get_cred(new);
88810 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88811 + set_tsk_need_resched(t);
88812 + }
88813 + }
88814 + read_unlock(&tasklist_lock);
88815 + rcu_read_unlock();
88816 + }
88817 +
88818 + return ret;
88819 +#else
88820 + return __commit_creds(new);
88821 +#endif
88822 +}
88823 +
88824 EXPORT_SYMBOL(commit_creds);
88825
88826 /**
88827 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88828 index 1adf62b..7736e06 100644
88829 --- a/kernel/debug/debug_core.c
88830 +++ b/kernel/debug/debug_core.c
88831 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88832 */
88833 static atomic_t masters_in_kgdb;
88834 static atomic_t slaves_in_kgdb;
88835 -static atomic_t kgdb_break_tasklet_var;
88836 +static atomic_unchecked_t kgdb_break_tasklet_var;
88837 atomic_t kgdb_setting_breakpoint;
88838
88839 struct task_struct *kgdb_usethread;
88840 @@ -134,7 +134,7 @@ int kgdb_single_step;
88841 static pid_t kgdb_sstep_pid;
88842
88843 /* to keep track of the CPU which is doing the single stepping*/
88844 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88845 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88846
88847 /*
88848 * If you are debugging a problem where roundup (the collection of
88849 @@ -549,7 +549,7 @@ return_normal:
88850 * kernel will only try for the value of sstep_tries before
88851 * giving up and continuing on.
88852 */
88853 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88854 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88855 (kgdb_info[cpu].task &&
88856 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88857 atomic_set(&kgdb_active, -1);
88858 @@ -647,8 +647,8 @@ cpu_master_loop:
88859 }
88860
88861 kgdb_restore:
88862 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88863 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88864 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88865 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88866 if (kgdb_info[sstep_cpu].task)
88867 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88868 else
88869 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88870 static void kgdb_tasklet_bpt(unsigned long ing)
88871 {
88872 kgdb_breakpoint();
88873 - atomic_set(&kgdb_break_tasklet_var, 0);
88874 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88875 }
88876
88877 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88878
88879 void kgdb_schedule_breakpoint(void)
88880 {
88881 - if (atomic_read(&kgdb_break_tasklet_var) ||
88882 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88883 atomic_read(&kgdb_active) != -1 ||
88884 atomic_read(&kgdb_setting_breakpoint))
88885 return;
88886 - atomic_inc(&kgdb_break_tasklet_var);
88887 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88888 tasklet_schedule(&kgdb_tasklet_breakpoint);
88889 }
88890 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88891 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88892 index 379650b..30c5180 100644
88893 --- a/kernel/debug/kdb/kdb_main.c
88894 +++ b/kernel/debug/kdb/kdb_main.c
88895 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88896 continue;
88897
88898 kdb_printf("%-20s%8u 0x%p ", mod->name,
88899 - mod->core_size, (void *)mod);
88900 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88901 #ifdef CONFIG_MODULE_UNLOAD
88902 kdb_printf("%4ld ", module_refcount(mod));
88903 #endif
88904 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88905 kdb_printf(" (Loading)");
88906 else
88907 kdb_printf(" (Live)");
88908 - kdb_printf(" 0x%p", mod->module_core);
88909 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88910
88911 #ifdef CONFIG_MODULE_UNLOAD
88912 {
88913 diff --git a/kernel/events/core.c b/kernel/events/core.c
88914 index 2ab0238..bf89262f5 100644
88915 --- a/kernel/events/core.c
88916 +++ b/kernel/events/core.c
88917 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88918 * 0 - disallow raw tracepoint access for unpriv
88919 * 1 - disallow cpu events for unpriv
88920 * 2 - disallow kernel profiling for unpriv
88921 + * 3 - disallow all unpriv perf event use
88922 */
88923 -int sysctl_perf_event_paranoid __read_mostly = 1;
88924 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88925 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88926 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88927 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88928 +#else
88929 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88930 +#endif
88931
88932 /* Minimum for 512 kiB + 1 user control page */
88933 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88934 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88935
88936 tmp *= sysctl_perf_cpu_time_max_percent;
88937 do_div(tmp, 100);
88938 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88939 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88940 }
88941
88942 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88943 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88944 }
88945 }
88946
88947 -static atomic64_t perf_event_id;
88948 +static atomic64_unchecked_t perf_event_id;
88949
88950 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88951 enum event_type_t event_type);
88952 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88953
88954 static inline u64 perf_event_count(struct perf_event *event)
88955 {
88956 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88957 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88958 }
88959
88960 static u64 perf_event_read(struct perf_event *event)
88961 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88962 mutex_lock(&event->child_mutex);
88963 total += perf_event_read(event);
88964 *enabled += event->total_time_enabled +
88965 - atomic64_read(&event->child_total_time_enabled);
88966 + atomic64_read_unchecked(&event->child_total_time_enabled);
88967 *running += event->total_time_running +
88968 - atomic64_read(&event->child_total_time_running);
88969 + atomic64_read_unchecked(&event->child_total_time_running);
88970
88971 list_for_each_entry(child, &event->child_list, child_list) {
88972 total += perf_event_read(child);
88973 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88974 userpg->offset -= local64_read(&event->hw.prev_count);
88975
88976 userpg->time_enabled = enabled +
88977 - atomic64_read(&event->child_total_time_enabled);
88978 + atomic64_read_unchecked(&event->child_total_time_enabled);
88979
88980 userpg->time_running = running +
88981 - atomic64_read(&event->child_total_time_running);
88982 + atomic64_read_unchecked(&event->child_total_time_running);
88983
88984 arch_perf_update_userpage(userpg, now);
88985
88986 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88987
88988 /* Data. */
88989 sp = perf_user_stack_pointer(regs);
88990 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88991 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88992 dyn_size = dump_size - rem;
88993
88994 perf_output_skip(handle, rem);
88995 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88996 values[n++] = perf_event_count(event);
88997 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88998 values[n++] = enabled +
88999 - atomic64_read(&event->child_total_time_enabled);
89000 + atomic64_read_unchecked(&event->child_total_time_enabled);
89001 }
89002 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89003 values[n++] = running +
89004 - atomic64_read(&event->child_total_time_running);
89005 + atomic64_read_unchecked(&event->child_total_time_running);
89006 }
89007 if (read_format & PERF_FORMAT_ID)
89008 values[n++] = primary_event_id(event);
89009 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89010 event->parent = parent_event;
89011
89012 event->ns = get_pid_ns(task_active_pid_ns(current));
89013 - event->id = atomic64_inc_return(&perf_event_id);
89014 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89015
89016 event->state = PERF_EVENT_STATE_INACTIVE;
89017
89018 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
89019 if (flags & ~PERF_FLAG_ALL)
89020 return -EINVAL;
89021
89022 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89023 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89024 + return -EACCES;
89025 +#endif
89026 +
89027 err = perf_copy_attr(attr_uptr, &attr);
89028 if (err)
89029 return err;
89030 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
89031 /*
89032 * Add back the child's count to the parent's count:
89033 */
89034 - atomic64_add(child_val, &parent_event->child_count);
89035 - atomic64_add(child_event->total_time_enabled,
89036 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89037 + atomic64_add_unchecked(child_event->total_time_enabled,
89038 &parent_event->child_total_time_enabled);
89039 - atomic64_add(child_event->total_time_running,
89040 + atomic64_add_unchecked(child_event->total_time_running,
89041 &parent_event->child_total_time_running);
89042
89043 /*
89044 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89045 index 569b2187..19940d9 100644
89046 --- a/kernel/events/internal.h
89047 +++ b/kernel/events/internal.h
89048 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89049 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89050 }
89051
89052 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89053 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89054 static inline unsigned long \
89055 func_name(struct perf_output_handle *handle, \
89056 - const void *buf, unsigned long len) \
89057 + const void user *buf, unsigned long len) \
89058 { \
89059 unsigned long size, written; \
89060 \
89061 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89062 return 0;
89063 }
89064
89065 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89066 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89067
89068 static inline unsigned long
89069 memcpy_skip(void *dst, const void *src, unsigned long n)
89070 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89071 return 0;
89072 }
89073
89074 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89075 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89076
89077 #ifndef arch_perf_out_copy_user
89078 #define arch_perf_out_copy_user arch_perf_out_copy_user
89079 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89080 }
89081 #endif
89082
89083 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89084 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89085
89086 /* Callchain handling */
89087 extern struct perf_callchain_entry *
89088 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89089 index ed8f2cd..fe8030c 100644
89090 --- a/kernel/events/uprobes.c
89091 +++ b/kernel/events/uprobes.c
89092 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89093 {
89094 struct page *page;
89095 uprobe_opcode_t opcode;
89096 - int result;
89097 + long result;
89098
89099 pagefault_disable();
89100 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89101 diff --git a/kernel/exit.c b/kernel/exit.c
89102 index 2116aac..d95df2a 100644
89103 --- a/kernel/exit.c
89104 +++ b/kernel/exit.c
89105 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
89106 struct task_struct *leader;
89107 int zap_leader;
89108 repeat:
89109 +#ifdef CONFIG_NET
89110 + gr_del_task_from_ip_table(p);
89111 +#endif
89112 +
89113 /* don't need to get the RCU readlock here - the process is dead and
89114 * can't be modifying its own credentials. But shut RCU-lockdep up */
89115 rcu_read_lock();
89116 @@ -670,6 +674,8 @@ void do_exit(long code)
89117 int group_dead;
89118 TASKS_RCU(int tasks_rcu_i);
89119
89120 + set_fs(USER_DS);
89121 +
89122 profile_task_exit(tsk);
89123
89124 WARN_ON(blk_needs_flush_plug(tsk));
89125 @@ -686,7 +692,6 @@ void do_exit(long code)
89126 * mm_release()->clear_child_tid() from writing to a user-controlled
89127 * kernel address.
89128 */
89129 - set_fs(USER_DS);
89130
89131 ptrace_event(PTRACE_EVENT_EXIT, code);
89132
89133 @@ -744,6 +749,9 @@ void do_exit(long code)
89134 tsk->exit_code = code;
89135 taskstats_exit(tsk, group_dead);
89136
89137 + gr_acl_handle_psacct(tsk, code);
89138 + gr_acl_handle_exit();
89139 +
89140 exit_mm(tsk);
89141
89142 if (group_dead)
89143 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89144 * Take down every thread in the group. This is called by fatal signals
89145 * as well as by sys_exit_group (below).
89146 */
89147 -void
89148 +__noreturn void
89149 do_group_exit(int exit_code)
89150 {
89151 struct signal_struct *sig = current->signal;
89152 diff --git a/kernel/fork.c b/kernel/fork.c
89153 index 9b7d746..5b898ab 100644
89154 --- a/kernel/fork.c
89155 +++ b/kernel/fork.c
89156 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89157 # endif
89158 #endif
89159
89160 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89161 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89162 + int node, void **lowmem_stack)
89163 +{
89164 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89165 + void *ret = NULL;
89166 + unsigned int i;
89167 +
89168 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89169 + if (*lowmem_stack == NULL)
89170 + goto out;
89171 +
89172 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89173 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89174 +
89175 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89176 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89177 + if (ret == NULL) {
89178 + free_thread_info(*lowmem_stack);
89179 + *lowmem_stack = NULL;
89180 + }
89181 +
89182 +out:
89183 + return ret;
89184 +}
89185 +
89186 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89187 +{
89188 + unmap_process_stacks(tsk);
89189 +}
89190 +#else
89191 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89192 + int node, void **lowmem_stack)
89193 +{
89194 + return alloc_thread_info_node(tsk, node);
89195 +}
89196 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89197 +{
89198 + free_thread_info(ti);
89199 +}
89200 +#endif
89201 +
89202 /* SLAB cache for signal_struct structures (tsk->signal) */
89203 static struct kmem_cache *signal_cachep;
89204
89205 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89206 /* SLAB cache for mm_struct structures (tsk->mm) */
89207 static struct kmem_cache *mm_cachep;
89208
89209 -static void account_kernel_stack(struct thread_info *ti, int account)
89210 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89211 {
89212 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89213 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89214 +#else
89215 struct zone *zone = page_zone(virt_to_page(ti));
89216 +#endif
89217
89218 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89219 }
89220
89221 void free_task(struct task_struct *tsk)
89222 {
89223 - account_kernel_stack(tsk->stack, -1);
89224 + account_kernel_stack(tsk, tsk->stack, -1);
89225 arch_release_thread_info(tsk->stack);
89226 - free_thread_info(tsk->stack);
89227 + gr_free_thread_info(tsk, tsk->stack);
89228 rt_mutex_debug_task_free(tsk);
89229 ftrace_graph_exit_task(tsk);
89230 put_seccomp_filter(tsk);
89231 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89232 {
89233 struct task_struct *tsk;
89234 struct thread_info *ti;
89235 + void *lowmem_stack;
89236 int node = tsk_fork_get_node(orig);
89237 int err;
89238
89239 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89240 if (!tsk)
89241 return NULL;
89242
89243 - ti = alloc_thread_info_node(tsk, node);
89244 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89245 if (!ti)
89246 goto free_tsk;
89247
89248 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89249 goto free_ti;
89250
89251 tsk->stack = ti;
89252 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89253 + tsk->lowmem_stack = lowmem_stack;
89254 +#endif
89255 #ifdef CONFIG_SECCOMP
89256 /*
89257 * We must handle setting up seccomp filters once we're under
89258 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89259 set_task_stack_end_magic(tsk);
89260
89261 #ifdef CONFIG_CC_STACKPROTECTOR
89262 - tsk->stack_canary = get_random_int();
89263 + tsk->stack_canary = pax_get_random_long();
89264 #endif
89265
89266 /*
89267 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89268 tsk->splice_pipe = NULL;
89269 tsk->task_frag.page = NULL;
89270
89271 - account_kernel_stack(ti, 1);
89272 + account_kernel_stack(tsk, ti, 1);
89273
89274 return tsk;
89275
89276 free_ti:
89277 - free_thread_info(ti);
89278 + gr_free_thread_info(tsk, ti);
89279 free_tsk:
89280 free_task_struct(tsk);
89281 return NULL;
89282 }
89283
89284 #ifdef CONFIG_MMU
89285 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89286 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89287 +{
89288 + struct vm_area_struct *tmp;
89289 + unsigned long charge;
89290 + struct file *file;
89291 + int retval;
89292 +
89293 + charge = 0;
89294 + if (mpnt->vm_flags & VM_ACCOUNT) {
89295 + unsigned long len = vma_pages(mpnt);
89296 +
89297 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89298 + goto fail_nomem;
89299 + charge = len;
89300 + }
89301 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89302 + if (!tmp)
89303 + goto fail_nomem;
89304 + *tmp = *mpnt;
89305 + tmp->vm_mm = mm;
89306 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89307 + retval = vma_dup_policy(mpnt, tmp);
89308 + if (retval)
89309 + goto fail_nomem_policy;
89310 + if (anon_vma_fork(tmp, mpnt))
89311 + goto fail_nomem_anon_vma_fork;
89312 + tmp->vm_flags &= ~VM_LOCKED;
89313 + tmp->vm_next = tmp->vm_prev = NULL;
89314 + tmp->vm_mirror = NULL;
89315 + file = tmp->vm_file;
89316 + if (file) {
89317 + struct inode *inode = file_inode(file);
89318 + struct address_space *mapping = file->f_mapping;
89319 +
89320 + get_file(file);
89321 + if (tmp->vm_flags & VM_DENYWRITE)
89322 + atomic_dec(&inode->i_writecount);
89323 + mutex_lock(&mapping->i_mmap_mutex);
89324 + if (tmp->vm_flags & VM_SHARED)
89325 + atomic_inc(&mapping->i_mmap_writable);
89326 + flush_dcache_mmap_lock(mapping);
89327 + /* insert tmp into the share list, just after mpnt */
89328 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89329 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89330 + else
89331 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89332 + flush_dcache_mmap_unlock(mapping);
89333 + mutex_unlock(&mapping->i_mmap_mutex);
89334 + }
89335 +
89336 + /*
89337 + * Clear hugetlb-related page reserves for children. This only
89338 + * affects MAP_PRIVATE mappings. Faults generated by the child
89339 + * are not guaranteed to succeed, even if read-only
89340 + */
89341 + if (is_vm_hugetlb_page(tmp))
89342 + reset_vma_resv_huge_pages(tmp);
89343 +
89344 + return tmp;
89345 +
89346 +fail_nomem_anon_vma_fork:
89347 + mpol_put(vma_policy(tmp));
89348 +fail_nomem_policy:
89349 + kmem_cache_free(vm_area_cachep, tmp);
89350 +fail_nomem:
89351 + vm_unacct_memory(charge);
89352 + return NULL;
89353 +}
89354 +
89355 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89356 {
89357 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89358 struct rb_node **rb_link, *rb_parent;
89359 int retval;
89360 - unsigned long charge;
89361
89362 uprobe_start_dup_mmap();
89363 down_write(&oldmm->mmap_sem);
89364 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89365
89366 prev = NULL;
89367 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89368 - struct file *file;
89369 -
89370 if (mpnt->vm_flags & VM_DONTCOPY) {
89371 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89372 -vma_pages(mpnt));
89373 continue;
89374 }
89375 - charge = 0;
89376 - if (mpnt->vm_flags & VM_ACCOUNT) {
89377 - unsigned long len = vma_pages(mpnt);
89378 -
89379 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89380 - goto fail_nomem;
89381 - charge = len;
89382 - }
89383 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89384 - if (!tmp)
89385 - goto fail_nomem;
89386 - *tmp = *mpnt;
89387 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89388 - retval = vma_dup_policy(mpnt, tmp);
89389 - if (retval)
89390 - goto fail_nomem_policy;
89391 - tmp->vm_mm = mm;
89392 - if (anon_vma_fork(tmp, mpnt))
89393 - goto fail_nomem_anon_vma_fork;
89394 - tmp->vm_flags &= ~VM_LOCKED;
89395 - tmp->vm_next = tmp->vm_prev = NULL;
89396 - file = tmp->vm_file;
89397 - if (file) {
89398 - struct inode *inode = file_inode(file);
89399 - struct address_space *mapping = file->f_mapping;
89400 -
89401 - get_file(file);
89402 - if (tmp->vm_flags & VM_DENYWRITE)
89403 - atomic_dec(&inode->i_writecount);
89404 - mutex_lock(&mapping->i_mmap_mutex);
89405 - if (tmp->vm_flags & VM_SHARED)
89406 - atomic_inc(&mapping->i_mmap_writable);
89407 - flush_dcache_mmap_lock(mapping);
89408 - /* insert tmp into the share list, just after mpnt */
89409 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89410 - vma_nonlinear_insert(tmp,
89411 - &mapping->i_mmap_nonlinear);
89412 - else
89413 - vma_interval_tree_insert_after(tmp, mpnt,
89414 - &mapping->i_mmap);
89415 - flush_dcache_mmap_unlock(mapping);
89416 - mutex_unlock(&mapping->i_mmap_mutex);
89417 + tmp = dup_vma(mm, oldmm, mpnt);
89418 + if (!tmp) {
89419 + retval = -ENOMEM;
89420 + goto out;
89421 }
89422
89423 /*
89424 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89425 if (retval)
89426 goto out;
89427 }
89428 +
89429 +#ifdef CONFIG_PAX_SEGMEXEC
89430 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89431 + struct vm_area_struct *mpnt_m;
89432 +
89433 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89434 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89435 +
89436 + if (!mpnt->vm_mirror)
89437 + continue;
89438 +
89439 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89440 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89441 + mpnt->vm_mirror = mpnt_m;
89442 + } else {
89443 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89444 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89445 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89446 + mpnt->vm_mirror->vm_mirror = mpnt;
89447 + }
89448 + }
89449 + BUG_ON(mpnt_m);
89450 + }
89451 +#endif
89452 +
89453 /* a new mm has just been created */
89454 arch_dup_mmap(oldmm, mm);
89455 retval = 0;
89456 @@ -486,14 +589,6 @@ out:
89457 up_write(&oldmm->mmap_sem);
89458 uprobe_end_dup_mmap();
89459 return retval;
89460 -fail_nomem_anon_vma_fork:
89461 - mpol_put(vma_policy(tmp));
89462 -fail_nomem_policy:
89463 - kmem_cache_free(vm_area_cachep, tmp);
89464 -fail_nomem:
89465 - retval = -ENOMEM;
89466 - vm_unacct_memory(charge);
89467 - goto out;
89468 }
89469
89470 static inline int mm_alloc_pgd(struct mm_struct *mm)
89471 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89472 return ERR_PTR(err);
89473
89474 mm = get_task_mm(task);
89475 - if (mm && mm != current->mm &&
89476 - !ptrace_may_access(task, mode)) {
89477 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89478 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89479 mmput(mm);
89480 mm = ERR_PTR(-EACCES);
89481 }
89482 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89483 spin_unlock(&fs->lock);
89484 return -EAGAIN;
89485 }
89486 - fs->users++;
89487 + atomic_inc(&fs->users);
89488 spin_unlock(&fs->lock);
89489 return 0;
89490 }
89491 tsk->fs = copy_fs_struct(fs);
89492 if (!tsk->fs)
89493 return -ENOMEM;
89494 + /* Carry through gr_chroot_dentry and is_chrooted instead
89495 + of recomputing it here. Already copied when the task struct
89496 + is duplicated. This allows pivot_root to not be treated as
89497 + a chroot
89498 + */
89499 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89500 +
89501 return 0;
89502 }
89503
89504 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89505 * parts of the process environment (as per the clone
89506 * flags). The actual kick-off is left to the caller.
89507 */
89508 -static struct task_struct *copy_process(unsigned long clone_flags,
89509 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89510 unsigned long stack_start,
89511 unsigned long stack_size,
89512 int __user *child_tidptr,
89513 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89514 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89515 #endif
89516 retval = -EAGAIN;
89517 +
89518 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89519 +
89520 if (atomic_read(&p->real_cred->user->processes) >=
89521 task_rlimit(p, RLIMIT_NPROC)) {
89522 if (p->real_cred->user != INIT_USER &&
89523 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89524 goto bad_fork_free_pid;
89525 }
89526
89527 + /* synchronizes with gr_set_acls()
89528 + we need to call this past the point of no return for fork()
89529 + */
89530 + gr_copy_label(p);
89531 +
89532 if (likely(p->pid)) {
89533 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89534
89535 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89536 bad_fork_free:
89537 free_task(p);
89538 fork_out:
89539 + gr_log_forkfail(retval);
89540 +
89541 return ERR_PTR(retval);
89542 }
89543
89544 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89545
89546 p = copy_process(clone_flags, stack_start, stack_size,
89547 child_tidptr, NULL, trace);
89548 + add_latent_entropy();
89549 /*
89550 * Do this prior waking up the new thread - the thread pointer
89551 * might get invalid after that point, if the thread exits quickly.
89552 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89553 if (clone_flags & CLONE_PARENT_SETTID)
89554 put_user(nr, parent_tidptr);
89555
89556 + gr_handle_brute_check();
89557 +
89558 if (clone_flags & CLONE_VFORK) {
89559 p->vfork_done = &vfork;
89560 init_completion(&vfork);
89561 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89562 mm_cachep = kmem_cache_create("mm_struct",
89563 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89564 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89565 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89566 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89567 mmap_init();
89568 nsproxy_cache_init();
89569 }
89570 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89571 return 0;
89572
89573 /* don't need lock here; in the worst case we'll do useless copy */
89574 - if (fs->users == 1)
89575 + if (atomic_read(&fs->users) == 1)
89576 return 0;
89577
89578 *new_fsp = copy_fs_struct(fs);
89579 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89580 fs = current->fs;
89581 spin_lock(&fs->lock);
89582 current->fs = new_fs;
89583 - if (--fs->users)
89584 + gr_set_chroot_entries(current, &current->fs->root);
89585 + if (atomic_dec_return(&fs->users))
89586 new_fs = NULL;
89587 else
89588 new_fs = fs;
89589 diff --git a/kernel/futex.c b/kernel/futex.c
89590 index 63678b5..512f9af 100644
89591 --- a/kernel/futex.c
89592 +++ b/kernel/futex.c
89593 @@ -201,7 +201,7 @@ struct futex_pi_state {
89594 atomic_t refcount;
89595
89596 union futex_key key;
89597 -};
89598 +} __randomize_layout;
89599
89600 /**
89601 * struct futex_q - The hashed futex queue entry, one per waiting task
89602 @@ -235,7 +235,7 @@ struct futex_q {
89603 struct rt_mutex_waiter *rt_waiter;
89604 union futex_key *requeue_pi_key;
89605 u32 bitset;
89606 -};
89607 +} __randomize_layout;
89608
89609 static const struct futex_q futex_q_init = {
89610 /* list gets initialized in queue_me()*/
89611 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89612 struct page *page, *page_head;
89613 int err, ro = 0;
89614
89615 +#ifdef CONFIG_PAX_SEGMEXEC
89616 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89617 + return -EFAULT;
89618 +#endif
89619 +
89620 /*
89621 * The futex address must be "naturally" aligned.
89622 */
89623 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89624
89625 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89626 {
89627 - int ret;
89628 + unsigned long ret;
89629
89630 pagefault_disable();
89631 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89632 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89633 {
89634 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89635 u32 curval;
89636 + mm_segment_t oldfs;
89637
89638 /*
89639 * This will fail and we want it. Some arch implementations do
89640 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89641 * implementation, the non-functional ones will return
89642 * -ENOSYS.
89643 */
89644 + oldfs = get_fs();
89645 + set_fs(USER_DS);
89646 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89647 futex_cmpxchg_enabled = 1;
89648 + set_fs(oldfs);
89649 #endif
89650 }
89651
89652 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89653 index 55c8c93..9ba7ad6 100644
89654 --- a/kernel/futex_compat.c
89655 +++ b/kernel/futex_compat.c
89656 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89657 return 0;
89658 }
89659
89660 -static void __user *futex_uaddr(struct robust_list __user *entry,
89661 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89662 compat_long_t futex_offset)
89663 {
89664 compat_uptr_t base = ptr_to_compat(entry);
89665 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89666 index b358a80..fc25240 100644
89667 --- a/kernel/gcov/base.c
89668 +++ b/kernel/gcov/base.c
89669 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89670 }
89671
89672 #ifdef CONFIG_MODULES
89673 -static inline int within(void *addr, void *start, unsigned long size)
89674 -{
89675 - return ((addr >= start) && (addr < start + size));
89676 -}
89677 -
89678 /* Update list and generate events when modules are unloaded. */
89679 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89680 void *data)
89681 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89682
89683 /* Remove entries located in module from linked list. */
89684 while ((info = gcov_info_next(info))) {
89685 - if (within(info, mod->module_core, mod->core_size)) {
89686 + if (within_module_core_rw((unsigned long)info, mod)) {
89687 gcov_info_unlink(prev, info);
89688 if (gcov_events_enabled)
89689 gcov_event(GCOV_REMOVE, info);
89690 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89691 index 9019f15..9a3c42e 100644
89692 --- a/kernel/jump_label.c
89693 +++ b/kernel/jump_label.c
89694 @@ -14,6 +14,7 @@
89695 #include <linux/err.h>
89696 #include <linux/static_key.h>
89697 #include <linux/jump_label_ratelimit.h>
89698 +#include <linux/mm.h>
89699
89700 #ifdef HAVE_JUMP_LABEL
89701
89702 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89703
89704 size = (((unsigned long)stop - (unsigned long)start)
89705 / sizeof(struct jump_entry));
89706 + pax_open_kernel();
89707 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89708 + pax_close_kernel();
89709 }
89710
89711 static void jump_label_update(struct static_key *key, int enable);
89712 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89713 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89714 struct jump_entry *iter;
89715
89716 + pax_open_kernel();
89717 for (iter = iter_start; iter < iter_stop; iter++) {
89718 if (within_module_init(iter->code, mod))
89719 iter->code = 0;
89720 }
89721 + pax_close_kernel();
89722 }
89723
89724 static int
89725 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89726 index 5c5987f..bc502b0 100644
89727 --- a/kernel/kallsyms.c
89728 +++ b/kernel/kallsyms.c
89729 @@ -11,6 +11,9 @@
89730 * Changed the compression method from stem compression to "table lookup"
89731 * compression (see scripts/kallsyms.c for a more complete description)
89732 */
89733 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89734 +#define __INCLUDED_BY_HIDESYM 1
89735 +#endif
89736 #include <linux/kallsyms.h>
89737 #include <linux/module.h>
89738 #include <linux/init.h>
89739 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89740
89741 static inline int is_kernel_inittext(unsigned long addr)
89742 {
89743 + if (system_state != SYSTEM_BOOTING)
89744 + return 0;
89745 +
89746 if (addr >= (unsigned long)_sinittext
89747 && addr <= (unsigned long)_einittext)
89748 return 1;
89749 return 0;
89750 }
89751
89752 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89753 +#ifdef CONFIG_MODULES
89754 +static inline int is_module_text(unsigned long addr)
89755 +{
89756 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89757 + return 1;
89758 +
89759 + addr = ktla_ktva(addr);
89760 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89761 +}
89762 +#else
89763 +static inline int is_module_text(unsigned long addr)
89764 +{
89765 + return 0;
89766 +}
89767 +#endif
89768 +#endif
89769 +
89770 static inline int is_kernel_text(unsigned long addr)
89771 {
89772 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89773 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89774
89775 static inline int is_kernel(unsigned long addr)
89776 {
89777 +
89778 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89779 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89780 + return 1;
89781 +
89782 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89783 +#else
89784 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89785 +#endif
89786 +
89787 return 1;
89788 return in_gate_area_no_mm(addr);
89789 }
89790
89791 static int is_ksym_addr(unsigned long addr)
89792 {
89793 +
89794 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89795 + if (is_module_text(addr))
89796 + return 0;
89797 +#endif
89798 +
89799 if (all_var)
89800 return is_kernel(addr);
89801
89802 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89803
89804 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89805 {
89806 - iter->name[0] = '\0';
89807 iter->nameoff = get_symbol_offset(new_pos);
89808 iter->pos = new_pos;
89809 }
89810 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89811 {
89812 struct kallsym_iter *iter = m->private;
89813
89814 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89815 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89816 + return 0;
89817 +#endif
89818 +
89819 /* Some debugging symbols have no name. Ignore them. */
89820 if (!iter->name[0])
89821 return 0;
89822 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89823 */
89824 type = iter->exported ? toupper(iter->type) :
89825 tolower(iter->type);
89826 +
89827 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89828 type, iter->name, iter->module_name);
89829 } else
89830 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89831 index 0aa69ea..a7fcafb 100644
89832 --- a/kernel/kcmp.c
89833 +++ b/kernel/kcmp.c
89834 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89835 struct task_struct *task1, *task2;
89836 int ret;
89837
89838 +#ifdef CONFIG_GRKERNSEC
89839 + return -ENOSYS;
89840 +#endif
89841 +
89842 rcu_read_lock();
89843
89844 /*
89845 diff --git a/kernel/kexec.c b/kernel/kexec.c
89846 index 2abf9f6..c40cf85 100644
89847 --- a/kernel/kexec.c
89848 +++ b/kernel/kexec.c
89849 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89850 compat_ulong_t, flags)
89851 {
89852 struct compat_kexec_segment in;
89853 - struct kexec_segment out, __user *ksegments;
89854 + struct kexec_segment out;
89855 + struct kexec_segment __user *ksegments;
89856 unsigned long i, result;
89857
89858 /* Don't allow clients that don't understand the native
89859 diff --git a/kernel/kmod.c b/kernel/kmod.c
89860 index 80f7a6d..3c476d3 100644
89861 --- a/kernel/kmod.c
89862 +++ b/kernel/kmod.c
89863 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89864 kfree(info->argv);
89865 }
89866
89867 -static int call_modprobe(char *module_name, int wait)
89868 +static int call_modprobe(char *module_name, char *module_param, int wait)
89869 {
89870 struct subprocess_info *info;
89871 static char *envp[] = {
89872 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89873 NULL
89874 };
89875
89876 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89877 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89878 if (!argv)
89879 goto out;
89880
89881 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89882 argv[1] = "-q";
89883 argv[2] = "--";
89884 argv[3] = module_name; /* check free_modprobe_argv() */
89885 - argv[4] = NULL;
89886 + argv[4] = module_param;
89887 + argv[5] = NULL;
89888
89889 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89890 NULL, free_modprobe_argv, NULL);
89891 @@ -129,9 +130,8 @@ out:
89892 * If module auto-loading support is disabled then this function
89893 * becomes a no-operation.
89894 */
89895 -int __request_module(bool wait, const char *fmt, ...)
89896 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89897 {
89898 - va_list args;
89899 char module_name[MODULE_NAME_LEN];
89900 unsigned int max_modprobes;
89901 int ret;
89902 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89903 if (!modprobe_path[0])
89904 return 0;
89905
89906 - va_start(args, fmt);
89907 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89908 - va_end(args);
89909 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89910 if (ret >= MODULE_NAME_LEN)
89911 return -ENAMETOOLONG;
89912
89913 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89914 if (ret)
89915 return ret;
89916
89917 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89918 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89919 + /* hack to workaround consolekit/udisks stupidity */
89920 + read_lock(&tasklist_lock);
89921 + if (!strcmp(current->comm, "mount") &&
89922 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89923 + read_unlock(&tasklist_lock);
89924 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89925 + return -EPERM;
89926 + }
89927 + read_unlock(&tasklist_lock);
89928 + }
89929 +#endif
89930 +
89931 /* If modprobe needs a service that is in a module, we get a recursive
89932 * loop. Limit the number of running kmod threads to max_threads/2 or
89933 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89934 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89935
89936 trace_module_request(module_name, wait, _RET_IP_);
89937
89938 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89939 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89940
89941 atomic_dec(&kmod_concurrent);
89942 return ret;
89943 }
89944 +
89945 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89946 +{
89947 + va_list args;
89948 + int ret;
89949 +
89950 + va_start(args, fmt);
89951 + ret = ____request_module(wait, module_param, fmt, args);
89952 + va_end(args);
89953 +
89954 + return ret;
89955 +}
89956 +
89957 +int __request_module(bool wait, const char *fmt, ...)
89958 +{
89959 + va_list args;
89960 + int ret;
89961 +
89962 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89963 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89964 + char module_param[MODULE_NAME_LEN];
89965 +
89966 + memset(module_param, 0, sizeof(module_param));
89967 +
89968 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89969 +
89970 + va_start(args, fmt);
89971 + ret = ____request_module(wait, module_param, fmt, args);
89972 + va_end(args);
89973 +
89974 + return ret;
89975 + }
89976 +#endif
89977 +
89978 + va_start(args, fmt);
89979 + ret = ____request_module(wait, NULL, fmt, args);
89980 + va_end(args);
89981 +
89982 + return ret;
89983 +}
89984 +
89985 EXPORT_SYMBOL(__request_module);
89986 #endif /* CONFIG_MODULES */
89987
89988 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89989 {
89990 +#ifdef CONFIG_GRKERNSEC
89991 + kfree(info->path);
89992 + info->path = info->origpath;
89993 +#endif
89994 if (info->cleanup)
89995 (*info->cleanup)(info);
89996 kfree(info);
89997 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89998 */
89999 set_user_nice(current, 0);
90000
90001 +#ifdef CONFIG_GRKERNSEC
90002 + /* this is race-free as far as userland is concerned as we copied
90003 + out the path to be used prior to this point and are now operating
90004 + on that copy
90005 + */
90006 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90007 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90008 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90009 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90010 + retval = -EPERM;
90011 + goto out;
90012 + }
90013 +#endif
90014 +
90015 retval = -ENOMEM;
90016 new = prepare_kernel_cred(current);
90017 if (!new)
90018 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
90019 commit_creds(new);
90020
90021 retval = do_execve(getname_kernel(sub_info->path),
90022 - (const char __user *const __user *)sub_info->argv,
90023 - (const char __user *const __user *)sub_info->envp);
90024 + (const char __user *const __force_user *)sub_info->argv,
90025 + (const char __user *const __force_user *)sub_info->envp);
90026 out:
90027 sub_info->retval = retval;
90028 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
90029 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
90030 *
90031 * Thus the __user pointer cast is valid here.
90032 */
90033 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90034 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90035
90036 /*
90037 * If ret is 0, either ____call_usermodehelper failed and the
90038 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90039 goto out;
90040
90041 INIT_WORK(&sub_info->work, __call_usermodehelper);
90042 +#ifdef CONFIG_GRKERNSEC
90043 + sub_info->origpath = path;
90044 + sub_info->path = kstrdup(path, gfp_mask);
90045 +#else
90046 sub_info->path = path;
90047 +#endif
90048 sub_info->argv = argv;
90049 sub_info->envp = envp;
90050
90051 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90052 static int proc_cap_handler(struct ctl_table *table, int write,
90053 void __user *buffer, size_t *lenp, loff_t *ppos)
90054 {
90055 - struct ctl_table t;
90056 + ctl_table_no_const t;
90057 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90058 kernel_cap_t new_cap;
90059 int err, i;
90060 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90061 index 3995f54..e247879 100644
90062 --- a/kernel/kprobes.c
90063 +++ b/kernel/kprobes.c
90064 @@ -31,6 +31,9 @@
90065 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90066 * <prasanna@in.ibm.com> added function-return probes.
90067 */
90068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90069 +#define __INCLUDED_BY_HIDESYM 1
90070 +#endif
90071 #include <linux/kprobes.h>
90072 #include <linux/hash.h>
90073 #include <linux/init.h>
90074 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90075
90076 static void *alloc_insn_page(void)
90077 {
90078 - return module_alloc(PAGE_SIZE);
90079 + return module_alloc_exec(PAGE_SIZE);
90080 }
90081
90082 static void free_insn_page(void *page)
90083 {
90084 - module_free(NULL, page);
90085 + module_free_exec(NULL, page);
90086 }
90087
90088 struct kprobe_insn_cache kprobe_insn_slots = {
90089 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90090 kprobe_type = "k";
90091
90092 if (sym)
90093 - seq_printf(pi, "%p %s %s+0x%x %s ",
90094 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90095 p->addr, kprobe_type, sym, offset,
90096 (modname ? modname : " "));
90097 else
90098 - seq_printf(pi, "%p %s %p ",
90099 + seq_printf(pi, "%pK %s %pK ",
90100 p->addr, kprobe_type, p->addr);
90101
90102 if (!pp)
90103 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90104 index 6683cce..daf8999 100644
90105 --- a/kernel/ksysfs.c
90106 +++ b/kernel/ksysfs.c
90107 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90108 {
90109 if (count+1 > UEVENT_HELPER_PATH_LEN)
90110 return -ENOENT;
90111 + if (!capable(CAP_SYS_ADMIN))
90112 + return -EPERM;
90113 memcpy(uevent_helper, buf, count);
90114 uevent_helper[count] = '\0';
90115 if (count && uevent_helper[count-1] == '\n')
90116 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90117 return count;
90118 }
90119
90120 -static struct bin_attribute notes_attr = {
90121 +static bin_attribute_no_const notes_attr __read_only = {
90122 .attr = {
90123 .name = "notes",
90124 .mode = S_IRUGO,
90125 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90126 index 88d0d44..e9ce0ee 100644
90127 --- a/kernel/locking/lockdep.c
90128 +++ b/kernel/locking/lockdep.c
90129 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90130 end = (unsigned long) &_end,
90131 addr = (unsigned long) obj;
90132
90133 +#ifdef CONFIG_PAX_KERNEXEC
90134 + start = ktla_ktva(start);
90135 +#endif
90136 +
90137 /*
90138 * static variable?
90139 */
90140 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90141 if (!static_obj(lock->key)) {
90142 debug_locks_off();
90143 printk("INFO: trying to register non-static key.\n");
90144 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90145 printk("the code is fine but needs lockdep annotation.\n");
90146 printk("turning off the locking correctness validator.\n");
90147 dump_stack();
90148 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90149 if (!class)
90150 return 0;
90151 }
90152 - atomic_inc((atomic_t *)&class->ops);
90153 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90154 if (very_verbose(class)) {
90155 printk("\nacquire class [%p] %s", class->key, class->name);
90156 if (class->name_version > 1)
90157 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90158 index ef43ac4..2720dfa 100644
90159 --- a/kernel/locking/lockdep_proc.c
90160 +++ b/kernel/locking/lockdep_proc.c
90161 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90162 return 0;
90163 }
90164
90165 - seq_printf(m, "%p", class->key);
90166 + seq_printf(m, "%pK", class->key);
90167 #ifdef CONFIG_DEBUG_LOCKDEP
90168 seq_printf(m, " OPS:%8ld", class->ops);
90169 #endif
90170 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90171
90172 list_for_each_entry(entry, &class->locks_after, entry) {
90173 if (entry->distance == 1) {
90174 - seq_printf(m, " -> [%p] ", entry->class->key);
90175 + seq_printf(m, " -> [%pK] ", entry->class->key);
90176 print_name(m, entry->class);
90177 seq_puts(m, "\n");
90178 }
90179 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90180 if (!class->key)
90181 continue;
90182
90183 - seq_printf(m, "[%p] ", class->key);
90184 + seq_printf(m, "[%pK] ", class->key);
90185 print_name(m, class);
90186 seq_puts(m, "\n");
90187 }
90188 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90189 if (!i)
90190 seq_line(m, '-', 40-namelen, namelen);
90191
90192 - snprintf(ip, sizeof(ip), "[<%p>]",
90193 + snprintf(ip, sizeof(ip), "[<%pK>]",
90194 (void *)class->contention_point[i]);
90195 seq_printf(m, "%40s %14lu %29s %pS\n",
90196 name, stats->contention_point[i],
90197 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90198 if (!i)
90199 seq_line(m, '-', 40-namelen, namelen);
90200
90201 - snprintf(ip, sizeof(ip), "[<%p>]",
90202 + snprintf(ip, sizeof(ip), "[<%pK>]",
90203 (void *)class->contending_point[i]);
90204 seq_printf(m, "%40s %14lu %29s %pS\n",
90205 name, stats->contending_point[i],
90206 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90207 index 9887a90..0cd2b1d 100644
90208 --- a/kernel/locking/mcs_spinlock.c
90209 +++ b/kernel/locking/mcs_spinlock.c
90210 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90211
90212 prev = decode_cpu(old);
90213 node->prev = prev;
90214 - ACCESS_ONCE(prev->next) = node;
90215 + ACCESS_ONCE_RW(prev->next) = node;
90216
90217 /*
90218 * Normally @prev is untouchable after the above store; because at that
90219 @@ -172,8 +172,8 @@ unqueue:
90220 * it will wait in Step-A.
90221 */
90222
90223 - ACCESS_ONCE(next->prev) = prev;
90224 - ACCESS_ONCE(prev->next) = next;
90225 + ACCESS_ONCE_RW(next->prev) = prev;
90226 + ACCESS_ONCE_RW(prev->next) = next;
90227
90228 return false;
90229 }
90230 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90231 node = this_cpu_ptr(&osq_node);
90232 next = xchg(&node->next, NULL);
90233 if (next) {
90234 - ACCESS_ONCE(next->locked) = 1;
90235 + ACCESS_ONCE_RW(next->locked) = 1;
90236 return;
90237 }
90238
90239 next = osq_wait_next(lock, node, NULL);
90240 if (next)
90241 - ACCESS_ONCE(next->locked) = 1;
90242 + ACCESS_ONCE_RW(next->locked) = 1;
90243 }
90244
90245 #endif
90246 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90247 index 4d60986..5d351c1 100644
90248 --- a/kernel/locking/mcs_spinlock.h
90249 +++ b/kernel/locking/mcs_spinlock.h
90250 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90251 */
90252 return;
90253 }
90254 - ACCESS_ONCE(prev->next) = node;
90255 + ACCESS_ONCE_RW(prev->next) = node;
90256
90257 /* Wait until the lock holder passes the lock down. */
90258 arch_mcs_spin_lock_contended(&node->locked);
90259 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90260 index 5cf6731..ce3bc5a 100644
90261 --- a/kernel/locking/mutex-debug.c
90262 +++ b/kernel/locking/mutex-debug.c
90263 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90264 }
90265
90266 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90267 - struct thread_info *ti)
90268 + struct task_struct *task)
90269 {
90270 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90271
90272 /* Mark the current thread as blocked on the lock: */
90273 - ti->task->blocked_on = waiter;
90274 + task->blocked_on = waiter;
90275 }
90276
90277 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90278 - struct thread_info *ti)
90279 + struct task_struct *task)
90280 {
90281 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90282 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90283 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90284 - ti->task->blocked_on = NULL;
90285 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90286 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90287 + task->blocked_on = NULL;
90288
90289 list_del_init(&waiter->list);
90290 waiter->task = NULL;
90291 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90292 index 0799fd3..d06ae3b 100644
90293 --- a/kernel/locking/mutex-debug.h
90294 +++ b/kernel/locking/mutex-debug.h
90295 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90296 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90297 extern void debug_mutex_add_waiter(struct mutex *lock,
90298 struct mutex_waiter *waiter,
90299 - struct thread_info *ti);
90300 + struct task_struct *task);
90301 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90302 - struct thread_info *ti);
90303 + struct task_struct *task);
90304 extern void debug_mutex_unlock(struct mutex *lock);
90305 extern void debug_mutex_init(struct mutex *lock, const char *name,
90306 struct lock_class_key *key);
90307 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90308 index dadbf88..4500507 100644
90309 --- a/kernel/locking/mutex.c
90310 +++ b/kernel/locking/mutex.c
90311 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90312 goto skip_wait;
90313
90314 debug_mutex_lock_common(lock, &waiter);
90315 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90316 + debug_mutex_add_waiter(lock, &waiter, task);
90317
90318 /* add waiting tasks to the end of the waitqueue (FIFO): */
90319 list_add_tail(&waiter.list, &lock->wait_list);
90320 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90321 schedule_preempt_disabled();
90322 spin_lock_mutex(&lock->wait_lock, flags);
90323 }
90324 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90325 + mutex_remove_waiter(lock, &waiter, task);
90326 /* set it to 0 if there are no waiters left: */
90327 if (likely(list_empty(&lock->wait_list)))
90328 atomic_set(&lock->count, 0);
90329 @@ -600,7 +600,7 @@ skip_wait:
90330 return 0;
90331
90332 err:
90333 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90334 + mutex_remove_waiter(lock, &waiter, task);
90335 spin_unlock_mutex(&lock->wait_lock, flags);
90336 debug_mutex_free_waiter(&waiter);
90337 mutex_release(&lock->dep_map, 1, ip);
90338 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90339 index 1d96dd0..994ff19 100644
90340 --- a/kernel/locking/rtmutex-tester.c
90341 +++ b/kernel/locking/rtmutex-tester.c
90342 @@ -22,7 +22,7 @@
90343 #define MAX_RT_TEST_MUTEXES 8
90344
90345 static spinlock_t rttest_lock;
90346 -static atomic_t rttest_event;
90347 +static atomic_unchecked_t rttest_event;
90348
90349 struct test_thread_data {
90350 int opcode;
90351 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90352
90353 case RTTEST_LOCKCONT:
90354 td->mutexes[td->opdata] = 1;
90355 - td->event = atomic_add_return(1, &rttest_event);
90356 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90357 return 0;
90358
90359 case RTTEST_RESET:
90360 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90361 return 0;
90362
90363 case RTTEST_RESETEVENT:
90364 - atomic_set(&rttest_event, 0);
90365 + atomic_set_unchecked(&rttest_event, 0);
90366 return 0;
90367
90368 default:
90369 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90370 return ret;
90371
90372 td->mutexes[id] = 1;
90373 - td->event = atomic_add_return(1, &rttest_event);
90374 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90375 rt_mutex_lock(&mutexes[id]);
90376 - td->event = atomic_add_return(1, &rttest_event);
90377 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90378 td->mutexes[id] = 4;
90379 return 0;
90380
90381 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90382 return ret;
90383
90384 td->mutexes[id] = 1;
90385 - td->event = atomic_add_return(1, &rttest_event);
90386 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90387 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90388 - td->event = atomic_add_return(1, &rttest_event);
90389 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90390 td->mutexes[id] = ret ? 0 : 4;
90391 return ret ? -EINTR : 0;
90392
90393 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90394 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90395 return ret;
90396
90397 - td->event = atomic_add_return(1, &rttest_event);
90398 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90399 rt_mutex_unlock(&mutexes[id]);
90400 - td->event = atomic_add_return(1, &rttest_event);
90401 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90402 td->mutexes[id] = 0;
90403 return 0;
90404
90405 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90406 break;
90407
90408 td->mutexes[dat] = 2;
90409 - td->event = atomic_add_return(1, &rttest_event);
90410 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90411 break;
90412
90413 default:
90414 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90415 return;
90416
90417 td->mutexes[dat] = 3;
90418 - td->event = atomic_add_return(1, &rttest_event);
90419 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90420 break;
90421
90422 case RTTEST_LOCKNOWAIT:
90423 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90424 return;
90425
90426 td->mutexes[dat] = 1;
90427 - td->event = atomic_add_return(1, &rttest_event);
90428 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90429 return;
90430
90431 default:
90432 diff --git a/kernel/module.c b/kernel/module.c
90433 index 88cec1d..d097c28 100644
90434 --- a/kernel/module.c
90435 +++ b/kernel/module.c
90436 @@ -60,6 +60,7 @@
90437 #include <linux/jump_label.h>
90438 #include <linux/pfn.h>
90439 #include <linux/bsearch.h>
90440 +#include <linux/grsecurity.h>
90441 #include <uapi/linux/module.h>
90442 #include "module-internal.h"
90443
90444 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90445
90446 /* Bounds of module allocation, for speeding __module_address.
90447 * Protected by module_mutex. */
90448 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90449 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90450 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90451
90452 int register_module_notifier(struct notifier_block * nb)
90453 {
90454 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90455 return true;
90456
90457 list_for_each_entry_rcu(mod, &modules, list) {
90458 - struct symsearch arr[] = {
90459 + struct symsearch modarr[] = {
90460 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90461 NOT_GPL_ONLY, false },
90462 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90463 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90464 if (mod->state == MODULE_STATE_UNFORMED)
90465 continue;
90466
90467 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90468 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90469 return true;
90470 }
90471 return false;
90472 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90473 if (!pcpusec->sh_size)
90474 return 0;
90475
90476 - if (align > PAGE_SIZE) {
90477 + if (align-1 >= PAGE_SIZE) {
90478 pr_warn("%s: per-cpu alignment %li > %li\n",
90479 mod->name, align, PAGE_SIZE);
90480 align = PAGE_SIZE;
90481 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90482 static ssize_t show_coresize(struct module_attribute *mattr,
90483 struct module_kobject *mk, char *buffer)
90484 {
90485 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90486 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90487 }
90488
90489 static struct module_attribute modinfo_coresize =
90490 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90491 static ssize_t show_initsize(struct module_attribute *mattr,
90492 struct module_kobject *mk, char *buffer)
90493 {
90494 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90495 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90496 }
90497
90498 static struct module_attribute modinfo_initsize =
90499 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90500 goto bad_version;
90501 }
90502
90503 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90504 + /*
90505 + * avoid potentially printing jibberish on attempted load
90506 + * of a module randomized with a different seed
90507 + */
90508 + pr_warn("no symbol version for %s\n", symname);
90509 +#else
90510 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90511 +#endif
90512 return 0;
90513
90514 bad_version:
90515 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90516 + /*
90517 + * avoid potentially printing jibberish on attempted load
90518 + * of a module randomized with a different seed
90519 + */
90520 + printk("attempted module disagrees about version of symbol %s\n",
90521 + symname);
90522 +#else
90523 printk("%s: disagrees about version of symbol %s\n",
90524 mod->name, symname);
90525 +#endif
90526 return 0;
90527 }
90528
90529 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90530 */
90531 #ifdef CONFIG_SYSFS
90532
90533 -#ifdef CONFIG_KALLSYMS
90534 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90535 static inline bool sect_empty(const Elf_Shdr *sect)
90536 {
90537 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90538 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90539 {
90540 unsigned int notes, loaded, i;
90541 struct module_notes_attrs *notes_attrs;
90542 - struct bin_attribute *nattr;
90543 + bin_attribute_no_const *nattr;
90544
90545 /* failed to create section attributes, so can't create notes */
90546 if (!mod->sect_attrs)
90547 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90548 static int module_add_modinfo_attrs(struct module *mod)
90549 {
90550 struct module_attribute *attr;
90551 - struct module_attribute *temp_attr;
90552 + module_attribute_no_const *temp_attr;
90553 int error = 0;
90554 int i;
90555
90556 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90557
90558 static void unset_module_core_ro_nx(struct module *mod)
90559 {
90560 - set_page_attributes(mod->module_core + mod->core_text_size,
90561 - mod->module_core + mod->core_size,
90562 + set_page_attributes(mod->module_core_rw,
90563 + mod->module_core_rw + mod->core_size_rw,
90564 set_memory_x);
90565 - set_page_attributes(mod->module_core,
90566 - mod->module_core + mod->core_ro_size,
90567 + set_page_attributes(mod->module_core_rx,
90568 + mod->module_core_rx + mod->core_size_rx,
90569 set_memory_rw);
90570 }
90571
90572 static void unset_module_init_ro_nx(struct module *mod)
90573 {
90574 - set_page_attributes(mod->module_init + mod->init_text_size,
90575 - mod->module_init + mod->init_size,
90576 + set_page_attributes(mod->module_init_rw,
90577 + mod->module_init_rw + mod->init_size_rw,
90578 set_memory_x);
90579 - set_page_attributes(mod->module_init,
90580 - mod->module_init + mod->init_ro_size,
90581 + set_page_attributes(mod->module_init_rx,
90582 + mod->module_init_rx + mod->init_size_rx,
90583 set_memory_rw);
90584 }
90585
90586 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90587 list_for_each_entry_rcu(mod, &modules, list) {
90588 if (mod->state == MODULE_STATE_UNFORMED)
90589 continue;
90590 - if ((mod->module_core) && (mod->core_text_size)) {
90591 - set_page_attributes(mod->module_core,
90592 - mod->module_core + mod->core_text_size,
90593 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90594 + set_page_attributes(mod->module_core_rx,
90595 + mod->module_core_rx + mod->core_size_rx,
90596 set_memory_rw);
90597 }
90598 - if ((mod->module_init) && (mod->init_text_size)) {
90599 - set_page_attributes(mod->module_init,
90600 - mod->module_init + mod->init_text_size,
90601 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90602 + set_page_attributes(mod->module_init_rx,
90603 + mod->module_init_rx + mod->init_size_rx,
90604 set_memory_rw);
90605 }
90606 }
90607 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90608 list_for_each_entry_rcu(mod, &modules, list) {
90609 if (mod->state == MODULE_STATE_UNFORMED)
90610 continue;
90611 - if ((mod->module_core) && (mod->core_text_size)) {
90612 - set_page_attributes(mod->module_core,
90613 - mod->module_core + mod->core_text_size,
90614 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90615 + set_page_attributes(mod->module_core_rx,
90616 + mod->module_core_rx + mod->core_size_rx,
90617 set_memory_ro);
90618 }
90619 - if ((mod->module_init) && (mod->init_text_size)) {
90620 - set_page_attributes(mod->module_init,
90621 - mod->module_init + mod->init_text_size,
90622 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90623 + set_page_attributes(mod->module_init_rx,
90624 + mod->module_init_rx + mod->init_size_rx,
90625 set_memory_ro);
90626 }
90627 }
90628 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90629
90630 /* This may be NULL, but that's OK */
90631 unset_module_init_ro_nx(mod);
90632 - module_free(mod, mod->module_init);
90633 + module_free(mod, mod->module_init_rw);
90634 + module_free_exec(mod, mod->module_init_rx);
90635 kfree(mod->args);
90636 percpu_modfree(mod);
90637
90638 /* Free lock-classes: */
90639 - lockdep_free_key_range(mod->module_core, mod->core_size);
90640 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90641 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90642
90643 /* Finally, free the core (containing the module structure) */
90644 unset_module_core_ro_nx(mod);
90645 - module_free(mod, mod->module_core);
90646 + module_free_exec(mod, mod->module_core_rx);
90647 + module_free(mod, mod->module_core_rw);
90648
90649 #ifdef CONFIG_MPU
90650 update_protections(current->mm);
90651 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90652 int ret = 0;
90653 const struct kernel_symbol *ksym;
90654
90655 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90656 + int is_fs_load = 0;
90657 + int register_filesystem_found = 0;
90658 + char *p;
90659 +
90660 + p = strstr(mod->args, "grsec_modharden_fs");
90661 + if (p) {
90662 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90663 + /* copy \0 as well */
90664 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90665 + is_fs_load = 1;
90666 + }
90667 +#endif
90668 +
90669 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90670 const char *name = info->strtab + sym[i].st_name;
90671
90672 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90673 + /* it's a real shame this will never get ripped and copied
90674 + upstream! ;(
90675 + */
90676 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90677 + register_filesystem_found = 1;
90678 +#endif
90679 +
90680 switch (sym[i].st_shndx) {
90681 case SHN_COMMON:
90682 /* Ignore common symbols */
90683 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90684 ksym = resolve_symbol_wait(mod, info, name);
90685 /* Ok if resolved. */
90686 if (ksym && !IS_ERR(ksym)) {
90687 + pax_open_kernel();
90688 sym[i].st_value = ksym->value;
90689 + pax_close_kernel();
90690 break;
90691 }
90692
90693 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90694 secbase = (unsigned long)mod_percpu(mod);
90695 else
90696 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90697 + pax_open_kernel();
90698 sym[i].st_value += secbase;
90699 + pax_close_kernel();
90700 break;
90701 }
90702 }
90703
90704 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90705 + if (is_fs_load && !register_filesystem_found) {
90706 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90707 + ret = -EPERM;
90708 + }
90709 +#endif
90710 +
90711 return ret;
90712 }
90713
90714 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90715 || s->sh_entsize != ~0UL
90716 || strstarts(sname, ".init"))
90717 continue;
90718 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90719 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90720 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90721 + else
90722 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90723 pr_debug("\t%s\n", sname);
90724 }
90725 - switch (m) {
90726 - case 0: /* executable */
90727 - mod->core_size = debug_align(mod->core_size);
90728 - mod->core_text_size = mod->core_size;
90729 - break;
90730 - case 1: /* RO: text and ro-data */
90731 - mod->core_size = debug_align(mod->core_size);
90732 - mod->core_ro_size = mod->core_size;
90733 - break;
90734 - case 3: /* whole core */
90735 - mod->core_size = debug_align(mod->core_size);
90736 - break;
90737 - }
90738 }
90739
90740 pr_debug("Init section allocation order:\n");
90741 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90742 || s->sh_entsize != ~0UL
90743 || !strstarts(sname, ".init"))
90744 continue;
90745 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90746 - | INIT_OFFSET_MASK);
90747 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90748 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90749 + else
90750 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90751 + s->sh_entsize |= INIT_OFFSET_MASK;
90752 pr_debug("\t%s\n", sname);
90753 }
90754 - switch (m) {
90755 - case 0: /* executable */
90756 - mod->init_size = debug_align(mod->init_size);
90757 - mod->init_text_size = mod->init_size;
90758 - break;
90759 - case 1: /* RO: text and ro-data */
90760 - mod->init_size = debug_align(mod->init_size);
90761 - mod->init_ro_size = mod->init_size;
90762 - break;
90763 - case 3: /* whole init */
90764 - mod->init_size = debug_align(mod->init_size);
90765 - break;
90766 - }
90767 }
90768 }
90769
90770 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90771
90772 /* Put symbol section at end of init part of module. */
90773 symsect->sh_flags |= SHF_ALLOC;
90774 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90775 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90776 info->index.sym) | INIT_OFFSET_MASK;
90777 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90778
90779 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90780 }
90781
90782 /* Append room for core symbols at end of core part. */
90783 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90784 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90785 - mod->core_size += strtab_size;
90786 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90787 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90788 + mod->core_size_rx += strtab_size;
90789
90790 /* Put string table section at end of init part of module. */
90791 strsect->sh_flags |= SHF_ALLOC;
90792 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90793 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90794 info->index.str) | INIT_OFFSET_MASK;
90795 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90796 }
90797 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90798 /* Make sure we get permanent strtab: don't use info->strtab. */
90799 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90800
90801 + pax_open_kernel();
90802 +
90803 /* Set types up while we still have access to sections. */
90804 for (i = 0; i < mod->num_symtab; i++)
90805 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90806
90807 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90808 - mod->core_strtab = s = mod->module_core + info->stroffs;
90809 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90810 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90811 src = mod->symtab;
90812 for (ndst = i = 0; i < mod->num_symtab; i++) {
90813 if (i == 0 ||
90814 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90815 }
90816 }
90817 mod->core_num_syms = ndst;
90818 +
90819 + pax_close_kernel();
90820 }
90821 #else
90822 static inline void layout_symtab(struct module *mod, struct load_info *info)
90823 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90824 return vmalloc_exec(size);
90825 }
90826
90827 -static void *module_alloc_update_bounds(unsigned long size)
90828 +static void *module_alloc_update_bounds_rw(unsigned long size)
90829 {
90830 void *ret = module_alloc(size);
90831
90832 if (ret) {
90833 mutex_lock(&module_mutex);
90834 /* Update module bounds. */
90835 - if ((unsigned long)ret < module_addr_min)
90836 - module_addr_min = (unsigned long)ret;
90837 - if ((unsigned long)ret + size > module_addr_max)
90838 - module_addr_max = (unsigned long)ret + size;
90839 + if ((unsigned long)ret < module_addr_min_rw)
90840 + module_addr_min_rw = (unsigned long)ret;
90841 + if ((unsigned long)ret + size > module_addr_max_rw)
90842 + module_addr_max_rw = (unsigned long)ret + size;
90843 + mutex_unlock(&module_mutex);
90844 + }
90845 + return ret;
90846 +}
90847 +
90848 +static void *module_alloc_update_bounds_rx(unsigned long size)
90849 +{
90850 + void *ret = module_alloc_exec(size);
90851 +
90852 + if (ret) {
90853 + mutex_lock(&module_mutex);
90854 + /* Update module bounds. */
90855 + if ((unsigned long)ret < module_addr_min_rx)
90856 + module_addr_min_rx = (unsigned long)ret;
90857 + if ((unsigned long)ret + size > module_addr_max_rx)
90858 + module_addr_max_rx = (unsigned long)ret + size;
90859 mutex_unlock(&module_mutex);
90860 }
90861 return ret;
90862 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90863 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90864
90865 if (info->index.sym == 0) {
90866 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90867 + /*
90868 + * avoid potentially printing jibberish on attempted load
90869 + * of a module randomized with a different seed
90870 + */
90871 + pr_warn("module has no symbols (stripped?)\n");
90872 +#else
90873 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90874 +#endif
90875 return ERR_PTR(-ENOEXEC);
90876 }
90877
90878 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90879 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90880 {
90881 const char *modmagic = get_modinfo(info, "vermagic");
90882 + const char *license = get_modinfo(info, "license");
90883 int err;
90884
90885 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90886 + if (!license || !license_is_gpl_compatible(license))
90887 + return -ENOEXEC;
90888 +#endif
90889 +
90890 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90891 modmagic = NULL;
90892
90893 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90894 }
90895
90896 /* Set up license info based on the info section */
90897 - set_license(mod, get_modinfo(info, "license"));
90898 + set_license(mod, license);
90899
90900 return 0;
90901 }
90902 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90903 void *ptr;
90904
90905 /* Do the allocs. */
90906 - ptr = module_alloc_update_bounds(mod->core_size);
90907 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90908 /*
90909 * The pointer to this block is stored in the module structure
90910 * which is inside the block. Just mark it as not being a
90911 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90912 if (!ptr)
90913 return -ENOMEM;
90914
90915 - memset(ptr, 0, mod->core_size);
90916 - mod->module_core = ptr;
90917 + memset(ptr, 0, mod->core_size_rw);
90918 + mod->module_core_rw = ptr;
90919
90920 - if (mod->init_size) {
90921 - ptr = module_alloc_update_bounds(mod->init_size);
90922 + if (mod->init_size_rw) {
90923 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90924 /*
90925 * The pointer to this block is stored in the module structure
90926 * which is inside the block. This block doesn't need to be
90927 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90928 */
90929 kmemleak_ignore(ptr);
90930 if (!ptr) {
90931 - module_free(mod, mod->module_core);
90932 + module_free(mod, mod->module_core_rw);
90933 return -ENOMEM;
90934 }
90935 - memset(ptr, 0, mod->init_size);
90936 - mod->module_init = ptr;
90937 + memset(ptr, 0, mod->init_size_rw);
90938 + mod->module_init_rw = ptr;
90939 } else
90940 - mod->module_init = NULL;
90941 + mod->module_init_rw = NULL;
90942 +
90943 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90944 + kmemleak_not_leak(ptr);
90945 + if (!ptr) {
90946 + if (mod->module_init_rw)
90947 + module_free(mod, mod->module_init_rw);
90948 + module_free(mod, mod->module_core_rw);
90949 + return -ENOMEM;
90950 + }
90951 +
90952 + pax_open_kernel();
90953 + memset(ptr, 0, mod->core_size_rx);
90954 + pax_close_kernel();
90955 + mod->module_core_rx = ptr;
90956 +
90957 + if (mod->init_size_rx) {
90958 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90959 + kmemleak_ignore(ptr);
90960 + if (!ptr && mod->init_size_rx) {
90961 + module_free_exec(mod, mod->module_core_rx);
90962 + if (mod->module_init_rw)
90963 + module_free(mod, mod->module_init_rw);
90964 + module_free(mod, mod->module_core_rw);
90965 + return -ENOMEM;
90966 + }
90967 +
90968 + pax_open_kernel();
90969 + memset(ptr, 0, mod->init_size_rx);
90970 + pax_close_kernel();
90971 + mod->module_init_rx = ptr;
90972 + } else
90973 + mod->module_init_rx = NULL;
90974
90975 /* Transfer each section which specifies SHF_ALLOC */
90976 pr_debug("final section addresses:\n");
90977 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90978 if (!(shdr->sh_flags & SHF_ALLOC))
90979 continue;
90980
90981 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90982 - dest = mod->module_init
90983 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90984 - else
90985 - dest = mod->module_core + shdr->sh_entsize;
90986 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90987 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90988 + dest = mod->module_init_rw
90989 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90990 + else
90991 + dest = mod->module_init_rx
90992 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90993 + } else {
90994 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90995 + dest = mod->module_core_rw + shdr->sh_entsize;
90996 + else
90997 + dest = mod->module_core_rx + shdr->sh_entsize;
90998 + }
90999 +
91000 + if (shdr->sh_type != SHT_NOBITS) {
91001 +
91002 +#ifdef CONFIG_PAX_KERNEXEC
91003 +#ifdef CONFIG_X86_64
91004 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91005 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91006 +#endif
91007 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91008 + pax_open_kernel();
91009 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91010 + pax_close_kernel();
91011 + } else
91012 +#endif
91013
91014 - if (shdr->sh_type != SHT_NOBITS)
91015 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91016 + }
91017 /* Update sh_addr to point to copy in image. */
91018 - shdr->sh_addr = (unsigned long)dest;
91019 +
91020 +#ifdef CONFIG_PAX_KERNEXEC
91021 + if (shdr->sh_flags & SHF_EXECINSTR)
91022 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91023 + else
91024 +#endif
91025 +
91026 + shdr->sh_addr = (unsigned long)dest;
91027 pr_debug("\t0x%lx %s\n",
91028 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91029 }
91030 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91031 * Do it before processing of module parameters, so the module
91032 * can provide parameter accessor functions of its own.
91033 */
91034 - if (mod->module_init)
91035 - flush_icache_range((unsigned long)mod->module_init,
91036 - (unsigned long)mod->module_init
91037 - + mod->init_size);
91038 - flush_icache_range((unsigned long)mod->module_core,
91039 - (unsigned long)mod->module_core + mod->core_size);
91040 + if (mod->module_init_rx)
91041 + flush_icache_range((unsigned long)mod->module_init_rx,
91042 + (unsigned long)mod->module_init_rx
91043 + + mod->init_size_rx);
91044 + flush_icache_range((unsigned long)mod->module_core_rx,
91045 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91046
91047 set_fs(old_fs);
91048 }
91049 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91050 static void module_deallocate(struct module *mod, struct load_info *info)
91051 {
91052 percpu_modfree(mod);
91053 - module_free(mod, mod->module_init);
91054 - module_free(mod, mod->module_core);
91055 + module_free_exec(mod, mod->module_init_rx);
91056 + module_free_exec(mod, mod->module_core_rx);
91057 + module_free(mod, mod->module_init_rw);
91058 + module_free(mod, mod->module_core_rw);
91059 }
91060
91061 int __weak module_finalize(const Elf_Ehdr *hdr,
91062 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91063 static int post_relocation(struct module *mod, const struct load_info *info)
91064 {
91065 /* Sort exception table now relocations are done. */
91066 + pax_open_kernel();
91067 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91068 + pax_close_kernel();
91069
91070 /* Copy relocated percpu area over. */
91071 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91072 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91073 mod->strtab = mod->core_strtab;
91074 #endif
91075 unset_module_init_ro_nx(mod);
91076 - module_free(mod, mod->module_init);
91077 - mod->module_init = NULL;
91078 - mod->init_size = 0;
91079 - mod->init_ro_size = 0;
91080 - mod->init_text_size = 0;
91081 + module_free(mod, mod->module_init_rw);
91082 + module_free_exec(mod, mod->module_init_rx);
91083 + mod->module_init_rw = NULL;
91084 + mod->module_init_rx = NULL;
91085 + mod->init_size_rw = 0;
91086 + mod->init_size_rx = 0;
91087 mutex_unlock(&module_mutex);
91088 wake_up_all(&module_wq);
91089
91090 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91091 module_bug_finalize(info->hdr, info->sechdrs, mod);
91092
91093 /* Set RO and NX regions for core */
91094 - set_section_ro_nx(mod->module_core,
91095 - mod->core_text_size,
91096 - mod->core_ro_size,
91097 - mod->core_size);
91098 + set_section_ro_nx(mod->module_core_rx,
91099 + mod->core_size_rx,
91100 + mod->core_size_rx,
91101 + mod->core_size_rx);
91102
91103 /* Set RO and NX regions for init */
91104 - set_section_ro_nx(mod->module_init,
91105 - mod->init_text_size,
91106 - mod->init_ro_size,
91107 - mod->init_size);
91108 + set_section_ro_nx(mod->module_init_rx,
91109 + mod->init_size_rx,
91110 + mod->init_size_rx,
91111 + mod->init_size_rx);
91112
91113 /* Mark state as coming so strong_try_module_get() ignores us,
91114 * but kallsyms etc. can see us. */
91115 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91116 if (err)
91117 goto free_unload;
91118
91119 + /* Now copy in args */
91120 + mod->args = strndup_user(uargs, ~0UL >> 1);
91121 + if (IS_ERR(mod->args)) {
91122 + err = PTR_ERR(mod->args);
91123 + goto free_unload;
91124 + }
91125 +
91126 /* Set up MODINFO_ATTR fields */
91127 setup_modinfo(mod, info);
91128
91129 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91130 + {
91131 + char *p, *p2;
91132 +
91133 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91134 + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
91135 + err = -EPERM;
91136 + goto free_modinfo;
91137 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91138 + p += sizeof("grsec_modharden_normal") - 1;
91139 + p2 = strstr(p, "_");
91140 + if (p2) {
91141 + *p2 = '\0';
91142 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91143 + *p2 = '_';
91144 + }
91145 + err = -EPERM;
91146 + goto free_modinfo;
91147 + }
91148 + }
91149 +#endif
91150 +
91151 /* Fix up syms, so that st_value is a pointer to location. */
91152 err = simplify_symbols(mod, info);
91153 if (err < 0)
91154 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91155
91156 flush_module_icache(mod);
91157
91158 - /* Now copy in args */
91159 - mod->args = strndup_user(uargs, ~0UL >> 1);
91160 - if (IS_ERR(mod->args)) {
91161 - err = PTR_ERR(mod->args);
91162 - goto free_arch_cleanup;
91163 - }
91164 -
91165 dynamic_debug_setup(info->debug, info->num_debug);
91166
91167 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91168 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91169 ddebug_cleanup:
91170 dynamic_debug_remove(info->debug);
91171 synchronize_sched();
91172 - kfree(mod->args);
91173 - free_arch_cleanup:
91174 module_arch_cleanup(mod);
91175 free_modinfo:
91176 free_modinfo(mod);
91177 + kfree(mod->args);
91178 free_unload:
91179 module_unload_free(mod);
91180 unlink_mod:
91181 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91182 unsigned long nextval;
91183
91184 /* At worse, next value is at end of module */
91185 - if (within_module_init(addr, mod))
91186 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91187 + if (within_module_init_rx(addr, mod))
91188 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91189 + else if (within_module_init_rw(addr, mod))
91190 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91191 + else if (within_module_core_rx(addr, mod))
91192 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91193 + else if (within_module_core_rw(addr, mod))
91194 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91195 else
91196 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91197 + return NULL;
91198
91199 /* Scan for closest preceding symbol, and next symbol. (ELF
91200 starts real symbols at 1). */
91201 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91202 return 0;
91203
91204 seq_printf(m, "%s %u",
91205 - mod->name, mod->init_size + mod->core_size);
91206 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91207 print_unload_info(m, mod);
91208
91209 /* Informative for users. */
91210 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91211 mod->state == MODULE_STATE_COMING ? "Loading":
91212 "Live");
91213 /* Used by oprofile and other similar tools. */
91214 - seq_printf(m, " 0x%pK", mod->module_core);
91215 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91216
91217 /* Taints info */
91218 if (mod->taints)
91219 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91220
91221 static int __init proc_modules_init(void)
91222 {
91223 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91224 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91225 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91226 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91227 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91228 +#else
91229 proc_create("modules", 0, NULL, &proc_modules_operations);
91230 +#endif
91231 +#else
91232 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91233 +#endif
91234 return 0;
91235 }
91236 module_init(proc_modules_init);
91237 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91238 {
91239 struct module *mod;
91240
91241 - if (addr < module_addr_min || addr > module_addr_max)
91242 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91243 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91244 return NULL;
91245
91246 list_for_each_entry_rcu(mod, &modules, list) {
91247 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91248 */
91249 struct module *__module_text_address(unsigned long addr)
91250 {
91251 - struct module *mod = __module_address(addr);
91252 + struct module *mod;
91253 +
91254 +#ifdef CONFIG_X86_32
91255 + addr = ktla_ktva(addr);
91256 +#endif
91257 +
91258 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91259 + return NULL;
91260 +
91261 + mod = __module_address(addr);
91262 +
91263 if (mod) {
91264 /* Make sure it's within the text section. */
91265 - if (!within(addr, mod->module_init, mod->init_text_size)
91266 - && !within(addr, mod->module_core, mod->core_text_size))
91267 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91268 mod = NULL;
91269 }
91270 return mod;
91271 diff --git a/kernel/notifier.c b/kernel/notifier.c
91272 index 4803da6..1c5eea6 100644
91273 --- a/kernel/notifier.c
91274 +++ b/kernel/notifier.c
91275 @@ -5,6 +5,7 @@
91276 #include <linux/rcupdate.h>
91277 #include <linux/vmalloc.h>
91278 #include <linux/reboot.h>
91279 +#include <linux/mm.h>
91280
91281 /*
91282 * Notifier list for kernel code which wants to be called
91283 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91284 while ((*nl) != NULL) {
91285 if (n->priority > (*nl)->priority)
91286 break;
91287 - nl = &((*nl)->next);
91288 + nl = (struct notifier_block **)&((*nl)->next);
91289 }
91290 - n->next = *nl;
91291 + pax_open_kernel();
91292 + *(const void **)&n->next = *nl;
91293 rcu_assign_pointer(*nl, n);
91294 + pax_close_kernel();
91295 return 0;
91296 }
91297
91298 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91299 return 0;
91300 if (n->priority > (*nl)->priority)
91301 break;
91302 - nl = &((*nl)->next);
91303 + nl = (struct notifier_block **)&((*nl)->next);
91304 }
91305 - n->next = *nl;
91306 + pax_open_kernel();
91307 + *(const void **)&n->next = *nl;
91308 rcu_assign_pointer(*nl, n);
91309 + pax_close_kernel();
91310 return 0;
91311 }
91312
91313 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91314 {
91315 while ((*nl) != NULL) {
91316 if ((*nl) == n) {
91317 + pax_open_kernel();
91318 rcu_assign_pointer(*nl, n->next);
91319 + pax_close_kernel();
91320 return 0;
91321 }
91322 - nl = &((*nl)->next);
91323 + nl = (struct notifier_block **)&((*nl)->next);
91324 }
91325 return -ENOENT;
91326 }
91327 diff --git a/kernel/padata.c b/kernel/padata.c
91328 index 161402f..598814c 100644
91329 --- a/kernel/padata.c
91330 +++ b/kernel/padata.c
91331 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91332 * seq_nr mod. number of cpus in use.
91333 */
91334
91335 - seq_nr = atomic_inc_return(&pd->seq_nr);
91336 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91337 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91338
91339 return padata_index_to_cpu(pd, cpu_index);
91340 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91341 padata_init_pqueues(pd);
91342 padata_init_squeues(pd);
91343 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91344 - atomic_set(&pd->seq_nr, -1);
91345 + atomic_set_unchecked(&pd->seq_nr, -1);
91346 atomic_set(&pd->reorder_objects, 0);
91347 atomic_set(&pd->refcnt, 0);
91348 pd->pinst = pinst;
91349 diff --git a/kernel/panic.c b/kernel/panic.c
91350 index cf80672..f6771b2 100644
91351 --- a/kernel/panic.c
91352 +++ b/kernel/panic.c
91353 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91354 /*
91355 * Stop ourself in panic -- architecture code may override this
91356 */
91357 -void __weak panic_smp_self_stop(void)
91358 +void __weak __noreturn panic_smp_self_stop(void)
91359 {
91360 while (1)
91361 cpu_relax();
91362 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91363 disable_trace_on_warning();
91364
91365 pr_warn("------------[ cut here ]------------\n");
91366 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91367 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91368 raw_smp_processor_id(), current->pid, file, line, caller);
91369
91370 if (args)
91371 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91372 */
91373 __visible void __stack_chk_fail(void)
91374 {
91375 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91376 + dump_stack();
91377 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91378 __builtin_return_address(0));
91379 }
91380 EXPORT_SYMBOL(__stack_chk_fail);
91381 diff --git a/kernel/pid.c b/kernel/pid.c
91382 index 82430c8..53d7793 100644
91383 --- a/kernel/pid.c
91384 +++ b/kernel/pid.c
91385 @@ -33,6 +33,7 @@
91386 #include <linux/rculist.h>
91387 #include <linux/bootmem.h>
91388 #include <linux/hash.h>
91389 +#include <linux/security.h>
91390 #include <linux/pid_namespace.h>
91391 #include <linux/init_task.h>
91392 #include <linux/syscalls.h>
91393 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91394
91395 int pid_max = PID_MAX_DEFAULT;
91396
91397 -#define RESERVED_PIDS 300
91398 +#define RESERVED_PIDS 500
91399
91400 int pid_max_min = RESERVED_PIDS + 1;
91401 int pid_max_max = PID_MAX_LIMIT;
91402 @@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
91403 */
91404 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91405 {
91406 + struct task_struct *task;
91407 +
91408 rcu_lockdep_assert(rcu_read_lock_held(),
91409 "find_task_by_pid_ns() needs rcu_read_lock()"
91410 " protection");
91411 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91412 +
91413 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91414 +
91415 + if (gr_pid_is_chrooted(task))
91416 + return NULL;
91417 +
91418 + return task;
91419 }
91420
91421 struct task_struct *find_task_by_vpid(pid_t vnr)
91422 @@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91423 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91424 }
91425
91426 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91427 +{
91428 + rcu_lockdep_assert(rcu_read_lock_held(),
91429 + "find_task_by_pid_ns() needs rcu_read_lock()"
91430 + " protection");
91431 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91432 +}
91433 +
91434 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91435 {
91436 struct pid *pid;
91437 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91438 index db95d8e..a0ca23f 100644
91439 --- a/kernel/pid_namespace.c
91440 +++ b/kernel/pid_namespace.c
91441 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91442 void __user *buffer, size_t *lenp, loff_t *ppos)
91443 {
91444 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91445 - struct ctl_table tmp = *table;
91446 + ctl_table_no_const tmp = *table;
91447
91448 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91449 return -EPERM;
91450 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91451 index bbef57f..5f94462 100644
91452 --- a/kernel/power/Kconfig
91453 +++ b/kernel/power/Kconfig
91454 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91455 config HIBERNATION
91456 bool "Hibernation (aka 'suspend to disk')"
91457 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91458 + depends on !GRKERNSEC_KMEM
91459 + depends on !PAX_MEMORY_SANITIZE
91460 select HIBERNATE_CALLBACKS
91461 select LZO_COMPRESS
91462 select LZO_DECOMPRESS
91463 diff --git a/kernel/power/process.c b/kernel/power/process.c
91464 index 5a6ec86..3a8c884 100644
91465 --- a/kernel/power/process.c
91466 +++ b/kernel/power/process.c
91467 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91468 unsigned int elapsed_msecs;
91469 bool wakeup = false;
91470 int sleep_usecs = USEC_PER_MSEC;
91471 + bool timedout = false;
91472
91473 do_gettimeofday(&start);
91474
91475 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91476
91477 while (true) {
91478 todo = 0;
91479 + if (time_after(jiffies, end_time))
91480 + timedout = true;
91481 read_lock(&tasklist_lock);
91482 for_each_process_thread(g, p) {
91483 if (p == current || !freeze_task(p))
91484 continue;
91485
91486 - if (!freezer_should_skip(p))
91487 + if (!freezer_should_skip(p)) {
91488 todo++;
91489 + if (timedout) {
91490 + printk(KERN_ERR "Task refusing to freeze:\n");
91491 + sched_show_task(p);
91492 + }
91493 + }
91494 }
91495 read_unlock(&tasklist_lock);
91496
91497 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91498 todo += wq_busy;
91499 }
91500
91501 - if (!todo || time_after(jiffies, end_time))
91502 + if (!todo || timedout)
91503 break;
91504
91505 if (pm_wakeup_pending()) {
91506 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91507 index ced2b84..ffc4791 100644
91508 --- a/kernel/printk/printk.c
91509 +++ b/kernel/printk/printk.c
91510 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91511 if (from_file && type != SYSLOG_ACTION_OPEN)
91512 return 0;
91513
91514 +#ifdef CONFIG_GRKERNSEC_DMESG
91515 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91516 + return -EPERM;
91517 +#endif
91518 +
91519 if (syslog_action_restricted(type)) {
91520 if (capable(CAP_SYSLOG))
91521 return 0;
91522 diff --git a/kernel/profile.c b/kernel/profile.c
91523 index 54bf5ba..df6e0a2 100644
91524 --- a/kernel/profile.c
91525 +++ b/kernel/profile.c
91526 @@ -37,7 +37,7 @@ struct profile_hit {
91527 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91528 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91529
91530 -static atomic_t *prof_buffer;
91531 +static atomic_unchecked_t *prof_buffer;
91532 static unsigned long prof_len, prof_shift;
91533
91534 int prof_on __read_mostly;
91535 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91536 hits[i].pc = 0;
91537 continue;
91538 }
91539 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91540 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91541 hits[i].hits = hits[i].pc = 0;
91542 }
91543 }
91544 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91545 * Add the current hit(s) and flush the write-queue out
91546 * to the global buffer:
91547 */
91548 - atomic_add(nr_hits, &prof_buffer[pc]);
91549 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91550 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91551 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91552 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91553 hits[i].pc = hits[i].hits = 0;
91554 }
91555 out:
91556 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91557 {
91558 unsigned long pc;
91559 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91560 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91561 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91562 }
91563 #endif /* !CONFIG_SMP */
91564
91565 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91566 return -EFAULT;
91567 buf++; p++; count--; read++;
91568 }
91569 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91570 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91571 if (copy_to_user(buf, (void *)pnt, count))
91572 return -EFAULT;
91573 read += count;
91574 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91575 }
91576 #endif
91577 profile_discard_flip_buffers();
91578 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91579 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91580 return count;
91581 }
91582
91583 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91584 index 54e7522..5b82dd6 100644
91585 --- a/kernel/ptrace.c
91586 +++ b/kernel/ptrace.c
91587 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91588 if (seize)
91589 flags |= PT_SEIZED;
91590 rcu_read_lock();
91591 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91592 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91593 flags |= PT_PTRACE_CAP;
91594 rcu_read_unlock();
91595 task->ptrace = flags;
91596 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91597 break;
91598 return -EIO;
91599 }
91600 - if (copy_to_user(dst, buf, retval))
91601 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91602 return -EFAULT;
91603 copied += retval;
91604 src += retval;
91605 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91606 bool seized = child->ptrace & PT_SEIZED;
91607 int ret = -EIO;
91608 siginfo_t siginfo, *si;
91609 - void __user *datavp = (void __user *) data;
91610 + void __user *datavp = (__force void __user *) data;
91611 unsigned long __user *datalp = datavp;
91612 unsigned long flags;
91613
91614 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91615 goto out;
91616 }
91617
91618 + if (gr_handle_ptrace(child, request)) {
91619 + ret = -EPERM;
91620 + goto out_put_task_struct;
91621 + }
91622 +
91623 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91624 ret = ptrace_attach(child, request, addr, data);
91625 /*
91626 * Some architectures need to do book-keeping after
91627 * a ptrace attach.
91628 */
91629 - if (!ret)
91630 + if (!ret) {
91631 arch_ptrace_attach(child);
91632 + gr_audit_ptrace(child);
91633 + }
91634 goto out_put_task_struct;
91635 }
91636
91637 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91638 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91639 if (copied != sizeof(tmp))
91640 return -EIO;
91641 - return put_user(tmp, (unsigned long __user *)data);
91642 + return put_user(tmp, (__force unsigned long __user *)data);
91643 }
91644
91645 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91646 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91647 }
91648
91649 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91650 - compat_long_t, addr, compat_long_t, data)
91651 + compat_ulong_t, addr, compat_ulong_t, data)
91652 {
91653 struct task_struct *child;
91654 long ret;
91655 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91656 goto out;
91657 }
91658
91659 + if (gr_handle_ptrace(child, request)) {
91660 + ret = -EPERM;
91661 + goto out_put_task_struct;
91662 + }
91663 +
91664 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91665 ret = ptrace_attach(child, request, addr, data);
91666 /*
91667 * Some architectures need to do book-keeping after
91668 * a ptrace attach.
91669 */
91670 - if (!ret)
91671 + if (!ret) {
91672 arch_ptrace_attach(child);
91673 + gr_audit_ptrace(child);
91674 + }
91675 goto out_put_task_struct;
91676 }
91677
91678 diff --git a/kernel/range.c b/kernel/range.c
91679 index 322ea8e..82cfc28 100644
91680 --- a/kernel/range.c
91681 +++ b/kernel/range.c
91682 @@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
91683 {
91684 const struct range *r1 = x1;
91685 const struct range *r2 = x2;
91686 - s64 start1, start2;
91687
91688 - start1 = r1->start;
91689 - start2 = r2->start;
91690 -
91691 - return start1 - start2;
91692 + if (r1->start < r2->start)
91693 + return -1;
91694 + if (r1->start > r2->start)
91695 + return 1;
91696 + return 0;
91697 }
91698
91699 int clean_sort_range(struct range *range, int az)
91700 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91701 index 240fa90..5fa56bd 100644
91702 --- a/kernel/rcu/rcutorture.c
91703 +++ b/kernel/rcu/rcutorture.c
91704 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91705 rcu_torture_count) = { 0 };
91706 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91707 rcu_torture_batch) = { 0 };
91708 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91709 -static atomic_t n_rcu_torture_alloc;
91710 -static atomic_t n_rcu_torture_alloc_fail;
91711 -static atomic_t n_rcu_torture_free;
91712 -static atomic_t n_rcu_torture_mberror;
91713 -static atomic_t n_rcu_torture_error;
91714 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91715 +static atomic_unchecked_t n_rcu_torture_alloc;
91716 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91717 +static atomic_unchecked_t n_rcu_torture_free;
91718 +static atomic_unchecked_t n_rcu_torture_mberror;
91719 +static atomic_unchecked_t n_rcu_torture_error;
91720 static long n_rcu_torture_barrier_error;
91721 static long n_rcu_torture_boost_ktrerror;
91722 static long n_rcu_torture_boost_rterror;
91723 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91724 static long n_rcu_torture_timers;
91725 static long n_barrier_attempts;
91726 static long n_barrier_successes;
91727 -static atomic_long_t n_cbfloods;
91728 +static atomic_long_unchecked_t n_cbfloods;
91729 static struct list_head rcu_torture_removed;
91730
91731 static int rcu_torture_writer_state;
91732 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91733
91734 spin_lock_bh(&rcu_torture_lock);
91735 if (list_empty(&rcu_torture_freelist)) {
91736 - atomic_inc(&n_rcu_torture_alloc_fail);
91737 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91738 spin_unlock_bh(&rcu_torture_lock);
91739 return NULL;
91740 }
91741 - atomic_inc(&n_rcu_torture_alloc);
91742 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91743 p = rcu_torture_freelist.next;
91744 list_del_init(p);
91745 spin_unlock_bh(&rcu_torture_lock);
91746 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91747 static void
91748 rcu_torture_free(struct rcu_torture *p)
91749 {
91750 - atomic_inc(&n_rcu_torture_free);
91751 + atomic_inc_unchecked(&n_rcu_torture_free);
91752 spin_lock_bh(&rcu_torture_lock);
91753 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91754 spin_unlock_bh(&rcu_torture_lock);
91755 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91756 i = rp->rtort_pipe_count;
91757 if (i > RCU_TORTURE_PIPE_LEN)
91758 i = RCU_TORTURE_PIPE_LEN;
91759 - atomic_inc(&rcu_torture_wcount[i]);
91760 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91761 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91762 rp->rtort_mbtest = 0;
91763 return true;
91764 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91765 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91766 do {
91767 schedule_timeout_interruptible(cbflood_inter_holdoff);
91768 - atomic_long_inc(&n_cbfloods);
91769 + atomic_long_inc_unchecked(&n_cbfloods);
91770 WARN_ON(signal_pending(current));
91771 for (i = 0; i < cbflood_n_burst; i++) {
91772 for (j = 0; j < cbflood_n_per_burst; j++) {
91773 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91774 i = old_rp->rtort_pipe_count;
91775 if (i > RCU_TORTURE_PIPE_LEN)
91776 i = RCU_TORTURE_PIPE_LEN;
91777 - atomic_inc(&rcu_torture_wcount[i]);
91778 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91779 old_rp->rtort_pipe_count++;
91780 switch (synctype[torture_random(&rand) % nsynctypes]) {
91781 case RTWS_DEF_FREE:
91782 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91783 return;
91784 }
91785 if (p->rtort_mbtest == 0)
91786 - atomic_inc(&n_rcu_torture_mberror);
91787 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91788 spin_lock(&rand_lock);
91789 cur_ops->read_delay(&rand);
91790 n_rcu_torture_timers++;
91791 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91792 continue;
91793 }
91794 if (p->rtort_mbtest == 0)
91795 - atomic_inc(&n_rcu_torture_mberror);
91796 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91797 cur_ops->read_delay(&rand);
91798 preempt_disable();
91799 pipe_count = p->rtort_pipe_count;
91800 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91801 rcu_torture_current,
91802 rcu_torture_current_version,
91803 list_empty(&rcu_torture_freelist),
91804 - atomic_read(&n_rcu_torture_alloc),
91805 - atomic_read(&n_rcu_torture_alloc_fail),
91806 - atomic_read(&n_rcu_torture_free));
91807 + atomic_read_unchecked(&n_rcu_torture_alloc),
91808 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91809 + atomic_read_unchecked(&n_rcu_torture_free));
91810 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91811 - atomic_read(&n_rcu_torture_mberror),
91812 + atomic_read_unchecked(&n_rcu_torture_mberror),
91813 n_rcu_torture_boost_ktrerror,
91814 n_rcu_torture_boost_rterror);
91815 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91816 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91817 n_barrier_successes,
91818 n_barrier_attempts,
91819 n_rcu_torture_barrier_error);
91820 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91821 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91822
91823 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91824 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91825 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91826 n_rcu_torture_barrier_error != 0 ||
91827 n_rcu_torture_boost_ktrerror != 0 ||
91828 n_rcu_torture_boost_rterror != 0 ||
91829 n_rcu_torture_boost_failure != 0 ||
91830 i > 1) {
91831 pr_cont("%s", "!!! ");
91832 - atomic_inc(&n_rcu_torture_error);
91833 + atomic_inc_unchecked(&n_rcu_torture_error);
91834 WARN_ON_ONCE(1);
91835 }
91836 pr_cont("Reader Pipe: ");
91837 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91838 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91839 pr_cont("Free-Block Circulation: ");
91840 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91841 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91842 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91843 }
91844 pr_cont("\n");
91845
91846 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91847
91848 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91849
91850 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91851 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91852 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91853 else if (torture_onoff_failures())
91854 rcu_torture_print_module_parms(cur_ops,
91855 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91856
91857 rcu_torture_current = NULL;
91858 rcu_torture_current_version = 0;
91859 - atomic_set(&n_rcu_torture_alloc, 0);
91860 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91861 - atomic_set(&n_rcu_torture_free, 0);
91862 - atomic_set(&n_rcu_torture_mberror, 0);
91863 - atomic_set(&n_rcu_torture_error, 0);
91864 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91865 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91866 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91867 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91868 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91869 n_rcu_torture_barrier_error = 0;
91870 n_rcu_torture_boost_ktrerror = 0;
91871 n_rcu_torture_boost_rterror = 0;
91872 n_rcu_torture_boost_failure = 0;
91873 n_rcu_torture_boosts = 0;
91874 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91875 - atomic_set(&rcu_torture_wcount[i], 0);
91876 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91877 for_each_possible_cpu(cpu) {
91878 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91879 per_cpu(rcu_torture_count, cpu)[i] = 0;
91880 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91881 index c0623fc..329c091 100644
91882 --- a/kernel/rcu/tiny.c
91883 +++ b/kernel/rcu/tiny.c
91884 @@ -42,7 +42,7 @@
91885 /* Forward declarations for tiny_plugin.h. */
91886 struct rcu_ctrlblk;
91887 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91888 -static void rcu_process_callbacks(struct softirq_action *unused);
91889 +static void rcu_process_callbacks(void);
91890 static void __call_rcu(struct rcu_head *head,
91891 void (*func)(struct rcu_head *rcu),
91892 struct rcu_ctrlblk *rcp);
91893 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91894 false));
91895 }
91896
91897 -static void rcu_process_callbacks(struct softirq_action *unused)
91898 +static __latent_entropy void rcu_process_callbacks(void)
91899 {
91900 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91901 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91902 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91903 index 858c565..7efd915 100644
91904 --- a/kernel/rcu/tiny_plugin.h
91905 +++ b/kernel/rcu/tiny_plugin.h
91906 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91907 dump_stack();
91908 }
91909 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91910 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91911 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91912 3 * rcu_jiffies_till_stall_check() + 3;
91913 else if (ULONG_CMP_GE(j, js))
91914 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91915 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91916 }
91917
91918 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91919 {
91920 rcp->ticks_this_gp = 0;
91921 rcp->gp_start = jiffies;
91922 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91923 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91924 }
91925
91926 static void check_cpu_stalls(void)
91927 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91928 index 9815447..2cdf92a 100644
91929 --- a/kernel/rcu/tree.c
91930 +++ b/kernel/rcu/tree.c
91931 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91932 */
91933 rdtp = this_cpu_ptr(&rcu_dynticks);
91934 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91935 - atomic_add(2, &rdtp->dynticks); /* QS. */
91936 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91937 smp_mb__after_atomic(); /* Later stuff after QS. */
91938 break;
91939 }
91940 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91941 rcu_prepare_for_idle(smp_processor_id());
91942 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91943 smp_mb__before_atomic(); /* See above. */
91944 - atomic_inc(&rdtp->dynticks);
91945 + atomic_inc_unchecked(&rdtp->dynticks);
91946 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91947 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91948 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91949 rcu_dynticks_task_enter();
91950
91951 /*
91952 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91953 {
91954 rcu_dynticks_task_exit();
91955 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91956 - atomic_inc(&rdtp->dynticks);
91957 + atomic_inc_unchecked(&rdtp->dynticks);
91958 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91959 smp_mb__after_atomic(); /* See above. */
91960 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91961 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91962 rcu_cleanup_after_idle(smp_processor_id());
91963 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91964 if (!user && !is_idle_task(current)) {
91965 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91966 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91967
91968 if (rdtp->dynticks_nmi_nesting == 0 &&
91969 - (atomic_read(&rdtp->dynticks) & 0x1))
91970 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91971 return;
91972 rdtp->dynticks_nmi_nesting++;
91973 smp_mb__before_atomic(); /* Force delay from prior write. */
91974 - atomic_inc(&rdtp->dynticks);
91975 + atomic_inc_unchecked(&rdtp->dynticks);
91976 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91977 smp_mb__after_atomic(); /* See above. */
91978 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91979 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91980 }
91981
91982 /**
91983 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91984 return;
91985 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91986 smp_mb__before_atomic(); /* See above. */
91987 - atomic_inc(&rdtp->dynticks);
91988 + atomic_inc_unchecked(&rdtp->dynticks);
91989 smp_mb__after_atomic(); /* Force delay to next write. */
91990 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91991 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91992 }
91993
91994 /**
91995 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91996 */
91997 bool notrace __rcu_is_watching(void)
91998 {
91999 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92000 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92001 }
92002
92003 /**
92004 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92005 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92006 bool *isidle, unsigned long *maxj)
92007 {
92008 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92009 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92010 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92011 if ((rdp->dynticks_snap & 0x1) == 0) {
92012 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92013 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92014 int *rcrmp;
92015 unsigned int snap;
92016
92017 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92018 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92019 snap = (unsigned int)rdp->dynticks_snap;
92020
92021 /*
92022 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92023 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92024 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92025 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92026 - ACCESS_ONCE(rdp->cond_resched_completed) =
92027 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92028 ACCESS_ONCE(rdp->mynode->completed);
92029 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92030 - ACCESS_ONCE(*rcrmp) =
92031 + ACCESS_ONCE_RW(*rcrmp) =
92032 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92033 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92034 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92035 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92036 rsp->gp_start = j;
92037 smp_wmb(); /* Record start time before stall time. */
92038 j1 = rcu_jiffies_till_stall_check();
92039 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92040 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92041 rsp->jiffies_resched = j + j1 / 2;
92042 }
92043
92044 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92045 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92046 return;
92047 }
92048 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92049 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92050 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92051
92052 /*
92053 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92054
92055 raw_spin_lock_irqsave(&rnp->lock, flags);
92056 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92057 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92058 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92059 3 * rcu_jiffies_till_stall_check() + 3;
92060 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92061
92062 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
92063 struct rcu_state *rsp;
92064
92065 for_each_rcu_flavor(rsp)
92066 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92067 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92068 }
92069
92070 /*
92071 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92072 raw_spin_unlock_irq(&rnp->lock);
92073 return 0;
92074 }
92075 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92076 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92077
92078 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92079 /*
92080 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92081 rdp = this_cpu_ptr(rsp->rda);
92082 rcu_preempt_check_blocked_tasks(rnp);
92083 rnp->qsmask = rnp->qsmaskinit;
92084 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92085 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92086 WARN_ON_ONCE(rnp->completed != rsp->completed);
92087 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92088 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92089 if (rnp == rdp->mynode)
92090 (void)__note_gp_changes(rsp, rnp, rdp);
92091 rcu_preempt_boost_start_gp(rnp);
92092 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92093 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92094 raw_spin_lock_irq(&rnp->lock);
92095 smp_mb__after_unlock_lock();
92096 - ACCESS_ONCE(rsp->gp_flags) =
92097 + ACCESS_ONCE_RW(rsp->gp_flags) =
92098 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
92099 raw_spin_unlock_irq(&rnp->lock);
92100 }
92101 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92102 rcu_for_each_node_breadth_first(rsp, rnp) {
92103 raw_spin_lock_irq(&rnp->lock);
92104 smp_mb__after_unlock_lock();
92105 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92106 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92107 rdp = this_cpu_ptr(rsp->rda);
92108 if (rnp == rdp->mynode)
92109 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92110 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92111 rcu_nocb_gp_set(rnp, nocb);
92112
92113 /* Declare grace period done. */
92114 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92115 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92116 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92117 rsp->fqs_state = RCU_GP_IDLE;
92118 rdp = this_cpu_ptr(rsp->rda);
92119 /* Advance CBs to reduce false positives below. */
92120 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92121 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92122 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92123 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92124 trace_rcu_grace_period(rsp->name,
92125 ACCESS_ONCE(rsp->gpnum),
92126 TPS("newreq"));
92127 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92128 */
92129 return false;
92130 }
92131 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92132 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92133 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92134 TPS("newreq"));
92135
92136 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92137 rsp->qlen += rdp->qlen;
92138 rdp->n_cbs_orphaned += rdp->qlen;
92139 rdp->qlen_lazy = 0;
92140 - ACCESS_ONCE(rdp->qlen) = 0;
92141 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92142 }
92143
92144 /*
92145 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92146 }
92147 smp_mb(); /* List handling before counting for rcu_barrier(). */
92148 rdp->qlen_lazy -= count_lazy;
92149 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92150 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92151 rdp->n_cbs_invoked += count;
92152
92153 /* Reinstate batch limit if we have worked down the excess. */
92154 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92155 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92156 return; /* Someone beat us to it. */
92157 }
92158 - ACCESS_ONCE(rsp->gp_flags) =
92159 + ACCESS_ONCE_RW(rsp->gp_flags) =
92160 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
92161 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92162 rcu_gp_kthread_wake(rsp);
92163 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92164 /*
92165 * Do RCU core processing for the current CPU.
92166 */
92167 -static void rcu_process_callbacks(struct softirq_action *unused)
92168 +static void rcu_process_callbacks(void)
92169 {
92170 struct rcu_state *rsp;
92171
92172 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92173 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92174 if (debug_rcu_head_queue(head)) {
92175 /* Probable double call_rcu(), so leak the callback. */
92176 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92177 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92178 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92179 return;
92180 }
92181 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92182 local_irq_restore(flags);
92183 return;
92184 }
92185 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92186 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92187 if (lazy)
92188 rdp->qlen_lazy++;
92189 else
92190 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
92191 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92192 * course be required on a 64-bit system.
92193 */
92194 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92195 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92196 (ulong)atomic_long_read(&rsp->expedited_done) +
92197 ULONG_MAX / 8)) {
92198 synchronize_sched();
92199 - atomic_long_inc(&rsp->expedited_wrap);
92200 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92201 return;
92202 }
92203
92204 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
92205 * Take a ticket. Note that atomic_inc_return() implies a
92206 * full memory barrier.
92207 */
92208 - snap = atomic_long_inc_return(&rsp->expedited_start);
92209 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92210 firstsnap = snap;
92211 if (!try_get_online_cpus()) {
92212 /* CPU hotplug operation in flight, fall back to normal GP. */
92213 wait_rcu_gp(call_rcu_sched);
92214 - atomic_long_inc(&rsp->expedited_normal);
92215 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92216 return;
92217 }
92218 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92219 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
92220 synchronize_sched_expedited_cpu_stop,
92221 NULL) == -EAGAIN) {
92222 put_online_cpus();
92223 - atomic_long_inc(&rsp->expedited_tryfail);
92224 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92225
92226 /* Check to see if someone else did our work for us. */
92227 s = atomic_long_read(&rsp->expedited_done);
92228 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92229 /* ensure test happens before caller kfree */
92230 smp_mb__before_atomic(); /* ^^^ */
92231 - atomic_long_inc(&rsp->expedited_workdone1);
92232 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92233 return;
92234 }
92235
92236 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
92237 udelay(trycount * num_online_cpus());
92238 } else {
92239 wait_rcu_gp(call_rcu_sched);
92240 - atomic_long_inc(&rsp->expedited_normal);
92241 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92242 return;
92243 }
92244
92245 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
92246 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92247 /* ensure test happens before caller kfree */
92248 smp_mb__before_atomic(); /* ^^^ */
92249 - atomic_long_inc(&rsp->expedited_workdone2);
92250 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92251 return;
92252 }
92253
92254 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
92255 if (!try_get_online_cpus()) {
92256 /* CPU hotplug operation in flight, use normal GP. */
92257 wait_rcu_gp(call_rcu_sched);
92258 - atomic_long_inc(&rsp->expedited_normal);
92259 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92260 return;
92261 }
92262 - snap = atomic_long_read(&rsp->expedited_start);
92263 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92264 smp_mb(); /* ensure read is before try_stop_cpus(). */
92265 }
92266 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92267 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92268
92269 /*
92270 * Everyone up to our most recent fetch is covered by our grace
92271 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92272 * than we did already did their update.
92273 */
92274 do {
92275 - atomic_long_inc(&rsp->expedited_done_tries);
92276 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92277 s = atomic_long_read(&rsp->expedited_done);
92278 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92279 /* ensure test happens before caller kfree */
92280 smp_mb__before_atomic(); /* ^^^ */
92281 - atomic_long_inc(&rsp->expedited_done_lost);
92282 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92283 break;
92284 }
92285 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92286 - atomic_long_inc(&rsp->expedited_done_exit);
92287 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92288
92289 put_online_cpus();
92290 }
92291 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92292 * ACCESS_ONCE() to prevent the compiler from speculating
92293 * the increment to precede the early-exit check.
92294 */
92295 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92296 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92297 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92298 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92299 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92300 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92301
92302 /* Increment ->n_barrier_done to prevent duplicate work. */
92303 smp_mb(); /* Keep increment after above mechanism. */
92304 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92305 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92306 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92307 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92308 smp_mb(); /* Keep increment before caller's subsequent code. */
92309 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92310 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92311 init_callback_list(rdp);
92312 rdp->qlen_lazy = 0;
92313 - ACCESS_ONCE(rdp->qlen) = 0;
92314 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92315 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92316 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92317 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92318 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92319 rdp->cpu = cpu;
92320 rdp->rsp = rsp;
92321 rcu_boot_init_nocb_percpu_data(rdp);
92322 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92323 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92324 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92325 rcu_sysidle_init_percpu_data(rdp->dynticks);
92326 - atomic_set(&rdp->dynticks->dynticks,
92327 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92328 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92329 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92330 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92331
92332 /* Add CPU to rcu_node bitmasks. */
92333 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92334 index bbdc45d..c882ccb 100644
92335 --- a/kernel/rcu/tree.h
92336 +++ b/kernel/rcu/tree.h
92337 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92338 long long dynticks_nesting; /* Track irq/process nesting level. */
92339 /* Process level is worth LLONG_MAX/2. */
92340 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92341 - atomic_t dynticks; /* Even value for idle, else odd. */
92342 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92343 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92344 long long dynticks_idle_nesting;
92345 /* irq/process nesting level from idle. */
92346 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92347 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92348 /* "Idle" excludes userspace execution. */
92349 unsigned long dynticks_idle_jiffies;
92350 /* End of last non-NMI non-idle period. */
92351 @@ -466,17 +466,17 @@ struct rcu_state {
92352 /* _rcu_barrier(). */
92353 /* End of fields guarded by barrier_mutex. */
92354
92355 - atomic_long_t expedited_start; /* Starting ticket. */
92356 - atomic_long_t expedited_done; /* Done ticket. */
92357 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92358 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92359 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92360 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92361 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92362 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92363 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92364 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92365 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92366 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92367 + atomic_long_t expedited_done; /* Done ticket. */
92368 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92369 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92370 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92371 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92372 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92373 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92374 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92375 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92376 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92377
92378 unsigned long jiffies_force_qs; /* Time at which to invoke */
92379 /* force_quiescent_state(). */
92380 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92381 index c1d7f27..a64bf49 100644
92382 --- a/kernel/rcu/tree_plugin.h
92383 +++ b/kernel/rcu/tree_plugin.h
92384 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92385 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92386 {
92387 return !rcu_preempted_readers_exp(rnp) &&
92388 - ACCESS_ONCE(rnp->expmask) == 0;
92389 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92390 }
92391
92392 /*
92393 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92394
92395 /* Clean up and exit. */
92396 smp_mb(); /* ensure expedited GP seen before counter increment. */
92397 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92398 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92399 sync_rcu_preempt_exp_count + 1;
92400 unlock_mb_ret:
92401 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92402 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92403 free_cpumask_var(cm);
92404 }
92405
92406 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92407 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92408 .store = &rcu_cpu_kthread_task,
92409 .thread_should_run = rcu_cpu_kthread_should_run,
92410 .thread_fn = rcu_cpu_kthread,
92411 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92412 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92413 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92414 cpu, ticks_value, ticks_title,
92415 - atomic_read(&rdtp->dynticks) & 0xfff,
92416 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92417 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92418 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92419 fast_no_hz);
92420 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92421 return;
92422 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92423 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92424 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92425 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92426 wake_up(&rdp_leader->nocb_wq);
92427 }
92428 }
92429 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92430
92431 /* Enqueue the callback on the nocb list and update counts. */
92432 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92433 - ACCESS_ONCE(*old_rhpp) = rhp;
92434 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92435 atomic_long_add(rhcount, &rdp->nocb_q_count);
92436 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92437 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92438 @@ -2286,7 +2286,7 @@ wait_again:
92439 continue; /* No CBs here, try next follower. */
92440
92441 /* Move callbacks to wait-for-GP list, which is empty. */
92442 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92443 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92444 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92445 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92446 rdp->nocb_gp_count_lazy =
92447 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92448 list = ACCESS_ONCE(rdp->nocb_follower_head);
92449 BUG_ON(!list);
92450 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92451 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92452 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92453 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92454 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92455 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92456 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92457 list = next;
92458 }
92459 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92460 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92461 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92462 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92463 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92464 rdp->nocb_p_count_lazy - cl;
92465 rdp->n_nocbs_invoked += c;
92466 }
92467 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92468 if (!rcu_nocb_need_deferred_wakeup(rdp))
92469 return;
92470 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92471 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92472 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92473 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92474 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92475 }
92476 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92477 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92478 "rcuo%c/%d", rsp->abbr, cpu);
92479 BUG_ON(IS_ERR(t));
92480 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92481 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92482 }
92483
92484 /*
92485 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92486
92487 /* Record start of fully idle period. */
92488 j = jiffies;
92489 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92490 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92491 smp_mb__before_atomic();
92492 - atomic_inc(&rdtp->dynticks_idle);
92493 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92494 smp_mb__after_atomic();
92495 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92496 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92497 }
92498
92499 /*
92500 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92501
92502 /* Record end of idle period. */
92503 smp_mb__before_atomic();
92504 - atomic_inc(&rdtp->dynticks_idle);
92505 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92506 smp_mb__after_atomic();
92507 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92508 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92509
92510 /*
92511 * If we are the timekeeping CPU, we are permitted to be non-idle
92512 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92513 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92514
92515 /* Pick up current idle and NMI-nesting counter and check. */
92516 - cur = atomic_read(&rdtp->dynticks_idle);
92517 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92518 if (cur & 0x1) {
92519 *isidle = false; /* We are not idle! */
92520 return;
92521 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92522 case RCU_SYSIDLE_NOT:
92523
92524 /* First time all are idle, so note a short idle period. */
92525 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92526 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92527 break;
92528
92529 case RCU_SYSIDLE_SHORT:
92530 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92531 {
92532 smp_mb();
92533 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92534 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92535 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92536 }
92537
92538 /*
92539 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92540 smp_mb(); /* grace period precedes setting inuse. */
92541
92542 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92543 - ACCESS_ONCE(rshp->inuse) = 0;
92544 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92545 }
92546
92547 /*
92548 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92549 static void rcu_dynticks_task_enter(void)
92550 {
92551 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92552 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92553 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92554 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92555 }
92556
92557 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92558 static void rcu_dynticks_task_exit(void)
92559 {
92560 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92561 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92562 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92563 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92564 }
92565 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92566 index 5cdc62e..cc52e88 100644
92567 --- a/kernel/rcu/tree_trace.c
92568 +++ b/kernel/rcu/tree_trace.c
92569 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92570 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92571 rdp->passed_quiesce, rdp->qs_pending);
92572 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92573 - atomic_read(&rdp->dynticks->dynticks),
92574 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92575 rdp->dynticks->dynticks_nesting,
92576 rdp->dynticks->dynticks_nmi_nesting,
92577 rdp->dynticks_fqs);
92578 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92579 struct rcu_state *rsp = (struct rcu_state *)m->private;
92580
92581 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
92582 - atomic_long_read(&rsp->expedited_start),
92583 + atomic_long_read_unchecked(&rsp->expedited_start),
92584 atomic_long_read(&rsp->expedited_done),
92585 - atomic_long_read(&rsp->expedited_wrap),
92586 - atomic_long_read(&rsp->expedited_tryfail),
92587 - atomic_long_read(&rsp->expedited_workdone1),
92588 - atomic_long_read(&rsp->expedited_workdone2),
92589 - atomic_long_read(&rsp->expedited_normal),
92590 - atomic_long_read(&rsp->expedited_stoppedcpus),
92591 - atomic_long_read(&rsp->expedited_done_tries),
92592 - atomic_long_read(&rsp->expedited_done_lost),
92593 - atomic_long_read(&rsp->expedited_done_exit));
92594 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92595 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92596 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92597 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92598 + atomic_long_read_unchecked(&rsp->expedited_normal),
92599 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92600 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92601 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92602 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92603 return 0;
92604 }
92605
92606 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92607 index 3ef8ba5..8c5ebfb6 100644
92608 --- a/kernel/rcu/update.c
92609 +++ b/kernel/rcu/update.c
92610 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92611 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92612 */
92613 if (till_stall_check < 3) {
92614 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92615 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92616 till_stall_check = 3;
92617 } else if (till_stall_check > 300) {
92618 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92619 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92620 till_stall_check = 300;
92621 }
92622 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92623 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92624 !ACCESS_ONCE(t->on_rq) ||
92625 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92626 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92627 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92628 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92629 list_del_init(&t->rcu_tasks_holdout_list);
92630 put_task_struct(t);
92631 return;
92632 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92633 !is_idle_task(t)) {
92634 get_task_struct(t);
92635 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92636 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92637 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92638 list_add(&t->rcu_tasks_holdout_list,
92639 &rcu_tasks_holdouts);
92640 }
92641 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92642 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92643 BUG_ON(IS_ERR(t));
92644 smp_mb(); /* Ensure others see full kthread. */
92645 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92646 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92647 mutex_unlock(&rcu_tasks_kthread_mutex);
92648 }
92649
92650 diff --git a/kernel/resource.c b/kernel/resource.c
92651 index 0bcebff..e7cd5b2 100644
92652 --- a/kernel/resource.c
92653 +++ b/kernel/resource.c
92654 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92655
92656 static int __init ioresources_init(void)
92657 {
92658 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92659 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92660 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92661 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92662 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92663 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92664 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92665 +#endif
92666 +#else
92667 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92668 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92669 +#endif
92670 return 0;
92671 }
92672 __initcall(ioresources_init);
92673 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92674 index 8a2e230..6020954 100644
92675 --- a/kernel/sched/auto_group.c
92676 +++ b/kernel/sched/auto_group.c
92677 @@ -11,7 +11,7 @@
92678
92679 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92680 static struct autogroup autogroup_default;
92681 -static atomic_t autogroup_seq_nr;
92682 +static atomic_unchecked_t autogroup_seq_nr;
92683
92684 void __init autogroup_init(struct task_struct *init_task)
92685 {
92686 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92687
92688 kref_init(&ag->kref);
92689 init_rwsem(&ag->lock);
92690 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92691 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92692 ag->tg = tg;
92693 #ifdef CONFIG_RT_GROUP_SCHED
92694 /*
92695 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92696 index a63f4dc..349bbb0 100644
92697 --- a/kernel/sched/completion.c
92698 +++ b/kernel/sched/completion.c
92699 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92700 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92701 * or number of jiffies left till timeout) if completed.
92702 */
92703 -long __sched
92704 +long __sched __intentional_overflow(-1)
92705 wait_for_completion_interruptible_timeout(struct completion *x,
92706 unsigned long timeout)
92707 {
92708 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92709 *
92710 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92711 */
92712 -int __sched wait_for_completion_killable(struct completion *x)
92713 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92714 {
92715 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92716 if (t == -ERESTARTSYS)
92717 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92718 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92719 * or number of jiffies left till timeout) if completed.
92720 */
92721 -long __sched
92722 +long __sched __intentional_overflow(-1)
92723 wait_for_completion_killable_timeout(struct completion *x,
92724 unsigned long timeout)
92725 {
92726 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92727 index efdca2f..e361dfb 100644
92728 --- a/kernel/sched/core.c
92729 +++ b/kernel/sched/core.c
92730 @@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92731 int sysctl_numa_balancing(struct ctl_table *table, int write,
92732 void __user *buffer, size_t *lenp, loff_t *ppos)
92733 {
92734 - struct ctl_table t;
92735 + ctl_table_no_const t;
92736 int err;
92737 int state = numabalancing_enabled;
92738
92739 @@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92740 next->active_mm = oldmm;
92741 atomic_inc(&oldmm->mm_count);
92742 enter_lazy_tlb(oldmm, next);
92743 - } else
92744 + } else {
92745 switch_mm(oldmm, mm, next);
92746 + populate_stack();
92747 + }
92748
92749 if (!prev->mm) {
92750 prev->active_mm = NULL;
92751 @@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92752 /* convert nice value [19,-20] to rlimit style value [1,40] */
92753 int nice_rlim = nice_to_rlimit(nice);
92754
92755 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92756 +
92757 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92758 capable(CAP_SYS_NICE));
92759 }
92760 @@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92761 nice = task_nice(current) + increment;
92762
92763 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92764 - if (increment < 0 && !can_nice(current, nice))
92765 + if (increment < 0 && (!can_nice(current, nice) ||
92766 + gr_handle_chroot_nice()))
92767 return -EPERM;
92768
92769 retval = security_task_setnice(current, nice);
92770 @@ -3470,6 +3475,7 @@ recheck:
92771 if (policy != p->policy && !rlim_rtprio)
92772 return -EPERM;
92773
92774 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92775 /* can't increase priority */
92776 if (attr->sched_priority > p->rt_priority &&
92777 attr->sched_priority > rlim_rtprio)
92778 @@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92779
92780 if (mm != &init_mm) {
92781 switch_mm(mm, &init_mm, current);
92782 + populate_stack();
92783 finish_arch_post_lock_switch();
92784 }
92785 mmdrop(mm);
92786 @@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92787
92788 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92789
92790 -static struct ctl_table sd_ctl_dir[] = {
92791 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92792 {
92793 .procname = "sched_domain",
92794 .mode = 0555,
92795 @@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92796 {}
92797 };
92798
92799 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92800 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92801 {
92802 - struct ctl_table *entry =
92803 + ctl_table_no_const *entry =
92804 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92805
92806 return entry;
92807 }
92808
92809 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92810 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92811 {
92812 - struct ctl_table *entry;
92813 + ctl_table_no_const *entry;
92814
92815 /*
92816 * In the intermediate directories, both the child directory and
92817 @@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92818 * will always be set. In the lowest directory the names are
92819 * static strings and all have proc handlers.
92820 */
92821 - for (entry = *tablep; entry->mode; entry++) {
92822 - if (entry->child)
92823 - sd_free_ctl_entry(&entry->child);
92824 + for (entry = tablep; entry->mode; entry++) {
92825 + if (entry->child) {
92826 + sd_free_ctl_entry(entry->child);
92827 + pax_open_kernel();
92828 + entry->child = NULL;
92829 + pax_close_kernel();
92830 + }
92831 if (entry->proc_handler == NULL)
92832 kfree(entry->procname);
92833 }
92834
92835 - kfree(*tablep);
92836 - *tablep = NULL;
92837 + kfree(tablep);
92838 }
92839
92840 static int min_load_idx = 0;
92841 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92842
92843 static void
92844 -set_table_entry(struct ctl_table *entry,
92845 +set_table_entry(ctl_table_no_const *entry,
92846 const char *procname, void *data, int maxlen,
92847 umode_t mode, proc_handler *proc_handler,
92848 bool load_idx)
92849 @@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
92850 static struct ctl_table *
92851 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92852 {
92853 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92854 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92855
92856 if (table == NULL)
92857 return NULL;
92858 @@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92859 return table;
92860 }
92861
92862 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92863 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92864 {
92865 - struct ctl_table *entry, *table;
92866 + ctl_table_no_const *entry, *table;
92867 struct sched_domain *sd;
92868 int domain_num = 0, i;
92869 char buf[32];
92870 @@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
92871 static void register_sched_domain_sysctl(void)
92872 {
92873 int i, cpu_num = num_possible_cpus();
92874 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92875 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92876 char buf[32];
92877
92878 WARN_ON(sd_ctl_dir[0].child);
92879 + pax_open_kernel();
92880 sd_ctl_dir[0].child = entry;
92881 + pax_close_kernel();
92882
92883 if (entry == NULL)
92884 return;
92885 @@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
92886 if (sd_sysctl_header)
92887 unregister_sysctl_table(sd_sysctl_header);
92888 sd_sysctl_header = NULL;
92889 - if (sd_ctl_dir[0].child)
92890 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92891 + if (sd_ctl_dir[0].child) {
92892 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92893 + pax_open_kernel();
92894 + sd_ctl_dir[0].child = NULL;
92895 + pax_close_kernel();
92896 + }
92897 }
92898 #else
92899 static void register_sched_domain_sysctl(void)
92900 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92901 index ef2b104..69961f6 100644
92902 --- a/kernel/sched/fair.c
92903 +++ b/kernel/sched/fair.c
92904 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92905
92906 static void reset_ptenuma_scan(struct task_struct *p)
92907 {
92908 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92909 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92910 p->mm->numa_scan_offset = 0;
92911 }
92912
92913 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92914 * run_rebalance_domains is triggered when needed from the scheduler tick.
92915 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92916 */
92917 -static void run_rebalance_domains(struct softirq_action *h)
92918 +static __latent_entropy void run_rebalance_domains(void)
92919 {
92920 struct rq *this_rq = this_rq();
92921 enum cpu_idle_type idle = this_rq->idle_balance ?
92922 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92923 index 2df8ef0..aae070f 100644
92924 --- a/kernel/sched/sched.h
92925 +++ b/kernel/sched/sched.h
92926 @@ -1140,7 +1140,7 @@ struct sched_class {
92927 #ifdef CONFIG_FAIR_GROUP_SCHED
92928 void (*task_move_group) (struct task_struct *p, int on_rq);
92929 #endif
92930 -};
92931 +} __do_const;
92932
92933 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92934 {
92935 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
92936 index 4ef9687..4f44028 100644
92937 --- a/kernel/seccomp.c
92938 +++ b/kernel/seccomp.c
92939 @@ -629,7 +629,9 @@ static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)
92940
92941 switch (action) {
92942 case SECCOMP_RET_ERRNO:
92943 - /* Set the low-order 16-bits as a errno. */
92944 + /* Set low-order bits as an errno, capped at MAX_ERRNO. */
92945 + if (data > MAX_ERRNO)
92946 + data = MAX_ERRNO;
92947 syscall_set_return_value(current, task_pt_regs(current),
92948 -data, 0);
92949 goto skip;
92950 diff --git a/kernel/signal.c b/kernel/signal.c
92951 index 8f0876f..1153a5a 100644
92952 --- a/kernel/signal.c
92953 +++ b/kernel/signal.c
92954 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92955
92956 int print_fatal_signals __read_mostly;
92957
92958 -static void __user *sig_handler(struct task_struct *t, int sig)
92959 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92960 {
92961 return t->sighand->action[sig - 1].sa.sa_handler;
92962 }
92963
92964 -static int sig_handler_ignored(void __user *handler, int sig)
92965 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92966 {
92967 /* Is it explicitly or implicitly ignored? */
92968 return handler == SIG_IGN ||
92969 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92970
92971 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92972 {
92973 - void __user *handler;
92974 + __sighandler_t handler;
92975
92976 handler = sig_handler(t, sig);
92977
92978 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92979 atomic_inc(&user->sigpending);
92980 rcu_read_unlock();
92981
92982 + if (!override_rlimit)
92983 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92984 +
92985 if (override_rlimit ||
92986 atomic_read(&user->sigpending) <=
92987 task_rlimit(t, RLIMIT_SIGPENDING)) {
92988 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92989
92990 int unhandled_signal(struct task_struct *tsk, int sig)
92991 {
92992 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92993 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92994 if (is_global_init(tsk))
92995 return 1;
92996 if (handler != SIG_IGN && handler != SIG_DFL)
92997 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92998 }
92999 }
93000
93001 + /* allow glibc communication via tgkill to other threads in our
93002 + thread group */
93003 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93004 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93005 + && gr_handle_signal(t, sig))
93006 + return -EPERM;
93007 +
93008 return security_task_kill(t, info, sig, 0);
93009 }
93010
93011 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93012 return send_signal(sig, info, p, 1);
93013 }
93014
93015 -static int
93016 +int
93017 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93018 {
93019 return send_signal(sig, info, t, 0);
93020 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93021 unsigned long int flags;
93022 int ret, blocked, ignored;
93023 struct k_sigaction *action;
93024 + int is_unhandled = 0;
93025
93026 spin_lock_irqsave(&t->sighand->siglock, flags);
93027 action = &t->sighand->action[sig-1];
93028 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93029 }
93030 if (action->sa.sa_handler == SIG_DFL)
93031 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93032 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93033 + is_unhandled = 1;
93034 ret = specific_send_sig_info(sig, info, t);
93035 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93036
93037 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93038 + normal operation */
93039 + if (is_unhandled) {
93040 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93041 + gr_handle_crash(t, sig);
93042 + }
93043 +
93044 return ret;
93045 }
93046
93047 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93048 ret = check_kill_permission(sig, info, p);
93049 rcu_read_unlock();
93050
93051 - if (!ret && sig)
93052 + if (!ret && sig) {
93053 ret = do_send_sig_info(sig, info, p, true);
93054 + if (!ret)
93055 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93056 + }
93057
93058 return ret;
93059 }
93060 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93061 int error = -ESRCH;
93062
93063 rcu_read_lock();
93064 - p = find_task_by_vpid(pid);
93065 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93066 + /* allow glibc communication via tgkill to other threads in our
93067 + thread group */
93068 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93069 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93070 + p = find_task_by_vpid_unrestricted(pid);
93071 + else
93072 +#endif
93073 + p = find_task_by_vpid(pid);
93074 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93075 error = check_kill_permission(sig, info, p);
93076 /*
93077 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93078 }
93079 seg = get_fs();
93080 set_fs(KERNEL_DS);
93081 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93082 - (stack_t __force __user *) &uoss,
93083 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93084 + (stack_t __force_user *) &uoss,
93085 compat_user_stack_pointer());
93086 set_fs(seg);
93087 if (ret >= 0 && uoss_ptr) {
93088 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93089 index 60d35ac5..59d289f 100644
93090 --- a/kernel/smpboot.c
93091 +++ b/kernel/smpboot.c
93092 @@ -289,7 +289,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93093 }
93094 smpboot_unpark_thread(plug_thread, cpu);
93095 }
93096 - list_add(&plug_thread->list, &hotplug_threads);
93097 + pax_list_add(&plug_thread->list, &hotplug_threads);
93098 out:
93099 mutex_unlock(&smpboot_threads_lock);
93100 put_online_cpus();
93101 @@ -307,7 +307,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93102 {
93103 get_online_cpus();
93104 mutex_lock(&smpboot_threads_lock);
93105 - list_del(&plug_thread->list);
93106 + pax_list_del(&plug_thread->list);
93107 smpboot_destroy_threads(plug_thread);
93108 mutex_unlock(&smpboot_threads_lock);
93109 put_online_cpus();
93110 diff --git a/kernel/softirq.c b/kernel/softirq.c
93111 index 0699add..d365ad8 100644
93112 --- a/kernel/softirq.c
93113 +++ b/kernel/softirq.c
93114 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93115 EXPORT_SYMBOL(irq_stat);
93116 #endif
93117
93118 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93119 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93120
93121 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93122
93123 @@ -266,7 +266,7 @@ restart:
93124 kstat_incr_softirqs_this_cpu(vec_nr);
93125
93126 trace_softirq_entry(vec_nr);
93127 - h->action(h);
93128 + h->action();
93129 trace_softirq_exit(vec_nr);
93130 if (unlikely(prev_count != preempt_count())) {
93131 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93132 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93133 or_softirq_pending(1UL << nr);
93134 }
93135
93136 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93137 +void __init open_softirq(int nr, void (*action)(void))
93138 {
93139 softirq_vec[nr].action = action;
93140 }
93141 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93142 }
93143 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93144
93145 -static void tasklet_action(struct softirq_action *a)
93146 +static void tasklet_action(void)
93147 {
93148 struct tasklet_struct *list;
93149
93150 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93151 }
93152 }
93153
93154 -static void tasklet_hi_action(struct softirq_action *a)
93155 +static __latent_entropy void tasklet_hi_action(void)
93156 {
93157 struct tasklet_struct *list;
93158
93159 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93160 .notifier_call = cpu_callback
93161 };
93162
93163 -static struct smp_hotplug_thread softirq_threads = {
93164 +static struct smp_hotplug_thread softirq_threads __read_only = {
93165 .store = &ksoftirqd,
93166 .thread_should_run = ksoftirqd_should_run,
93167 .thread_fn = run_ksoftirqd,
93168 diff --git a/kernel/sys.c b/kernel/sys.c
93169 index 1eaa2f0..d80d27c 100644
93170 --- a/kernel/sys.c
93171 +++ b/kernel/sys.c
93172 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93173 error = -EACCES;
93174 goto out;
93175 }
93176 +
93177 + if (gr_handle_chroot_setpriority(p, niceval)) {
93178 + error = -EACCES;
93179 + goto out;
93180 + }
93181 +
93182 no_nice = security_task_setnice(p, niceval);
93183 if (no_nice) {
93184 error = no_nice;
93185 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93186 goto error;
93187 }
93188
93189 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93190 + goto error;
93191 +
93192 + if (!gid_eq(new->gid, old->gid)) {
93193 + /* make sure we generate a learn log for what will
93194 + end up being a role transition after a full-learning
93195 + policy is generated
93196 + CAP_SETGID is required to perform a transition
93197 + we may not log a CAP_SETGID check above, e.g.
93198 + in the case where new rgid = old egid
93199 + */
93200 + gr_learn_cap(current, new, CAP_SETGID);
93201 + }
93202 +
93203 if (rgid != (gid_t) -1 ||
93204 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93205 new->sgid = new->egid;
93206 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93207 old = current_cred();
93208
93209 retval = -EPERM;
93210 +
93211 + if (gr_check_group_change(kgid, kgid, kgid))
93212 + goto error;
93213 +
93214 if (ns_capable(old->user_ns, CAP_SETGID))
93215 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93216 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93217 @@ -405,7 +429,7 @@ error:
93218 /*
93219 * change the user struct in a credentials set to match the new UID
93220 */
93221 -static int set_user(struct cred *new)
93222 +int set_user(struct cred *new)
93223 {
93224 struct user_struct *new_user;
93225
93226 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93227 goto error;
93228 }
93229
93230 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93231 + goto error;
93232 +
93233 if (!uid_eq(new->uid, old->uid)) {
93234 + /* make sure we generate a learn log for what will
93235 + end up being a role transition after a full-learning
93236 + policy is generated
93237 + CAP_SETUID is required to perform a transition
93238 + we may not log a CAP_SETUID check above, e.g.
93239 + in the case where new ruid = old euid
93240 + */
93241 + gr_learn_cap(current, new, CAP_SETUID);
93242 retval = set_user(new);
93243 if (retval < 0)
93244 goto error;
93245 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93246 old = current_cred();
93247
93248 retval = -EPERM;
93249 +
93250 + if (gr_check_crash_uid(kuid))
93251 + goto error;
93252 + if (gr_check_user_change(kuid, kuid, kuid))
93253 + goto error;
93254 +
93255 if (ns_capable(old->user_ns, CAP_SETUID)) {
93256 new->suid = new->uid = kuid;
93257 if (!uid_eq(kuid, old->uid)) {
93258 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93259 goto error;
93260 }
93261
93262 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93263 + goto error;
93264 +
93265 if (ruid != (uid_t) -1) {
93266 new->uid = kruid;
93267 if (!uid_eq(kruid, old->uid)) {
93268 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93269 goto error;
93270 }
93271
93272 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93273 + goto error;
93274 +
93275 if (rgid != (gid_t) -1)
93276 new->gid = krgid;
93277 if (egid != (gid_t) -1)
93278 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93279 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93280 ns_capable(old->user_ns, CAP_SETUID)) {
93281 if (!uid_eq(kuid, old->fsuid)) {
93282 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93283 + goto error;
93284 +
93285 new->fsuid = kuid;
93286 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93287 goto change_okay;
93288 }
93289 }
93290
93291 +error:
93292 abort_creds(new);
93293 return old_fsuid;
93294
93295 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93296 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93297 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93298 ns_capable(old->user_ns, CAP_SETGID)) {
93299 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93300 + goto error;
93301 +
93302 if (!gid_eq(kgid, old->fsgid)) {
93303 new->fsgid = kgid;
93304 goto change_okay;
93305 }
93306 }
93307
93308 +error:
93309 abort_creds(new);
93310 return old_fsgid;
93311
93312 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93313 return -EFAULT;
93314
93315 down_read(&uts_sem);
93316 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93317 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93318 __OLD_UTS_LEN);
93319 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93320 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93321 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93322 __OLD_UTS_LEN);
93323 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93324 - error |= __copy_to_user(&name->release, &utsname()->release,
93325 + error |= __copy_to_user(name->release, &utsname()->release,
93326 __OLD_UTS_LEN);
93327 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93328 - error |= __copy_to_user(&name->version, &utsname()->version,
93329 + error |= __copy_to_user(name->version, &utsname()->version,
93330 __OLD_UTS_LEN);
93331 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93332 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93333 + error |= __copy_to_user(name->machine, &utsname()->machine,
93334 __OLD_UTS_LEN);
93335 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93336 up_read(&uts_sem);
93337 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93338 */
93339 new_rlim->rlim_cur = 1;
93340 }
93341 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93342 + is changed to a lower value. Since tasks can be created by the same
93343 + user in between this limit change and an execve by this task, force
93344 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93345 + */
93346 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93347 + tsk->flags |= PF_NPROC_EXCEEDED;
93348 }
93349 if (!retval) {
93350 if (old_rlim)
93351 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93352 index 15f2511..181b356 100644
93353 --- a/kernel/sysctl.c
93354 +++ b/kernel/sysctl.c
93355 @@ -94,7 +94,6 @@
93356
93357
93358 #if defined(CONFIG_SYSCTL)
93359 -
93360 /* External variables not in a header file. */
93361 extern int max_threads;
93362 extern int suid_dumpable;
93363 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93364
93365 /* Constants used for minimum and maximum */
93366 #ifdef CONFIG_LOCKUP_DETECTOR
93367 -static int sixty = 60;
93368 +static int sixty __read_only = 60;
93369 #endif
93370
93371 -static int __maybe_unused neg_one = -1;
93372 +static int __maybe_unused neg_one __read_only = -1;
93373
93374 -static int zero;
93375 -static int __maybe_unused one = 1;
93376 -static int __maybe_unused two = 2;
93377 -static int __maybe_unused four = 4;
93378 -static unsigned long one_ul = 1;
93379 -static int one_hundred = 100;
93380 +static int zero __read_only = 0;
93381 +static int __maybe_unused one __read_only = 1;
93382 +static int __maybe_unused two __read_only = 2;
93383 +static int __maybe_unused three __read_only = 3;
93384 +static int __maybe_unused four __read_only = 4;
93385 +static unsigned long one_ul __read_only = 1;
93386 +static int one_hundred __read_only = 100;
93387 #ifdef CONFIG_PRINTK
93388 -static int ten_thousand = 10000;
93389 +static int ten_thousand __read_only = 10000;
93390 #endif
93391
93392 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93393 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93394 void __user *buffer, size_t *lenp, loff_t *ppos);
93395 #endif
93396
93397 -#ifdef CONFIG_PRINTK
93398 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93399 void __user *buffer, size_t *lenp, loff_t *ppos);
93400 -#endif
93401
93402 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93403 void __user *buffer, size_t *lenp, loff_t *ppos);
93404 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93405
93406 #endif
93407
93408 +extern struct ctl_table grsecurity_table[];
93409 +
93410 static struct ctl_table kern_table[];
93411 static struct ctl_table vm_table[];
93412 static struct ctl_table fs_table[];
93413 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93414 int sysctl_legacy_va_layout;
93415 #endif
93416
93417 +#ifdef CONFIG_PAX_SOFTMODE
93418 +static struct ctl_table pax_table[] = {
93419 + {
93420 + .procname = "softmode",
93421 + .data = &pax_softmode,
93422 + .maxlen = sizeof(unsigned int),
93423 + .mode = 0600,
93424 + .proc_handler = &proc_dointvec,
93425 + },
93426 +
93427 + { }
93428 +};
93429 +#endif
93430 +
93431 /* The default sysctl tables: */
93432
93433 static struct ctl_table sysctl_base_table[] = {
93434 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93435 #endif
93436
93437 static struct ctl_table kern_table[] = {
93438 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93439 + {
93440 + .procname = "grsecurity",
93441 + .mode = 0500,
93442 + .child = grsecurity_table,
93443 + },
93444 +#endif
93445 +
93446 +#ifdef CONFIG_PAX_SOFTMODE
93447 + {
93448 + .procname = "pax",
93449 + .mode = 0500,
93450 + .child = pax_table,
93451 + },
93452 +#endif
93453 +
93454 {
93455 .procname = "sched_child_runs_first",
93456 .data = &sysctl_sched_child_runs_first,
93457 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93458 .data = &modprobe_path,
93459 .maxlen = KMOD_PATH_LEN,
93460 .mode = 0644,
93461 - .proc_handler = proc_dostring,
93462 + .proc_handler = proc_dostring_modpriv,
93463 },
93464 {
93465 .procname = "modules_disabled",
93466 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93467 .extra1 = &zero,
93468 .extra2 = &one,
93469 },
93470 +#endif
93471 {
93472 .procname = "kptr_restrict",
93473 .data = &kptr_restrict,
93474 .maxlen = sizeof(int),
93475 .mode = 0644,
93476 .proc_handler = proc_dointvec_minmax_sysadmin,
93477 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93478 + .extra1 = &two,
93479 +#else
93480 .extra1 = &zero,
93481 +#endif
93482 .extra2 = &two,
93483 },
93484 -#endif
93485 {
93486 .procname = "ngroups_max",
93487 .data = &ngroups_max,
93488 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93489 */
93490 {
93491 .procname = "perf_event_paranoid",
93492 - .data = &sysctl_perf_event_paranoid,
93493 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93494 + .data = &sysctl_perf_event_legitimately_concerned,
93495 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93496 .mode = 0644,
93497 - .proc_handler = proc_dointvec,
93498 + /* go ahead, be a hero */
93499 + .proc_handler = proc_dointvec_minmax_sysadmin,
93500 + .extra1 = &neg_one,
93501 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93502 + .extra2 = &three,
93503 +#else
93504 + .extra2 = &two,
93505 +#endif
93506 },
93507 {
93508 .procname = "perf_event_mlock_kb",
93509 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93510 .proc_handler = proc_dointvec_minmax,
93511 .extra1 = &zero,
93512 },
93513 + {
93514 + .procname = "heap_stack_gap",
93515 + .data = &sysctl_heap_stack_gap,
93516 + .maxlen = sizeof(sysctl_heap_stack_gap),
93517 + .mode = 0644,
93518 + .proc_handler = proc_doulongvec_minmax,
93519 + },
93520 #else
93521 {
93522 .procname = "nr_trim_pages",
93523 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93524 (char __user *)buffer, lenp, ppos);
93525 }
93526
93527 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93528 + void __user *buffer, size_t *lenp, loff_t *ppos)
93529 +{
93530 + if (write && !capable(CAP_SYS_MODULE))
93531 + return -EPERM;
93532 +
93533 + return _proc_do_string(table->data, table->maxlen, write,
93534 + buffer, lenp, ppos);
93535 +}
93536 +
93537 static size_t proc_skip_spaces(char **buf)
93538 {
93539 size_t ret;
93540 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93541 len = strlen(tmp);
93542 if (len > *size)
93543 len = *size;
93544 + if (len > sizeof(tmp))
93545 + len = sizeof(tmp);
93546 if (copy_to_user(*buf, tmp, len))
93547 return -EFAULT;
93548 *size -= len;
93549 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93550 static int proc_taint(struct ctl_table *table, int write,
93551 void __user *buffer, size_t *lenp, loff_t *ppos)
93552 {
93553 - struct ctl_table t;
93554 + ctl_table_no_const t;
93555 unsigned long tmptaint = get_taint();
93556 int err;
93557
93558 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93559 return err;
93560 }
93561
93562 -#ifdef CONFIG_PRINTK
93563 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93564 void __user *buffer, size_t *lenp, loff_t *ppos)
93565 {
93566 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93567
93568 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93569 }
93570 -#endif
93571
93572 struct do_proc_dointvec_minmax_conv_param {
93573 int *min;
93574 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93575 return -ENOSYS;
93576 }
93577
93578 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93579 + void __user *buffer, size_t *lenp, loff_t *ppos)
93580 +{
93581 + return -ENOSYS;
93582 +}
93583 +
93584 int proc_dointvec(struct ctl_table *table, int write,
93585 void __user *buffer, size_t *lenp, loff_t *ppos)
93586 {
93587 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93588 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93589 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93590 EXPORT_SYMBOL(proc_dostring);
93591 +EXPORT_SYMBOL(proc_dostring_modpriv);
93592 EXPORT_SYMBOL(proc_doulongvec_minmax);
93593 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93594 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93595 index b312fcc7..753d72d 100644
93596 --- a/kernel/taskstats.c
93597 +++ b/kernel/taskstats.c
93598 @@ -28,9 +28,12 @@
93599 #include <linux/fs.h>
93600 #include <linux/file.h>
93601 #include <linux/pid_namespace.h>
93602 +#include <linux/grsecurity.h>
93603 #include <net/genetlink.h>
93604 #include <linux/atomic.h>
93605
93606 +extern int gr_is_taskstats_denied(int pid);
93607 +
93608 /*
93609 * Maximum length of a cpumask that can be specified in
93610 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93611 @@ -576,6 +579,9 @@ err:
93612
93613 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93614 {
93615 + if (gr_is_taskstats_denied(current->pid))
93616 + return -EACCES;
93617 +
93618 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93619 return cmd_attr_register_cpumask(info);
93620 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93621 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93622 index a7077d3..dd48a49 100644
93623 --- a/kernel/time/alarmtimer.c
93624 +++ b/kernel/time/alarmtimer.c
93625 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93626 struct platform_device *pdev;
93627 int error = 0;
93628 int i;
93629 - struct k_clock alarm_clock = {
93630 + static struct k_clock alarm_clock = {
93631 .clock_getres = alarm_clock_getres,
93632 .clock_get = alarm_clock_get,
93633 .timer_create = alarm_timer_create,
93634 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93635 index d8c724c..6b331a4 100644
93636 --- a/kernel/time/hrtimer.c
93637 +++ b/kernel/time/hrtimer.c
93638 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93639 local_irq_restore(flags);
93640 }
93641
93642 -static void run_hrtimer_softirq(struct softirq_action *h)
93643 +static __latent_entropy void run_hrtimer_softirq(void)
93644 {
93645 hrtimer_peek_ahead_timers();
93646 }
93647 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93648 index a16b678..8c5bd9d 100644
93649 --- a/kernel/time/posix-cpu-timers.c
93650 +++ b/kernel/time/posix-cpu-timers.c
93651 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93652
93653 static __init int init_posix_cpu_timers(void)
93654 {
93655 - struct k_clock process = {
93656 + static struct k_clock process = {
93657 .clock_getres = process_cpu_clock_getres,
93658 .clock_get = process_cpu_clock_get,
93659 .timer_create = process_cpu_timer_create,
93660 .nsleep = process_cpu_nsleep,
93661 .nsleep_restart = process_cpu_nsleep_restart,
93662 };
93663 - struct k_clock thread = {
93664 + static struct k_clock thread = {
93665 .clock_getres = thread_cpu_clock_getres,
93666 .clock_get = thread_cpu_clock_get,
93667 .timer_create = thread_cpu_timer_create,
93668 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93669 index 31ea01f..7fc61ef 100644
93670 --- a/kernel/time/posix-timers.c
93671 +++ b/kernel/time/posix-timers.c
93672 @@ -43,6 +43,7 @@
93673 #include <linux/hash.h>
93674 #include <linux/posix-clock.h>
93675 #include <linux/posix-timers.h>
93676 +#include <linux/grsecurity.h>
93677 #include <linux/syscalls.h>
93678 #include <linux/wait.h>
93679 #include <linux/workqueue.h>
93680 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93681 * which we beg off on and pass to do_sys_settimeofday().
93682 */
93683
93684 -static struct k_clock posix_clocks[MAX_CLOCKS];
93685 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93686
93687 /*
93688 * These ones are defined below.
93689 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93690 */
93691 static __init int init_posix_timers(void)
93692 {
93693 - struct k_clock clock_realtime = {
93694 + static struct k_clock clock_realtime = {
93695 .clock_getres = hrtimer_get_res,
93696 .clock_get = posix_clock_realtime_get,
93697 .clock_set = posix_clock_realtime_set,
93698 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93699 .timer_get = common_timer_get,
93700 .timer_del = common_timer_del,
93701 };
93702 - struct k_clock clock_monotonic = {
93703 + static struct k_clock clock_monotonic = {
93704 .clock_getres = hrtimer_get_res,
93705 .clock_get = posix_ktime_get_ts,
93706 .nsleep = common_nsleep,
93707 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93708 .timer_get = common_timer_get,
93709 .timer_del = common_timer_del,
93710 };
93711 - struct k_clock clock_monotonic_raw = {
93712 + static struct k_clock clock_monotonic_raw = {
93713 .clock_getres = hrtimer_get_res,
93714 .clock_get = posix_get_monotonic_raw,
93715 };
93716 - struct k_clock clock_realtime_coarse = {
93717 + static struct k_clock clock_realtime_coarse = {
93718 .clock_getres = posix_get_coarse_res,
93719 .clock_get = posix_get_realtime_coarse,
93720 };
93721 - struct k_clock clock_monotonic_coarse = {
93722 + static struct k_clock clock_monotonic_coarse = {
93723 .clock_getres = posix_get_coarse_res,
93724 .clock_get = posix_get_monotonic_coarse,
93725 };
93726 - struct k_clock clock_tai = {
93727 + static struct k_clock clock_tai = {
93728 .clock_getres = hrtimer_get_res,
93729 .clock_get = posix_get_tai,
93730 .nsleep = common_nsleep,
93731 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93732 .timer_get = common_timer_get,
93733 .timer_del = common_timer_del,
93734 };
93735 - struct k_clock clock_boottime = {
93736 + static struct k_clock clock_boottime = {
93737 .clock_getres = hrtimer_get_res,
93738 .clock_get = posix_get_boottime,
93739 .nsleep = common_nsleep,
93740 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93741 return;
93742 }
93743
93744 - posix_clocks[clock_id] = *new_clock;
93745 + posix_clocks[clock_id] = new_clock;
93746 }
93747 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93748
93749 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93750 return (id & CLOCKFD_MASK) == CLOCKFD ?
93751 &clock_posix_dynamic : &clock_posix_cpu;
93752
93753 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93754 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93755 return NULL;
93756 - return &posix_clocks[id];
93757 + return posix_clocks[id];
93758 }
93759
93760 static int common_timer_create(struct k_itimer *new_timer)
93761 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93762 struct k_clock *kc = clockid_to_kclock(which_clock);
93763 struct k_itimer *new_timer;
93764 int error, new_timer_id;
93765 - sigevent_t event;
93766 + sigevent_t event = { };
93767 int it_id_set = IT_ID_NOT_SET;
93768
93769 if (!kc)
93770 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93771 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93772 return -EFAULT;
93773
93774 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93775 + have their clock_set fptr set to a nosettime dummy function
93776 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93777 + call common_clock_set, which calls do_sys_settimeofday, which
93778 + we hook
93779 + */
93780 +
93781 return kc->clock_set(which_clock, &new_tp);
93782 }
93783
93784 diff --git a/kernel/time/time.c b/kernel/time/time.c
93785 index 22d5d3b..70caeb2 100644
93786 --- a/kernel/time/time.c
93787 +++ b/kernel/time/time.c
93788 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93789 return error;
93790
93791 if (tz) {
93792 + /* we log in do_settimeofday called below, so don't log twice
93793 + */
93794 + if (!tv)
93795 + gr_log_timechange();
93796 +
93797 sys_tz = *tz;
93798 update_vsyscall_tz();
93799 if (firsttime) {
93800 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93801 index ec1791f..6a086cd 100644
93802 --- a/kernel/time/timekeeping.c
93803 +++ b/kernel/time/timekeeping.c
93804 @@ -15,6 +15,7 @@
93805 #include <linux/init.h>
93806 #include <linux/mm.h>
93807 #include <linux/sched.h>
93808 +#include <linux/grsecurity.h>
93809 #include <linux/syscore_ops.h>
93810 #include <linux/clocksource.h>
93811 #include <linux/jiffies.h>
93812 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93813 if (!timespec_valid_strict(tv))
93814 return -EINVAL;
93815
93816 + gr_log_timechange();
93817 +
93818 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93819 write_seqcount_begin(&tk_core.seq);
93820
93821 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93822 index 3260ffd..c93cd5e 100644
93823 --- a/kernel/time/timer.c
93824 +++ b/kernel/time/timer.c
93825 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93826 /*
93827 * This function runs timers and the timer-tq in bottom half context.
93828 */
93829 -static void run_timer_softirq(struct softirq_action *h)
93830 +static __latent_entropy void run_timer_softirq(void)
93831 {
93832 struct tvec_base *base = __this_cpu_read(tvec_bases);
93833
93834 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93835 *
93836 * In all cases the return value is guaranteed to be non-negative.
93837 */
93838 -signed long __sched schedule_timeout(signed long timeout)
93839 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93840 {
93841 struct timer_list timer;
93842 unsigned long expire;
93843 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93844 index 61ed862..3b52c65 100644
93845 --- a/kernel/time/timer_list.c
93846 +++ b/kernel/time/timer_list.c
93847 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93848
93849 static void print_name_offset(struct seq_file *m, void *sym)
93850 {
93851 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93852 + SEQ_printf(m, "<%p>", NULL);
93853 +#else
93854 char symname[KSYM_NAME_LEN];
93855
93856 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93857 SEQ_printf(m, "<%pK>", sym);
93858 else
93859 SEQ_printf(m, "%s", symname);
93860 +#endif
93861 }
93862
93863 static void
93864 @@ -119,7 +123,11 @@ next_one:
93865 static void
93866 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93867 {
93868 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93869 + SEQ_printf(m, " .base: %p\n", NULL);
93870 +#else
93871 SEQ_printf(m, " .base: %pK\n", base);
93872 +#endif
93873 SEQ_printf(m, " .index: %d\n",
93874 base->index);
93875 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93876 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93877 {
93878 struct proc_dir_entry *pe;
93879
93880 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93881 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93882 +#else
93883 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93884 +#endif
93885 if (!pe)
93886 return -ENOMEM;
93887 return 0;
93888 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93889 index 1fb08f2..ca4bb1e 100644
93890 --- a/kernel/time/timer_stats.c
93891 +++ b/kernel/time/timer_stats.c
93892 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93893 static unsigned long nr_entries;
93894 static struct entry entries[MAX_ENTRIES];
93895
93896 -static atomic_t overflow_count;
93897 +static atomic_unchecked_t overflow_count;
93898
93899 /*
93900 * The entries are in a hash-table, for fast lookup:
93901 @@ -140,7 +140,7 @@ static void reset_entries(void)
93902 nr_entries = 0;
93903 memset(entries, 0, sizeof(entries));
93904 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93905 - atomic_set(&overflow_count, 0);
93906 + atomic_set_unchecked(&overflow_count, 0);
93907 }
93908
93909 static struct entry *alloc_entry(void)
93910 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93911 if (likely(entry))
93912 entry->count++;
93913 else
93914 - atomic_inc(&overflow_count);
93915 + atomic_inc_unchecked(&overflow_count);
93916
93917 out_unlock:
93918 raw_spin_unlock_irqrestore(lock, flags);
93919 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93920
93921 static void print_name_offset(struct seq_file *m, unsigned long addr)
93922 {
93923 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93924 + seq_printf(m, "<%p>", NULL);
93925 +#else
93926 char symname[KSYM_NAME_LEN];
93927
93928 if (lookup_symbol_name(addr, symname) < 0)
93929 - seq_printf(m, "<%p>", (void *)addr);
93930 + seq_printf(m, "<%pK>", (void *)addr);
93931 else
93932 seq_printf(m, "%s", symname);
93933 +#endif
93934 }
93935
93936 static int tstats_show(struct seq_file *m, void *v)
93937 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93938
93939 seq_puts(m, "Timer Stats Version: v0.3\n");
93940 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93941 - if (atomic_read(&overflow_count))
93942 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93943 + if (atomic_read_unchecked(&overflow_count))
93944 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93945 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93946
93947 for (i = 0; i < nr_entries; i++) {
93948 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93949 {
93950 struct proc_dir_entry *pe;
93951
93952 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93953 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93954 +#else
93955 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93956 +#endif
93957 if (!pe)
93958 return -ENOMEM;
93959 return 0;
93960 diff --git a/kernel/torture.c b/kernel/torture.c
93961 index dd70993..0bf694b 100644
93962 --- a/kernel/torture.c
93963 +++ b/kernel/torture.c
93964 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93965 mutex_lock(&fullstop_mutex);
93966 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93967 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93968 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93969 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93970 } else {
93971 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93972 }
93973 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93974 if (!torture_must_stop()) {
93975 if (stutter > 1) {
93976 schedule_timeout_interruptible(stutter - 1);
93977 - ACCESS_ONCE(stutter_pause_test) = 2;
93978 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93979 }
93980 schedule_timeout_interruptible(1);
93981 - ACCESS_ONCE(stutter_pause_test) = 1;
93982 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93983 }
93984 if (!torture_must_stop())
93985 schedule_timeout_interruptible(stutter);
93986 - ACCESS_ONCE(stutter_pause_test) = 0;
93987 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93988 torture_shutdown_absorb("torture_stutter");
93989 } while (!torture_must_stop());
93990 torture_kthread_stopping("torture_stutter");
93991 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93992 schedule_timeout_uninterruptible(10);
93993 return true;
93994 }
93995 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93996 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93997 mutex_unlock(&fullstop_mutex);
93998 torture_shutdown_cleanup();
93999 torture_shuffle_cleanup();
94000 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94001 index c1bd4ad..4b861dc 100644
94002 --- a/kernel/trace/blktrace.c
94003 +++ b/kernel/trace/blktrace.c
94004 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94005 struct blk_trace *bt = filp->private_data;
94006 char buf[16];
94007
94008 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94009 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94010
94011 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94012 }
94013 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94014 return 1;
94015
94016 bt = buf->chan->private_data;
94017 - atomic_inc(&bt->dropped);
94018 + atomic_inc_unchecked(&bt->dropped);
94019 return 0;
94020 }
94021
94022 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94023
94024 bt->dir = dir;
94025 bt->dev = dev;
94026 - atomic_set(&bt->dropped, 0);
94027 + atomic_set_unchecked(&bt->dropped, 0);
94028 INIT_LIST_HEAD(&bt->running_list);
94029
94030 ret = -EIO;
94031 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94032 index 124e2c7..762ca29 100644
94033 --- a/kernel/trace/ftrace.c
94034 +++ b/kernel/trace/ftrace.c
94035 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94036 if (unlikely(ftrace_disabled))
94037 return 0;
94038
94039 + ret = ftrace_arch_code_modify_prepare();
94040 + FTRACE_WARN_ON(ret);
94041 + if (ret)
94042 + return 0;
94043 +
94044 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94045 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94046 if (ret) {
94047 ftrace_bug(ret, ip);
94048 - return 0;
94049 }
94050 - return 1;
94051 + return ret ? 0 : 1;
94052 }
94053
94054 /*
94055 @@ -4529,8 +4534,10 @@ static int ftrace_process_locs(struct module *mod,
94056 if (!count)
94057 return 0;
94058
94059 + pax_open_kernel();
94060 sort(start, count, sizeof(*start),
94061 ftrace_cmp_ips, ftrace_swap_ips);
94062 + pax_close_kernel();
94063
94064 start_pg = ftrace_allocate_pages(count);
94065 if (!start_pg)
94066 @@ -5377,7 +5384,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94067
94068 if (t->ret_stack == NULL) {
94069 atomic_set(&t->tracing_graph_pause, 0);
94070 - atomic_set(&t->trace_overrun, 0);
94071 + atomic_set_unchecked(&t->trace_overrun, 0);
94072 t->curr_ret_stack = -1;
94073 /* Make sure the tasks see the -1 first: */
94074 smp_wmb();
94075 @@ -5590,7 +5597,7 @@ static void
94076 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94077 {
94078 atomic_set(&t->tracing_graph_pause, 0);
94079 - atomic_set(&t->trace_overrun, 0);
94080 + atomic_set_unchecked(&t->trace_overrun, 0);
94081 t->ftrace_timestamp = 0;
94082 /* make curr_ret_stack visible before we add the ret_stack */
94083 smp_wmb();
94084 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94085 index a56e07c..d46f0ba 100644
94086 --- a/kernel/trace/ring_buffer.c
94087 +++ b/kernel/trace/ring_buffer.c
94088 @@ -352,9 +352,9 @@ struct buffer_data_page {
94089 */
94090 struct buffer_page {
94091 struct list_head list; /* list of buffer pages */
94092 - local_t write; /* index for next write */
94093 + local_unchecked_t write; /* index for next write */
94094 unsigned read; /* index for next read */
94095 - local_t entries; /* entries on this page */
94096 + local_unchecked_t entries; /* entries on this page */
94097 unsigned long real_end; /* real end of data */
94098 struct buffer_data_page *page; /* Actual data page */
94099 };
94100 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94101 unsigned long last_overrun;
94102 local_t entries_bytes;
94103 local_t entries;
94104 - local_t overrun;
94105 - local_t commit_overrun;
94106 + local_unchecked_t overrun;
94107 + local_unchecked_t commit_overrun;
94108 local_t dropped_events;
94109 local_t committing;
94110 local_t commits;
94111 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94112 *
94113 * We add a counter to the write field to denote this.
94114 */
94115 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94116 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94117 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94118 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94119
94120 /*
94121 * Just make sure we have seen our old_write and synchronize
94122 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94123 * cmpxchg to only update if an interrupt did not already
94124 * do it for us. If the cmpxchg fails, we don't care.
94125 */
94126 - (void)local_cmpxchg(&next_page->write, old_write, val);
94127 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94128 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94129 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94130
94131 /*
94132 * No need to worry about races with clearing out the commit.
94133 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94134
94135 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94136 {
94137 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94138 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94139 }
94140
94141 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94142 {
94143 - return local_read(&bpage->write) & RB_WRITE_MASK;
94144 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94145 }
94146
94147 static int
94148 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94149 * bytes consumed in ring buffer from here.
94150 * Increment overrun to account for the lost events.
94151 */
94152 - local_add(page_entries, &cpu_buffer->overrun);
94153 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94154 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94155 }
94156
94157 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94158 * it is our responsibility to update
94159 * the counters.
94160 */
94161 - local_add(entries, &cpu_buffer->overrun);
94162 + local_add_unchecked(entries, &cpu_buffer->overrun);
94163 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94164
94165 /*
94166 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94167 if (tail == BUF_PAGE_SIZE)
94168 tail_page->real_end = 0;
94169
94170 - local_sub(length, &tail_page->write);
94171 + local_sub_unchecked(length, &tail_page->write);
94172 return;
94173 }
94174
94175 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94176 rb_event_set_padding(event);
94177
94178 /* Set the write back to the previous setting */
94179 - local_sub(length, &tail_page->write);
94180 + local_sub_unchecked(length, &tail_page->write);
94181 return;
94182 }
94183
94184 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94185
94186 /* Set write to end of buffer */
94187 length = (tail + length) - BUF_PAGE_SIZE;
94188 - local_sub(length, &tail_page->write);
94189 + local_sub_unchecked(length, &tail_page->write);
94190 }
94191
94192 /*
94193 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94194 * about it.
94195 */
94196 if (unlikely(next_page == commit_page)) {
94197 - local_inc(&cpu_buffer->commit_overrun);
94198 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94199 goto out_reset;
94200 }
94201
94202 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94203 cpu_buffer->tail_page) &&
94204 (cpu_buffer->commit_page ==
94205 cpu_buffer->reader_page))) {
94206 - local_inc(&cpu_buffer->commit_overrun);
94207 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94208 goto out_reset;
94209 }
94210 }
94211 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94212 length += RB_LEN_TIME_EXTEND;
94213
94214 tail_page = cpu_buffer->tail_page;
94215 - write = local_add_return(length, &tail_page->write);
94216 + write = local_add_return_unchecked(length, &tail_page->write);
94217
94218 /* set write to only the index of the write */
94219 write &= RB_WRITE_MASK;
94220 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94221 kmemcheck_annotate_bitfield(event, bitfield);
94222 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94223
94224 - local_inc(&tail_page->entries);
94225 + local_inc_unchecked(&tail_page->entries);
94226
94227 /*
94228 * If this is the first commit on the page, then update
94229 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94230
94231 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94232 unsigned long write_mask =
94233 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94234 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94235 unsigned long event_length = rb_event_length(event);
94236 /*
94237 * This is on the tail page. It is possible that
94238 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94239 */
94240 old_index += write_mask;
94241 new_index += write_mask;
94242 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94243 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94244 if (index == old_index) {
94245 /* update counters */
94246 local_sub(event_length, &cpu_buffer->entries_bytes);
94247 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94248
94249 /* Do the likely case first */
94250 if (likely(bpage->page == (void *)addr)) {
94251 - local_dec(&bpage->entries);
94252 + local_dec_unchecked(&bpage->entries);
94253 return;
94254 }
94255
94256 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94257 start = bpage;
94258 do {
94259 if (bpage->page == (void *)addr) {
94260 - local_dec(&bpage->entries);
94261 + local_dec_unchecked(&bpage->entries);
94262 return;
94263 }
94264 rb_inc_page(cpu_buffer, &bpage);
94265 @@ -3173,7 +3173,7 @@ static inline unsigned long
94266 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94267 {
94268 return local_read(&cpu_buffer->entries) -
94269 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94270 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94271 }
94272
94273 /**
94274 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94275 return 0;
94276
94277 cpu_buffer = buffer->buffers[cpu];
94278 - ret = local_read(&cpu_buffer->overrun);
94279 + ret = local_read_unchecked(&cpu_buffer->overrun);
94280
94281 return ret;
94282 }
94283 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94284 return 0;
94285
94286 cpu_buffer = buffer->buffers[cpu];
94287 - ret = local_read(&cpu_buffer->commit_overrun);
94288 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94289
94290 return ret;
94291 }
94292 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94293 /* if you care about this being correct, lock the buffer */
94294 for_each_buffer_cpu(buffer, cpu) {
94295 cpu_buffer = buffer->buffers[cpu];
94296 - overruns += local_read(&cpu_buffer->overrun);
94297 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94298 }
94299
94300 return overruns;
94301 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94302 /*
94303 * Reset the reader page to size zero.
94304 */
94305 - local_set(&cpu_buffer->reader_page->write, 0);
94306 - local_set(&cpu_buffer->reader_page->entries, 0);
94307 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94308 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94309 local_set(&cpu_buffer->reader_page->page->commit, 0);
94310 cpu_buffer->reader_page->real_end = 0;
94311
94312 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94313 * want to compare with the last_overrun.
94314 */
94315 smp_mb();
94316 - overwrite = local_read(&(cpu_buffer->overrun));
94317 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94318
94319 /*
94320 * Here's the tricky part.
94321 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94322
94323 cpu_buffer->head_page
94324 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94325 - local_set(&cpu_buffer->head_page->write, 0);
94326 - local_set(&cpu_buffer->head_page->entries, 0);
94327 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94328 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94329 local_set(&cpu_buffer->head_page->page->commit, 0);
94330
94331 cpu_buffer->head_page->read = 0;
94332 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94333
94334 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94335 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94336 - local_set(&cpu_buffer->reader_page->write, 0);
94337 - local_set(&cpu_buffer->reader_page->entries, 0);
94338 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94339 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94340 local_set(&cpu_buffer->reader_page->page->commit, 0);
94341 cpu_buffer->reader_page->read = 0;
94342
94343 local_set(&cpu_buffer->entries_bytes, 0);
94344 - local_set(&cpu_buffer->overrun, 0);
94345 - local_set(&cpu_buffer->commit_overrun, 0);
94346 + local_set_unchecked(&cpu_buffer->overrun, 0);
94347 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94348 local_set(&cpu_buffer->dropped_events, 0);
94349 local_set(&cpu_buffer->entries, 0);
94350 local_set(&cpu_buffer->committing, 0);
94351 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94352 rb_init_page(bpage);
94353 bpage = reader->page;
94354 reader->page = *data_page;
94355 - local_set(&reader->write, 0);
94356 - local_set(&reader->entries, 0);
94357 + local_set_unchecked(&reader->write, 0);
94358 + local_set_unchecked(&reader->entries, 0);
94359 reader->read = 0;
94360 *data_page = bpage;
94361
94362 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94363 index 426962b..e8e2d9a 100644
94364 --- a/kernel/trace/trace.c
94365 +++ b/kernel/trace/trace.c
94366 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94367 return 0;
94368 }
94369
94370 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94371 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94372 {
94373 /* do nothing if flag is already set */
94374 if (!!(trace_flags & mask) == !!enabled)
94375 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94376 index 385391f..8d2250f 100644
94377 --- a/kernel/trace/trace.h
94378 +++ b/kernel/trace/trace.h
94379 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94380 void trace_printk_init_buffers(void);
94381 void trace_printk_start_comm(void);
94382 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94383 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94384 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94385
94386 /*
94387 * Normal trace_printk() and friends allocates special buffers
94388 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94389 index 57b67b1..66082a9 100644
94390 --- a/kernel/trace/trace_clock.c
94391 +++ b/kernel/trace/trace_clock.c
94392 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94393 return now;
94394 }
94395
94396 -static atomic64_t trace_counter;
94397 +static atomic64_unchecked_t trace_counter;
94398
94399 /*
94400 * trace_clock_counter(): simply an atomic counter.
94401 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94402 */
94403 u64 notrace trace_clock_counter(void)
94404 {
94405 - return atomic64_add_return(1, &trace_counter);
94406 + return atomic64_inc_return_unchecked(&trace_counter);
94407 }
94408 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94409 index 1b0df1e..4ebb965 100644
94410 --- a/kernel/trace/trace_events.c
94411 +++ b/kernel/trace/trace_events.c
94412 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94413 return 0;
94414 }
94415
94416 -struct ftrace_module_file_ops;
94417 static void __add_event_to_tracers(struct ftrace_event_call *call);
94418
94419 /* Add an additional event_call dynamically */
94420 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94421 index f0a0c98..3692dc8 100644
94422 --- a/kernel/trace/trace_functions_graph.c
94423 +++ b/kernel/trace/trace_functions_graph.c
94424 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94425
94426 /* The return trace stack is full */
94427 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94428 - atomic_inc(&current->trace_overrun);
94429 + atomic_inc_unchecked(&current->trace_overrun);
94430 return -EBUSY;
94431 }
94432
94433 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94434 *ret = current->ret_stack[index].ret;
94435 trace->func = current->ret_stack[index].func;
94436 trace->calltime = current->ret_stack[index].calltime;
94437 - trace->overrun = atomic_read(&current->trace_overrun);
94438 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94439 trace->depth = index;
94440 }
94441
94442 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94443 index 0abd9b8..6a663a2 100644
94444 --- a/kernel/trace/trace_mmiotrace.c
94445 +++ b/kernel/trace/trace_mmiotrace.c
94446 @@ -24,7 +24,7 @@ struct header_iter {
94447 static struct trace_array *mmio_trace_array;
94448 static bool overrun_detected;
94449 static unsigned long prev_overruns;
94450 -static atomic_t dropped_count;
94451 +static atomic_unchecked_t dropped_count;
94452
94453 static void mmio_reset_data(struct trace_array *tr)
94454 {
94455 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94456
94457 static unsigned long count_overruns(struct trace_iterator *iter)
94458 {
94459 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94460 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94461 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94462
94463 if (over > prev_overruns)
94464 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94465 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94466 sizeof(*entry), 0, pc);
94467 if (!event) {
94468 - atomic_inc(&dropped_count);
94469 + atomic_inc_unchecked(&dropped_count);
94470 return;
94471 }
94472 entry = ring_buffer_event_data(event);
94473 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94474 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94475 sizeof(*entry), 0, pc);
94476 if (!event) {
94477 - atomic_inc(&dropped_count);
94478 + atomic_inc_unchecked(&dropped_count);
94479 return;
94480 }
94481 entry = ring_buffer_event_data(event);
94482 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94483 index c6977d5..d243785 100644
94484 --- a/kernel/trace/trace_output.c
94485 +++ b/kernel/trace/trace_output.c
94486 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94487 goto out;
94488 }
94489
94490 + pax_open_kernel();
94491 if (event->funcs->trace == NULL)
94492 - event->funcs->trace = trace_nop_print;
94493 + *(void **)&event->funcs->trace = trace_nop_print;
94494 if (event->funcs->raw == NULL)
94495 - event->funcs->raw = trace_nop_print;
94496 + *(void **)&event->funcs->raw = trace_nop_print;
94497 if (event->funcs->hex == NULL)
94498 - event->funcs->hex = trace_nop_print;
94499 + *(void **)&event->funcs->hex = trace_nop_print;
94500 if (event->funcs->binary == NULL)
94501 - event->funcs->binary = trace_nop_print;
94502 + *(void **)&event->funcs->binary = trace_nop_print;
94503 + pax_close_kernel();
94504
94505 key = event->type & (EVENT_HASHSIZE - 1);
94506
94507 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94508 index 1f24ed9..10407ec 100644
94509 --- a/kernel/trace/trace_seq.c
94510 +++ b/kernel/trace/trace_seq.c
94511 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94512
94513 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94514 if (!IS_ERR(p)) {
94515 - p = mangle_path(s->buffer + s->len, p, "\n");
94516 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94517 if (p) {
94518 s->len = p - s->buffer;
94519 return 1;
94520 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94521 index 16eddb3..758b308 100644
94522 --- a/kernel/trace/trace_stack.c
94523 +++ b/kernel/trace/trace_stack.c
94524 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94525 return;
94526
94527 /* we do not handle interrupt stacks yet */
94528 - if (!object_is_on_stack(stack))
94529 + if (!object_starts_on_stack(stack))
94530 return;
94531
94532 local_irq_save(flags);
94533 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94534 index 29228c4..301bc8c 100644
94535 --- a/kernel/trace/trace_syscalls.c
94536 +++ b/kernel/trace/trace_syscalls.c
94537 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94538 int num;
94539
94540 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94541 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94542 + return -EINVAL;
94543
94544 mutex_lock(&syscall_trace_lock);
94545 if (!sys_perf_refcount_enter)
94546 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94547 int num;
94548
94549 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94550 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94551 + return;
94552
94553 mutex_lock(&syscall_trace_lock);
94554 sys_perf_refcount_enter--;
94555 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94556 int num;
94557
94558 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94559 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94560 + return -EINVAL;
94561
94562 mutex_lock(&syscall_trace_lock);
94563 if (!sys_perf_refcount_exit)
94564 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94565 int num;
94566
94567 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94568 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94569 + return;
94570
94571 mutex_lock(&syscall_trace_lock);
94572 sys_perf_refcount_exit--;
94573 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94574 index a2e37c5..4fa859b 100644
94575 --- a/kernel/user_namespace.c
94576 +++ b/kernel/user_namespace.c
94577 @@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
94578 !kgid_has_mapping(parent_ns, group))
94579 return -EPERM;
94580
94581 +#ifdef CONFIG_GRKERNSEC
94582 + /*
94583 + * This doesn't really inspire confidence:
94584 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94585 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94586 + * Increases kernel attack surface in areas developers
94587 + * previously cared little about ("low importance due
94588 + * to requiring "root" capability")
94589 + * To be removed when this code receives *proper* review
94590 + */
94591 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94592 + !capable(CAP_SETGID))
94593 + return -EPERM;
94594 +#endif
94595 +
94596 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94597 if (!ns)
94598 return -ENOMEM;
94599 @@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94600 if (atomic_read(&current->mm->mm_users) > 1)
94601 return -EINVAL;
94602
94603 - if (current->fs->users != 1)
94604 + if (atomic_read(&current->fs->users) != 1)
94605 return -EINVAL;
94606
94607 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94608 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94609 index c8eac43..4b5f08f 100644
94610 --- a/kernel/utsname_sysctl.c
94611 +++ b/kernel/utsname_sysctl.c
94612 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94613 static int proc_do_uts_string(struct ctl_table *table, int write,
94614 void __user *buffer, size_t *lenp, loff_t *ppos)
94615 {
94616 - struct ctl_table uts_table;
94617 + ctl_table_no_const uts_table;
94618 int r;
94619 memcpy(&uts_table, table, sizeof(uts_table));
94620 uts_table.data = get_uts(table, write);
94621 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94622 index 70bf118..4be3c37 100644
94623 --- a/kernel/watchdog.c
94624 +++ b/kernel/watchdog.c
94625 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94626 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94627 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94628
94629 -static struct smp_hotplug_thread watchdog_threads = {
94630 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94631 .store = &softlockup_watchdog,
94632 .thread_should_run = watchdog_should_run,
94633 .thread_fn = watchdog,
94634 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94635 index 66940a5..a44fed0 100644
94636 --- a/kernel/workqueue.c
94637 +++ b/kernel/workqueue.c
94638 @@ -4499,7 +4499,7 @@ static void rebind_workers(struct worker_pool *pool)
94639 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94640 worker_flags |= WORKER_REBOUND;
94641 worker_flags &= ~WORKER_UNBOUND;
94642 - ACCESS_ONCE(worker->flags) = worker_flags;
94643 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94644 }
94645
94646 spin_unlock_irq(&pool->lock);
94647 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94648 index 4e35a5d..8a1f3f0 100644
94649 --- a/lib/Kconfig.debug
94650 +++ b/lib/Kconfig.debug
94651 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94652
94653 config DEBUG_WW_MUTEX_SLOWPATH
94654 bool "Wait/wound mutex debugging: Slowpath testing"
94655 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94656 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94657 select DEBUG_LOCK_ALLOC
94658 select DEBUG_SPINLOCK
94659 select DEBUG_MUTEXES
94660 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94661
94662 config DEBUG_LOCK_ALLOC
94663 bool "Lock debugging: detect incorrect freeing of live locks"
94664 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94665 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94666 select DEBUG_SPINLOCK
94667 select DEBUG_MUTEXES
94668 select LOCKDEP
94669 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94670
94671 config PROVE_LOCKING
94672 bool "Lock debugging: prove locking correctness"
94673 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94674 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94675 select LOCKDEP
94676 select DEBUG_SPINLOCK
94677 select DEBUG_MUTEXES
94678 @@ -976,7 +976,7 @@ config LOCKDEP
94679
94680 config LOCK_STAT
94681 bool "Lock usage statistics"
94682 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94683 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94684 select LOCKDEP
94685 select DEBUG_SPINLOCK
94686 select DEBUG_MUTEXES
94687 @@ -1449,6 +1449,7 @@ config LATENCYTOP
94688 depends on DEBUG_KERNEL
94689 depends on STACKTRACE_SUPPORT
94690 depends on PROC_FS
94691 + depends on !GRKERNSEC_HIDESYM
94692 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94693 select KALLSYMS
94694 select KALLSYMS_ALL
94695 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94696 config DEBUG_STRICT_USER_COPY_CHECKS
94697 bool "Strict user copy size checks"
94698 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94699 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94700 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94701 help
94702 Enabling this option turns a certain set of sanity checks for user
94703 copy operations into compile time failures.
94704 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94705
94706 config PROVIDE_OHCI1394_DMA_INIT
94707 bool "Remote debugging over FireWire early on boot"
94708 - depends on PCI && X86
94709 + depends on PCI && X86 && !GRKERNSEC
94710 help
94711 If you want to debug problems which hang or crash the kernel early
94712 on boot and the crashing machine has a FireWire port, you can use
94713 diff --git a/lib/Makefile b/lib/Makefile
94714 index 0211d2b..93f5cc3 100644
94715 --- a/lib/Makefile
94716 +++ b/lib/Makefile
94717 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94718 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94719 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94720 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94721 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94722 +obj-y += list_debug.o
94723 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94724
94725 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94726 diff --git a/lib/average.c b/lib/average.c
94727 index 114d1be..ab0350c 100644
94728 --- a/lib/average.c
94729 +++ b/lib/average.c
94730 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94731 {
94732 unsigned long internal = ACCESS_ONCE(avg->internal);
94733
94734 - ACCESS_ONCE(avg->internal) = internal ?
94735 + ACCESS_ONCE_RW(avg->internal) = internal ?
94736 (((internal << avg->weight) - internal) +
94737 (val << avg->factor)) >> avg->weight :
94738 (val << avg->factor);
94739 diff --git a/lib/bitmap.c b/lib/bitmap.c
94740 index b499ab6..fbdb76c 100644
94741 --- a/lib/bitmap.c
94742 +++ b/lib/bitmap.c
94743 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94744 {
94745 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94746 u32 chunk;
94747 - const char __user __force *ubuf = (const char __user __force *)buf;
94748 + const char __user *ubuf = (const char __force_user *)buf;
94749
94750 bitmap_zero(maskp, nmaskbits);
94751
94752 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94753 {
94754 if (!access_ok(VERIFY_READ, ubuf, ulen))
94755 return -EFAULT;
94756 - return __bitmap_parse((const char __force *)ubuf,
94757 + return __bitmap_parse((const char __force_kernel *)ubuf,
94758 ulen, 1, maskp, nmaskbits);
94759
94760 }
94761 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94762 {
94763 unsigned a, b;
94764 int c, old_c, totaldigits;
94765 - const char __user __force *ubuf = (const char __user __force *)buf;
94766 + const char __user *ubuf = (const char __force_user *)buf;
94767 int exp_digit, in_range;
94768
94769 totaldigits = c = 0;
94770 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94771 {
94772 if (!access_ok(VERIFY_READ, ubuf, ulen))
94773 return -EFAULT;
94774 - return __bitmap_parselist((const char __force *)ubuf,
94775 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94776 ulen, 1, maskp, nmaskbits);
94777 }
94778 EXPORT_SYMBOL(bitmap_parselist_user);
94779 diff --git a/lib/bug.c b/lib/bug.c
94780 index d1d7c78..b354235 100644
94781 --- a/lib/bug.c
94782 +++ b/lib/bug.c
94783 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94784 return BUG_TRAP_TYPE_NONE;
94785
94786 bug = find_bug(bugaddr);
94787 + if (!bug)
94788 + return BUG_TRAP_TYPE_NONE;
94789
94790 file = NULL;
94791 line = 0;
94792 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94793 index 547f7f9..a6d4ba0 100644
94794 --- a/lib/debugobjects.c
94795 +++ b/lib/debugobjects.c
94796 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94797 if (limit > 4)
94798 return;
94799
94800 - is_on_stack = object_is_on_stack(addr);
94801 + is_on_stack = object_starts_on_stack(addr);
94802 if (is_on_stack == onstack)
94803 return;
94804
94805 diff --git a/lib/div64.c b/lib/div64.c
94806 index 4382ad7..08aa558 100644
94807 --- a/lib/div64.c
94808 +++ b/lib/div64.c
94809 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94810 EXPORT_SYMBOL(__div64_32);
94811
94812 #ifndef div_s64_rem
94813 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94814 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94815 {
94816 u64 quotient;
94817
94818 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94819 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94820 */
94821 #ifndef div64_u64
94822 -u64 div64_u64(u64 dividend, u64 divisor)
94823 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94824 {
94825 u32 high = divisor >> 32;
94826 u64 quot;
94827 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94828 index add80cc..0d27550 100644
94829 --- a/lib/dma-debug.c
94830 +++ b/lib/dma-debug.c
94831 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94832
94833 void dma_debug_add_bus(struct bus_type *bus)
94834 {
94835 - struct notifier_block *nb;
94836 + notifier_block_no_const *nb;
94837
94838 if (global_disable)
94839 return;
94840 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94841
94842 static void check_for_stack(struct device *dev, void *addr)
94843 {
94844 - if (object_is_on_stack(addr))
94845 + if (object_starts_on_stack(addr))
94846 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94847 "stack [addr=%p]\n", addr);
94848 }
94849 diff --git a/lib/hash.c b/lib/hash.c
94850 index fea973f..386626f 100644
94851 --- a/lib/hash.c
94852 +++ b/lib/hash.c
94853 @@ -14,7 +14,7 @@
94854 #include <linux/hash.h>
94855 #include <linux/cache.h>
94856
94857 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94858 +static struct fast_hash_ops arch_hash_ops __read_only = {
94859 .hash = jhash,
94860 .hash2 = jhash2,
94861 };
94862 diff --git a/lib/inflate.c b/lib/inflate.c
94863 index 013a761..c28f3fc 100644
94864 --- a/lib/inflate.c
94865 +++ b/lib/inflate.c
94866 @@ -269,7 +269,7 @@ static void free(void *where)
94867 malloc_ptr = free_mem_ptr;
94868 }
94869 #else
94870 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94871 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94872 #define free(a) kfree(a)
94873 #endif
94874
94875 diff --git a/lib/ioremap.c b/lib/ioremap.c
94876 index 0c9216c..863bd89 100644
94877 --- a/lib/ioremap.c
94878 +++ b/lib/ioremap.c
94879 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94880 unsigned long next;
94881
94882 phys_addr -= addr;
94883 - pmd = pmd_alloc(&init_mm, pud, addr);
94884 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94885 if (!pmd)
94886 return -ENOMEM;
94887 do {
94888 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94889 unsigned long next;
94890
94891 phys_addr -= addr;
94892 - pud = pud_alloc(&init_mm, pgd, addr);
94893 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94894 if (!pud)
94895 return -ENOMEM;
94896 do {
94897 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94898 index bd2bea9..6b3c95e 100644
94899 --- a/lib/is_single_threaded.c
94900 +++ b/lib/is_single_threaded.c
94901 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94902 struct task_struct *p, *t;
94903 bool ret;
94904
94905 + if (!mm)
94906 + return true;
94907 +
94908 if (atomic_read(&task->signal->live) != 1)
94909 return false;
94910
94911 diff --git a/lib/kobject.c b/lib/kobject.c
94912 index 58751bb..93a1853 100644
94913 --- a/lib/kobject.c
94914 +++ b/lib/kobject.c
94915 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94916
94917
94918 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94919 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94920 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94921
94922 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94923 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94924 {
94925 enum kobj_ns_type type = ops->type;
94926 int error;
94927 diff --git a/lib/list_debug.c b/lib/list_debug.c
94928 index c24c2f7..f0296f4 100644
94929 --- a/lib/list_debug.c
94930 +++ b/lib/list_debug.c
94931 @@ -11,7 +11,9 @@
94932 #include <linux/bug.h>
94933 #include <linux/kernel.h>
94934 #include <linux/rculist.h>
94935 +#include <linux/mm.h>
94936
94937 +#ifdef CONFIG_DEBUG_LIST
94938 /*
94939 * Insert a new entry between two known consecutive entries.
94940 *
94941 @@ -19,21 +21,40 @@
94942 * the prev/next entries already!
94943 */
94944
94945 +static bool __list_add_debug(struct list_head *new,
94946 + struct list_head *prev,
94947 + struct list_head *next)
94948 +{
94949 + if (unlikely(next->prev != prev)) {
94950 + printk(KERN_ERR "list_add corruption. next->prev should be "
94951 + "prev (%p), but was %p. (next=%p).\n",
94952 + prev, next->prev, next);
94953 + BUG();
94954 + return false;
94955 + }
94956 + if (unlikely(prev->next != next)) {
94957 + printk(KERN_ERR "list_add corruption. prev->next should be "
94958 + "next (%p), but was %p. (prev=%p).\n",
94959 + next, prev->next, prev);
94960 + BUG();
94961 + return false;
94962 + }
94963 + if (unlikely(new == prev || new == next)) {
94964 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94965 + new, prev, next);
94966 + BUG();
94967 + return false;
94968 + }
94969 + return true;
94970 +}
94971 +
94972 void __list_add(struct list_head *new,
94973 - struct list_head *prev,
94974 - struct list_head *next)
94975 + struct list_head *prev,
94976 + struct list_head *next)
94977 {
94978 - WARN(next->prev != prev,
94979 - "list_add corruption. next->prev should be "
94980 - "prev (%p), but was %p. (next=%p).\n",
94981 - prev, next->prev, next);
94982 - WARN(prev->next != next,
94983 - "list_add corruption. prev->next should be "
94984 - "next (%p), but was %p. (prev=%p).\n",
94985 - next, prev->next, prev);
94986 - WARN(new == prev || new == next,
94987 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94988 - new, prev, next);
94989 + if (!__list_add_debug(new, prev, next))
94990 + return;
94991 +
94992 next->prev = new;
94993 new->next = next;
94994 new->prev = prev;
94995 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94996 }
94997 EXPORT_SYMBOL(__list_add);
94998
94999 -void __list_del_entry(struct list_head *entry)
95000 +static bool __list_del_entry_debug(struct list_head *entry)
95001 {
95002 struct list_head *prev, *next;
95003
95004 prev = entry->prev;
95005 next = entry->next;
95006
95007 - if (WARN(next == LIST_POISON1,
95008 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95009 - entry, LIST_POISON1) ||
95010 - WARN(prev == LIST_POISON2,
95011 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95012 - entry, LIST_POISON2) ||
95013 - WARN(prev->next != entry,
95014 - "list_del corruption. prev->next should be %p, "
95015 - "but was %p\n", entry, prev->next) ||
95016 - WARN(next->prev != entry,
95017 - "list_del corruption. next->prev should be %p, "
95018 - "but was %p\n", entry, next->prev))
95019 + if (unlikely(next == LIST_POISON1)) {
95020 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95021 + entry, LIST_POISON1);
95022 + BUG();
95023 + return false;
95024 + }
95025 + if (unlikely(prev == LIST_POISON2)) {
95026 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95027 + entry, LIST_POISON2);
95028 + BUG();
95029 + return false;
95030 + }
95031 + if (unlikely(entry->prev->next != entry)) {
95032 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95033 + "but was %p\n", entry, prev->next);
95034 + BUG();
95035 + return false;
95036 + }
95037 + if (unlikely(entry->next->prev != entry)) {
95038 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95039 + "but was %p\n", entry, next->prev);
95040 + BUG();
95041 + return false;
95042 + }
95043 + return true;
95044 +}
95045 +
95046 +void __list_del_entry(struct list_head *entry)
95047 +{
95048 + if (!__list_del_entry_debug(entry))
95049 return;
95050
95051 - __list_del(prev, next);
95052 + __list_del(entry->prev, entry->next);
95053 }
95054 EXPORT_SYMBOL(__list_del_entry);
95055
95056 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95057 void __list_add_rcu(struct list_head *new,
95058 struct list_head *prev, struct list_head *next)
95059 {
95060 - WARN(next->prev != prev,
95061 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95062 - prev, next->prev, next);
95063 - WARN(prev->next != next,
95064 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95065 - next, prev->next, prev);
95066 + if (!__list_add_debug(new, prev, next))
95067 + return;
95068 +
95069 new->next = next;
95070 new->prev = prev;
95071 rcu_assign_pointer(list_next_rcu(prev), new);
95072 next->prev = new;
95073 }
95074 EXPORT_SYMBOL(__list_add_rcu);
95075 +#endif
95076 +
95077 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95078 +{
95079 +#ifdef CONFIG_DEBUG_LIST
95080 + if (!__list_add_debug(new, prev, next))
95081 + return;
95082 +#endif
95083 +
95084 + pax_open_kernel();
95085 + next->prev = new;
95086 + new->next = next;
95087 + new->prev = prev;
95088 + prev->next = new;
95089 + pax_close_kernel();
95090 +}
95091 +EXPORT_SYMBOL(__pax_list_add);
95092 +
95093 +void pax_list_del(struct list_head *entry)
95094 +{
95095 +#ifdef CONFIG_DEBUG_LIST
95096 + if (!__list_del_entry_debug(entry))
95097 + return;
95098 +#endif
95099 +
95100 + pax_open_kernel();
95101 + __list_del(entry->prev, entry->next);
95102 + entry->next = LIST_POISON1;
95103 + entry->prev = LIST_POISON2;
95104 + pax_close_kernel();
95105 +}
95106 +EXPORT_SYMBOL(pax_list_del);
95107 +
95108 +void pax_list_del_init(struct list_head *entry)
95109 +{
95110 + pax_open_kernel();
95111 + __list_del(entry->prev, entry->next);
95112 + INIT_LIST_HEAD(entry);
95113 + pax_close_kernel();
95114 +}
95115 +EXPORT_SYMBOL(pax_list_del_init);
95116 +
95117 +void __pax_list_add_rcu(struct list_head *new,
95118 + struct list_head *prev, struct list_head *next)
95119 +{
95120 +#ifdef CONFIG_DEBUG_LIST
95121 + if (!__list_add_debug(new, prev, next))
95122 + return;
95123 +#endif
95124 +
95125 + pax_open_kernel();
95126 + new->next = next;
95127 + new->prev = prev;
95128 + rcu_assign_pointer(list_next_rcu(prev), new);
95129 + next->prev = new;
95130 + pax_close_kernel();
95131 +}
95132 +EXPORT_SYMBOL(__pax_list_add_rcu);
95133 +
95134 +void pax_list_del_rcu(struct list_head *entry)
95135 +{
95136 +#ifdef CONFIG_DEBUG_LIST
95137 + if (!__list_del_entry_debug(entry))
95138 + return;
95139 +#endif
95140 +
95141 + pax_open_kernel();
95142 + __list_del(entry->prev, entry->next);
95143 + entry->next = LIST_POISON1;
95144 + entry->prev = LIST_POISON2;
95145 + pax_close_kernel();
95146 +}
95147 +EXPORT_SYMBOL(pax_list_del_rcu);
95148 diff --git a/lib/lockref.c b/lib/lockref.c
95149 index d2233de..fa1a2f6 100644
95150 --- a/lib/lockref.c
95151 +++ b/lib/lockref.c
95152 @@ -48,13 +48,13 @@
95153 void lockref_get(struct lockref *lockref)
95154 {
95155 CMPXCHG_LOOP(
95156 - new.count++;
95157 + __lockref_inc(&new);
95158 ,
95159 return;
95160 );
95161
95162 spin_lock(&lockref->lock);
95163 - lockref->count++;
95164 + __lockref_inc(lockref);
95165 spin_unlock(&lockref->lock);
95166 }
95167 EXPORT_SYMBOL(lockref_get);
95168 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95169 int retval;
95170
95171 CMPXCHG_LOOP(
95172 - new.count++;
95173 + __lockref_inc(&new);
95174 if (!old.count)
95175 return 0;
95176 ,
95177 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95178 spin_lock(&lockref->lock);
95179 retval = 0;
95180 if (lockref->count) {
95181 - lockref->count++;
95182 + __lockref_inc(lockref);
95183 retval = 1;
95184 }
95185 spin_unlock(&lockref->lock);
95186 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95187 int lockref_get_or_lock(struct lockref *lockref)
95188 {
95189 CMPXCHG_LOOP(
95190 - new.count++;
95191 + __lockref_inc(&new);
95192 if (!old.count)
95193 break;
95194 ,
95195 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95196 spin_lock(&lockref->lock);
95197 if (!lockref->count)
95198 return 0;
95199 - lockref->count++;
95200 + __lockref_inc(lockref);
95201 spin_unlock(&lockref->lock);
95202 return 1;
95203 }
95204 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95205 int lockref_put_or_lock(struct lockref *lockref)
95206 {
95207 CMPXCHG_LOOP(
95208 - new.count--;
95209 + __lockref_dec(&new);
95210 if (old.count <= 1)
95211 break;
95212 ,
95213 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95214 spin_lock(&lockref->lock);
95215 if (lockref->count <= 1)
95216 return 0;
95217 - lockref->count--;
95218 + __lockref_dec(lockref);
95219 spin_unlock(&lockref->lock);
95220 return 1;
95221 }
95222 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95223 int retval;
95224
95225 CMPXCHG_LOOP(
95226 - new.count++;
95227 + __lockref_inc(&new);
95228 if ((int)old.count < 0)
95229 return 0;
95230 ,
95231 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95232 spin_lock(&lockref->lock);
95233 retval = 0;
95234 if ((int) lockref->count >= 0) {
95235 - lockref->count++;
95236 + __lockref_inc(lockref);
95237 retval = 1;
95238 }
95239 spin_unlock(&lockref->lock);
95240 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95241 index 6111bcb..02e816b 100644
95242 --- a/lib/percpu-refcount.c
95243 +++ b/lib/percpu-refcount.c
95244 @@ -31,7 +31,7 @@
95245 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
95246 */
95247
95248 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
95249 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
95250
95251 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
95252
95253 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95254 index 3291a8e..346a91e 100644
95255 --- a/lib/radix-tree.c
95256 +++ b/lib/radix-tree.c
95257 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95258 int nr;
95259 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95260 };
95261 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95262 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95263
95264 static inline void *ptr_to_indirect(void *ptr)
95265 {
95266 diff --git a/lib/random32.c b/lib/random32.c
95267 index 0bee183..526f12f 100644
95268 --- a/lib/random32.c
95269 +++ b/lib/random32.c
95270 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
95271 }
95272 #endif
95273
95274 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95275 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95276
95277 /**
95278 * prandom_u32_state - seeded pseudo-random number generator.
95279 diff --git a/lib/rbtree.c b/lib/rbtree.c
95280 index c16c81a..4dcbda1 100644
95281 --- a/lib/rbtree.c
95282 +++ b/lib/rbtree.c
95283 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95284 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95285
95286 static const struct rb_augment_callbacks dummy_callbacks = {
95287 - dummy_propagate, dummy_copy, dummy_rotate
95288 + .propagate = dummy_propagate,
95289 + .copy = dummy_copy,
95290 + .rotate = dummy_rotate
95291 };
95292
95293 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95294 diff --git a/lib/show_mem.c b/lib/show_mem.c
95295 index 5e25627..3ed9d7f 100644
95296 --- a/lib/show_mem.c
95297 +++ b/lib/show_mem.c
95298 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95299 quicklist_total_size());
95300 #endif
95301 #ifdef CONFIG_MEMORY_FAILURE
95302 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95303 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95304 #endif
95305 }
95306 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95307 index bb2b201..46abaf9 100644
95308 --- a/lib/strncpy_from_user.c
95309 +++ b/lib/strncpy_from_user.c
95310 @@ -21,7 +21,7 @@
95311 */
95312 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95313 {
95314 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95315 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95316 long res = 0;
95317
95318 /*
95319 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95320 index a28df52..3d55877 100644
95321 --- a/lib/strnlen_user.c
95322 +++ b/lib/strnlen_user.c
95323 @@ -26,7 +26,7 @@
95324 */
95325 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95326 {
95327 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95328 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95329 long align, res = 0;
95330 unsigned long c;
95331
95332 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95333 index 4abda07..b9d3765 100644
95334 --- a/lib/swiotlb.c
95335 +++ b/lib/swiotlb.c
95336 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95337
95338 void
95339 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95340 - dma_addr_t dev_addr)
95341 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95342 {
95343 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95344
95345 diff --git a/lib/usercopy.c b/lib/usercopy.c
95346 index 4f5b1dd..7cab418 100644
95347 --- a/lib/usercopy.c
95348 +++ b/lib/usercopy.c
95349 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95350 WARN(1, "Buffer overflow detected!\n");
95351 }
95352 EXPORT_SYMBOL(copy_from_user_overflow);
95353 +
95354 +void copy_to_user_overflow(void)
95355 +{
95356 + WARN(1, "Buffer overflow detected!\n");
95357 +}
95358 +EXPORT_SYMBOL(copy_to_user_overflow);
95359 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95360 index ec337f6..8484eb2 100644
95361 --- a/lib/vsprintf.c
95362 +++ b/lib/vsprintf.c
95363 @@ -16,6 +16,9 @@
95364 * - scnprintf and vscnprintf
95365 */
95366
95367 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95368 +#define __INCLUDED_BY_HIDESYM 1
95369 +#endif
95370 #include <stdarg.h>
95371 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95372 #include <linux/types.h>
95373 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95374 #ifdef CONFIG_KALLSYMS
95375 if (*fmt == 'B')
95376 sprint_backtrace(sym, value);
95377 - else if (*fmt != 'f' && *fmt != 's')
95378 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95379 sprint_symbol(sym, value);
95380 else
95381 sprint_symbol_no_offset(sym, value);
95382 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95383 return number(buf, end, num, spec);
95384 }
95385
95386 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95387 +int kptr_restrict __read_mostly = 2;
95388 +#else
95389 int kptr_restrict __read_mostly;
95390 +#endif
95391
95392 /*
95393 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95394 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95395 *
95396 * - 'F' For symbolic function descriptor pointers with offset
95397 * - 'f' For simple symbolic function names without offset
95398 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95399 * - 'S' For symbolic direct pointers with offset
95400 * - 's' For symbolic direct pointers without offset
95401 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95402 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95403 * - 'B' For backtraced symbolic direct pointers with offset
95404 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95405 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95406
95407 if (!ptr && *fmt != 'K') {
95408 /*
95409 - * Print (null) with the same width as a pointer so it makes
95410 + * Print (nil) with the same width as a pointer so it makes
95411 * tabular output look nice.
95412 */
95413 if (spec.field_width == -1)
95414 spec.field_width = default_width;
95415 - return string(buf, end, "(null)", spec);
95416 + return string(buf, end, "(nil)", spec);
95417 }
95418
95419 switch (*fmt) {
95420 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95421 /* Fallthrough */
95422 case 'S':
95423 case 's':
95424 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95425 + break;
95426 +#else
95427 + return symbol_string(buf, end, ptr, spec, fmt);
95428 +#endif
95429 + case 'X':
95430 + ptr = dereference_function_descriptor(ptr);
95431 + case 'A':
95432 case 'B':
95433 return symbol_string(buf, end, ptr, spec, fmt);
95434 case 'R':
95435 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95436 va_end(va);
95437 return buf;
95438 }
95439 + case 'P':
95440 + break;
95441 case 'K':
95442 /*
95443 * %pK cannot be used in IRQ context because its test
95444 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95445 ((const struct file *)ptr)->f_path.dentry,
95446 spec, fmt);
95447 }
95448 +
95449 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95450 + /* 'P' = approved pointers to copy to userland,
95451 + as in the /proc/kallsyms case, as we make it display nothing
95452 + for non-root users, and the real contents for root users
95453 + 'X' = approved simple symbols
95454 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95455 + above
95456 + */
95457 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95458 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95459 + dump_stack();
95460 + ptr = NULL;
95461 + }
95462 +#endif
95463 +
95464 spec.flags |= SMALL;
95465 if (spec.field_width == -1) {
95466 spec.field_width = default_width;
95467 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95468 typeof(type) value; \
95469 if (sizeof(type) == 8) { \
95470 args = PTR_ALIGN(args, sizeof(u32)); \
95471 - *(u32 *)&value = *(u32 *)args; \
95472 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95473 + *(u32 *)&value = *(const u32 *)args; \
95474 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95475 } else { \
95476 args = PTR_ALIGN(args, sizeof(type)); \
95477 - value = *(typeof(type) *)args; \
95478 + value = *(const typeof(type) *)args; \
95479 } \
95480 args += sizeof(type); \
95481 value; \
95482 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95483 case FORMAT_TYPE_STR: {
95484 const char *str_arg = args;
95485 args += strlen(str_arg) + 1;
95486 - str = string(str, end, (char *)str_arg, spec);
95487 + str = string(str, end, str_arg, spec);
95488 break;
95489 }
95490
95491 diff --git a/localversion-grsec b/localversion-grsec
95492 new file mode 100644
95493 index 0000000..7cd6065
95494 --- /dev/null
95495 +++ b/localversion-grsec
95496 @@ -0,0 +1 @@
95497 +-grsec
95498 diff --git a/mm/Kconfig b/mm/Kconfig
95499 index 1d1ae6b..0f05885 100644
95500 --- a/mm/Kconfig
95501 +++ b/mm/Kconfig
95502 @@ -341,10 +341,11 @@ config KSM
95503 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95504
95505 config DEFAULT_MMAP_MIN_ADDR
95506 - int "Low address space to protect from user allocation"
95507 + int "Low address space to protect from user allocation"
95508 depends on MMU
95509 - default 4096
95510 - help
95511 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95512 + default 65536
95513 + help
95514 This is the portion of low virtual memory which should be protected
95515 from userspace allocation. Keeping a user from writing to low pages
95516 can help reduce the impact of kernel NULL pointer bugs.
95517 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
95518
95519 config HWPOISON_INJECT
95520 tristate "HWPoison pages injector"
95521 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95522 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95523 select PROC_PAGE_MONITOR
95524
95525 config NOMMU_INITIAL_TRIM_EXCESS
95526 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95527 index 0ae0df5..82ac56b 100644
95528 --- a/mm/backing-dev.c
95529 +++ b/mm/backing-dev.c
95530 @@ -12,7 +12,7 @@
95531 #include <linux/device.h>
95532 #include <trace/events/writeback.h>
95533
95534 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95535 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95536
95537 struct backing_dev_info default_backing_dev_info = {
95538 .name = "default",
95539 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95540 return err;
95541
95542 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95543 - atomic_long_inc_return(&bdi_seq));
95544 + atomic_long_inc_return_unchecked(&bdi_seq));
95545 if (err) {
95546 bdi_destroy(bdi);
95547 return err;
95548 diff --git a/mm/filemap.c b/mm/filemap.c
95549 index 37beab9..2c55a85 100644
95550 --- a/mm/filemap.c
95551 +++ b/mm/filemap.c
95552 @@ -2097,7 +2097,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95553 struct address_space *mapping = file->f_mapping;
95554
95555 if (!mapping->a_ops->readpage)
95556 - return -ENOEXEC;
95557 + return -ENODEV;
95558 file_accessed(file);
95559 vma->vm_ops = &generic_file_vm_ops;
95560 return 0;
95561 @@ -2275,6 +2275,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95562 *pos = i_size_read(inode);
95563
95564 if (limit != RLIM_INFINITY) {
95565 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95566 if (*pos >= limit) {
95567 send_sig(SIGXFSZ, current, 0);
95568 return -EFBIG;
95569 diff --git a/mm/fremap.c b/mm/fremap.c
95570 index 72b8fa3..c5b39f1 100644
95571 --- a/mm/fremap.c
95572 +++ b/mm/fremap.c
95573 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95574 retry:
95575 vma = find_vma(mm, start);
95576
95577 +#ifdef CONFIG_PAX_SEGMEXEC
95578 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95579 + goto out;
95580 +#endif
95581 +
95582 /*
95583 * Make sure the vma is shared, that it supports prefaulting,
95584 * and that the remapped range is valid and fully within
95585 diff --git a/mm/gup.c b/mm/gup.c
95586 index a0d57ec..79d469ce 100644
95587 --- a/mm/gup.c
95588 +++ b/mm/gup.c
95589 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95590 unsigned int fault_flags = 0;
95591 int ret;
95592
95593 - /* For mlock, just skip the stack guard page. */
95594 - if ((*flags & FOLL_MLOCK) &&
95595 - (stack_guard_page_start(vma, address) ||
95596 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95597 - return -ENOENT;
95598 if (*flags & FOLL_WRITE)
95599 fault_flags |= FAULT_FLAG_WRITE;
95600 if (nonblocking)
95601 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95602 if (!(gup_flags & FOLL_FORCE))
95603 gup_flags |= FOLL_NUMA;
95604
95605 - do {
95606 + while (nr_pages) {
95607 struct page *page;
95608 unsigned int foll_flags = gup_flags;
95609 unsigned int page_increm;
95610
95611 /* first iteration or cross vma bound */
95612 if (!vma || start >= vma->vm_end) {
95613 - vma = find_extend_vma(mm, start);
95614 + vma = find_vma(mm, start);
95615 if (!vma && in_gate_area(mm, start)) {
95616 int ret;
95617 ret = get_gate_page(mm, start & PAGE_MASK,
95618 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95619 goto next_page;
95620 }
95621
95622 - if (!vma || check_vma_flags(vma, gup_flags))
95623 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95624 return i ? : -EFAULT;
95625 if (is_vm_hugetlb_page(vma)) {
95626 i = follow_hugetlb_page(mm, vma, pages, vmas,
95627 @@ -518,7 +513,7 @@ next_page:
95628 i += page_increm;
95629 start += page_increm * PAGE_SIZE;
95630 nr_pages -= page_increm;
95631 - } while (nr_pages);
95632 + }
95633 return i;
95634 }
95635 EXPORT_SYMBOL(__get_user_pages);
95636 diff --git a/mm/highmem.c b/mm/highmem.c
95637 index 123bcd3..0de52ba 100644
95638 --- a/mm/highmem.c
95639 +++ b/mm/highmem.c
95640 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95641 * So no dangers, even with speculative execution.
95642 */
95643 page = pte_page(pkmap_page_table[i]);
95644 + pax_open_kernel();
95645 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95646 -
95647 + pax_close_kernel();
95648 set_page_address(page, NULL);
95649 need_flush = 1;
95650 }
95651 @@ -259,9 +260,11 @@ start:
95652 }
95653 }
95654 vaddr = PKMAP_ADDR(last_pkmap_nr);
95655 +
95656 + pax_open_kernel();
95657 set_pte_at(&init_mm, vaddr,
95658 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95659 -
95660 + pax_close_kernel();
95661 pkmap_count[last_pkmap_nr] = 1;
95662 set_page_address(page, (void *)vaddr);
95663
95664 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95665 index 9fd7227..5628939 100644
95666 --- a/mm/hugetlb.c
95667 +++ b/mm/hugetlb.c
95668 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95669 struct ctl_table *table, int write,
95670 void __user *buffer, size_t *length, loff_t *ppos)
95671 {
95672 + ctl_table_no_const t;
95673 struct hstate *h = &default_hstate;
95674 unsigned long tmp = h->max_huge_pages;
95675 int ret;
95676 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95677 if (!hugepages_supported())
95678 return -ENOTSUPP;
95679
95680 - table->data = &tmp;
95681 - table->maxlen = sizeof(unsigned long);
95682 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95683 + t = *table;
95684 + t.data = &tmp;
95685 + t.maxlen = sizeof(unsigned long);
95686 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95687 if (ret)
95688 goto out;
95689
95690 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95691 struct hstate *h = &default_hstate;
95692 unsigned long tmp;
95693 int ret;
95694 + ctl_table_no_const hugetlb_table;
95695
95696 if (!hugepages_supported())
95697 return -ENOTSUPP;
95698 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95699 if (write && hstate_is_gigantic(h))
95700 return -EINVAL;
95701
95702 - table->data = &tmp;
95703 - table->maxlen = sizeof(unsigned long);
95704 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95705 + hugetlb_table = *table;
95706 + hugetlb_table.data = &tmp;
95707 + hugetlb_table.maxlen = sizeof(unsigned long);
95708 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95709 if (ret)
95710 goto out;
95711
95712 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95713 mutex_unlock(&mapping->i_mmap_mutex);
95714 }
95715
95716 +#ifdef CONFIG_PAX_SEGMEXEC
95717 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95718 +{
95719 + struct mm_struct *mm = vma->vm_mm;
95720 + struct vm_area_struct *vma_m;
95721 + unsigned long address_m;
95722 + pte_t *ptep_m;
95723 +
95724 + vma_m = pax_find_mirror_vma(vma);
95725 + if (!vma_m)
95726 + return;
95727 +
95728 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95729 + address_m = address + SEGMEXEC_TASK_SIZE;
95730 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95731 + get_page(page_m);
95732 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95733 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95734 +}
95735 +#endif
95736 +
95737 /*
95738 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95739 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95740 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95741 make_huge_pte(vma, new_page, 1));
95742 page_remove_rmap(old_page);
95743 hugepage_add_new_anon_rmap(new_page, vma, address);
95744 +
95745 +#ifdef CONFIG_PAX_SEGMEXEC
95746 + pax_mirror_huge_pte(vma, address, new_page);
95747 +#endif
95748 +
95749 /* Make the old page be freed below */
95750 new_page = old_page;
95751 }
95752 @@ -3063,6 +3093,10 @@ retry:
95753 && (vma->vm_flags & VM_SHARED)));
95754 set_huge_pte_at(mm, address, ptep, new_pte);
95755
95756 +#ifdef CONFIG_PAX_SEGMEXEC
95757 + pax_mirror_huge_pte(vma, address, page);
95758 +#endif
95759 +
95760 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95761 /* Optimization, do the COW without a second fault */
95762 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95763 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95764 struct hstate *h = hstate_vma(vma);
95765 struct address_space *mapping;
95766
95767 +#ifdef CONFIG_PAX_SEGMEXEC
95768 + struct vm_area_struct *vma_m;
95769 +#endif
95770 +
95771 address &= huge_page_mask(h);
95772
95773 ptep = huge_pte_offset(mm, address);
95774 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95775 VM_FAULT_SET_HINDEX(hstate_index(h));
95776 }
95777
95778 +#ifdef CONFIG_PAX_SEGMEXEC
95779 + vma_m = pax_find_mirror_vma(vma);
95780 + if (vma_m) {
95781 + unsigned long address_m;
95782 +
95783 + if (vma->vm_start > vma_m->vm_start) {
95784 + address_m = address;
95785 + address -= SEGMEXEC_TASK_SIZE;
95786 + vma = vma_m;
95787 + h = hstate_vma(vma);
95788 + } else
95789 + address_m = address + SEGMEXEC_TASK_SIZE;
95790 +
95791 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95792 + return VM_FAULT_OOM;
95793 + address_m &= HPAGE_MASK;
95794 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95795 + }
95796 +#endif
95797 +
95798 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95799 if (!ptep)
95800 return VM_FAULT_OOM;
95801 diff --git a/mm/internal.h b/mm/internal.h
95802 index a4f90ba..fbdc32b 100644
95803 --- a/mm/internal.h
95804 +++ b/mm/internal.h
95805 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95806
95807 extern int __isolate_free_page(struct page *page, unsigned int order);
95808 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95809 +extern void free_compound_page(struct page *page);
95810 extern void prep_compound_page(struct page *page, unsigned long order);
95811 #ifdef CONFIG_MEMORY_FAILURE
95812 extern bool is_free_buddy_page(struct page *page);
95813 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95814
95815 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95816 unsigned long, unsigned long,
95817 - unsigned long, unsigned long);
95818 + unsigned long, unsigned long) __intentional_overflow(-1);
95819
95820 extern void set_pageblock_order(void);
95821 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95822 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95823 index e34a3cb..a810efe 100644
95824 --- a/mm/iov_iter.c
95825 +++ b/mm/iov_iter.c
95826 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95827
95828 while (bytes) {
95829 char __user *buf = iov->iov_base + base;
95830 - int copy = min(bytes, iov->iov_len - base);
95831 + size_t copy = min(bytes, iov->iov_len - base);
95832
95833 base = 0;
95834 left = __copy_from_user_inatomic(vaddr, buf, copy);
95835 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95836
95837 kaddr = kmap_atomic(page);
95838 if (likely(i->nr_segs == 1)) {
95839 - int left;
95840 + size_t left;
95841 char __user *buf = i->iov->iov_base + i->iov_offset;
95842 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95843 copied = bytes - left;
95844 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95845 * zero-length segments (without overruning the iovec).
95846 */
95847 while (bytes || unlikely(i->count && !iov->iov_len)) {
95848 - int copy;
95849 + size_t copy;
95850
95851 copy = min(bytes, iov->iov_len - base);
95852 BUG_ON(!i->count || i->count < copy);
95853 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95854 index 3cda50c..032ba634 100644
95855 --- a/mm/kmemleak.c
95856 +++ b/mm/kmemleak.c
95857 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95858
95859 for (i = 0; i < object->trace_len; i++) {
95860 void *ptr = (void *)object->trace[i];
95861 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95862 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95863 }
95864 }
95865
95866 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95867 return -ENOMEM;
95868 }
95869
95870 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95871 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95872 &kmemleak_fops);
95873 if (!dentry)
95874 pr_warning("Failed to create the debugfs kmemleak file\n");
95875 diff --git a/mm/maccess.c b/mm/maccess.c
95876 index d53adf9..03a24bf 100644
95877 --- a/mm/maccess.c
95878 +++ b/mm/maccess.c
95879 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95880 set_fs(KERNEL_DS);
95881 pagefault_disable();
95882 ret = __copy_from_user_inatomic(dst,
95883 - (__force const void __user *)src, size);
95884 + (const void __force_user *)src, size);
95885 pagefault_enable();
95886 set_fs(old_fs);
95887
95888 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95889
95890 set_fs(KERNEL_DS);
95891 pagefault_disable();
95892 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95893 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95894 pagefault_enable();
95895 set_fs(old_fs);
95896
95897 diff --git a/mm/madvise.c b/mm/madvise.c
95898 index 0938b30..199abe8 100644
95899 --- a/mm/madvise.c
95900 +++ b/mm/madvise.c
95901 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95902 pgoff_t pgoff;
95903 unsigned long new_flags = vma->vm_flags;
95904
95905 +#ifdef CONFIG_PAX_SEGMEXEC
95906 + struct vm_area_struct *vma_m;
95907 +#endif
95908 +
95909 switch (behavior) {
95910 case MADV_NORMAL:
95911 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95912 @@ -126,6 +130,13 @@ success:
95913 /*
95914 * vm_flags is protected by the mmap_sem held in write mode.
95915 */
95916 +
95917 +#ifdef CONFIG_PAX_SEGMEXEC
95918 + vma_m = pax_find_mirror_vma(vma);
95919 + if (vma_m)
95920 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95921 +#endif
95922 +
95923 vma->vm_flags = new_flags;
95924
95925 out:
95926 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95927 struct vm_area_struct **prev,
95928 unsigned long start, unsigned long end)
95929 {
95930 +
95931 +#ifdef CONFIG_PAX_SEGMEXEC
95932 + struct vm_area_struct *vma_m;
95933 +#endif
95934 +
95935 *prev = vma;
95936 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95937 return -EINVAL;
95938 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95939 zap_page_range(vma, start, end - start, &details);
95940 } else
95941 zap_page_range(vma, start, end - start, NULL);
95942 +
95943 +#ifdef CONFIG_PAX_SEGMEXEC
95944 + vma_m = pax_find_mirror_vma(vma);
95945 + if (vma_m) {
95946 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95947 + struct zap_details details = {
95948 + .nonlinear_vma = vma_m,
95949 + .last_index = ULONG_MAX,
95950 + };
95951 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95952 + } else
95953 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95954 + }
95955 +#endif
95956 +
95957 return 0;
95958 }
95959
95960 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95961 if (end < start)
95962 return error;
95963
95964 +#ifdef CONFIG_PAX_SEGMEXEC
95965 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95966 + if (end > SEGMEXEC_TASK_SIZE)
95967 + return error;
95968 + } else
95969 +#endif
95970 +
95971 + if (end > TASK_SIZE)
95972 + return error;
95973 +
95974 error = 0;
95975 if (end == start)
95976 return error;
95977 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95978 index 8639f6b..b623882a 100644
95979 --- a/mm/memory-failure.c
95980 +++ b/mm/memory-failure.c
95981 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95982
95983 int sysctl_memory_failure_recovery __read_mostly = 1;
95984
95985 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95986 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95987
95988 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95989
95990 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95991 pfn, t->comm, t->pid);
95992 si.si_signo = SIGBUS;
95993 si.si_errno = 0;
95994 - si.si_addr = (void *)addr;
95995 + si.si_addr = (void __user *)addr;
95996 #ifdef __ARCH_SI_TRAPNO
95997 si.si_trapno = trapno;
95998 #endif
95999 @@ -791,7 +791,7 @@ static struct page_state {
96000 unsigned long res;
96001 char *msg;
96002 int (*action)(struct page *p, unsigned long pfn);
96003 -} error_states[] = {
96004 +} __do_const error_states[] = {
96005 { reserved, reserved, "reserved kernel", me_kernel },
96006 /*
96007 * free pages are specially detected outside this table:
96008 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96009 nr_pages = 1 << compound_order(hpage);
96010 else /* normal page or thp */
96011 nr_pages = 1;
96012 - atomic_long_add(nr_pages, &num_poisoned_pages);
96013 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96014
96015 /*
96016 * We need/can do nothing about count=0 pages.
96017 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96018 if (PageHWPoison(hpage)) {
96019 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96020 || (p != hpage && TestSetPageHWPoison(hpage))) {
96021 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96022 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96023 unlock_page(hpage);
96024 return 0;
96025 }
96026 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96027 */
96028 if (!PageHWPoison(p)) {
96029 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96030 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96031 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96032 put_page(hpage);
96033 res = 0;
96034 goto out;
96035 }
96036 if (hwpoison_filter(p)) {
96037 if (TestClearPageHWPoison(p))
96038 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96039 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96040 unlock_page(hpage);
96041 put_page(hpage);
96042 return 0;
96043 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96044 return 0;
96045 }
96046 if (TestClearPageHWPoison(p))
96047 - atomic_long_dec(&num_poisoned_pages);
96048 + atomic_long_dec_unchecked(&num_poisoned_pages);
96049 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96050 return 0;
96051 }
96052 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96053 */
96054 if (TestClearPageHWPoison(page)) {
96055 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96056 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96057 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96058 freeit = 1;
96059 if (PageHuge(page))
96060 clear_page_hwpoison_huge_page(page);
96061 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96062 if (PageHuge(page)) {
96063 set_page_hwpoison_huge_page(hpage);
96064 dequeue_hwpoisoned_huge_page(hpage);
96065 - atomic_long_add(1 << compound_order(hpage),
96066 + atomic_long_add_unchecked(1 << compound_order(hpage),
96067 &num_poisoned_pages);
96068 } else {
96069 SetPageHWPoison(page);
96070 - atomic_long_inc(&num_poisoned_pages);
96071 + atomic_long_inc_unchecked(&num_poisoned_pages);
96072 }
96073 }
96074 return ret;
96075 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96076 put_page(page);
96077 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96078 SetPageHWPoison(page);
96079 - atomic_long_inc(&num_poisoned_pages);
96080 + atomic_long_inc_unchecked(&num_poisoned_pages);
96081 return 0;
96082 }
96083
96084 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96085 if (!is_free_buddy_page(page))
96086 pr_info("soft offline: %#lx: page leaked\n",
96087 pfn);
96088 - atomic_long_inc(&num_poisoned_pages);
96089 + atomic_long_inc_unchecked(&num_poisoned_pages);
96090 }
96091 } else {
96092 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96093 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96094 if (PageHuge(page)) {
96095 set_page_hwpoison_huge_page(hpage);
96096 dequeue_hwpoisoned_huge_page(hpage);
96097 - atomic_long_add(1 << compound_order(hpage),
96098 + atomic_long_add_unchecked(1 << compound_order(hpage),
96099 &num_poisoned_pages);
96100 } else {
96101 SetPageHWPoison(page);
96102 - atomic_long_inc(&num_poisoned_pages);
96103 + atomic_long_inc_unchecked(&num_poisoned_pages);
96104 }
96105 }
96106 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96107 diff --git a/mm/memory.c b/mm/memory.c
96108 index d442584..0600e22 100644
96109 --- a/mm/memory.c
96110 +++ b/mm/memory.c
96111 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96112 free_pte_range(tlb, pmd, addr);
96113 } while (pmd++, addr = next, addr != end);
96114
96115 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96116 start &= PUD_MASK;
96117 if (start < floor)
96118 return;
96119 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96120 pmd = pmd_offset(pud, start);
96121 pud_clear(pud);
96122 pmd_free_tlb(tlb, pmd, start);
96123 +#endif
96124 +
96125 }
96126
96127 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96128 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96129 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96130 } while (pud++, addr = next, addr != end);
96131
96132 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96133 start &= PGDIR_MASK;
96134 if (start < floor)
96135 return;
96136 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96137 pud = pud_offset(pgd, start);
96138 pgd_clear(pgd);
96139 pud_free_tlb(tlb, pud, start);
96140 +#endif
96141 +
96142 }
96143
96144 /*
96145 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96146 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96147 */
96148 if (vma->vm_ops)
96149 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96150 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96151 vma->vm_ops->fault);
96152 if (vma->vm_file)
96153 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96154 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96155 vma->vm_file->f_op->mmap);
96156 dump_stack();
96157 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96158 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96159 page_add_file_rmap(page);
96160 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96161
96162 +#ifdef CONFIG_PAX_SEGMEXEC
96163 + pax_mirror_file_pte(vma, addr, page, ptl);
96164 +#endif
96165 +
96166 retval = 0;
96167 pte_unmap_unlock(pte, ptl);
96168 return retval;
96169 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96170 if (!page_count(page))
96171 return -EINVAL;
96172 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96173 +
96174 +#ifdef CONFIG_PAX_SEGMEXEC
96175 + struct vm_area_struct *vma_m;
96176 +#endif
96177 +
96178 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96179 BUG_ON(vma->vm_flags & VM_PFNMAP);
96180 vma->vm_flags |= VM_MIXEDMAP;
96181 +
96182 +#ifdef CONFIG_PAX_SEGMEXEC
96183 + vma_m = pax_find_mirror_vma(vma);
96184 + if (vma_m)
96185 + vma_m->vm_flags |= VM_MIXEDMAP;
96186 +#endif
96187 +
96188 }
96189 return insert_page(vma, addr, page, vma->vm_page_prot);
96190 }
96191 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96192 unsigned long pfn)
96193 {
96194 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96195 + BUG_ON(vma->vm_mirror);
96196
96197 if (addr < vma->vm_start || addr >= vma->vm_end)
96198 return -EFAULT;
96199 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96200
96201 BUG_ON(pud_huge(*pud));
96202
96203 - pmd = pmd_alloc(mm, pud, addr);
96204 + pmd = (mm == &init_mm) ?
96205 + pmd_alloc_kernel(mm, pud, addr) :
96206 + pmd_alloc(mm, pud, addr);
96207 if (!pmd)
96208 return -ENOMEM;
96209 do {
96210 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96211 unsigned long next;
96212 int err;
96213
96214 - pud = pud_alloc(mm, pgd, addr);
96215 + pud = (mm == &init_mm) ?
96216 + pud_alloc_kernel(mm, pgd, addr) :
96217 + pud_alloc(mm, pgd, addr);
96218 if (!pud)
96219 return -ENOMEM;
96220 do {
96221 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96222 return ret;
96223 }
96224
96225 +#ifdef CONFIG_PAX_SEGMEXEC
96226 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96227 +{
96228 + struct mm_struct *mm = vma->vm_mm;
96229 + spinlock_t *ptl;
96230 + pte_t *pte, entry;
96231 +
96232 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96233 + entry = *pte;
96234 + if (!pte_present(entry)) {
96235 + if (!pte_none(entry)) {
96236 + BUG_ON(pte_file(entry));
96237 + free_swap_and_cache(pte_to_swp_entry(entry));
96238 + pte_clear_not_present_full(mm, address, pte, 0);
96239 + }
96240 + } else {
96241 + struct page *page;
96242 +
96243 + flush_cache_page(vma, address, pte_pfn(entry));
96244 + entry = ptep_clear_flush(vma, address, pte);
96245 + BUG_ON(pte_dirty(entry));
96246 + page = vm_normal_page(vma, address, entry);
96247 + if (page) {
96248 + update_hiwater_rss(mm);
96249 + if (PageAnon(page))
96250 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96251 + else
96252 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96253 + page_remove_rmap(page);
96254 + page_cache_release(page);
96255 + }
96256 + }
96257 + pte_unmap_unlock(pte, ptl);
96258 +}
96259 +
96260 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96261 + *
96262 + * the ptl of the lower mapped page is held on entry and is not released on exit
96263 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96264 + */
96265 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96266 +{
96267 + struct mm_struct *mm = vma->vm_mm;
96268 + unsigned long address_m;
96269 + spinlock_t *ptl_m;
96270 + struct vm_area_struct *vma_m;
96271 + pmd_t *pmd_m;
96272 + pte_t *pte_m, entry_m;
96273 +
96274 + BUG_ON(!page_m || !PageAnon(page_m));
96275 +
96276 + vma_m = pax_find_mirror_vma(vma);
96277 + if (!vma_m)
96278 + return;
96279 +
96280 + BUG_ON(!PageLocked(page_m));
96281 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96282 + address_m = address + SEGMEXEC_TASK_SIZE;
96283 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96284 + pte_m = pte_offset_map(pmd_m, address_m);
96285 + ptl_m = pte_lockptr(mm, pmd_m);
96286 + if (ptl != ptl_m) {
96287 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96288 + if (!pte_none(*pte_m))
96289 + goto out;
96290 + }
96291 +
96292 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96293 + page_cache_get(page_m);
96294 + page_add_anon_rmap(page_m, vma_m, address_m);
96295 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96296 + set_pte_at(mm, address_m, pte_m, entry_m);
96297 + update_mmu_cache(vma_m, address_m, pte_m);
96298 +out:
96299 + if (ptl != ptl_m)
96300 + spin_unlock(ptl_m);
96301 + pte_unmap(pte_m);
96302 + unlock_page(page_m);
96303 +}
96304 +
96305 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96306 +{
96307 + struct mm_struct *mm = vma->vm_mm;
96308 + unsigned long address_m;
96309 + spinlock_t *ptl_m;
96310 + struct vm_area_struct *vma_m;
96311 + pmd_t *pmd_m;
96312 + pte_t *pte_m, entry_m;
96313 +
96314 + BUG_ON(!page_m || PageAnon(page_m));
96315 +
96316 + vma_m = pax_find_mirror_vma(vma);
96317 + if (!vma_m)
96318 + return;
96319 +
96320 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96321 + address_m = address + SEGMEXEC_TASK_SIZE;
96322 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96323 + pte_m = pte_offset_map(pmd_m, address_m);
96324 + ptl_m = pte_lockptr(mm, pmd_m);
96325 + if (ptl != ptl_m) {
96326 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96327 + if (!pte_none(*pte_m))
96328 + goto out;
96329 + }
96330 +
96331 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96332 + page_cache_get(page_m);
96333 + page_add_file_rmap(page_m);
96334 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96335 + set_pte_at(mm, address_m, pte_m, entry_m);
96336 + update_mmu_cache(vma_m, address_m, pte_m);
96337 +out:
96338 + if (ptl != ptl_m)
96339 + spin_unlock(ptl_m);
96340 + pte_unmap(pte_m);
96341 +}
96342 +
96343 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96344 +{
96345 + struct mm_struct *mm = vma->vm_mm;
96346 + unsigned long address_m;
96347 + spinlock_t *ptl_m;
96348 + struct vm_area_struct *vma_m;
96349 + pmd_t *pmd_m;
96350 + pte_t *pte_m, entry_m;
96351 +
96352 + vma_m = pax_find_mirror_vma(vma);
96353 + if (!vma_m)
96354 + return;
96355 +
96356 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96357 + address_m = address + SEGMEXEC_TASK_SIZE;
96358 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96359 + pte_m = pte_offset_map(pmd_m, address_m);
96360 + ptl_m = pte_lockptr(mm, pmd_m);
96361 + if (ptl != ptl_m) {
96362 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96363 + if (!pte_none(*pte_m))
96364 + goto out;
96365 + }
96366 +
96367 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96368 + set_pte_at(mm, address_m, pte_m, entry_m);
96369 +out:
96370 + if (ptl != ptl_m)
96371 + spin_unlock(ptl_m);
96372 + pte_unmap(pte_m);
96373 +}
96374 +
96375 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96376 +{
96377 + struct page *page_m;
96378 + pte_t entry;
96379 +
96380 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96381 + goto out;
96382 +
96383 + entry = *pte;
96384 + page_m = vm_normal_page(vma, address, entry);
96385 + if (!page_m)
96386 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96387 + else if (PageAnon(page_m)) {
96388 + if (pax_find_mirror_vma(vma)) {
96389 + pte_unmap_unlock(pte, ptl);
96390 + lock_page(page_m);
96391 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96392 + if (pte_same(entry, *pte))
96393 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96394 + else
96395 + unlock_page(page_m);
96396 + }
96397 + } else
96398 + pax_mirror_file_pte(vma, address, page_m, ptl);
96399 +
96400 +out:
96401 + pte_unmap_unlock(pte, ptl);
96402 +}
96403 +#endif
96404 +
96405 /*
96406 * This routine handles present pages, when users try to write
96407 * to a shared page. It is done by copying the page to a new address
96408 @@ -2225,6 +2432,12 @@ gotten:
96409 */
96410 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96411 if (likely(pte_same(*page_table, orig_pte))) {
96412 +
96413 +#ifdef CONFIG_PAX_SEGMEXEC
96414 + if (pax_find_mirror_vma(vma))
96415 + BUG_ON(!trylock_page(new_page));
96416 +#endif
96417 +
96418 if (old_page) {
96419 if (!PageAnon(old_page)) {
96420 dec_mm_counter_fast(mm, MM_FILEPAGES);
96421 @@ -2278,6 +2491,10 @@ gotten:
96422 page_remove_rmap(old_page);
96423 }
96424
96425 +#ifdef CONFIG_PAX_SEGMEXEC
96426 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96427 +#endif
96428 +
96429 /* Free the old page.. */
96430 new_page = old_page;
96431 ret |= VM_FAULT_WRITE;
96432 @@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96433 swap_free(entry);
96434 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96435 try_to_free_swap(page);
96436 +
96437 +#ifdef CONFIG_PAX_SEGMEXEC
96438 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96439 +#endif
96440 +
96441 unlock_page(page);
96442 if (page != swapcache) {
96443 /*
96444 @@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96445
96446 /* No need to invalidate - it was non-present before */
96447 update_mmu_cache(vma, address, page_table);
96448 +
96449 +#ifdef CONFIG_PAX_SEGMEXEC
96450 + pax_mirror_anon_pte(vma, address, page, ptl);
96451 +#endif
96452 +
96453 unlock:
96454 pte_unmap_unlock(page_table, ptl);
96455 out:
96456 @@ -2594,40 +2821,6 @@ out_release:
96457 }
96458
96459 /*
96460 - * This is like a special single-page "expand_{down|up}wards()",
96461 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96462 - * doesn't hit another vma.
96463 - */
96464 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96465 -{
96466 - address &= PAGE_MASK;
96467 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96468 - struct vm_area_struct *prev = vma->vm_prev;
96469 -
96470 - /*
96471 - * Is there a mapping abutting this one below?
96472 - *
96473 - * That's only ok if it's the same stack mapping
96474 - * that has gotten split..
96475 - */
96476 - if (prev && prev->vm_end == address)
96477 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96478 -
96479 - return expand_downwards(vma, address - PAGE_SIZE);
96480 - }
96481 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96482 - struct vm_area_struct *next = vma->vm_next;
96483 -
96484 - /* As VM_GROWSDOWN but s/below/above/ */
96485 - if (next && next->vm_start == address + PAGE_SIZE)
96486 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96487 -
96488 - return expand_upwards(vma, address + PAGE_SIZE);
96489 - }
96490 - return 0;
96491 -}
96492 -
96493 -/*
96494 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96495 * but allow concurrent faults), and pte mapped but not yet locked.
96496 * We return with mmap_sem still held, but pte unmapped and unlocked.
96497 @@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96498 unsigned int flags)
96499 {
96500 struct mem_cgroup *memcg;
96501 - struct page *page;
96502 + struct page *page = NULL;
96503 spinlock_t *ptl;
96504 pte_t entry;
96505
96506 - pte_unmap(page_table);
96507 -
96508 - /* Check if we need to add a guard page to the stack */
96509 - if (check_stack_guard_page(vma, address) < 0)
96510 - return VM_FAULT_SIGSEGV;
96511 -
96512 - /* Use the zero-page for reads */
96513 if (!(flags & FAULT_FLAG_WRITE)) {
96514 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96515 vma->vm_page_prot));
96516 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96517 + ptl = pte_lockptr(mm, pmd);
96518 + spin_lock(ptl);
96519 if (!pte_none(*page_table))
96520 goto unlock;
96521 goto setpte;
96522 }
96523
96524 /* Allocate our own private page. */
96525 + pte_unmap(page_table);
96526 +
96527 if (unlikely(anon_vma_prepare(vma)))
96528 goto oom;
96529 page = alloc_zeroed_user_highpage_movable(vma, address);
96530 @@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96531 if (!pte_none(*page_table))
96532 goto release;
96533
96534 +#ifdef CONFIG_PAX_SEGMEXEC
96535 + if (pax_find_mirror_vma(vma))
96536 + BUG_ON(!trylock_page(page));
96537 +#endif
96538 +
96539 inc_mm_counter_fast(mm, MM_ANONPAGES);
96540 page_add_new_anon_rmap(page, vma, address);
96541 mem_cgroup_commit_charge(page, memcg, false);
96542 @@ -2690,6 +2884,12 @@ setpte:
96543
96544 /* No need to invalidate - it was non-present before */
96545 update_mmu_cache(vma, address, page_table);
96546 +
96547 +#ifdef CONFIG_PAX_SEGMEXEC
96548 + if (page)
96549 + pax_mirror_anon_pte(vma, address, page, ptl);
96550 +#endif
96551 +
96552 unlock:
96553 pte_unmap_unlock(page_table, ptl);
96554 return 0;
96555 @@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96556 return ret;
96557 }
96558 do_set_pte(vma, address, fault_page, pte, false, false);
96559 +
96560 +#ifdef CONFIG_PAX_SEGMEXEC
96561 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96562 +#endif
96563 +
96564 unlock_page(fault_page);
96565 unlock_out:
96566 pte_unmap_unlock(pte, ptl);
96567 @@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96568 page_cache_release(fault_page);
96569 goto uncharge_out;
96570 }
96571 +
96572 +#ifdef CONFIG_PAX_SEGMEXEC
96573 + if (pax_find_mirror_vma(vma))
96574 + BUG_ON(!trylock_page(new_page));
96575 +#endif
96576 +
96577 do_set_pte(vma, address, new_page, pte, true, true);
96578 +
96579 +#ifdef CONFIG_PAX_SEGMEXEC
96580 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96581 +#endif
96582 +
96583 mem_cgroup_commit_charge(new_page, memcg, false);
96584 lru_cache_add_active_or_unevictable(new_page, vma);
96585 pte_unmap_unlock(pte, ptl);
96586 @@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96587 return ret;
96588 }
96589 do_set_pte(vma, address, fault_page, pte, true, false);
96590 +
96591 +#ifdef CONFIG_PAX_SEGMEXEC
96592 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96593 +#endif
96594 +
96595 pte_unmap_unlock(pte, ptl);
96596
96597 if (set_page_dirty(fault_page))
96598 @@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96599 if (flags & FAULT_FLAG_WRITE)
96600 flush_tlb_fix_spurious_fault(vma, address);
96601 }
96602 +
96603 +#ifdef CONFIG_PAX_SEGMEXEC
96604 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96605 + return 0;
96606 +#endif
96607 +
96608 unlock:
96609 pte_unmap_unlock(pte, ptl);
96610 return 0;
96611 @@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96612 pmd_t *pmd;
96613 pte_t *pte;
96614
96615 +#ifdef CONFIG_PAX_SEGMEXEC
96616 + struct vm_area_struct *vma_m;
96617 +#endif
96618 +
96619 if (unlikely(is_vm_hugetlb_page(vma)))
96620 return hugetlb_fault(mm, vma, address, flags);
96621
96622 +#ifdef CONFIG_PAX_SEGMEXEC
96623 + vma_m = pax_find_mirror_vma(vma);
96624 + if (vma_m) {
96625 + unsigned long address_m;
96626 + pgd_t *pgd_m;
96627 + pud_t *pud_m;
96628 + pmd_t *pmd_m;
96629 +
96630 + if (vma->vm_start > vma_m->vm_start) {
96631 + address_m = address;
96632 + address -= SEGMEXEC_TASK_SIZE;
96633 + vma = vma_m;
96634 + } else
96635 + address_m = address + SEGMEXEC_TASK_SIZE;
96636 +
96637 + pgd_m = pgd_offset(mm, address_m);
96638 + pud_m = pud_alloc(mm, pgd_m, address_m);
96639 + if (!pud_m)
96640 + return VM_FAULT_OOM;
96641 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96642 + if (!pmd_m)
96643 + return VM_FAULT_OOM;
96644 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96645 + return VM_FAULT_OOM;
96646 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96647 + }
96648 +#endif
96649 +
96650 pgd = pgd_offset(mm, address);
96651 pud = pud_alloc(mm, pgd, address);
96652 if (!pud)
96653 @@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96654 spin_unlock(&mm->page_table_lock);
96655 return 0;
96656 }
96657 +
96658 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96659 +{
96660 + pud_t *new = pud_alloc_one(mm, address);
96661 + if (!new)
96662 + return -ENOMEM;
96663 +
96664 + smp_wmb(); /* See comment in __pte_alloc */
96665 +
96666 + spin_lock(&mm->page_table_lock);
96667 + if (pgd_present(*pgd)) /* Another has populated it */
96668 + pud_free(mm, new);
96669 + else
96670 + pgd_populate_kernel(mm, pgd, new);
96671 + spin_unlock(&mm->page_table_lock);
96672 + return 0;
96673 +}
96674 #endif /* __PAGETABLE_PUD_FOLDED */
96675
96676 #ifndef __PAGETABLE_PMD_FOLDED
96677 @@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96678 spin_unlock(&mm->page_table_lock);
96679 return 0;
96680 }
96681 +
96682 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96683 +{
96684 + pmd_t *new = pmd_alloc_one(mm, address);
96685 + if (!new)
96686 + return -ENOMEM;
96687 +
96688 + smp_wmb(); /* See comment in __pte_alloc */
96689 +
96690 + spin_lock(&mm->page_table_lock);
96691 +#ifndef __ARCH_HAS_4LEVEL_HACK
96692 + if (pud_present(*pud)) /* Another has populated it */
96693 + pmd_free(mm, new);
96694 + else
96695 + pud_populate_kernel(mm, pud, new);
96696 +#else
96697 + if (pgd_present(*pud)) /* Another has populated it */
96698 + pmd_free(mm, new);
96699 + else
96700 + pgd_populate_kernel(mm, pud, new);
96701 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96702 + spin_unlock(&mm->page_table_lock);
96703 + return 0;
96704 +}
96705 #endif /* __PAGETABLE_PMD_FOLDED */
96706
96707 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96708 @@ -3547,8 +3847,8 @@ out:
96709 return ret;
96710 }
96711
96712 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96713 - void *buf, int len, int write)
96714 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96715 + void *buf, size_t len, int write)
96716 {
96717 resource_size_t phys_addr;
96718 unsigned long prot = 0;
96719 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96720 * Access another process' address space as given in mm. If non-NULL, use the
96721 * given task for page fault accounting.
96722 */
96723 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96724 - unsigned long addr, void *buf, int len, int write)
96725 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96726 + unsigned long addr, void *buf, size_t len, int write)
96727 {
96728 struct vm_area_struct *vma;
96729 void *old_buf = buf;
96730 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96731 down_read(&mm->mmap_sem);
96732 /* ignore errors, just check how much was successfully transferred */
96733 while (len) {
96734 - int bytes, ret, offset;
96735 + ssize_t bytes, ret, offset;
96736 void *maddr;
96737 struct page *page = NULL;
96738
96739 @@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96740 *
96741 * The caller must hold a reference on @mm.
96742 */
96743 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96744 - void *buf, int len, int write)
96745 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96746 + void *buf, size_t len, int write)
96747 {
96748 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96749 }
96750 @@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96751 * Source/target buffer must be kernel space,
96752 * Do not walk the page table directly, use get_user_pages
96753 */
96754 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96755 - void *buf, int len, int write)
96756 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96757 + void *buf, size_t len, int write)
96758 {
96759 struct mm_struct *mm;
96760 - int ret;
96761 + ssize_t ret;
96762
96763 mm = get_task_mm(tsk);
96764 if (!mm)
96765 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96766 index e58725a..e0be017 100644
96767 --- a/mm/mempolicy.c
96768 +++ b/mm/mempolicy.c
96769 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96770 unsigned long vmstart;
96771 unsigned long vmend;
96772
96773 +#ifdef CONFIG_PAX_SEGMEXEC
96774 + struct vm_area_struct *vma_m;
96775 +#endif
96776 +
96777 vma = find_vma(mm, start);
96778 if (!vma || vma->vm_start > start)
96779 return -EFAULT;
96780 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96781 err = vma_replace_policy(vma, new_pol);
96782 if (err)
96783 goto out;
96784 +
96785 +#ifdef CONFIG_PAX_SEGMEXEC
96786 + vma_m = pax_find_mirror_vma(vma);
96787 + if (vma_m) {
96788 + err = vma_replace_policy(vma_m, new_pol);
96789 + if (err)
96790 + goto out;
96791 + }
96792 +#endif
96793 +
96794 }
96795
96796 out:
96797 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96798
96799 if (end < start)
96800 return -EINVAL;
96801 +
96802 +#ifdef CONFIG_PAX_SEGMEXEC
96803 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96804 + if (end > SEGMEXEC_TASK_SIZE)
96805 + return -EINVAL;
96806 + } else
96807 +#endif
96808 +
96809 + if (end > TASK_SIZE)
96810 + return -EINVAL;
96811 +
96812 if (end == start)
96813 return 0;
96814
96815 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96816 */
96817 tcred = __task_cred(task);
96818 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96819 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96820 - !capable(CAP_SYS_NICE)) {
96821 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96822 rcu_read_unlock();
96823 err = -EPERM;
96824 goto out_put;
96825 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96826 goto out;
96827 }
96828
96829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96830 + if (mm != current->mm &&
96831 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96832 + mmput(mm);
96833 + err = -EPERM;
96834 + goto out;
96835 + }
96836 +#endif
96837 +
96838 err = do_migrate_pages(mm, old, new,
96839 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96840
96841 diff --git a/mm/migrate.c b/mm/migrate.c
96842 index 0143995..b294728 100644
96843 --- a/mm/migrate.c
96844 +++ b/mm/migrate.c
96845 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96846 */
96847 tcred = __task_cred(task);
96848 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96849 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96850 - !capable(CAP_SYS_NICE)) {
96851 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96852 rcu_read_unlock();
96853 err = -EPERM;
96854 goto out;
96855 diff --git a/mm/mlock.c b/mm/mlock.c
96856 index 73cf098..ab547c7 100644
96857 --- a/mm/mlock.c
96858 +++ b/mm/mlock.c
96859 @@ -14,6 +14,7 @@
96860 #include <linux/pagevec.h>
96861 #include <linux/mempolicy.h>
96862 #include <linux/syscalls.h>
96863 +#include <linux/security.h>
96864 #include <linux/sched.h>
96865 #include <linux/export.h>
96866 #include <linux/rmap.h>
96867 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96868 {
96869 unsigned long nstart, end, tmp;
96870 struct vm_area_struct * vma, * prev;
96871 - int error;
96872 + int error = 0;
96873
96874 VM_BUG_ON(start & ~PAGE_MASK);
96875 VM_BUG_ON(len != PAGE_ALIGN(len));
96876 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96877 return -EINVAL;
96878 if (end == start)
96879 return 0;
96880 + if (end > TASK_SIZE)
96881 + return -EINVAL;
96882 +
96883 vma = find_vma(current->mm, start);
96884 if (!vma || vma->vm_start > start)
96885 return -ENOMEM;
96886 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96887 for (nstart = start ; ; ) {
96888 vm_flags_t newflags;
96889
96890 +#ifdef CONFIG_PAX_SEGMEXEC
96891 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96892 + break;
96893 +#endif
96894 +
96895 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96896
96897 newflags = vma->vm_flags & ~VM_LOCKED;
96898 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96899 locked += current->mm->locked_vm;
96900
96901 /* check against resource limits */
96902 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96903 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96904 error = do_mlock(start, len, 1);
96905
96906 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96907 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96908 vm_flags_t newflags;
96909
96910 +#ifdef CONFIG_PAX_SEGMEXEC
96911 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96912 + break;
96913 +#endif
96914 +
96915 newflags = vma->vm_flags & ~VM_LOCKED;
96916 if (flags & MCL_CURRENT)
96917 newflags |= VM_LOCKED;
96918 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96919 lock_limit >>= PAGE_SHIFT;
96920
96921 ret = -ENOMEM;
96922 +
96923 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96924 +
96925 down_write(&current->mm->mmap_sem);
96926 -
96927 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96928 capable(CAP_IPC_LOCK))
96929 ret = do_mlockall(flags);
96930 diff --git a/mm/mmap.c b/mm/mmap.c
96931 index 1620adb..6b35ac8 100644
96932 --- a/mm/mmap.c
96933 +++ b/mm/mmap.c
96934 @@ -41,6 +41,7 @@
96935 #include <linux/notifier.h>
96936 #include <linux/memory.h>
96937 #include <linux/printk.h>
96938 +#include <linux/random.h>
96939
96940 #include <asm/uaccess.h>
96941 #include <asm/cacheflush.h>
96942 @@ -57,6 +58,16 @@
96943 #define arch_rebalance_pgtables(addr, len) (addr)
96944 #endif
96945
96946 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96947 +{
96948 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96949 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96950 + up_read(&mm->mmap_sem);
96951 + BUG();
96952 + }
96953 +#endif
96954 +}
96955 +
96956 static void unmap_region(struct mm_struct *mm,
96957 struct vm_area_struct *vma, struct vm_area_struct *prev,
96958 unsigned long start, unsigned long end);
96959 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96960 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96961 *
96962 */
96963 -pgprot_t protection_map[16] = {
96964 +pgprot_t protection_map[16] __read_only = {
96965 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96966 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96967 };
96968
96969 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96970 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96971 {
96972 - return __pgprot(pgprot_val(protection_map[vm_flags &
96973 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96974 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96975 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96976 +
96977 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96978 + if (!(__supported_pte_mask & _PAGE_NX) &&
96979 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96980 + (vm_flags & (VM_READ | VM_WRITE)))
96981 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96982 +#endif
96983 +
96984 + return prot;
96985 }
96986 EXPORT_SYMBOL(vm_get_page_prot);
96987
96988 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96989 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96990 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96991 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96992 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96993 /*
96994 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96995 * other variables. It can be updated by several CPUs frequently.
96996 @@ -152,7 +173,7 @@ EXPORT_SYMBOL_GPL(vm_memory_committed);
96997 */
96998 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
96999 {
97000 - unsigned long free, allowed, reserve;
97001 + long free, allowed, reserve;
97002
97003 VM_WARN_ONCE(percpu_counter_read(&vm_committed_as) <
97004 -(s64)vm_committed_as_batch * num_online_cpus(),
97005 @@ -220,7 +241,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
97006 */
97007 if (mm) {
97008 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
97009 - allowed -= min(mm->total_vm / 32, reserve);
97010 + allowed -= min_t(long, mm->total_vm / 32, reserve);
97011 }
97012
97013 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
97014 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97015 struct vm_area_struct *next = vma->vm_next;
97016
97017 might_sleep();
97018 + BUG_ON(vma->vm_mirror);
97019 if (vma->vm_ops && vma->vm_ops->close)
97020 vma->vm_ops->close(vma);
97021 if (vma->vm_file)
97022 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
97023
97024 SYSCALL_DEFINE1(brk, unsigned long, brk)
97025 {
97026 + unsigned long rlim;
97027 unsigned long retval;
97028 unsigned long newbrk, oldbrk;
97029 struct mm_struct *mm = current->mm;
97030 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97031 * segment grow beyond its set limit the in case where the limit is
97032 * not page aligned -Ram Gupta
97033 */
97034 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
97035 + rlim = rlimit(RLIMIT_DATA);
97036 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97037 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97038 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97039 + rlim = 4096 * PAGE_SIZE;
97040 +#endif
97041 + if (check_data_rlimit(rlim, brk, mm->start_brk,
97042 mm->end_data, mm->start_data))
97043 goto out;
97044
97045 @@ -976,6 +1005,12 @@ static int
97046 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97047 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97048 {
97049 +
97050 +#ifdef CONFIG_PAX_SEGMEXEC
97051 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97052 + return 0;
97053 +#endif
97054 +
97055 if (is_mergeable_vma(vma, file, vm_flags) &&
97056 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97057 if (vma->vm_pgoff == vm_pgoff)
97058 @@ -995,6 +1030,12 @@ static int
97059 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97060 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97061 {
97062 +
97063 +#ifdef CONFIG_PAX_SEGMEXEC
97064 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97065 + return 0;
97066 +#endif
97067 +
97068 if (is_mergeable_vma(vma, file, vm_flags) &&
97069 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97070 pgoff_t vm_pglen;
97071 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97072 struct vm_area_struct *area, *next;
97073 int err;
97074
97075 +#ifdef CONFIG_PAX_SEGMEXEC
97076 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97077 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97078 +
97079 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97080 +#endif
97081 +
97082 /*
97083 * We later require that vma->vm_flags == vm_flags,
97084 * so this tests vma->vm_flags & VM_SPECIAL, too.
97085 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97086 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97087 next = next->vm_next;
97088
97089 +#ifdef CONFIG_PAX_SEGMEXEC
97090 + if (prev)
97091 + prev_m = pax_find_mirror_vma(prev);
97092 + if (area)
97093 + area_m = pax_find_mirror_vma(area);
97094 + if (next)
97095 + next_m = pax_find_mirror_vma(next);
97096 +#endif
97097 +
97098 /*
97099 * Can it merge with the predecessor?
97100 */
97101 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97102 /* cases 1, 6 */
97103 err = vma_adjust(prev, prev->vm_start,
97104 next->vm_end, prev->vm_pgoff, NULL);
97105 - } else /* cases 2, 5, 7 */
97106 +
97107 +#ifdef CONFIG_PAX_SEGMEXEC
97108 + if (!err && prev_m)
97109 + err = vma_adjust(prev_m, prev_m->vm_start,
97110 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97111 +#endif
97112 +
97113 + } else { /* cases 2, 5, 7 */
97114 err = vma_adjust(prev, prev->vm_start,
97115 end, prev->vm_pgoff, NULL);
97116 +
97117 +#ifdef CONFIG_PAX_SEGMEXEC
97118 + if (!err && prev_m)
97119 + err = vma_adjust(prev_m, prev_m->vm_start,
97120 + end_m, prev_m->vm_pgoff, NULL);
97121 +#endif
97122 +
97123 + }
97124 if (err)
97125 return NULL;
97126 khugepaged_enter_vma_merge(prev, vm_flags);
97127 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97128 mpol_equal(policy, vma_policy(next)) &&
97129 can_vma_merge_before(next, vm_flags,
97130 anon_vma, file, pgoff+pglen)) {
97131 - if (prev && addr < prev->vm_end) /* case 4 */
97132 + if (prev && addr < prev->vm_end) { /* case 4 */
97133 err = vma_adjust(prev, prev->vm_start,
97134 addr, prev->vm_pgoff, NULL);
97135 - else /* cases 3, 8 */
97136 +
97137 +#ifdef CONFIG_PAX_SEGMEXEC
97138 + if (!err && prev_m)
97139 + err = vma_adjust(prev_m, prev_m->vm_start,
97140 + addr_m, prev_m->vm_pgoff, NULL);
97141 +#endif
97142 +
97143 + } else { /* cases 3, 8 */
97144 err = vma_adjust(area, addr, next->vm_end,
97145 next->vm_pgoff - pglen, NULL);
97146 +
97147 +#ifdef CONFIG_PAX_SEGMEXEC
97148 + if (!err && area_m)
97149 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97150 + next_m->vm_pgoff - pglen, NULL);
97151 +#endif
97152 +
97153 + }
97154 if (err)
97155 return NULL;
97156 khugepaged_enter_vma_merge(area, vm_flags);
97157 @@ -1208,8 +1295,10 @@ none:
97158 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97159 struct file *file, long pages)
97160 {
97161 - const unsigned long stack_flags
97162 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97163 +
97164 +#ifdef CONFIG_PAX_RANDMMAP
97165 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97166 +#endif
97167
97168 mm->total_vm += pages;
97169
97170 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97171 mm->shared_vm += pages;
97172 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97173 mm->exec_vm += pages;
97174 - } else if (flags & stack_flags)
97175 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97176 mm->stack_vm += pages;
97177 }
97178 #endif /* CONFIG_PROC_FS */
97179 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97180 locked += mm->locked_vm;
97181 lock_limit = rlimit(RLIMIT_MEMLOCK);
97182 lock_limit >>= PAGE_SHIFT;
97183 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97184 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97185 return -EAGAIN;
97186 }
97187 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97188 * (the exception is when the underlying filesystem is noexec
97189 * mounted, in which case we dont add PROT_EXEC.)
97190 */
97191 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97192 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97193 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97194 prot |= PROT_EXEC;
97195
97196 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97197 /* Obtain the address to map to. we verify (or select) it and ensure
97198 * that it represents a valid section of the address space.
97199 */
97200 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97201 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97202 if (addr & ~PAGE_MASK)
97203 return addr;
97204
97205 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97206 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97207 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97208
97209 +#ifdef CONFIG_PAX_MPROTECT
97210 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97211 +
97212 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97213 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97214 + mm->binfmt->handle_mmap)
97215 + mm->binfmt->handle_mmap(file);
97216 +#endif
97217 +
97218 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97219 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97220 + gr_log_rwxmmap(file);
97221 +
97222 +#ifdef CONFIG_PAX_EMUPLT
97223 + vm_flags &= ~VM_EXEC;
97224 +#else
97225 + return -EPERM;
97226 +#endif
97227 +
97228 + }
97229 +
97230 + if (!(vm_flags & VM_EXEC))
97231 + vm_flags &= ~VM_MAYEXEC;
97232 +#else
97233 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97234 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97235 +#endif
97236 + else
97237 + vm_flags &= ~VM_MAYWRITE;
97238 + }
97239 +#endif
97240 +
97241 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97242 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97243 + vm_flags &= ~VM_PAGEEXEC;
97244 +#endif
97245 +
97246 if (flags & MAP_LOCKED)
97247 if (!can_do_mlock())
97248 return -EPERM;
97249 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97250 vm_flags |= VM_NORESERVE;
97251 }
97252
97253 + if (!gr_acl_handle_mmap(file, prot))
97254 + return -EACCES;
97255 +
97256 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97257 if (!IS_ERR_VALUE(addr) &&
97258 ((vm_flags & VM_LOCKED) ||
97259 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97260 vm_flags_t vm_flags = vma->vm_flags;
97261
97262 /* If it was private or non-writable, the write bit is already clear */
97263 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97264 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97265 return 0;
97266
97267 /* The backer wishes to know when pages are first written to? */
97268 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97269 struct rb_node **rb_link, *rb_parent;
97270 unsigned long charged = 0;
97271
97272 +#ifdef CONFIG_PAX_SEGMEXEC
97273 + struct vm_area_struct *vma_m = NULL;
97274 +#endif
97275 +
97276 + /*
97277 + * mm->mmap_sem is required to protect against another thread
97278 + * changing the mappings in case we sleep.
97279 + */
97280 + verify_mm_writelocked(mm);
97281 +
97282 /* Check against address space limit. */
97283 +
97284 +#ifdef CONFIG_PAX_RANDMMAP
97285 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97286 +#endif
97287 +
97288 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97289 unsigned long nr_pages;
97290
97291 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97292
97293 /* Clear old maps */
97294 error = -ENOMEM;
97295 -munmap_back:
97296 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97297 if (do_munmap(mm, addr, len))
97298 return -ENOMEM;
97299 - goto munmap_back;
97300 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97301 }
97302
97303 /*
97304 @@ -1595,6 +1739,16 @@ munmap_back:
97305 goto unacct_error;
97306 }
97307
97308 +#ifdef CONFIG_PAX_SEGMEXEC
97309 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97310 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97311 + if (!vma_m) {
97312 + error = -ENOMEM;
97313 + goto free_vma;
97314 + }
97315 + }
97316 +#endif
97317 +
97318 vma->vm_mm = mm;
97319 vma->vm_start = addr;
97320 vma->vm_end = addr + len;
97321 @@ -1625,6 +1779,13 @@ munmap_back:
97322 if (error)
97323 goto unmap_and_free_vma;
97324
97325 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97326 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97327 + vma->vm_flags |= VM_PAGEEXEC;
97328 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97329 + }
97330 +#endif
97331 +
97332 /* Can addr have changed??
97333 *
97334 * Answer: Yes, several device drivers can do it in their
97335 @@ -1643,6 +1804,12 @@ munmap_back:
97336 }
97337
97338 vma_link(mm, vma, prev, rb_link, rb_parent);
97339 +
97340 +#ifdef CONFIG_PAX_SEGMEXEC
97341 + if (vma_m)
97342 + BUG_ON(pax_mirror_vma(vma_m, vma));
97343 +#endif
97344 +
97345 /* Once vma denies write, undo our temporary denial count */
97346 if (file) {
97347 if (vm_flags & VM_SHARED)
97348 @@ -1655,6 +1822,7 @@ out:
97349 perf_event_mmap(vma);
97350
97351 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97352 + track_exec_limit(mm, addr, addr + len, vm_flags);
97353 if (vm_flags & VM_LOCKED) {
97354 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97355 vma == get_gate_vma(current->mm)))
97356 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97357 if (vm_flags & VM_DENYWRITE)
97358 allow_write_access(file);
97359 free_vma:
97360 +
97361 +#ifdef CONFIG_PAX_SEGMEXEC
97362 + if (vma_m)
97363 + kmem_cache_free(vm_area_cachep, vma_m);
97364 +#endif
97365 +
97366 kmem_cache_free(vm_area_cachep, vma);
97367 unacct_error:
97368 if (charged)
97369 @@ -1699,7 +1873,63 @@ unacct_error:
97370 return error;
97371 }
97372
97373 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97374 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97375 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97376 +{
97377 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97378 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97379 +
97380 + return 0;
97381 +}
97382 +#endif
97383 +
97384 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97385 +{
97386 + if (!vma) {
97387 +#ifdef CONFIG_STACK_GROWSUP
97388 + if (addr > sysctl_heap_stack_gap)
97389 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97390 + else
97391 + vma = find_vma(current->mm, 0);
97392 + if (vma && (vma->vm_flags & VM_GROWSUP))
97393 + return false;
97394 +#endif
97395 + return true;
97396 + }
97397 +
97398 + if (addr + len > vma->vm_start)
97399 + return false;
97400 +
97401 + if (vma->vm_flags & VM_GROWSDOWN)
97402 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97403 +#ifdef CONFIG_STACK_GROWSUP
97404 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97405 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97406 +#endif
97407 + else if (offset)
97408 + return offset <= vma->vm_start - addr - len;
97409 +
97410 + return true;
97411 +}
97412 +
97413 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97414 +{
97415 + if (vma->vm_start < len)
97416 + return -ENOMEM;
97417 +
97418 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97419 + if (offset <= vma->vm_start - len)
97420 + return vma->vm_start - len - offset;
97421 + else
97422 + return -ENOMEM;
97423 + }
97424 +
97425 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97426 + return vma->vm_start - len - sysctl_heap_stack_gap;
97427 + return -ENOMEM;
97428 +}
97429 +
97430 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97431 {
97432 /*
97433 * We implement the search by looking for an rbtree node that
97434 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97435 }
97436 }
97437
97438 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97439 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97440 check_current:
97441 /* Check if current node has a suitable gap */
97442 if (gap_start > high_limit)
97443 return -ENOMEM;
97444 +
97445 + if (gap_end - gap_start > info->threadstack_offset)
97446 + gap_start += info->threadstack_offset;
97447 + else
97448 + gap_start = gap_end;
97449 +
97450 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97451 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97452 + gap_start += sysctl_heap_stack_gap;
97453 + else
97454 + gap_start = gap_end;
97455 + }
97456 + if (vma->vm_flags & VM_GROWSDOWN) {
97457 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97458 + gap_end -= sysctl_heap_stack_gap;
97459 + else
97460 + gap_end = gap_start;
97461 + }
97462 if (gap_end >= low_limit && gap_end - gap_start >= length)
97463 goto found;
97464
97465 @@ -1801,7 +2049,7 @@ found:
97466 return gap_start;
97467 }
97468
97469 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97470 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97471 {
97472 struct mm_struct *mm = current->mm;
97473 struct vm_area_struct *vma;
97474 @@ -1855,6 +2103,24 @@ check_current:
97475 gap_end = vma->vm_start;
97476 if (gap_end < low_limit)
97477 return -ENOMEM;
97478 +
97479 + if (gap_end - gap_start > info->threadstack_offset)
97480 + gap_end -= info->threadstack_offset;
97481 + else
97482 + gap_end = gap_start;
97483 +
97484 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97485 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97486 + gap_start += sysctl_heap_stack_gap;
97487 + else
97488 + gap_start = gap_end;
97489 + }
97490 + if (vma->vm_flags & VM_GROWSDOWN) {
97491 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97492 + gap_end -= sysctl_heap_stack_gap;
97493 + else
97494 + gap_end = gap_start;
97495 + }
97496 if (gap_start <= high_limit && gap_end - gap_start >= length)
97497 goto found;
97498
97499 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97500 struct mm_struct *mm = current->mm;
97501 struct vm_area_struct *vma;
97502 struct vm_unmapped_area_info info;
97503 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97504
97505 if (len > TASK_SIZE - mmap_min_addr)
97506 return -ENOMEM;
97507 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97508 if (flags & MAP_FIXED)
97509 return addr;
97510
97511 +#ifdef CONFIG_PAX_RANDMMAP
97512 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97513 +#endif
97514 +
97515 if (addr) {
97516 addr = PAGE_ALIGN(addr);
97517 vma = find_vma(mm, addr);
97518 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97519 - (!vma || addr + len <= vma->vm_start))
97520 + check_heap_stack_gap(vma, addr, len, offset))
97521 return addr;
97522 }
97523
97524 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97525 info.low_limit = mm->mmap_base;
97526 info.high_limit = TASK_SIZE;
97527 info.align_mask = 0;
97528 + info.threadstack_offset = offset;
97529 return vm_unmapped_area(&info);
97530 }
97531 #endif
97532 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97533 struct mm_struct *mm = current->mm;
97534 unsigned long addr = addr0;
97535 struct vm_unmapped_area_info info;
97536 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97537
97538 /* requested length too big for entire address space */
97539 if (len > TASK_SIZE - mmap_min_addr)
97540 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97541 if (flags & MAP_FIXED)
97542 return addr;
97543
97544 +#ifdef CONFIG_PAX_RANDMMAP
97545 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97546 +#endif
97547 +
97548 /* requesting a specific address */
97549 if (addr) {
97550 addr = PAGE_ALIGN(addr);
97551 vma = find_vma(mm, addr);
97552 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97553 - (!vma || addr + len <= vma->vm_start))
97554 + check_heap_stack_gap(vma, addr, len, offset))
97555 return addr;
97556 }
97557
97558 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97559 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97560 info.high_limit = mm->mmap_base;
97561 info.align_mask = 0;
97562 + info.threadstack_offset = offset;
97563 addr = vm_unmapped_area(&info);
97564
97565 /*
97566 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97567 VM_BUG_ON(addr != -ENOMEM);
97568 info.flags = 0;
97569 info.low_limit = TASK_UNMAPPED_BASE;
97570 +
97571 +#ifdef CONFIG_PAX_RANDMMAP
97572 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97573 + info.low_limit += mm->delta_mmap;
97574 +#endif
97575 +
97576 info.high_limit = TASK_SIZE;
97577 addr = vm_unmapped_area(&info);
97578 }
97579 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97580 return vma;
97581 }
97582
97583 +#ifdef CONFIG_PAX_SEGMEXEC
97584 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97585 +{
97586 + struct vm_area_struct *vma_m;
97587 +
97588 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97589 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97590 + BUG_ON(vma->vm_mirror);
97591 + return NULL;
97592 + }
97593 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97594 + vma_m = vma->vm_mirror;
97595 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97596 + BUG_ON(vma->vm_file != vma_m->vm_file);
97597 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97598 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97599 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97600 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97601 + return vma_m;
97602 +}
97603 +#endif
97604 +
97605 /*
97606 * Verify that the stack growth is acceptable and
97607 * update accounting. This is shared with both the
97608 @@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97609
97610 /* Stack limit test */
97611 actual_size = size;
97612 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
97613 - actual_size -= PAGE_SIZE;
97614 + gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
97615 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97616 return -ENOMEM;
97617
97618 @@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97619 locked = mm->locked_vm + grow;
97620 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97621 limit >>= PAGE_SHIFT;
97622 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97623 if (locked > limit && !capable(CAP_IPC_LOCK))
97624 return -ENOMEM;
97625 }
97626 @@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97627 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97628 * vma is the last one with address > vma->vm_end. Have to extend vma.
97629 */
97630 +#ifndef CONFIG_IA64
97631 +static
97632 +#endif
97633 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97634 {
97635 int error;
97636 + bool locknext;
97637
97638 if (!(vma->vm_flags & VM_GROWSUP))
97639 return -EFAULT;
97640
97641 + /* Also guard against wrapping around to address 0. */
97642 + if (address < PAGE_ALIGN(address+1))
97643 + address = PAGE_ALIGN(address+1);
97644 + else
97645 + return -ENOMEM;
97646 +
97647 /*
97648 * We must make sure the anon_vma is allocated
97649 * so that the anon_vma locking is not a noop.
97650 */
97651 if (unlikely(anon_vma_prepare(vma)))
97652 return -ENOMEM;
97653 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97654 + if (locknext && anon_vma_prepare(vma->vm_next))
97655 + return -ENOMEM;
97656 vma_lock_anon_vma(vma);
97657 + if (locknext)
97658 + vma_lock_anon_vma(vma->vm_next);
97659
97660 /*
97661 * vma->vm_start/vm_end cannot change under us because the caller
97662 * is required to hold the mmap_sem in read mode. We need the
97663 - * anon_vma lock to serialize against concurrent expand_stacks.
97664 - * Also guard against wrapping around to address 0.
97665 + * anon_vma locks to serialize against concurrent expand_stacks
97666 + * and expand_upwards.
97667 */
97668 - if (address < PAGE_ALIGN(address+4))
97669 - address = PAGE_ALIGN(address+4);
97670 - else {
97671 - vma_unlock_anon_vma(vma);
97672 - return -ENOMEM;
97673 - }
97674 error = 0;
97675
97676 /* Somebody else might have raced and expanded it already */
97677 - if (address > vma->vm_end) {
97678 + 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)
97679 + error = -ENOMEM;
97680 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97681 unsigned long size, grow;
97682
97683 size = address - vma->vm_start;
97684 @@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97685 }
97686 }
97687 }
97688 + if (locknext)
97689 + vma_unlock_anon_vma(vma->vm_next);
97690 vma_unlock_anon_vma(vma);
97691 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97692 validate_mm(vma->vm_mm);
97693 @@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97694 unsigned long address)
97695 {
97696 int error;
97697 + bool lockprev = false;
97698 + struct vm_area_struct *prev;
97699
97700 /*
97701 * We must make sure the anon_vma is allocated
97702 @@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97703 if (error)
97704 return error;
97705
97706 + prev = vma->vm_prev;
97707 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97708 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97709 +#endif
97710 + if (lockprev && anon_vma_prepare(prev))
97711 + return -ENOMEM;
97712 + if (lockprev)
97713 + vma_lock_anon_vma(prev);
97714 +
97715 vma_lock_anon_vma(vma);
97716
97717 /*
97718 @@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97719 */
97720
97721 /* Somebody else might have raced and expanded it already */
97722 - if (address < vma->vm_start) {
97723 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97724 + error = -ENOMEM;
97725 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97726 unsigned long size, grow;
97727
97728 +#ifdef CONFIG_PAX_SEGMEXEC
97729 + struct vm_area_struct *vma_m;
97730 +
97731 + vma_m = pax_find_mirror_vma(vma);
97732 +#endif
97733 +
97734 size = vma->vm_end - address;
97735 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97736
97737 @@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97738 vma->vm_pgoff -= grow;
97739 anon_vma_interval_tree_post_update_vma(vma);
97740 vma_gap_update(vma);
97741 +
97742 +#ifdef CONFIG_PAX_SEGMEXEC
97743 + if (vma_m) {
97744 + anon_vma_interval_tree_pre_update_vma(vma_m);
97745 + vma_m->vm_start -= grow << PAGE_SHIFT;
97746 + vma_m->vm_pgoff -= grow;
97747 + anon_vma_interval_tree_post_update_vma(vma_m);
97748 + vma_gap_update(vma_m);
97749 + }
97750 +#endif
97751 +
97752 spin_unlock(&vma->vm_mm->page_table_lock);
97753
97754 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97755 perf_event_mmap(vma);
97756 }
97757 }
97758 }
97759 vma_unlock_anon_vma(vma);
97760 + if (lockprev)
97761 + vma_unlock_anon_vma(prev);
97762 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97763 validate_mm(vma->vm_mm);
97764 return error;
97765 @@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97766 do {
97767 long nrpages = vma_pages(vma);
97768
97769 +#ifdef CONFIG_PAX_SEGMEXEC
97770 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97771 + vma = remove_vma(vma);
97772 + continue;
97773 + }
97774 +#endif
97775 +
97776 if (vma->vm_flags & VM_ACCOUNT)
97777 nr_accounted += nrpages;
97778 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97779 @@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97780 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97781 vma->vm_prev = NULL;
97782 do {
97783 +
97784 +#ifdef CONFIG_PAX_SEGMEXEC
97785 + if (vma->vm_mirror) {
97786 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97787 + vma->vm_mirror->vm_mirror = NULL;
97788 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97789 + vma->vm_mirror = NULL;
97790 + }
97791 +#endif
97792 +
97793 vma_rb_erase(vma, &mm->mm_rb);
97794 mm->map_count--;
97795 tail_vma = vma;
97796 @@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97797 struct vm_area_struct *new;
97798 int err = -ENOMEM;
97799
97800 +#ifdef CONFIG_PAX_SEGMEXEC
97801 + struct vm_area_struct *vma_m, *new_m = NULL;
97802 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97803 +#endif
97804 +
97805 if (is_vm_hugetlb_page(vma) && (addr &
97806 ~(huge_page_mask(hstate_vma(vma)))))
97807 return -EINVAL;
97808
97809 +#ifdef CONFIG_PAX_SEGMEXEC
97810 + vma_m = pax_find_mirror_vma(vma);
97811 +#endif
97812 +
97813 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97814 if (!new)
97815 goto out_err;
97816
97817 +#ifdef CONFIG_PAX_SEGMEXEC
97818 + if (vma_m) {
97819 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97820 + if (!new_m) {
97821 + kmem_cache_free(vm_area_cachep, new);
97822 + goto out_err;
97823 + }
97824 + }
97825 +#endif
97826 +
97827 /* most fields are the same, copy all, and then fixup */
97828 *new = *vma;
97829
97830 @@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97831 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97832 }
97833
97834 +#ifdef CONFIG_PAX_SEGMEXEC
97835 + if (vma_m) {
97836 + *new_m = *vma_m;
97837 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97838 + new_m->vm_mirror = new;
97839 + new->vm_mirror = new_m;
97840 +
97841 + if (new_below)
97842 + new_m->vm_end = addr_m;
97843 + else {
97844 + new_m->vm_start = addr_m;
97845 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97846 + }
97847 + }
97848 +#endif
97849 +
97850 err = vma_dup_policy(vma, new);
97851 if (err)
97852 goto out_free_vma;
97853 @@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97854 else
97855 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97856
97857 +#ifdef CONFIG_PAX_SEGMEXEC
97858 + if (!err && vma_m) {
97859 + struct mempolicy *pol = vma_policy(new);
97860 +
97861 + if (anon_vma_clone(new_m, vma_m))
97862 + goto out_free_mpol;
97863 +
97864 + mpol_get(pol);
97865 + set_vma_policy(new_m, pol);
97866 +
97867 + if (new_m->vm_file)
97868 + get_file(new_m->vm_file);
97869 +
97870 + if (new_m->vm_ops && new_m->vm_ops->open)
97871 + new_m->vm_ops->open(new_m);
97872 +
97873 + if (new_below)
97874 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97875 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97876 + else
97877 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97878 +
97879 + if (err) {
97880 + if (new_m->vm_ops && new_m->vm_ops->close)
97881 + new_m->vm_ops->close(new_m);
97882 + if (new_m->vm_file)
97883 + fput(new_m->vm_file);
97884 + mpol_put(pol);
97885 + }
97886 + }
97887 +#endif
97888 +
97889 /* Success. */
97890 if (!err)
97891 return 0;
97892 @@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97893 new->vm_ops->close(new);
97894 if (new->vm_file)
97895 fput(new->vm_file);
97896 - unlink_anon_vmas(new);
97897 out_free_mpol:
97898 mpol_put(vma_policy(new));
97899 out_free_vma:
97900 +
97901 +#ifdef CONFIG_PAX_SEGMEXEC
97902 + if (new_m) {
97903 + unlink_anon_vmas(new_m);
97904 + kmem_cache_free(vm_area_cachep, new_m);
97905 + }
97906 +#endif
97907 +
97908 + unlink_anon_vmas(new);
97909 kmem_cache_free(vm_area_cachep, new);
97910 out_err:
97911 return err;
97912 @@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97913 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97914 unsigned long addr, int new_below)
97915 {
97916 +
97917 +#ifdef CONFIG_PAX_SEGMEXEC
97918 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97919 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97920 + if (mm->map_count >= sysctl_max_map_count-1)
97921 + return -ENOMEM;
97922 + } else
97923 +#endif
97924 +
97925 if (mm->map_count >= sysctl_max_map_count)
97926 return -ENOMEM;
97927
97928 @@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97929 * work. This now handles partial unmappings.
97930 * Jeremy Fitzhardinge <jeremy@goop.org>
97931 */
97932 +#ifdef CONFIG_PAX_SEGMEXEC
97933 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97934 {
97935 + int ret = __do_munmap(mm, start, len);
97936 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97937 + return ret;
97938 +
97939 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97940 +}
97941 +
97942 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97943 +#else
97944 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97945 +#endif
97946 +{
97947 unsigned long end;
97948 struct vm_area_struct *vma, *prev, *last;
97949
97950 + /*
97951 + * mm->mmap_sem is required to protect against another thread
97952 + * changing the mappings in case we sleep.
97953 + */
97954 + verify_mm_writelocked(mm);
97955 +
97956 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97957 return -EINVAL;
97958
97959 @@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97960 /* Fix up all other VM information */
97961 remove_vma_list(mm, vma);
97962
97963 + track_exec_limit(mm, start, end, 0UL);
97964 +
97965 return 0;
97966 }
97967
97968 @@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
97969 int ret;
97970 struct mm_struct *mm = current->mm;
97971
97972 +
97973 +#ifdef CONFIG_PAX_SEGMEXEC
97974 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97975 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97976 + return -EINVAL;
97977 +#endif
97978 +
97979 down_write(&mm->mmap_sem);
97980 ret = do_munmap(mm, start, len);
97981 up_write(&mm->mmap_sem);
97982 @@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97983 return vm_munmap(addr, len);
97984 }
97985
97986 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97987 -{
97988 -#ifdef CONFIG_DEBUG_VM
97989 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97990 - WARN_ON(1);
97991 - up_read(&mm->mmap_sem);
97992 - }
97993 -#endif
97994 -}
97995 -
97996 /*
97997 * this is really a simplified "do_mmap". it only handles
97998 * anonymous maps. eventually we may be able to do some
97999 @@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98000 struct rb_node **rb_link, *rb_parent;
98001 pgoff_t pgoff = addr >> PAGE_SHIFT;
98002 int error;
98003 + unsigned long charged;
98004
98005 len = PAGE_ALIGN(len);
98006 if (!len)
98007 @@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98008
98009 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98010
98011 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98012 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98013 + flags &= ~VM_EXEC;
98014 +
98015 +#ifdef CONFIG_PAX_MPROTECT
98016 + if (mm->pax_flags & MF_PAX_MPROTECT)
98017 + flags &= ~VM_MAYEXEC;
98018 +#endif
98019 +
98020 + }
98021 +#endif
98022 +
98023 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98024 if (error & ~PAGE_MASK)
98025 return error;
98026
98027 + charged = len >> PAGE_SHIFT;
98028 +
98029 error = mlock_future_check(mm, mm->def_flags, len);
98030 if (error)
98031 return error;
98032 @@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98033 /*
98034 * Clear old maps. this also does some error checking for us
98035 */
98036 - munmap_back:
98037 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98038 if (do_munmap(mm, addr, len))
98039 return -ENOMEM;
98040 - goto munmap_back;
98041 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98042 }
98043
98044 /* Check against address space limits *after* clearing old maps... */
98045 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98046 + if (!may_expand_vm(mm, charged))
98047 return -ENOMEM;
98048
98049 if (mm->map_count > sysctl_max_map_count)
98050 return -ENOMEM;
98051
98052 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98053 + if (security_vm_enough_memory_mm(mm, charged))
98054 return -ENOMEM;
98055
98056 /* Can we just expand an old private anonymous mapping? */
98057 @@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98058 */
98059 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98060 if (!vma) {
98061 - vm_unacct_memory(len >> PAGE_SHIFT);
98062 + vm_unacct_memory(charged);
98063 return -ENOMEM;
98064 }
98065
98066 @@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98067 vma_link(mm, vma, prev, rb_link, rb_parent);
98068 out:
98069 perf_event_mmap(vma);
98070 - mm->total_vm += len >> PAGE_SHIFT;
98071 + mm->total_vm += charged;
98072 if (flags & VM_LOCKED)
98073 - mm->locked_vm += (len >> PAGE_SHIFT);
98074 + mm->locked_vm += charged;
98075 vma->vm_flags |= VM_SOFTDIRTY;
98076 + track_exec_limit(mm, addr, addr + len, flags);
98077 return addr;
98078 }
98079
98080 @@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
98081 while (vma) {
98082 if (vma->vm_flags & VM_ACCOUNT)
98083 nr_accounted += vma_pages(vma);
98084 + vma->vm_mirror = NULL;
98085 vma = remove_vma(vma);
98086 }
98087 vm_unacct_memory(nr_accounted);
98088 @@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98089 struct vm_area_struct *prev;
98090 struct rb_node **rb_link, *rb_parent;
98091
98092 +#ifdef CONFIG_PAX_SEGMEXEC
98093 + struct vm_area_struct *vma_m = NULL;
98094 +#endif
98095 +
98096 + if (security_mmap_addr(vma->vm_start))
98097 + return -EPERM;
98098 +
98099 /*
98100 * The vm_pgoff of a purely anonymous vma should be irrelevant
98101 * until its first write fault, when page's anon_vma and index
98102 @@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98103 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98104 return -ENOMEM;
98105
98106 +#ifdef CONFIG_PAX_SEGMEXEC
98107 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98108 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98109 + if (!vma_m)
98110 + return -ENOMEM;
98111 + }
98112 +#endif
98113 +
98114 vma_link(mm, vma, prev, rb_link, rb_parent);
98115 +
98116 +#ifdef CONFIG_PAX_SEGMEXEC
98117 + if (vma_m)
98118 + BUG_ON(pax_mirror_vma(vma_m, vma));
98119 +#endif
98120 +
98121 return 0;
98122 }
98123
98124 @@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98125 struct rb_node **rb_link, *rb_parent;
98126 bool faulted_in_anon_vma = true;
98127
98128 + BUG_ON(vma->vm_mirror);
98129 +
98130 /*
98131 * If anonymous vma has not yet been faulted, update new pgoff
98132 * to match new location, to increase its chance of merging.
98133 @@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98134 return NULL;
98135 }
98136
98137 +#ifdef CONFIG_PAX_SEGMEXEC
98138 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98139 +{
98140 + struct vm_area_struct *prev_m;
98141 + struct rb_node **rb_link_m, *rb_parent_m;
98142 + struct mempolicy *pol_m;
98143 +
98144 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98145 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98146 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98147 + *vma_m = *vma;
98148 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98149 + if (anon_vma_clone(vma_m, vma))
98150 + return -ENOMEM;
98151 + pol_m = vma_policy(vma_m);
98152 + mpol_get(pol_m);
98153 + set_vma_policy(vma_m, pol_m);
98154 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98155 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98156 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98157 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98158 + if (vma_m->vm_file)
98159 + get_file(vma_m->vm_file);
98160 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98161 + vma_m->vm_ops->open(vma_m);
98162 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98163 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98164 + vma_m->vm_mirror = vma;
98165 + vma->vm_mirror = vma_m;
98166 + return 0;
98167 +}
98168 +#endif
98169 +
98170 /*
98171 * Return true if the calling process may expand its vm space by the passed
98172 * number of pages
98173 @@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98174
98175 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98176
98177 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98178 if (cur + npages > lim)
98179 return 0;
98180 return 1;
98181 @@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
98182 vma->vm_start = addr;
98183 vma->vm_end = addr + len;
98184
98185 +#ifdef CONFIG_PAX_MPROTECT
98186 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98187 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98188 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98189 + return ERR_PTR(-EPERM);
98190 + if (!(vm_flags & VM_EXEC))
98191 + vm_flags &= ~VM_MAYEXEC;
98192 +#else
98193 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98194 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98195 +#endif
98196 + else
98197 + vm_flags &= ~VM_MAYWRITE;
98198 + }
98199 +#endif
98200 +
98201 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98202 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98203
98204 diff --git a/mm/mprotect.c b/mm/mprotect.c
98205 index ace9345..63320dc 100644
98206 --- a/mm/mprotect.c
98207 +++ b/mm/mprotect.c
98208 @@ -24,10 +24,18 @@
98209 #include <linux/migrate.h>
98210 #include <linux/perf_event.h>
98211 #include <linux/ksm.h>
98212 +#include <linux/sched/sysctl.h>
98213 +
98214 +#ifdef CONFIG_PAX_MPROTECT
98215 +#include <linux/elf.h>
98216 +#include <linux/binfmts.h>
98217 +#endif
98218 +
98219 #include <asm/uaccess.h>
98220 #include <asm/pgtable.h>
98221 #include <asm/cacheflush.h>
98222 #include <asm/tlbflush.h>
98223 +#include <asm/mmu_context.h>
98224
98225 /*
98226 * For a prot_numa update we only hold mmap_sem for read so there is a
98227 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98228 return pages;
98229 }
98230
98231 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98232 +/* called while holding the mmap semaphor for writing except stack expansion */
98233 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98234 +{
98235 + unsigned long oldlimit, newlimit = 0UL;
98236 +
98237 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98238 + return;
98239 +
98240 + spin_lock(&mm->page_table_lock);
98241 + oldlimit = mm->context.user_cs_limit;
98242 + if ((prot & VM_EXEC) && oldlimit < end)
98243 + /* USER_CS limit moved up */
98244 + newlimit = end;
98245 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98246 + /* USER_CS limit moved down */
98247 + newlimit = start;
98248 +
98249 + if (newlimit) {
98250 + mm->context.user_cs_limit = newlimit;
98251 +
98252 +#ifdef CONFIG_SMP
98253 + wmb();
98254 + cpus_clear(mm->context.cpu_user_cs_mask);
98255 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98256 +#endif
98257 +
98258 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98259 + }
98260 + spin_unlock(&mm->page_table_lock);
98261 + if (newlimit == end) {
98262 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98263 +
98264 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98265 + if (is_vm_hugetlb_page(vma))
98266 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98267 + else
98268 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98269 + }
98270 +}
98271 +#endif
98272 +
98273 int
98274 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98275 unsigned long start, unsigned long end, unsigned long newflags)
98276 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98277 int error;
98278 int dirty_accountable = 0;
98279
98280 +#ifdef CONFIG_PAX_SEGMEXEC
98281 + struct vm_area_struct *vma_m = NULL;
98282 + unsigned long start_m, end_m;
98283 +
98284 + start_m = start + SEGMEXEC_TASK_SIZE;
98285 + end_m = end + SEGMEXEC_TASK_SIZE;
98286 +#endif
98287 +
98288 if (newflags == oldflags) {
98289 *pprev = vma;
98290 return 0;
98291 }
98292
98293 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98294 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98295 +
98296 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98297 + return -ENOMEM;
98298 +
98299 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98300 + return -ENOMEM;
98301 + }
98302 +
98303 /*
98304 * If we make a private mapping writable we increase our commit;
98305 * but (without finer accounting) cannot reduce our commit if we
98306 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98307 }
98308 }
98309
98310 +#ifdef CONFIG_PAX_SEGMEXEC
98311 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98312 + if (start != vma->vm_start) {
98313 + error = split_vma(mm, vma, start, 1);
98314 + if (error)
98315 + goto fail;
98316 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98317 + *pprev = (*pprev)->vm_next;
98318 + }
98319 +
98320 + if (end != vma->vm_end) {
98321 + error = split_vma(mm, vma, end, 0);
98322 + if (error)
98323 + goto fail;
98324 + }
98325 +
98326 + if (pax_find_mirror_vma(vma)) {
98327 + error = __do_munmap(mm, start_m, end_m - start_m);
98328 + if (error)
98329 + goto fail;
98330 + } else {
98331 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98332 + if (!vma_m) {
98333 + error = -ENOMEM;
98334 + goto fail;
98335 + }
98336 + vma->vm_flags = newflags;
98337 + error = pax_mirror_vma(vma_m, vma);
98338 + if (error) {
98339 + vma->vm_flags = oldflags;
98340 + goto fail;
98341 + }
98342 + }
98343 + }
98344 +#endif
98345 +
98346 /*
98347 * First try to merge with previous and/or next vma.
98348 */
98349 @@ -314,7 +418,19 @@ success:
98350 * vm_flags and vm_page_prot are protected by the mmap_sem
98351 * held in write mode.
98352 */
98353 +
98354 +#ifdef CONFIG_PAX_SEGMEXEC
98355 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98356 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98357 +#endif
98358 +
98359 vma->vm_flags = newflags;
98360 +
98361 +#ifdef CONFIG_PAX_MPROTECT
98362 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98363 + mm->binfmt->handle_mprotect(vma, newflags);
98364 +#endif
98365 +
98366 dirty_accountable = vma_wants_writenotify(vma);
98367 vma_set_page_prot(vma);
98368
98369 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98370 end = start + len;
98371 if (end <= start)
98372 return -ENOMEM;
98373 +
98374 +#ifdef CONFIG_PAX_SEGMEXEC
98375 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98376 + if (end > SEGMEXEC_TASK_SIZE)
98377 + return -EINVAL;
98378 + } else
98379 +#endif
98380 +
98381 + if (end > TASK_SIZE)
98382 + return -EINVAL;
98383 +
98384 if (!arch_validate_prot(prot))
98385 return -EINVAL;
98386
98387 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98388 /*
98389 * Does the application expect PROT_READ to imply PROT_EXEC:
98390 */
98391 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98392 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98393 prot |= PROT_EXEC;
98394
98395 vm_flags = calc_vm_prot_bits(prot);
98396 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98397 if (start > vma->vm_start)
98398 prev = vma;
98399
98400 +#ifdef CONFIG_PAX_MPROTECT
98401 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98402 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98403 +#endif
98404 +
98405 for (nstart = start ; ; ) {
98406 unsigned long newflags;
98407
98408 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98409
98410 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98411 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98412 + if (prot & (PROT_WRITE | PROT_EXEC))
98413 + gr_log_rwxmprotect(vma);
98414 +
98415 + error = -EACCES;
98416 + goto out;
98417 + }
98418 +
98419 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98420 error = -EACCES;
98421 goto out;
98422 }
98423 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98424 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98425 if (error)
98426 goto out;
98427 +
98428 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98429 +
98430 nstart = tmp;
98431
98432 if (nstart < prev->vm_end)
98433 diff --git a/mm/mremap.c b/mm/mremap.c
98434 index b147f66..98a695ab 100644
98435 --- a/mm/mremap.c
98436 +++ b/mm/mremap.c
98437 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98438 continue;
98439 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98440 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98441 +
98442 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98443 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98444 + pte = pte_exprotect(pte);
98445 +#endif
98446 +
98447 pte = move_soft_dirty_pte(pte);
98448 set_pte_at(mm, new_addr, new_pte, pte);
98449 }
98450 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98451 if (is_vm_hugetlb_page(vma))
98452 goto Einval;
98453
98454 +#ifdef CONFIG_PAX_SEGMEXEC
98455 + if (pax_find_mirror_vma(vma))
98456 + goto Einval;
98457 +#endif
98458 +
98459 /* We can't remap across vm area boundaries */
98460 if (old_len > vma->vm_end - addr)
98461 goto Efault;
98462 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98463 unsigned long ret = -EINVAL;
98464 unsigned long charged = 0;
98465 unsigned long map_flags;
98466 + unsigned long pax_task_size = TASK_SIZE;
98467
98468 if (new_addr & ~PAGE_MASK)
98469 goto out;
98470
98471 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98472 +#ifdef CONFIG_PAX_SEGMEXEC
98473 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98474 + pax_task_size = SEGMEXEC_TASK_SIZE;
98475 +#endif
98476 +
98477 + pax_task_size -= PAGE_SIZE;
98478 +
98479 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98480 goto out;
98481
98482 /* Check if the location we're moving into overlaps the
98483 * old location at all, and fail if it does.
98484 */
98485 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98486 - goto out;
98487 -
98488 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98489 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98490 goto out;
98491
98492 ret = do_munmap(mm, new_addr, new_len);
98493 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98494 unsigned long ret = -EINVAL;
98495 unsigned long charged = 0;
98496 bool locked = false;
98497 + unsigned long pax_task_size = TASK_SIZE;
98498
98499 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98500 return ret;
98501 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98502 if (!new_len)
98503 return ret;
98504
98505 +#ifdef CONFIG_PAX_SEGMEXEC
98506 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98507 + pax_task_size = SEGMEXEC_TASK_SIZE;
98508 +#endif
98509 +
98510 + pax_task_size -= PAGE_SIZE;
98511 +
98512 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98513 + old_len > pax_task_size || addr > pax_task_size-old_len)
98514 + return ret;
98515 +
98516 down_write(&current->mm->mmap_sem);
98517
98518 if (flags & MREMAP_FIXED) {
98519 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98520 new_addr = addr;
98521 }
98522 ret = addr;
98523 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98524 goto out;
98525 }
98526 }
98527 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98528 goto out;
98529 }
98530
98531 + map_flags = vma->vm_flags;
98532 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98533 + if (!(ret & ~PAGE_MASK)) {
98534 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98535 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98536 + }
98537 }
98538 out:
98539 if (ret & ~PAGE_MASK)
98540 diff --git a/mm/nommu.c b/mm/nommu.c
98541 index bd1808e..22cbc6a 100644
98542 --- a/mm/nommu.c
98543 +++ b/mm/nommu.c
98544 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98545 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98546 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98547 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98548 -int heap_stack_gap = 0;
98549
98550 atomic_long_t mmap_pages_allocated;
98551
98552 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98553 EXPORT_SYMBOL(find_vma);
98554
98555 /*
98556 - * find a VMA
98557 - * - we don't extend stack VMAs under NOMMU conditions
98558 - */
98559 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98560 -{
98561 - return find_vma(mm, addr);
98562 -}
98563 -
98564 -/*
98565 * expand a stack to a given address
98566 * - not supported under NOMMU conditions
98567 */
98568 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98569
98570 /* most fields are the same, copy all, and then fixup */
98571 *new = *vma;
98572 + INIT_LIST_HEAD(&new->anon_vma_chain);
98573 *region = *vma->vm_region;
98574 new->vm_region = region;
98575
98576 @@ -1905,7 +1896,7 @@ EXPORT_SYMBOL(unmap_mapping_range);
98577 */
98578 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98579 {
98580 - unsigned long free, allowed, reserve;
98581 + long free, allowed, reserve;
98582
98583 vm_acct_memory(pages);
98584
98585 @@ -1969,7 +1960,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98586 */
98587 if (mm) {
98588 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
98589 - allowed -= min(mm->total_vm / 32, reserve);
98590 + allowed -= min_t(long, mm->total_vm / 32, reserve);
98591 }
98592
98593 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
98594 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98595 }
98596 EXPORT_SYMBOL(generic_file_remap_pages);
98597
98598 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98599 - unsigned long addr, void *buf, int len, int write)
98600 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98601 + unsigned long addr, void *buf, size_t len, int write)
98602 {
98603 struct vm_area_struct *vma;
98604
98605 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98606 *
98607 * The caller must hold a reference on @mm.
98608 */
98609 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98610 - void *buf, int len, int write)
98611 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98612 + void *buf, size_t len, int write)
98613 {
98614 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98615 }
98616 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98617 * Access another process' address space.
98618 * - source/target buffer must be kernel space
98619 */
98620 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98621 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98622 {
98623 struct mm_struct *mm;
98624
98625 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98626 index 437174a..8b86707 100644
98627 --- a/mm/page-writeback.c
98628 +++ b/mm/page-writeback.c
98629 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98630 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98631 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98632 */
98633 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98634 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98635 unsigned long thresh,
98636 unsigned long bg_thresh,
98637 unsigned long dirty,
98638 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98639 index 616a2c9..0e755f6 100644
98640 --- a/mm/page_alloc.c
98641 +++ b/mm/page_alloc.c
98642 @@ -59,6 +59,7 @@
98643 #include <linux/page-debug-flags.h>
98644 #include <linux/hugetlb.h>
98645 #include <linux/sched/rt.h>
98646 +#include <linux/random.h>
98647
98648 #include <asm/sections.h>
98649 #include <asm/tlbflush.h>
98650 @@ -356,7 +357,7 @@ out:
98651 * This usage means that zero-order pages may not be compound.
98652 */
98653
98654 -static void free_compound_page(struct page *page)
98655 +void free_compound_page(struct page *page)
98656 {
98657 __free_pages_ok(page, compound_order(page));
98658 }
98659 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98660 int i;
98661 int bad = 0;
98662
98663 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98664 + unsigned long index = 1UL << order;
98665 +#endif
98666 +
98667 trace_mm_page_free(page, order);
98668 kmemcheck_free_shadow(page, order);
98669
98670 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98671 debug_check_no_obj_freed(page_address(page),
98672 PAGE_SIZE << order);
98673 }
98674 +
98675 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98676 + for (; index; --index)
98677 + sanitize_highpage(page + index - 1);
98678 +#endif
98679 +
98680 arch_free_page(page, order);
98681 kernel_map_pages(page, 1 << order, 0);
98682
98683 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98684 local_irq_restore(flags);
98685 }
98686
98687 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98688 +bool __meminitdata extra_latent_entropy;
98689 +
98690 +static int __init setup_pax_extra_latent_entropy(char *str)
98691 +{
98692 + extra_latent_entropy = true;
98693 + return 0;
98694 +}
98695 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98696 +
98697 +volatile u64 latent_entropy __latent_entropy;
98698 +EXPORT_SYMBOL(latent_entropy);
98699 +#endif
98700 +
98701 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98702 {
98703 unsigned int nr_pages = 1 << order;
98704 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98705 __ClearPageReserved(p);
98706 set_page_count(p, 0);
98707
98708 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98709 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98710 + u64 hash = 0;
98711 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98712 + const u64 *data = lowmem_page_address(page);
98713 +
98714 + for (index = 0; index < end; index++)
98715 + hash ^= hash + data[index];
98716 + latent_entropy ^= hash;
98717 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98718 + }
98719 +#endif
98720 +
98721 page_zone(page)->managed_pages += nr_pages;
98722 set_page_refcounted(page);
98723 __free_pages(page, order);
98724 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98725 arch_alloc_page(page, order);
98726 kernel_map_pages(page, 1 << order, 1);
98727
98728 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98729 if (gfp_flags & __GFP_ZERO)
98730 prep_zero_page(page, order, gfp_flags);
98731 +#endif
98732
98733 if (order && (gfp_flags & __GFP_COMP))
98734 prep_compound_page(page, order);
98735 @@ -1602,7 +1642,7 @@ again:
98736 }
98737
98738 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98739 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98740 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98741 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98742 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98743
98744 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98745 do {
98746 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98747 high_wmark_pages(zone) - low_wmark_pages(zone) -
98748 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98749 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98750 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98751 } while (zone++ != preferred_zone);
98752 }
98753 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98754
98755 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98756 high_wmark_pages(zone) - low_wmark_pages(zone) -
98757 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98758 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98759
98760 setup_zone_migrate_reserve(zone);
98761 spin_unlock_irqrestore(&zone->lock, flags);
98762 diff --git a/mm/percpu.c b/mm/percpu.c
98763 index 014bab6..db5a76f 100644
98764 --- a/mm/percpu.c
98765 +++ b/mm/percpu.c
98766 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98767 static unsigned int pcpu_high_unit_cpu __read_mostly;
98768
98769 /* the address of the first chunk which starts with the kernel static area */
98770 -void *pcpu_base_addr __read_mostly;
98771 +void *pcpu_base_addr __read_only;
98772 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98773
98774 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98775 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98776 index 5077afc..846c9ef 100644
98777 --- a/mm/process_vm_access.c
98778 +++ b/mm/process_vm_access.c
98779 @@ -13,6 +13,7 @@
98780 #include <linux/uio.h>
98781 #include <linux/sched.h>
98782 #include <linux/highmem.h>
98783 +#include <linux/security.h>
98784 #include <linux/ptrace.h>
98785 #include <linux/slab.h>
98786 #include <linux/syscalls.h>
98787 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98788 ssize_t iov_len;
98789 size_t total_len = iov_iter_count(iter);
98790
98791 + return -ENOSYS; // PaX: until properly audited
98792 +
98793 /*
98794 * Work out how many pages of struct pages we're going to need
98795 * when eventually calling get_user_pages
98796 */
98797 for (i = 0; i < riovcnt; i++) {
98798 iov_len = rvec[i].iov_len;
98799 - if (iov_len > 0) {
98800 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98801 - + iov_len)
98802 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98803 - / PAGE_SIZE + 1;
98804 - nr_pages = max(nr_pages, nr_pages_iov);
98805 - }
98806 + if (iov_len <= 0)
98807 + continue;
98808 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98809 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98810 + nr_pages = max(nr_pages, nr_pages_iov);
98811 }
98812
98813 if (nr_pages == 0)
98814 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98815 goto free_proc_pages;
98816 }
98817
98818 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98819 + rc = -EPERM;
98820 + goto put_task_struct;
98821 + }
98822 +
98823 mm = mm_access(task, PTRACE_MODE_ATTACH);
98824 if (!mm || IS_ERR(mm)) {
98825 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98826 diff --git a/mm/rmap.c b/mm/rmap.c
98827 index 3e4c721..a5e3e39 100644
98828 --- a/mm/rmap.c
98829 +++ b/mm/rmap.c
98830 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98831 struct anon_vma *anon_vma = vma->anon_vma;
98832 struct anon_vma_chain *avc;
98833
98834 +#ifdef CONFIG_PAX_SEGMEXEC
98835 + struct anon_vma_chain *avc_m = NULL;
98836 +#endif
98837 +
98838 might_sleep();
98839 if (unlikely(!anon_vma)) {
98840 struct mm_struct *mm = vma->vm_mm;
98841 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98842 if (!avc)
98843 goto out_enomem;
98844
98845 +#ifdef CONFIG_PAX_SEGMEXEC
98846 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98847 + if (!avc_m)
98848 + goto out_enomem_free_avc;
98849 +#endif
98850 +
98851 anon_vma = find_mergeable_anon_vma(vma);
98852 allocated = NULL;
98853 if (!anon_vma) {
98854 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98855 /* page_table_lock to protect against threads */
98856 spin_lock(&mm->page_table_lock);
98857 if (likely(!vma->anon_vma)) {
98858 +
98859 +#ifdef CONFIG_PAX_SEGMEXEC
98860 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98861 +
98862 + if (vma_m) {
98863 + BUG_ON(vma_m->anon_vma);
98864 + vma_m->anon_vma = anon_vma;
98865 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98866 + avc_m = NULL;
98867 + }
98868 +#endif
98869 +
98870 vma->anon_vma = anon_vma;
98871 anon_vma_chain_link(vma, avc, anon_vma);
98872 allocated = NULL;
98873 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98874
98875 if (unlikely(allocated))
98876 put_anon_vma(allocated);
98877 +
98878 +#ifdef CONFIG_PAX_SEGMEXEC
98879 + if (unlikely(avc_m))
98880 + anon_vma_chain_free(avc_m);
98881 +#endif
98882 +
98883 if (unlikely(avc))
98884 anon_vma_chain_free(avc);
98885 }
98886 return 0;
98887
98888 out_enomem_free_avc:
98889 +
98890 +#ifdef CONFIG_PAX_SEGMEXEC
98891 + if (avc_m)
98892 + anon_vma_chain_free(avc_m);
98893 +#endif
98894 +
98895 anon_vma_chain_free(avc);
98896 out_enomem:
98897 return -ENOMEM;
98898 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98899 * Attach the anon_vmas from src to dst.
98900 * Returns 0 on success, -ENOMEM on failure.
98901 */
98902 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98903 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98904 {
98905 struct anon_vma_chain *avc, *pavc;
98906 struct anon_vma *root = NULL;
98907 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98908 * the corresponding VMA in the parent process is attached to.
98909 * Returns 0 on success, non-zero on failure.
98910 */
98911 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98912 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98913 {
98914 struct anon_vma_chain *avc;
98915 struct anon_vma *anon_vma;
98916 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98917 void __init anon_vma_init(void)
98918 {
98919 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98920 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98921 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98922 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98923 + anon_vma_ctor);
98924 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98925 + SLAB_PANIC|SLAB_NO_SANITIZE);
98926 }
98927
98928 /*
98929 diff --git a/mm/shmem.c b/mm/shmem.c
98930 index 0b4ba55..bcef4ae 100644
98931 --- a/mm/shmem.c
98932 +++ b/mm/shmem.c
98933 @@ -33,7 +33,7 @@
98934 #include <linux/swap.h>
98935 #include <linux/aio.h>
98936
98937 -static struct vfsmount *shm_mnt;
98938 +struct vfsmount *shm_mnt;
98939
98940 #ifdef CONFIG_SHMEM
98941 /*
98942 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98943 #define BOGO_DIRENT_SIZE 20
98944
98945 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98946 -#define SHORT_SYMLINK_LEN 128
98947 +#define SHORT_SYMLINK_LEN 64
98948
98949 /*
98950 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98951 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98952 static int shmem_xattr_validate(const char *name)
98953 {
98954 struct { const char *prefix; size_t len; } arr[] = {
98955 +
98956 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98957 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98958 +#endif
98959 +
98960 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98961 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98962 };
98963 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98964 if (err)
98965 return err;
98966
98967 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98968 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98969 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98970 + return -EOPNOTSUPP;
98971 + if (size > 8)
98972 + return -EINVAL;
98973 + }
98974 +#endif
98975 +
98976 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98977 }
98978
98979 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98980 int err = -ENOMEM;
98981
98982 /* Round up to L1_CACHE_BYTES to resist false sharing */
98983 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98984 - L1_CACHE_BYTES), GFP_KERNEL);
98985 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98986 if (!sbinfo)
98987 return -ENOMEM;
98988
98989 diff --git a/mm/slab.c b/mm/slab.c
98990 index f34e053..78a3839 100644
98991 --- a/mm/slab.c
98992 +++ b/mm/slab.c
98993 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98994 if ((x)->max_freeable < i) \
98995 (x)->max_freeable = i; \
98996 } while (0)
98997 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98998 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98999 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99000 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99001 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99002 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99003 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99004 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99005 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99006 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99007 #else
99008 #define STATS_INC_ACTIVE(x) do { } while (0)
99009 #define STATS_DEC_ACTIVE(x) do { } while (0)
99010 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99011 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99012 #define STATS_INC_FREEHIT(x) do { } while (0)
99013 #define STATS_INC_FREEMISS(x) do { } while (0)
99014 +#define STATS_INC_SANITIZED(x) do { } while (0)
99015 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99016 #endif
99017
99018 #if DEBUG
99019 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99020 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99021 */
99022 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99023 - const struct page *page, void *obj)
99024 + const struct page *page, const void *obj)
99025 {
99026 u32 offset = (obj - page->s_mem);
99027 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99028 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
99029 * structures first. Without this, further allocations will bug.
99030 */
99031 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
99032 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99033 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99034 slab_state = PARTIAL_NODE;
99035
99036 slab_early_init = 0;
99037 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99038
99039 cachep = find_mergeable(size, align, flags, name, ctor);
99040 if (cachep) {
99041 - cachep->refcount++;
99042 + atomic_inc(&cachep->refcount);
99043
99044 /*
99045 * Adjust the object sizes so that we clear
99046 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99047 struct array_cache *ac = cpu_cache_get(cachep);
99048
99049 check_irq_off();
99050 +
99051 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99052 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99053 + STATS_INC_NOT_SANITIZED(cachep);
99054 + else {
99055 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99056 +
99057 + if (cachep->ctor)
99058 + cachep->ctor(objp);
99059 +
99060 + STATS_INC_SANITIZED(cachep);
99061 + }
99062 +#endif
99063 +
99064 kmemleak_free_recursive(objp, cachep->flags);
99065 objp = cache_free_debugcheck(cachep, objp, caller);
99066
99067 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
99068
99069 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99070 return;
99071 + VM_BUG_ON(!virt_addr_valid(objp));
99072 local_irq_save(flags);
99073 kfree_debugcheck(objp);
99074 c = virt_to_cache(objp);
99075 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99076 }
99077 /* cpu stats */
99078 {
99079 - unsigned long allochit = atomic_read(&cachep->allochit);
99080 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99081 - unsigned long freehit = atomic_read(&cachep->freehit);
99082 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99083 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99084 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99085 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99086 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99087
99088 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99089 allochit, allocmiss, freehit, freemiss);
99090 }
99091 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99092 + {
99093 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99094 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99095 +
99096 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99097 + }
99098 +#endif
99099 #endif
99100 }
99101
99102 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
99103 static int __init slab_proc_init(void)
99104 {
99105 #ifdef CONFIG_DEBUG_SLAB_LEAK
99106 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99107 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99108 #endif
99109 return 0;
99110 }
99111 module_init(slab_proc_init);
99112 #endif
99113
99114 +bool is_usercopy_object(const void *ptr)
99115 +{
99116 + struct page *page;
99117 + struct kmem_cache *cachep;
99118 +
99119 + if (ZERO_OR_NULL_PTR(ptr))
99120 + return false;
99121 +
99122 + if (!slab_is_available())
99123 + return false;
99124 +
99125 + if (!virt_addr_valid(ptr))
99126 + return false;
99127 +
99128 + page = virt_to_head_page(ptr);
99129 +
99130 + if (!PageSlab(page))
99131 + return false;
99132 +
99133 + cachep = page->slab_cache;
99134 + return cachep->flags & SLAB_USERCOPY;
99135 +}
99136 +
99137 +#ifdef CONFIG_PAX_USERCOPY
99138 +const char *check_heap_object(const void *ptr, unsigned long n)
99139 +{
99140 + struct page *page;
99141 + struct kmem_cache *cachep;
99142 + unsigned int objnr;
99143 + unsigned long offset;
99144 +
99145 + if (ZERO_OR_NULL_PTR(ptr))
99146 + return "<null>";
99147 +
99148 + if (!virt_addr_valid(ptr))
99149 + return NULL;
99150 +
99151 + page = virt_to_head_page(ptr);
99152 +
99153 + if (!PageSlab(page))
99154 + return NULL;
99155 +
99156 + cachep = page->slab_cache;
99157 + if (!(cachep->flags & SLAB_USERCOPY))
99158 + return cachep->name;
99159 +
99160 + objnr = obj_to_index(cachep, page, ptr);
99161 + BUG_ON(objnr >= cachep->num);
99162 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99163 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99164 + return NULL;
99165 +
99166 + return cachep->name;
99167 +}
99168 +#endif
99169 +
99170 /**
99171 * ksize - get the actual amount of memory allocated for a given object
99172 * @objp: Pointer to the object
99173 diff --git a/mm/slab.h b/mm/slab.h
99174 index ab019e6..fbcac34 100644
99175 --- a/mm/slab.h
99176 +++ b/mm/slab.h
99177 @@ -22,7 +22,7 @@ struct kmem_cache {
99178 unsigned int align; /* Alignment as calculated */
99179 unsigned long flags; /* Active flags on the slab */
99180 const char *name; /* Slab name for sysfs */
99181 - int refcount; /* Use counter */
99182 + atomic_t refcount; /* Use counter */
99183 void (*ctor)(void *); /* Called on object slot creation */
99184 struct list_head list; /* List of all slab caches on the system */
99185 };
99186 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
99187 /* The slab cache that manages slab cache information */
99188 extern struct kmem_cache *kmem_cache;
99189
99190 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99191 +#ifdef CONFIG_X86_64
99192 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99193 +#else
99194 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99195 +#endif
99196 +enum pax_sanitize_mode {
99197 + PAX_SANITIZE_SLAB_OFF = 0,
99198 + PAX_SANITIZE_SLAB_FAST,
99199 + PAX_SANITIZE_SLAB_FULL,
99200 +};
99201 +extern enum pax_sanitize_mode pax_sanitize_slab;
99202 +#endif
99203 +
99204 unsigned long calculate_alignment(unsigned long flags,
99205 unsigned long align, unsigned long size);
99206
99207 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
99208
99209 /* Legal flag mask for kmem_cache_create(), for various configurations */
99210 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99211 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99212 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99213 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99214
99215 #if defined(CONFIG_DEBUG_SLAB)
99216 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99217 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99218 return s;
99219
99220 page = virt_to_head_page(x);
99221 +
99222 + BUG_ON(!PageSlab(page));
99223 +
99224 cachep = page->slab_cache;
99225 if (slab_equal_or_root(cachep, s))
99226 return cachep;
99227 diff --git a/mm/slab_common.c b/mm/slab_common.c
99228 index dcdab81..3576646 100644
99229 --- a/mm/slab_common.c
99230 +++ b/mm/slab_common.c
99231 @@ -25,11 +25,35 @@
99232
99233 #include "slab.h"
99234
99235 -enum slab_state slab_state;
99236 +enum slab_state slab_state __read_only;
99237 LIST_HEAD(slab_caches);
99238 DEFINE_MUTEX(slab_mutex);
99239 struct kmem_cache *kmem_cache;
99240
99241 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99242 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99243 +static int __init pax_sanitize_slab_setup(char *str)
99244 +{
99245 + if (!str)
99246 + return 0;
99247 +
99248 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99249 + pr_info("PaX slab sanitization: %s\n", "disabled");
99250 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99251 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99252 + pr_info("PaX slab sanitization: %s\n", "fast");
99253 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99254 + } else if (!strcmp(str, "full")) {
99255 + pr_info("PaX slab sanitization: %s\n", "full");
99256 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99257 + } else
99258 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99259 +
99260 + return 0;
99261 +}
99262 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99263 +#endif
99264 +
99265 /*
99266 * Set of flags that will prevent slab merging
99267 */
99268 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
99269 * Merge control. If this is set then no merging of slab caches will occur.
99270 * (Could be removed. This was introduced to pacify the merge skeptics.)
99271 */
99272 -static int slab_nomerge;
99273 +static int slab_nomerge = 1;
99274
99275 static int __init setup_slab_nomerge(char *str)
99276 {
99277 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
99278 /*
99279 * We may have set a slab to be unmergeable during bootstrap.
99280 */
99281 - if (s->refcount < 0)
99282 + if (atomic_read(&s->refcount) < 0)
99283 return 1;
99284
99285 return 0;
99286 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99287 if (err)
99288 goto out_free_cache;
99289
99290 - s->refcount = 1;
99291 + atomic_set(&s->refcount, 1);
99292 list_add(&s->list, &slab_caches);
99293 out:
99294 if (err)
99295 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99296 */
99297 flags &= CACHE_CREATE_MASK;
99298
99299 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99300 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99301 + flags |= SLAB_NO_SANITIZE;
99302 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99303 + flags &= ~SLAB_NO_SANITIZE;
99304 +#endif
99305 +
99306 s = __kmem_cache_alias(name, size, align, flags, ctor);
99307 if (s)
99308 goto out_unlock;
99309 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99310
99311 mutex_lock(&slab_mutex);
99312
99313 - s->refcount--;
99314 - if (s->refcount)
99315 + if (!atomic_dec_and_test(&s->refcount))
99316 goto out_unlock;
99317
99318 if (memcg_cleanup_cache_params(s) != 0)
99319 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99320 rcu_barrier();
99321
99322 memcg_free_cache_params(s);
99323 -#ifdef SLAB_SUPPORTS_SYSFS
99324 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99325 sysfs_slab_remove(s);
99326 #else
99327 slab_kmem_cache_release(s);
99328 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99329 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99330 name, size, err);
99331
99332 - s->refcount = -1; /* Exempt from merging for now */
99333 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99334 }
99335
99336 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99337 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99338
99339 create_boot_cache(s, name, size, flags);
99340 list_add(&s->list, &slab_caches);
99341 - s->refcount = 1;
99342 + atomic_set(&s->refcount, 1);
99343 return s;
99344 }
99345
99346 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99347 EXPORT_SYMBOL(kmalloc_dma_caches);
99348 #endif
99349
99350 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99351 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99352 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99353 +#endif
99354 +
99355 /*
99356 * Conversion table for small slabs sizes / 8 to the index in the
99357 * kmalloc array. This is necessary for slabs < 192 since we have non power
99358 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99359 return kmalloc_dma_caches[index];
99360
99361 #endif
99362 +
99363 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99364 + if (unlikely((flags & GFP_USERCOPY)))
99365 + return kmalloc_usercopy_caches[index];
99366 +
99367 +#endif
99368 +
99369 return kmalloc_caches[index];
99370 }
99371
99372 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99373 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99374 if (!kmalloc_caches[i]) {
99375 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99376 - 1 << i, flags);
99377 + 1 << i, SLAB_USERCOPY | flags);
99378 }
99379
99380 /*
99381 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99382 * earlier power of two caches
99383 */
99384 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99385 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99386 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99387
99388 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99389 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99390 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99391 }
99392
99393 /* Kmalloc array is now usable */
99394 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99395 }
99396 }
99397 #endif
99398 +
99399 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99400 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99401 + struct kmem_cache *s = kmalloc_caches[i];
99402 +
99403 + if (s) {
99404 + int size = kmalloc_size(i);
99405 + char *n = kasprintf(GFP_NOWAIT,
99406 + "usercopy-kmalloc-%d", size);
99407 +
99408 + BUG_ON(!n);
99409 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99410 + size, SLAB_USERCOPY | flags);
99411 + }
99412 + }
99413 +#endif
99414 +
99415 }
99416 #endif /* !CONFIG_SLOB */
99417
99418 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99419 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99420 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99421 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99422 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99423 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99424 +#endif
99425 #endif
99426 seq_putc(m, '\n');
99427 }
99428 diff --git a/mm/slob.c b/mm/slob.c
99429 index 96a8620..3e7e663 100644
99430 --- a/mm/slob.c
99431 +++ b/mm/slob.c
99432 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99433 /*
99434 * Return the size of a slob block.
99435 */
99436 -static slobidx_t slob_units(slob_t *s)
99437 +static slobidx_t slob_units(const slob_t *s)
99438 {
99439 if (s->units > 0)
99440 return s->units;
99441 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99442 /*
99443 * Return the next free slob block pointer after this one.
99444 */
99445 -static slob_t *slob_next(slob_t *s)
99446 +static slob_t *slob_next(const slob_t *s)
99447 {
99448 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99449 slobidx_t next;
99450 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99451 /*
99452 * Returns true if s is the last free block in its page.
99453 */
99454 -static int slob_last(slob_t *s)
99455 +static int slob_last(const slob_t *s)
99456 {
99457 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99458 }
99459
99460 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99461 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99462 {
99463 - void *page;
99464 + struct page *page;
99465
99466 #ifdef CONFIG_NUMA
99467 if (node != NUMA_NO_NODE)
99468 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99469 if (!page)
99470 return NULL;
99471
99472 - return page_address(page);
99473 + __SetPageSlab(page);
99474 + return page;
99475 }
99476
99477 -static void slob_free_pages(void *b, int order)
99478 +static void slob_free_pages(struct page *sp, int order)
99479 {
99480 if (current->reclaim_state)
99481 current->reclaim_state->reclaimed_slab += 1 << order;
99482 - free_pages((unsigned long)b, order);
99483 + __ClearPageSlab(sp);
99484 + page_mapcount_reset(sp);
99485 + sp->private = 0;
99486 + __free_pages(sp, order);
99487 }
99488
99489 /*
99490 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99491
99492 /* Not enough space: must allocate a new page */
99493 if (!b) {
99494 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99495 - if (!b)
99496 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99497 + if (!sp)
99498 return NULL;
99499 - sp = virt_to_page(b);
99500 - __SetPageSlab(sp);
99501 + b = page_address(sp);
99502
99503 spin_lock_irqsave(&slob_lock, flags);
99504 sp->units = SLOB_UNITS(PAGE_SIZE);
99505 sp->freelist = b;
99506 + sp->private = 0;
99507 INIT_LIST_HEAD(&sp->lru);
99508 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99509 set_slob_page_free(sp, slob_list);
99510 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99511 /*
99512 * slob_free: entry point into the slob allocator.
99513 */
99514 -static void slob_free(void *block, int size)
99515 +static void slob_free(struct kmem_cache *c, void *block, int size)
99516 {
99517 struct page *sp;
99518 slob_t *prev, *next, *b = (slob_t *)block;
99519 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99520 if (slob_page_free(sp))
99521 clear_slob_page_free(sp);
99522 spin_unlock_irqrestore(&slob_lock, flags);
99523 - __ClearPageSlab(sp);
99524 - page_mapcount_reset(sp);
99525 - slob_free_pages(b, 0);
99526 + slob_free_pages(sp, 0);
99527 return;
99528 }
99529
99530 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99531 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99532 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99533 +#endif
99534 +
99535 if (!slob_page_free(sp)) {
99536 /* This slob page is about to become partially free. Easy! */
99537 sp->units = units;
99538 @@ -424,11 +431,10 @@ out:
99539 */
99540
99541 static __always_inline void *
99542 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99543 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99544 {
99545 - unsigned int *m;
99546 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99547 - void *ret;
99548 + slob_t *m;
99549 + void *ret = NULL;
99550
99551 gfp &= gfp_allowed_mask;
99552
99553 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99554
99555 if (!m)
99556 return NULL;
99557 - *m = size;
99558 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99559 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99560 + m[0].units = size;
99561 + m[1].units = align;
99562 ret = (void *)m + align;
99563
99564 trace_kmalloc_node(caller, ret,
99565 size, size + align, gfp, node);
99566 } else {
99567 unsigned int order = get_order(size);
99568 + struct page *page;
99569
99570 if (likely(order))
99571 gfp |= __GFP_COMP;
99572 - ret = slob_new_pages(gfp, order, node);
99573 + page = slob_new_pages(gfp, order, node);
99574 + if (page) {
99575 + ret = page_address(page);
99576 + page->private = size;
99577 + }
99578
99579 trace_kmalloc_node(caller, ret,
99580 size, PAGE_SIZE << order, gfp, node);
99581 }
99582
99583 - kmemleak_alloc(ret, size, 1, gfp);
99584 + return ret;
99585 +}
99586 +
99587 +static __always_inline void *
99588 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99589 +{
99590 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99591 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99592 +
99593 + if (!ZERO_OR_NULL_PTR(ret))
99594 + kmemleak_alloc(ret, size, 1, gfp);
99595 return ret;
99596 }
99597
99598 @@ -491,34 +515,112 @@ void kfree(const void *block)
99599 return;
99600 kmemleak_free(block);
99601
99602 + VM_BUG_ON(!virt_addr_valid(block));
99603 sp = virt_to_page(block);
99604 - if (PageSlab(sp)) {
99605 + VM_BUG_ON(!PageSlab(sp));
99606 + if (!sp->private) {
99607 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99608 - unsigned int *m = (unsigned int *)(block - align);
99609 - slob_free(m, *m + align);
99610 - } else
99611 + slob_t *m = (slob_t *)(block - align);
99612 + slob_free(NULL, m, m[0].units + align);
99613 + } else {
99614 + __ClearPageSlab(sp);
99615 + page_mapcount_reset(sp);
99616 + sp->private = 0;
99617 __free_pages(sp, compound_order(sp));
99618 + }
99619 }
99620 EXPORT_SYMBOL(kfree);
99621
99622 +bool is_usercopy_object(const void *ptr)
99623 +{
99624 + if (!slab_is_available())
99625 + return false;
99626 +
99627 + // PAX: TODO
99628 +
99629 + return false;
99630 +}
99631 +
99632 +#ifdef CONFIG_PAX_USERCOPY
99633 +const char *check_heap_object(const void *ptr, unsigned long n)
99634 +{
99635 + struct page *page;
99636 + const slob_t *free;
99637 + const void *base;
99638 + unsigned long flags;
99639 +
99640 + if (ZERO_OR_NULL_PTR(ptr))
99641 + return "<null>";
99642 +
99643 + if (!virt_addr_valid(ptr))
99644 + return NULL;
99645 +
99646 + page = virt_to_head_page(ptr);
99647 + if (!PageSlab(page))
99648 + return NULL;
99649 +
99650 + if (page->private) {
99651 + base = page;
99652 + if (base <= ptr && n <= page->private - (ptr - base))
99653 + return NULL;
99654 + return "<slob>";
99655 + }
99656 +
99657 + /* some tricky double walking to find the chunk */
99658 + spin_lock_irqsave(&slob_lock, flags);
99659 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99660 + free = page->freelist;
99661 +
99662 + while (!slob_last(free) && (void *)free <= ptr) {
99663 + base = free + slob_units(free);
99664 + free = slob_next(free);
99665 + }
99666 +
99667 + while (base < (void *)free) {
99668 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99669 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99670 + int offset;
99671 +
99672 + if (ptr < base + align)
99673 + break;
99674 +
99675 + offset = ptr - base - align;
99676 + if (offset >= m) {
99677 + base += size;
99678 + continue;
99679 + }
99680 +
99681 + if (n > m - offset)
99682 + break;
99683 +
99684 + spin_unlock_irqrestore(&slob_lock, flags);
99685 + return NULL;
99686 + }
99687 +
99688 + spin_unlock_irqrestore(&slob_lock, flags);
99689 + return "<slob>";
99690 +}
99691 +#endif
99692 +
99693 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99694 size_t ksize(const void *block)
99695 {
99696 struct page *sp;
99697 int align;
99698 - unsigned int *m;
99699 + slob_t *m;
99700
99701 BUG_ON(!block);
99702 if (unlikely(block == ZERO_SIZE_PTR))
99703 return 0;
99704
99705 sp = virt_to_page(block);
99706 - if (unlikely(!PageSlab(sp)))
99707 - return PAGE_SIZE << compound_order(sp);
99708 + VM_BUG_ON(!PageSlab(sp));
99709 + if (sp->private)
99710 + return sp->private;
99711
99712 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99713 - m = (unsigned int *)(block - align);
99714 - return SLOB_UNITS(*m) * SLOB_UNIT;
99715 + m = (slob_t *)(block - align);
99716 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99717 }
99718 EXPORT_SYMBOL(ksize);
99719
99720 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99721
99722 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99723 {
99724 - void *b;
99725 + void *b = NULL;
99726
99727 flags &= gfp_allowed_mask;
99728
99729 lockdep_trace_alloc(flags);
99730
99731 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99732 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99733 +#else
99734 if (c->size < PAGE_SIZE) {
99735 b = slob_alloc(c->size, flags, c->align, node);
99736 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99737 SLOB_UNITS(c->size) * SLOB_UNIT,
99738 flags, node);
99739 } else {
99740 - b = slob_new_pages(flags, get_order(c->size), node);
99741 + struct page *sp;
99742 +
99743 + sp = slob_new_pages(flags, get_order(c->size), node);
99744 + if (sp) {
99745 + b = page_address(sp);
99746 + sp->private = c->size;
99747 + }
99748 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99749 PAGE_SIZE << get_order(c->size),
99750 flags, node);
99751 }
99752 +#endif
99753
99754 if (b && c->ctor)
99755 c->ctor(b);
99756 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99757 EXPORT_SYMBOL(kmem_cache_alloc_node);
99758 #endif
99759
99760 -static void __kmem_cache_free(void *b, int size)
99761 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99762 {
99763 - if (size < PAGE_SIZE)
99764 - slob_free(b, size);
99765 + struct page *sp;
99766 +
99767 + sp = virt_to_page(b);
99768 + BUG_ON(!PageSlab(sp));
99769 + if (!sp->private)
99770 + slob_free(c, b, size);
99771 else
99772 - slob_free_pages(b, get_order(size));
99773 + slob_free_pages(sp, get_order(size));
99774 }
99775
99776 static void kmem_rcu_free(struct rcu_head *head)
99777 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99778 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99779 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99780
99781 - __kmem_cache_free(b, slob_rcu->size);
99782 + __kmem_cache_free(NULL, b, slob_rcu->size);
99783 }
99784
99785 void kmem_cache_free(struct kmem_cache *c, void *b)
99786 {
99787 + int size = c->size;
99788 +
99789 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99790 + if (size + c->align < PAGE_SIZE) {
99791 + size += c->align;
99792 + b -= c->align;
99793 + }
99794 +#endif
99795 +
99796 kmemleak_free_recursive(b, c->flags);
99797 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99798 struct slob_rcu *slob_rcu;
99799 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99800 - slob_rcu->size = c->size;
99801 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99802 + slob_rcu->size = size;
99803 call_rcu(&slob_rcu->head, kmem_rcu_free);
99804 } else {
99805 - __kmem_cache_free(b, c->size);
99806 + __kmem_cache_free(c, b, size);
99807 }
99808
99809 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99810 + trace_kfree(_RET_IP_, b);
99811 +#else
99812 trace_kmem_cache_free(_RET_IP_, b);
99813 +#endif
99814 +
99815 }
99816 EXPORT_SYMBOL(kmem_cache_free);
99817
99818 diff --git a/mm/slub.c b/mm/slub.c
99819 index ae7b9f1..7b3fdbe 100644
99820 --- a/mm/slub.c
99821 +++ b/mm/slub.c
99822 @@ -197,7 +197,7 @@ struct track {
99823
99824 enum track_item { TRACK_ALLOC, TRACK_FREE };
99825
99826 -#ifdef CONFIG_SYSFS
99827 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99828 static int sysfs_slab_add(struct kmem_cache *);
99829 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99830 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99831 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99832 if (!t->addr)
99833 return;
99834
99835 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99836 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99837 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99838 #ifdef CONFIG_STACKTRACE
99839 {
99840 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99841
99842 slab_free_hook(s, x);
99843
99844 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99845 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99846 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99847 + if (s->ctor)
99848 + s->ctor(x);
99849 + }
99850 +#endif
99851 +
99852 redo:
99853 /*
99854 * Determine the currently cpus per cpu slab.
99855 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99856 s->inuse = size;
99857
99858 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99859 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99860 + (!(flags & SLAB_NO_SANITIZE)) ||
99861 +#endif
99862 s->ctor)) {
99863 /*
99864 * Relocate free pointer after the object if it is not
99865 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99866 EXPORT_SYMBOL(__kmalloc_node);
99867 #endif
99868
99869 +bool is_usercopy_object(const void *ptr)
99870 +{
99871 + struct page *page;
99872 + struct kmem_cache *s;
99873 +
99874 + if (ZERO_OR_NULL_PTR(ptr))
99875 + return false;
99876 +
99877 + if (!slab_is_available())
99878 + return false;
99879 +
99880 + if (!virt_addr_valid(ptr))
99881 + return false;
99882 +
99883 + page = virt_to_head_page(ptr);
99884 +
99885 + if (!PageSlab(page))
99886 + return false;
99887 +
99888 + s = page->slab_cache;
99889 + return s->flags & SLAB_USERCOPY;
99890 +}
99891 +
99892 +#ifdef CONFIG_PAX_USERCOPY
99893 +const char *check_heap_object(const void *ptr, unsigned long n)
99894 +{
99895 + struct page *page;
99896 + struct kmem_cache *s;
99897 + unsigned long offset;
99898 +
99899 + if (ZERO_OR_NULL_PTR(ptr))
99900 + return "<null>";
99901 +
99902 + if (!virt_addr_valid(ptr))
99903 + return NULL;
99904 +
99905 + page = virt_to_head_page(ptr);
99906 +
99907 + if (!PageSlab(page))
99908 + return NULL;
99909 +
99910 + s = page->slab_cache;
99911 + if (!(s->flags & SLAB_USERCOPY))
99912 + return s->name;
99913 +
99914 + offset = (ptr - page_address(page)) % s->size;
99915 + if (offset <= s->object_size && n <= s->object_size - offset)
99916 + return NULL;
99917 +
99918 + return s->name;
99919 +}
99920 +#endif
99921 +
99922 size_t ksize(const void *object)
99923 {
99924 struct page *page;
99925 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
99926 if (unlikely(ZERO_OR_NULL_PTR(x)))
99927 return;
99928
99929 + VM_BUG_ON(!virt_addr_valid(x));
99930 page = virt_to_head_page(x);
99931 if (unlikely(!PageSlab(page))) {
99932 BUG_ON(!PageCompound(page));
99933 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99934 int i;
99935 struct kmem_cache *c;
99936
99937 - s->refcount++;
99938 + atomic_inc(&s->refcount);
99939
99940 /*
99941 * Adjust the object sizes so that we clear
99942 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99943 }
99944
99945 if (sysfs_slab_alias(s, name)) {
99946 - s->refcount--;
99947 + atomic_dec(&s->refcount);
99948 s = NULL;
99949 }
99950 }
99951 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99952 }
99953 #endif
99954
99955 -#ifdef CONFIG_SYSFS
99956 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99957 static int count_inuse(struct page *page)
99958 {
99959 return page->inuse;
99960 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99961 len += sprintf(buf + len, "%7ld ", l->count);
99962
99963 if (l->addr)
99964 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99965 + len += sprintf(buf + len, "%pS", NULL);
99966 +#else
99967 len += sprintf(buf + len, "%pS", (void *)l->addr);
99968 +#endif
99969 else
99970 len += sprintf(buf + len, "<not-available>");
99971
99972 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99973 validate_slab_cache(kmalloc_caches[9]);
99974 }
99975 #else
99976 -#ifdef CONFIG_SYSFS
99977 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99978 static void resiliency_test(void) {};
99979 #endif
99980 #endif
99981
99982 -#ifdef CONFIG_SYSFS
99983 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99984 enum slab_stat_type {
99985 SL_ALL, /* All slabs */
99986 SL_PARTIAL, /* Only partially allocated slabs */
99987 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99988 {
99989 if (!s->ctor)
99990 return 0;
99991 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99992 + return sprintf(buf, "%pS\n", NULL);
99993 +#else
99994 return sprintf(buf, "%pS\n", s->ctor);
99995 +#endif
99996 }
99997 SLAB_ATTR_RO(ctor);
99998
99999 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100000 {
100001 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100002 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100003 }
100004 SLAB_ATTR_RO(aliases);
100005
100006 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100007 SLAB_ATTR_RO(cache_dma);
100008 #endif
100009
100010 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100011 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100012 +{
100013 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100014 +}
100015 +SLAB_ATTR_RO(usercopy);
100016 +#endif
100017 +
100018 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100019 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100020 +{
100021 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100022 +}
100023 +SLAB_ATTR_RO(sanitize);
100024 +#endif
100025 +
100026 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100027 {
100028 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100029 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
100030 * as well as cause other issues like converting a mergeable
100031 * cache into an umergeable one.
100032 */
100033 - if (s->refcount > 1)
100034 + if (atomic_read(&s->refcount) > 1)
100035 return -EINVAL;
100036
100037 s->flags &= ~SLAB_TRACE;
100038 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
100039 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
100040 size_t length)
100041 {
100042 - if (s->refcount > 1)
100043 + if (atomic_read(&s->refcount) > 1)
100044 return -EINVAL;
100045
100046 s->flags &= ~SLAB_FAILSLAB;
100047 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
100048 #ifdef CONFIG_ZONE_DMA
100049 &cache_dma_attr.attr,
100050 #endif
100051 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100052 + &usercopy_attr.attr,
100053 +#endif
100054 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100055 + &sanitize_attr.attr,
100056 +#endif
100057 #ifdef CONFIG_NUMA
100058 &remote_node_defrag_ratio_attr.attr,
100059 #endif
100060 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
100061 return name;
100062 }
100063
100064 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100065 static int sysfs_slab_add(struct kmem_cache *s)
100066 {
100067 int err;
100068 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100069 kobject_del(&s->kobj);
100070 kobject_put(&s->kobj);
100071 }
100072 +#endif
100073
100074 /*
100075 * Need to buffer aliases during bootup until sysfs becomes
100076 @@ -5154,6 +5251,7 @@ struct saved_alias {
100077
100078 static struct saved_alias *alias_list;
100079
100080 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100081 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100082 {
100083 struct saved_alias *al;
100084 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100085 alias_list = al;
100086 return 0;
100087 }
100088 +#endif
100089
100090 static int __init slab_sysfs_init(void)
100091 {
100092 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100093 index 4cba9c2..b4f9fcc 100644
100094 --- a/mm/sparse-vmemmap.c
100095 +++ b/mm/sparse-vmemmap.c
100096 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100097 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100098 if (!p)
100099 return NULL;
100100 - pud_populate(&init_mm, pud, p);
100101 + pud_populate_kernel(&init_mm, pud, p);
100102 }
100103 return pud;
100104 }
100105 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100106 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100107 if (!p)
100108 return NULL;
100109 - pgd_populate(&init_mm, pgd, p);
100110 + pgd_populate_kernel(&init_mm, pgd, p);
100111 }
100112 return pgd;
100113 }
100114 diff --git a/mm/sparse.c b/mm/sparse.c
100115 index d1b48b6..6e8590e 100644
100116 --- a/mm/sparse.c
100117 +++ b/mm/sparse.c
100118 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100119
100120 for (i = 0; i < PAGES_PER_SECTION; i++) {
100121 if (PageHWPoison(&memmap[i])) {
100122 - atomic_long_sub(1, &num_poisoned_pages);
100123 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100124 ClearPageHWPoison(&memmap[i]);
100125 }
100126 }
100127 diff --git a/mm/swap.c b/mm/swap.c
100128 index 8a12b33..7068e78 100644
100129 --- a/mm/swap.c
100130 +++ b/mm/swap.c
100131 @@ -31,6 +31,7 @@
100132 #include <linux/memcontrol.h>
100133 #include <linux/gfp.h>
100134 #include <linux/uio.h>
100135 +#include <linux/hugetlb.h>
100136
100137 #include "internal.h"
100138
100139 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100140
100141 __page_cache_release(page);
100142 dtor = get_compound_page_dtor(page);
100143 + if (!PageHuge(page))
100144 + BUG_ON(dtor != free_compound_page);
100145 (*dtor)(page);
100146 }
100147
100148 diff --git a/mm/swapfile.c b/mm/swapfile.c
100149 index 8798b2e..348f9dd 100644
100150 --- a/mm/swapfile.c
100151 +++ b/mm/swapfile.c
100152 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100153
100154 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100155 /* Activity counter to indicate that a swapon or swapoff has occurred */
100156 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100157 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100158
100159 static inline unsigned char swap_count(unsigned char ent)
100160 {
100161 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100162 spin_unlock(&swap_lock);
100163
100164 err = 0;
100165 - atomic_inc(&proc_poll_event);
100166 + atomic_inc_unchecked(&proc_poll_event);
100167 wake_up_interruptible(&proc_poll_wait);
100168
100169 out_dput:
100170 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100171
100172 poll_wait(file, &proc_poll_wait, wait);
100173
100174 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100175 - seq->poll_event = atomic_read(&proc_poll_event);
100176 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100177 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100178 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100179 }
100180
100181 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100182 return ret;
100183
100184 seq = file->private_data;
100185 - seq->poll_event = atomic_read(&proc_poll_event);
100186 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100187 return 0;
100188 }
100189
100190 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100191 (frontswap_map) ? "FS" : "");
100192
100193 mutex_unlock(&swapon_mutex);
100194 - atomic_inc(&proc_poll_event);
100195 + atomic_inc_unchecked(&proc_poll_event);
100196 wake_up_interruptible(&proc_poll_wait);
100197
100198 if (S_ISREG(inode->i_mode))
100199 diff --git a/mm/util.c b/mm/util.c
100200 index fec39d4..3e60325 100644
100201 --- a/mm/util.c
100202 +++ b/mm/util.c
100203 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
100204 void arch_pick_mmap_layout(struct mm_struct *mm)
100205 {
100206 mm->mmap_base = TASK_UNMAPPED_BASE;
100207 +
100208 +#ifdef CONFIG_PAX_RANDMMAP
100209 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100210 + mm->mmap_base += mm->delta_mmap;
100211 +#endif
100212 +
100213 mm->get_unmapped_area = arch_get_unmapped_area;
100214 }
100215 #endif
100216 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100217 if (!mm->arg_end)
100218 goto out_mm; /* Shh! No looking before we're done */
100219
100220 + if (gr_acl_handle_procpidmem(task))
100221 + goto out_mm;
100222 +
100223 len = mm->arg_end - mm->arg_start;
100224
100225 if (len > buflen)
100226 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100227 index 90520af..24231aa 100644
100228 --- a/mm/vmalloc.c
100229 +++ b/mm/vmalloc.c
100230 @@ -40,6 +40,21 @@ struct vfree_deferred {
100231 };
100232 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100233
100234 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100235 +struct stack_deferred_llist {
100236 + struct llist_head list;
100237 + void *stack;
100238 + void *lowmem_stack;
100239 +};
100240 +
100241 +struct stack_deferred {
100242 + struct stack_deferred_llist list;
100243 + struct work_struct wq;
100244 +};
100245 +
100246 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100247 +#endif
100248 +
100249 static void __vunmap(const void *, int);
100250
100251 static void free_work(struct work_struct *w)
100252 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100253 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100254 struct llist_node *llnode = llist_del_all(&p->list);
100255 while (llnode) {
100256 - void *p = llnode;
100257 + void *x = llnode;
100258 llnode = llist_next(llnode);
100259 - __vunmap(p, 1);
100260 + __vunmap(x, 1);
100261 }
100262 }
100263
100264 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100265 +static void unmap_work(struct work_struct *w)
100266 +{
100267 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100268 + struct llist_node *llnode = llist_del_all(&p->list.list);
100269 + while (llnode) {
100270 + struct stack_deferred_llist *x =
100271 + llist_entry((struct llist_head *)llnode,
100272 + struct stack_deferred_llist, list);
100273 + void *stack = ACCESS_ONCE(x->stack);
100274 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100275 + llnode = llist_next(llnode);
100276 + __vunmap(stack, 0);
100277 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100278 + }
100279 +}
100280 +#endif
100281 +
100282 /*** Page table manipulation functions ***/
100283
100284 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100285 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100286
100287 pte = pte_offset_kernel(pmd, addr);
100288 do {
100289 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100290 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100291 +
100292 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100293 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100294 + BUG_ON(!pte_exec(*pte));
100295 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100296 + continue;
100297 + }
100298 +#endif
100299 +
100300 + {
100301 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100302 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100303 + }
100304 } while (pte++, addr += PAGE_SIZE, addr != end);
100305 }
100306
100307 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100308 pte = pte_alloc_kernel(pmd, addr);
100309 if (!pte)
100310 return -ENOMEM;
100311 +
100312 + pax_open_kernel();
100313 do {
100314 struct page *page = pages[*nr];
100315
100316 - if (WARN_ON(!pte_none(*pte)))
100317 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100318 + if (pgprot_val(prot) & _PAGE_NX)
100319 +#endif
100320 +
100321 + if (!pte_none(*pte)) {
100322 + pax_close_kernel();
100323 + WARN_ON(1);
100324 return -EBUSY;
100325 - if (WARN_ON(!page))
100326 + }
100327 + if (!page) {
100328 + pax_close_kernel();
100329 + WARN_ON(1);
100330 return -ENOMEM;
100331 + }
100332 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100333 (*nr)++;
100334 } while (pte++, addr += PAGE_SIZE, addr != end);
100335 + pax_close_kernel();
100336 return 0;
100337 }
100338
100339 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100340 pmd_t *pmd;
100341 unsigned long next;
100342
100343 - pmd = pmd_alloc(&init_mm, pud, addr);
100344 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100345 if (!pmd)
100346 return -ENOMEM;
100347 do {
100348 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100349 pud_t *pud;
100350 unsigned long next;
100351
100352 - pud = pud_alloc(&init_mm, pgd, addr);
100353 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100354 if (!pud)
100355 return -ENOMEM;
100356 do {
100357 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100358 if (addr >= MODULES_VADDR && addr < MODULES_END)
100359 return 1;
100360 #endif
100361 +
100362 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100363 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100364 + return 1;
100365 +#endif
100366 +
100367 return is_vmalloc_addr(x);
100368 }
100369
100370 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100371
100372 if (!pgd_none(*pgd)) {
100373 pud_t *pud = pud_offset(pgd, addr);
100374 +#ifdef CONFIG_X86
100375 + if (!pud_large(*pud))
100376 +#endif
100377 if (!pud_none(*pud)) {
100378 pmd_t *pmd = pmd_offset(pud, addr);
100379 +#ifdef CONFIG_X86
100380 + if (!pmd_large(*pmd))
100381 +#endif
100382 if (!pmd_none(*pmd)) {
100383 pte_t *ptep, pte;
100384
100385 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100386 for_each_possible_cpu(i) {
100387 struct vmap_block_queue *vbq;
100388 struct vfree_deferred *p;
100389 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100390 + struct stack_deferred *p2;
100391 +#endif
100392
100393 vbq = &per_cpu(vmap_block_queue, i);
100394 spin_lock_init(&vbq->lock);
100395 INIT_LIST_HEAD(&vbq->free);
100396 +
100397 p = &per_cpu(vfree_deferred, i);
100398 init_llist_head(&p->list);
100399 INIT_WORK(&p->wq, free_work);
100400 +
100401 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100402 + p2 = &per_cpu(stack_deferred, i);
100403 + init_llist_head(&p2->list.list);
100404 + INIT_WORK(&p2->wq, unmap_work);
100405 +#endif
100406 }
100407
100408 /* Import existing vmlist entries. */
100409 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100410 struct vm_struct *area;
100411
100412 BUG_ON(in_interrupt());
100413 +
100414 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100415 + if (flags & VM_KERNEXEC) {
100416 + if (start != VMALLOC_START || end != VMALLOC_END)
100417 + return NULL;
100418 + start = (unsigned long)MODULES_EXEC_VADDR;
100419 + end = (unsigned long)MODULES_EXEC_END;
100420 + }
100421 +#endif
100422 +
100423 if (flags & VM_IOREMAP)
100424 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100425
100426 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100427 }
100428 EXPORT_SYMBOL(vunmap);
100429
100430 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100431 +void unmap_process_stacks(struct task_struct *task)
100432 +{
100433 + if (unlikely(in_interrupt())) {
100434 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100435 + struct stack_deferred_llist *list = task->stack;
100436 + list->stack = task->stack;
100437 + list->lowmem_stack = task->lowmem_stack;
100438 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100439 + schedule_work(&p->wq);
100440 + } else {
100441 + __vunmap(task->stack, 0);
100442 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100443 + }
100444 +}
100445 +#endif
100446 +
100447 /**
100448 * vmap - map an array of pages into virtually contiguous space
100449 * @pages: array of page pointers
100450 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100451 if (count > totalram_pages)
100452 return NULL;
100453
100454 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100455 + if (!(pgprot_val(prot) & _PAGE_NX))
100456 + flags |= VM_KERNEXEC;
100457 +#endif
100458 +
100459 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100460 __builtin_return_address(0));
100461 if (!area)
100462 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100463 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100464 goto fail;
100465
100466 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100467 + if (!(pgprot_val(prot) & _PAGE_NX))
100468 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100469 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100470 + else
100471 +#endif
100472 +
100473 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100474 start, end, node, gfp_mask, caller);
100475 if (!area)
100476 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100477 * For tight control over page level allocator and protection flags
100478 * use __vmalloc() instead.
100479 */
100480 -
100481 void *vmalloc_exec(unsigned long size)
100482 {
100483 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100484 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100485 NUMA_NO_NODE, __builtin_return_address(0));
100486 }
100487
100488 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100489 {
100490 struct vm_struct *area;
100491
100492 + BUG_ON(vma->vm_mirror);
100493 +
100494 size = PAGE_ALIGN(size);
100495
100496 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100497 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100498 v->addr, v->addr + v->size, v->size);
100499
100500 if (v->caller)
100501 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100502 + seq_printf(m, " %pK", v->caller);
100503 +#else
100504 seq_printf(m, " %pS", v->caller);
100505 +#endif
100506
100507 if (v->nr_pages)
100508 seq_printf(m, " pages=%d", v->nr_pages);
100509 diff --git a/mm/vmstat.c b/mm/vmstat.c
100510 index 1b12d39..57b29b2 100644
100511 --- a/mm/vmstat.c
100512 +++ b/mm/vmstat.c
100513 @@ -22,6 +22,7 @@
100514 #include <linux/writeback.h>
100515 #include <linux/compaction.h>
100516 #include <linux/mm_inline.h>
100517 +#include <linux/grsecurity.h>
100518
100519 #include "internal.h"
100520
100521 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100522 *
100523 * vm_stat contains the global counters
100524 */
100525 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100526 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100527 EXPORT_SYMBOL(vm_stat);
100528
100529 #ifdef CONFIG_SMP
100530 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100531
100532 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100533 if (diff[i]) {
100534 - atomic_long_add(diff[i], &vm_stat[i]);
100535 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100536 changes++;
100537 }
100538 return changes;
100539 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100540 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100541 if (v) {
100542
100543 - atomic_long_add(v, &zone->vm_stat[i]);
100544 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100545 global_diff[i] += v;
100546 #ifdef CONFIG_NUMA
100547 /* 3 seconds idle till flush */
100548 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100549
100550 v = p->vm_stat_diff[i];
100551 p->vm_stat_diff[i] = 0;
100552 - atomic_long_add(v, &zone->vm_stat[i]);
100553 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100554 global_diff[i] += v;
100555 }
100556 }
100557 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100558 if (pset->vm_stat_diff[i]) {
100559 int v = pset->vm_stat_diff[i];
100560 pset->vm_stat_diff[i] = 0;
100561 - atomic_long_add(v, &zone->vm_stat[i]);
100562 - atomic_long_add(v, &vm_stat[i]);
100563 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100564 + atomic_long_add_unchecked(v, &vm_stat[i]);
100565 }
100566 }
100567 #endif
100568 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100569 stat_items_size += sizeof(struct vm_event_state);
100570 #endif
100571
100572 - v = kmalloc(stat_items_size, GFP_KERNEL);
100573 + v = kzalloc(stat_items_size, GFP_KERNEL);
100574 m->private = v;
100575 if (!v)
100576 return ERR_PTR(-ENOMEM);
100577 +
100578 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100579 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100580 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100581 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100582 + && !in_group_p(grsec_proc_gid)
100583 +#endif
100584 + )
100585 + return (unsigned long *)m->private + *pos;
100586 +#endif
100587 +#endif
100588 +
100589 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100590 v[i] = global_page_state(i);
100591 v += NR_VM_ZONE_STAT_ITEMS;
100592 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100593 cpu_notifier_register_done();
100594 #endif
100595 #ifdef CONFIG_PROC_FS
100596 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100597 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100598 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100599 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100600 + {
100601 + mode_t gr_mode = S_IRUGO;
100602 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100603 + gr_mode = S_IRUSR;
100604 +#endif
100605 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100606 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100607 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100608 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100609 + }
100610 #endif
100611 return 0;
100612 }
100613 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100614 index 64c6bed..b79a5de 100644
100615 --- a/net/8021q/vlan.c
100616 +++ b/net/8021q/vlan.c
100617 @@ -481,7 +481,7 @@ out:
100618 return NOTIFY_DONE;
100619 }
100620
100621 -static struct notifier_block vlan_notifier_block __read_mostly = {
100622 +static struct notifier_block vlan_notifier_block = {
100623 .notifier_call = vlan_device_event,
100624 };
100625
100626 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100627 err = -EPERM;
100628 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100629 break;
100630 - if ((args.u.name_type >= 0) &&
100631 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100632 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100633 struct vlan_net *vn;
100634
100635 vn = net_generic(net, vlan_net_id);
100636 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100637 index 8ac8a5c..991defc 100644
100638 --- a/net/8021q/vlan_netlink.c
100639 +++ b/net/8021q/vlan_netlink.c
100640 @@ -238,7 +238,7 @@ nla_put_failure:
100641 return -EMSGSIZE;
100642 }
100643
100644 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100645 +struct rtnl_link_ops vlan_link_ops = {
100646 .kind = "vlan",
100647 .maxtype = IFLA_VLAN_MAX,
100648 .policy = vlan_policy,
100649 diff --git a/net/9p/client.c b/net/9p/client.c
100650 index e86a9bea..e91f70e 100644
100651 --- a/net/9p/client.c
100652 +++ b/net/9p/client.c
100653 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100654 len - inline_len);
100655 } else {
100656 err = copy_from_user(ename + inline_len,
100657 - uidata, len - inline_len);
100658 + (char __force_user *)uidata, len - inline_len);
100659 if (err) {
100660 err = -EFAULT;
100661 goto out_err;
100662 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100663 kernel_buf = 1;
100664 indata = data;
100665 } else
100666 - indata = (__force char *)udata;
100667 + indata = (__force_kernel char *)udata;
100668 /*
100669 * response header len is 11
100670 * PDU Header(7) + IO Size (4)
100671 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100672 kernel_buf = 1;
100673 odata = data;
100674 } else
100675 - odata = (char *)udata;
100676 + odata = (char __force_kernel *)udata;
100677 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100678 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100679 fid->fid, offset, rsize);
100680 diff --git a/net/9p/mod.c b/net/9p/mod.c
100681 index 6ab36ae..6f1841b 100644
100682 --- a/net/9p/mod.c
100683 +++ b/net/9p/mod.c
100684 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100685 void v9fs_register_trans(struct p9_trans_module *m)
100686 {
100687 spin_lock(&v9fs_trans_lock);
100688 - list_add_tail(&m->list, &v9fs_trans_list);
100689 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100690 spin_unlock(&v9fs_trans_lock);
100691 }
100692 EXPORT_SYMBOL(v9fs_register_trans);
100693 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100694 void v9fs_unregister_trans(struct p9_trans_module *m)
100695 {
100696 spin_lock(&v9fs_trans_lock);
100697 - list_del_init(&m->list);
100698 + pax_list_del_init((struct list_head *)&m->list);
100699 spin_unlock(&v9fs_trans_lock);
100700 }
100701 EXPORT_SYMBOL(v9fs_unregister_trans);
100702 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100703 index 80d08f6..de63fd1 100644
100704 --- a/net/9p/trans_fd.c
100705 +++ b/net/9p/trans_fd.c
100706 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100707 oldfs = get_fs();
100708 set_fs(get_ds());
100709 /* The cast to a user pointer is valid due to the set_fs() */
100710 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100711 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100712 set_fs(oldfs);
100713
100714 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100715 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100716 index af46bc4..f9adfcd 100644
100717 --- a/net/appletalk/atalk_proc.c
100718 +++ b/net/appletalk/atalk_proc.c
100719 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100720 struct proc_dir_entry *p;
100721 int rc = -ENOMEM;
100722
100723 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100724 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100725 if (!atalk_proc_dir)
100726 goto out;
100727
100728 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100729 index 876fbe8..8bbea9f 100644
100730 --- a/net/atm/atm_misc.c
100731 +++ b/net/atm/atm_misc.c
100732 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100733 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100734 return 1;
100735 atm_return(vcc, truesize);
100736 - atomic_inc(&vcc->stats->rx_drop);
100737 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100738 return 0;
100739 }
100740 EXPORT_SYMBOL(atm_charge);
100741 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100742 }
100743 }
100744 atm_return(vcc, guess);
100745 - atomic_inc(&vcc->stats->rx_drop);
100746 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100747 return NULL;
100748 }
100749 EXPORT_SYMBOL(atm_alloc_charge);
100750 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100751
100752 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100753 {
100754 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100755 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100756 __SONET_ITEMS
100757 #undef __HANDLE_ITEM
100758 }
100759 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100760
100761 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100762 {
100763 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100764 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100765 __SONET_ITEMS
100766 #undef __HANDLE_ITEM
100767 }
100768 diff --git a/net/atm/lec.c b/net/atm/lec.c
100769 index 4b98f89..5a2f6cb 100644
100770 --- a/net/atm/lec.c
100771 +++ b/net/atm/lec.c
100772 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100773 }
100774
100775 static struct lane2_ops lane2_ops = {
100776 - lane2_resolve, /* resolve, spec 3.1.3 */
100777 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100778 - NULL /* associate indicator, spec 3.1.5 */
100779 + .resolve = lane2_resolve,
100780 + .associate_req = lane2_associate_req,
100781 + .associate_indicator = NULL
100782 };
100783
100784 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100785 diff --git a/net/atm/lec.h b/net/atm/lec.h
100786 index 4149db1..f2ab682 100644
100787 --- a/net/atm/lec.h
100788 +++ b/net/atm/lec.h
100789 @@ -48,7 +48,7 @@ struct lane2_ops {
100790 const u8 *tlvs, u32 sizeoftlvs);
100791 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100792 const u8 *tlvs, u32 sizeoftlvs);
100793 -};
100794 +} __no_const;
100795
100796 /*
100797 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100798 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100799 index d1b2d9a..d549f7f 100644
100800 --- a/net/atm/mpoa_caches.c
100801 +++ b/net/atm/mpoa_caches.c
100802 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100803
100804
100805 static struct in_cache_ops ingress_ops = {
100806 - in_cache_add_entry, /* add_entry */
100807 - in_cache_get, /* get */
100808 - in_cache_get_with_mask, /* get_with_mask */
100809 - in_cache_get_by_vcc, /* get_by_vcc */
100810 - in_cache_put, /* put */
100811 - in_cache_remove_entry, /* remove_entry */
100812 - cache_hit, /* cache_hit */
100813 - clear_count_and_expired, /* clear_count */
100814 - check_resolving_entries, /* check_resolving */
100815 - refresh_entries, /* refresh */
100816 - in_destroy_cache /* destroy_cache */
100817 + .add_entry = in_cache_add_entry,
100818 + .get = in_cache_get,
100819 + .get_with_mask = in_cache_get_with_mask,
100820 + .get_by_vcc = in_cache_get_by_vcc,
100821 + .put = in_cache_put,
100822 + .remove_entry = in_cache_remove_entry,
100823 + .cache_hit = cache_hit,
100824 + .clear_count = clear_count_and_expired,
100825 + .check_resolving = check_resolving_entries,
100826 + .refresh = refresh_entries,
100827 + .destroy_cache = in_destroy_cache
100828 };
100829
100830 static struct eg_cache_ops egress_ops = {
100831 - eg_cache_add_entry, /* add_entry */
100832 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100833 - eg_cache_get_by_tag, /* get_by_tag */
100834 - eg_cache_get_by_vcc, /* get_by_vcc */
100835 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100836 - eg_cache_put, /* put */
100837 - eg_cache_remove_entry, /* remove_entry */
100838 - update_eg_cache_entry, /* update */
100839 - clear_expired, /* clear_expired */
100840 - eg_destroy_cache /* destroy_cache */
100841 + .add_entry = eg_cache_add_entry,
100842 + .get_by_cache_id = eg_cache_get_by_cache_id,
100843 + .get_by_tag = eg_cache_get_by_tag,
100844 + .get_by_vcc = eg_cache_get_by_vcc,
100845 + .get_by_src_ip = eg_cache_get_by_src_ip,
100846 + .put = eg_cache_put,
100847 + .remove_entry = eg_cache_remove_entry,
100848 + .update = update_eg_cache_entry,
100849 + .clear_expired = clear_expired,
100850 + .destroy_cache = eg_destroy_cache
100851 };
100852
100853
100854 diff --git a/net/atm/proc.c b/net/atm/proc.c
100855 index bbb6461..cf04016 100644
100856 --- a/net/atm/proc.c
100857 +++ b/net/atm/proc.c
100858 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100859 const struct k_atm_aal_stats *stats)
100860 {
100861 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100862 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100863 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100864 - atomic_read(&stats->rx_drop));
100865 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100866 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100867 + atomic_read_unchecked(&stats->rx_drop));
100868 }
100869
100870 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100871 diff --git a/net/atm/resources.c b/net/atm/resources.c
100872 index 0447d5d..3cf4728 100644
100873 --- a/net/atm/resources.c
100874 +++ b/net/atm/resources.c
100875 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100876 static void copy_aal_stats(struct k_atm_aal_stats *from,
100877 struct atm_aal_stats *to)
100878 {
100879 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100880 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100881 __AAL_STAT_ITEMS
100882 #undef __HANDLE_ITEM
100883 }
100884 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100885 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100886 struct atm_aal_stats *to)
100887 {
100888 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100889 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100890 __AAL_STAT_ITEMS
100891 #undef __HANDLE_ITEM
100892 }
100893 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100894 index 919a5ce..cc6b444 100644
100895 --- a/net/ax25/sysctl_net_ax25.c
100896 +++ b/net/ax25/sysctl_net_ax25.c
100897 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100898 {
100899 char path[sizeof("net/ax25/") + IFNAMSIZ];
100900 int k;
100901 - struct ctl_table *table;
100902 + ctl_table_no_const *table;
100903
100904 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100905 if (!table)
100906 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100907 index 1e80539..676c37a 100644
100908 --- a/net/batman-adv/bat_iv_ogm.c
100909 +++ b/net/batman-adv/bat_iv_ogm.c
100910 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100911
100912 /* randomize initial seqno to avoid collision */
100913 get_random_bytes(&random_seqno, sizeof(random_seqno));
100914 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100915 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100916
100917 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100918 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100919 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100920 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100921
100922 /* change sequence number to network order */
100923 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100924 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100925 batadv_ogm_packet->seqno = htonl(seqno);
100926 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100927 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100928
100929 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100930
100931 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100932 return;
100933
100934 /* could be changed by schedule_own_packet() */
100935 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100936 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100937
100938 if (ogm_packet->flags & BATADV_DIRECTLINK)
100939 has_directlink_flag = true;
100940 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100941 index 00f9e14..e1c7203 100644
100942 --- a/net/batman-adv/fragmentation.c
100943 +++ b/net/batman-adv/fragmentation.c
100944 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100945 frag_header.packet_type = BATADV_UNICAST_FRAG;
100946 frag_header.version = BATADV_COMPAT_VERSION;
100947 frag_header.ttl = BATADV_TTL;
100948 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100949 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100950 frag_header.reserved = 0;
100951 frag_header.no = 0;
100952 frag_header.total_size = htons(skb->len);
100953 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100954 index 5467955..75ad4e3 100644
100955 --- a/net/batman-adv/soft-interface.c
100956 +++ b/net/batman-adv/soft-interface.c
100957 @@ -296,7 +296,7 @@ send:
100958 primary_if->net_dev->dev_addr);
100959
100960 /* set broadcast sequence number */
100961 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100962 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100963 bcast_packet->seqno = htonl(seqno);
100964
100965 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100966 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100967 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100968
100969 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100970 - atomic_set(&bat_priv->bcast_seqno, 1);
100971 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100972 atomic_set(&bat_priv->tt.vn, 0);
100973 atomic_set(&bat_priv->tt.local_changes, 0);
100974 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100975 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100976
100977 /* randomize initial seqno to avoid collision */
100978 get_random_bytes(&random_seqno, sizeof(random_seqno));
100979 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100980 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100981
100982 bat_priv->primary_if = NULL;
100983 bat_priv->num_ifaces = 0;
100984 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100985 return 0;
100986 }
100987
100988 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
100989 +struct rtnl_link_ops batadv_link_ops = {
100990 .kind = "batadv",
100991 .priv_size = sizeof(struct batadv_priv),
100992 .setup = batadv_softif_init_early,
100993 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100994 index 8854c05..ee5d5497 100644
100995 --- a/net/batman-adv/types.h
100996 +++ b/net/batman-adv/types.h
100997 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100998 struct batadv_hard_iface_bat_iv {
100999 unsigned char *ogm_buff;
101000 int ogm_buff_len;
101001 - atomic_t ogm_seqno;
101002 + atomic_unchecked_t ogm_seqno;
101003 };
101004
101005 /**
101006 @@ -768,7 +768,7 @@ struct batadv_priv {
101007 atomic_t bonding;
101008 atomic_t fragmentation;
101009 atomic_t packet_size_max;
101010 - atomic_t frag_seqno;
101011 + atomic_unchecked_t frag_seqno;
101012 #ifdef CONFIG_BATMAN_ADV_BLA
101013 atomic_t bridge_loop_avoidance;
101014 #endif
101015 @@ -787,7 +787,7 @@ struct batadv_priv {
101016 #endif
101017 uint32_t isolation_mark;
101018 uint32_t isolation_mark_mask;
101019 - atomic_t bcast_seqno;
101020 + atomic_unchecked_t bcast_seqno;
101021 atomic_t bcast_queue_left;
101022 atomic_t batman_queue_left;
101023 char num_ifaces;
101024 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
101025 index cfbb39e..0bbfc9d 100644
101026 --- a/net/bluetooth/6lowpan.c
101027 +++ b/net/bluetooth/6lowpan.c
101028 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
101029
101030 drop:
101031 dev->stats.rx_dropped++;
101032 - kfree_skb(skb);
101033 return NET_RX_DROP;
101034 }
101035
101036 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
101037 index 85bcc21..ce82722d 100644
101038 --- a/net/bluetooth/bnep/core.c
101039 +++ b/net/bluetooth/bnep/core.c
101040 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
101041
101042 BT_DBG("");
101043
101044 + if (!l2cap_is_socket(sock))
101045 + return -EBADFD;
101046 +
101047 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
101048 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
101049
101050 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
101051 index 67fe5e8..278a194 100644
101052 --- a/net/bluetooth/cmtp/core.c
101053 +++ b/net/bluetooth/cmtp/core.c
101054 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
101055
101056 BT_DBG("");
101057
101058 + if (!l2cap_is_socket(sock))
101059 + return -EBADFD;
101060 +
101061 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
101062 if (!session)
101063 return -ENOMEM;
101064 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101065 index 115f149..f0ba286 100644
101066 --- a/net/bluetooth/hci_sock.c
101067 +++ b/net/bluetooth/hci_sock.c
101068 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101069 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101070 }
101071
101072 - len = min_t(unsigned int, len, sizeof(uf));
101073 + len = min((size_t)len, sizeof(uf));
101074 if (copy_from_user(&uf, optval, len)) {
101075 err = -EFAULT;
101076 break;
101077 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
101078 index 1b7d605..02ebd10 100644
101079 --- a/net/bluetooth/hidp/core.c
101080 +++ b/net/bluetooth/hidp/core.c
101081 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
101082 {
101083 struct hidp_session *session;
101084 struct l2cap_conn *conn;
101085 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
101086 + struct l2cap_chan *chan;
101087 int ret;
101088
101089 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
101090 if (ret)
101091 return ret;
101092
101093 + chan = l2cap_pi(ctrl_sock->sk)->chan;
101094 conn = NULL;
101095 l2cap_chan_lock(chan);
101096 if (chan->conn)
101097 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101098 index b6f9777..36d3039 100644
101099 --- a/net/bluetooth/l2cap_core.c
101100 +++ b/net/bluetooth/l2cap_core.c
101101 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101102 break;
101103
101104 case L2CAP_CONF_RFC:
101105 - if (olen == sizeof(rfc))
101106 - memcpy(&rfc, (void *)val, olen);
101107 + if (olen != sizeof(rfc))
101108 + break;
101109 +
101110 + memcpy(&rfc, (void *)val, olen);
101111
101112 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101113 rfc.mode != chan->mode)
101114 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101115 index 31f106e..323f606 100644
101116 --- a/net/bluetooth/l2cap_sock.c
101117 +++ b/net/bluetooth/l2cap_sock.c
101118 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101119 struct sock *sk = sock->sk;
101120 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101121 struct l2cap_options opts;
101122 - int len, err = 0;
101123 + int err = 0;
101124 + size_t len = optlen;
101125 u32 opt;
101126
101127 BT_DBG("sk %p", sk);
101128 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101129 opts.max_tx = chan->max_tx;
101130 opts.txwin_size = chan->tx_win;
101131
101132 - len = min_t(unsigned int, sizeof(opts), optlen);
101133 + len = min(sizeof(opts), len);
101134 if (copy_from_user((char *) &opts, optval, len)) {
101135 err = -EFAULT;
101136 break;
101137 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101138 struct bt_security sec;
101139 struct bt_power pwr;
101140 struct l2cap_conn *conn;
101141 - int len, err = 0;
101142 + int err = 0;
101143 + size_t len = optlen;
101144 u32 opt;
101145
101146 BT_DBG("sk %p", sk);
101147 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101148
101149 sec.level = BT_SECURITY_LOW;
101150
101151 - len = min_t(unsigned int, sizeof(sec), optlen);
101152 + len = min(sizeof(sec), len);
101153 if (copy_from_user((char *) &sec, optval, len)) {
101154 err = -EFAULT;
101155 break;
101156 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101157
101158 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101159
101160 - len = min_t(unsigned int, sizeof(pwr), optlen);
101161 + len = min(sizeof(pwr), len);
101162 if (copy_from_user((char *) &pwr, optval, len)) {
101163 err = -EFAULT;
101164 break;
101165 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101166 index 8bbbb5e..6fc0950 100644
101167 --- a/net/bluetooth/rfcomm/sock.c
101168 +++ b/net/bluetooth/rfcomm/sock.c
101169 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101170 struct sock *sk = sock->sk;
101171 struct bt_security sec;
101172 int err = 0;
101173 - size_t len;
101174 + size_t len = optlen;
101175 u32 opt;
101176
101177 BT_DBG("sk %p", sk);
101178 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101179
101180 sec.level = BT_SECURITY_LOW;
101181
101182 - len = min_t(unsigned int, sizeof(sec), optlen);
101183 + len = min(sizeof(sec), len);
101184 if (copy_from_user((char *) &sec, optval, len)) {
101185 err = -EFAULT;
101186 break;
101187 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101188 index 8e385a0..a5bdd8e 100644
101189 --- a/net/bluetooth/rfcomm/tty.c
101190 +++ b/net/bluetooth/rfcomm/tty.c
101191 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101192 BT_DBG("tty %p id %d", tty, tty->index);
101193
101194 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101195 - dev->channel, dev->port.count);
101196 + dev->channel, atomic_read(&dev->port.count));
101197
101198 err = tty_port_open(&dev->port, tty, filp);
101199 if (err)
101200 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101201 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101202
101203 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101204 - dev->port.count);
101205 + atomic_read(&dev->port.count));
101206
101207 tty_port_close(&dev->port, tty, filp);
101208 }
101209 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101210 index e5ec470..cbfabd1 100644
101211 --- a/net/bridge/br_netlink.c
101212 +++ b/net/bridge/br_netlink.c
101213 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
101214 .get_link_af_size = br_get_link_af_size,
101215 };
101216
101217 -struct rtnl_link_ops br_link_ops __read_mostly = {
101218 +struct rtnl_link_ops br_link_ops = {
101219 .kind = "bridge",
101220 .priv_size = sizeof(struct net_bridge),
101221 .setup = br_dev_setup,
101222 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101223 index d9a8c05..8dadc6c6 100644
101224 --- a/net/bridge/netfilter/ebtables.c
101225 +++ b/net/bridge/netfilter/ebtables.c
101226 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101227 tmp.valid_hooks = t->table->valid_hooks;
101228 }
101229 mutex_unlock(&ebt_mutex);
101230 - if (copy_to_user(user, &tmp, *len) != 0) {
101231 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101232 BUGPRINT("c2u Didn't work\n");
101233 ret = -EFAULT;
101234 break;
101235 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101236 goto out;
101237 tmp.valid_hooks = t->valid_hooks;
101238
101239 - if (copy_to_user(user, &tmp, *len) != 0) {
101240 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101241 ret = -EFAULT;
101242 break;
101243 }
101244 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101245 tmp.entries_size = t->table->entries_size;
101246 tmp.valid_hooks = t->table->valid_hooks;
101247
101248 - if (copy_to_user(user, &tmp, *len) != 0) {
101249 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101250 ret = -EFAULT;
101251 break;
101252 }
101253 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101254 index f5afda1..dcf770a 100644
101255 --- a/net/caif/cfctrl.c
101256 +++ b/net/caif/cfctrl.c
101257 @@ -10,6 +10,7 @@
101258 #include <linux/spinlock.h>
101259 #include <linux/slab.h>
101260 #include <linux/pkt_sched.h>
101261 +#include <linux/sched.h>
101262 #include <net/caif/caif_layer.h>
101263 #include <net/caif/cfpkt.h>
101264 #include <net/caif/cfctrl.h>
101265 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101266 memset(&dev_info, 0, sizeof(dev_info));
101267 dev_info.id = 0xff;
101268 cfsrvl_init(&this->serv, 0, &dev_info, false);
101269 - atomic_set(&this->req_seq_no, 1);
101270 - atomic_set(&this->rsp_seq_no, 1);
101271 + atomic_set_unchecked(&this->req_seq_no, 1);
101272 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101273 this->serv.layer.receive = cfctrl_recv;
101274 sprintf(this->serv.layer.name, "ctrl");
101275 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101276 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101277 struct cfctrl_request_info *req)
101278 {
101279 spin_lock_bh(&ctrl->info_list_lock);
101280 - atomic_inc(&ctrl->req_seq_no);
101281 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101282 + atomic_inc_unchecked(&ctrl->req_seq_no);
101283 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101284 list_add_tail(&req->list, &ctrl->list);
101285 spin_unlock_bh(&ctrl->info_list_lock);
101286 }
101287 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101288 if (p != first)
101289 pr_warn("Requests are not received in order\n");
101290
101291 - atomic_set(&ctrl->rsp_seq_no,
101292 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101293 p->sequence_no);
101294 list_del(&p->list);
101295 goto out;
101296 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101297 index 4589ff67..46d6b8f 100644
101298 --- a/net/caif/chnl_net.c
101299 +++ b/net/caif/chnl_net.c
101300 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101301 };
101302
101303
101304 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101305 +static struct rtnl_link_ops ipcaif_link_ops = {
101306 .kind = "caif",
101307 .priv_size = sizeof(struct chnl_net),
101308 .setup = ipcaif_net_setup,
101309 diff --git a/net/can/af_can.c b/net/can/af_can.c
101310 index ce82337..5d17b4d 100644
101311 --- a/net/can/af_can.c
101312 +++ b/net/can/af_can.c
101313 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101314 };
101315
101316 /* notifier block for netdevice event */
101317 -static struct notifier_block can_netdev_notifier __read_mostly = {
101318 +static struct notifier_block can_netdev_notifier = {
101319 .notifier_call = can_notifier,
101320 };
101321
101322 diff --git a/net/can/bcm.c b/net/can/bcm.c
101323 index dcb75c0..24b1b43 100644
101324 --- a/net/can/bcm.c
101325 +++ b/net/can/bcm.c
101326 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101327 }
101328
101329 /* create /proc/net/can-bcm directory */
101330 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101331 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101332 return 0;
101333 }
101334
101335 diff --git a/net/can/gw.c b/net/can/gw.c
101336 index 050a211..bb9fe33 100644
101337 --- a/net/can/gw.c
101338 +++ b/net/can/gw.c
101339 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101340 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101341
101342 static HLIST_HEAD(cgw_list);
101343 -static struct notifier_block notifier;
101344
101345 static struct kmem_cache *cgw_cache __read_mostly;
101346
101347 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101348 return err;
101349 }
101350
101351 +static struct notifier_block notifier = {
101352 + .notifier_call = cgw_notifier
101353 +};
101354 +
101355 static __init int cgw_module_init(void)
101356 {
101357 /* sanitize given module parameter */
101358 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101359 return -ENOMEM;
101360
101361 /* set notifier */
101362 - notifier.notifier_call = cgw_notifier;
101363 register_netdevice_notifier(&notifier);
101364
101365 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101366 diff --git a/net/can/proc.c b/net/can/proc.c
101367 index 1a19b98..df2b4ec 100644
101368 --- a/net/can/proc.c
101369 +++ b/net/can/proc.c
101370 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101371 void can_init_proc(void)
101372 {
101373 /* create /proc/net/can directory */
101374 - can_dir = proc_mkdir("can", init_net.proc_net);
101375 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101376
101377 if (!can_dir) {
101378 printk(KERN_INFO "can: failed to create /proc/net/can . "
101379 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101380 index 8d1653c..77ad145 100644
101381 --- a/net/ceph/messenger.c
101382 +++ b/net/ceph/messenger.c
101383 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101384 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101385
101386 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101387 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101388 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101389
101390 static struct page *zero_page; /* used in certain error cases */
101391
101392 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101393 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101394 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101395
101396 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101397 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101398 s = addr_str[i];
101399
101400 switch (ss->ss_family) {
101401 diff --git a/net/compat.c b/net/compat.c
101402 index bc8aeef..f9c070c 100644
101403 --- a/net/compat.c
101404 +++ b/net/compat.c
101405 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101406 return -EFAULT;
101407 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101408 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101409 - kmsg->msg_name = compat_ptr(tmp1);
101410 - kmsg->msg_iov = compat_ptr(tmp2);
101411 - kmsg->msg_control = compat_ptr(tmp3);
101412 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101413 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101414 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101415 return 0;
101416 }
101417
101418 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101419
101420 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101421 if (mode == VERIFY_READ) {
101422 - int err = move_addr_to_kernel(kern_msg->msg_name,
101423 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101424 kern_msg->msg_namelen,
101425 kern_address);
101426 if (err < 0)
101427 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101428 }
101429
101430 tot_len = iov_from_user_compat_to_kern(kern_iov,
101431 - (struct compat_iovec __user *)kern_msg->msg_iov,
101432 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101433 kern_msg->msg_iovlen);
101434 if (tot_len >= 0)
101435 kern_msg->msg_iov = kern_iov;
101436 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101437
101438 #define CMSG_COMPAT_FIRSTHDR(msg) \
101439 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101440 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101441 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101442 (struct compat_cmsghdr __user *)NULL)
101443
101444 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101445 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101446 (ucmlen) <= (unsigned long) \
101447 ((mhdr)->msg_controllen - \
101448 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101449 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101450
101451 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101452 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101453 {
101454 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101455 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101456 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101457 msg->msg_controllen)
101458 return NULL;
101459 return (struct compat_cmsghdr __user *)ptr;
101460 @@ -223,7 +223,7 @@ Efault:
101461
101462 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101463 {
101464 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101465 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101466 struct compat_cmsghdr cmhdr;
101467 struct compat_timeval ctv;
101468 struct compat_timespec cts[3];
101469 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101470
101471 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101472 {
101473 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101474 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101475 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101476 int fdnum = scm->fp->count;
101477 struct file **fp = scm->fp->fp;
101478 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101479 return -EFAULT;
101480 old_fs = get_fs();
101481 set_fs(KERNEL_DS);
101482 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101483 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101484 set_fs(old_fs);
101485
101486 return err;
101487 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101488 len = sizeof(ktime);
101489 old_fs = get_fs();
101490 set_fs(KERNEL_DS);
101491 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101492 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101493 set_fs(old_fs);
101494
101495 if (!err) {
101496 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101497 case MCAST_JOIN_GROUP:
101498 case MCAST_LEAVE_GROUP:
101499 {
101500 - struct compat_group_req __user *gr32 = (void *)optval;
101501 + struct compat_group_req __user *gr32 = (void __user *)optval;
101502 struct group_req __user *kgr =
101503 compat_alloc_user_space(sizeof(struct group_req));
101504 u32 interface;
101505 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101506 case MCAST_BLOCK_SOURCE:
101507 case MCAST_UNBLOCK_SOURCE:
101508 {
101509 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101510 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101511 struct group_source_req __user *kgsr = compat_alloc_user_space(
101512 sizeof(struct group_source_req));
101513 u32 interface;
101514 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101515 }
101516 case MCAST_MSFILTER:
101517 {
101518 - struct compat_group_filter __user *gf32 = (void *)optval;
101519 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101520 struct group_filter __user *kgf;
101521 u32 interface, fmode, numsrc;
101522
101523 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101524 char __user *optval, int __user *optlen,
101525 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101526 {
101527 - struct compat_group_filter __user *gf32 = (void *)optval;
101528 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101529 struct group_filter __user *kgf;
101530 int __user *koptlen;
101531 u32 interface, fmode, numsrc;
101532 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101533
101534 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101535 return -EINVAL;
101536 - if (copy_from_user(a, args, nas[call]))
101537 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101538 return -EFAULT;
101539 a0 = a[0];
101540 a1 = a[1];
101541 diff --git a/net/core/datagram.c b/net/core/datagram.c
101542 index fdbc9a8..cd6972c 100644
101543 --- a/net/core/datagram.c
101544 +++ b/net/core/datagram.c
101545 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101546 }
101547
101548 kfree_skb(skb);
101549 - atomic_inc(&sk->sk_drops);
101550 + atomic_inc_unchecked(&sk->sk_drops);
101551 sk_mem_reclaim_partial(sk);
101552
101553 return err;
101554 diff --git a/net/core/dev.c b/net/core/dev.c
101555 index 8440968..e14d2b7 100644
101556 --- a/net/core/dev.c
101557 +++ b/net/core/dev.c
101558 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101559 {
101560 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101561 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101562 - atomic_long_inc(&dev->rx_dropped);
101563 + atomic_long_inc_unchecked(&dev->rx_dropped);
101564 kfree_skb(skb);
101565 return NET_RX_DROP;
101566 }
101567 }
101568
101569 if (unlikely(!is_skb_forwardable(dev, skb))) {
101570 - atomic_long_inc(&dev->rx_dropped);
101571 + atomic_long_inc_unchecked(&dev->rx_dropped);
101572 kfree_skb(skb);
101573 return NET_RX_DROP;
101574 }
101575 @@ -2994,7 +2994,7 @@ recursion_alert:
101576 drop:
101577 rcu_read_unlock_bh();
101578
101579 - atomic_long_inc(&dev->tx_dropped);
101580 + atomic_long_inc_unchecked(&dev->tx_dropped);
101581 kfree_skb_list(skb);
101582 return rc;
101583 out:
101584 @@ -3337,7 +3337,7 @@ enqueue:
101585
101586 local_irq_restore(flags);
101587
101588 - atomic_long_inc(&skb->dev->rx_dropped);
101589 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101590 kfree_skb(skb);
101591 return NET_RX_DROP;
101592 }
101593 @@ -3414,7 +3414,7 @@ int netif_rx_ni(struct sk_buff *skb)
101594 }
101595 EXPORT_SYMBOL(netif_rx_ni);
101596
101597 -static void net_tx_action(struct softirq_action *h)
101598 +static __latent_entropy void net_tx_action(void)
101599 {
101600 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101601
101602 @@ -3747,7 +3747,7 @@ ncls:
101603 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101604 } else {
101605 drop:
101606 - atomic_long_inc(&skb->dev->rx_dropped);
101607 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101608 kfree_skb(skb);
101609 /* Jamal, now you will not able to escape explaining
101610 * me how you were going to use this. :-)
101611 @@ -4511,7 +4511,7 @@ void netif_napi_del(struct napi_struct *napi)
101612 }
101613 EXPORT_SYMBOL(netif_napi_del);
101614
101615 -static void net_rx_action(struct softirq_action *h)
101616 +static __latent_entropy void net_rx_action(void)
101617 {
101618 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101619 unsigned long time_limit = jiffies + 2;
101620 @@ -5247,7 +5247,7 @@ void netdev_upper_dev_unlink(struct net_device *dev,
101621 }
101622 EXPORT_SYMBOL(netdev_upper_dev_unlink);
101623
101624 -void netdev_adjacent_add_links(struct net_device *dev)
101625 +static void netdev_adjacent_add_links(struct net_device *dev)
101626 {
101627 struct netdev_adjacent *iter;
101628
101629 @@ -5272,7 +5272,7 @@ void netdev_adjacent_add_links(struct net_device *dev)
101630 }
101631 }
101632
101633 -void netdev_adjacent_del_links(struct net_device *dev)
101634 +static void netdev_adjacent_del_links(struct net_device *dev)
101635 {
101636 struct netdev_adjacent *iter;
101637
101638 @@ -6557,8 +6557,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101639 } else {
101640 netdev_stats_to_stats64(storage, &dev->stats);
101641 }
101642 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101643 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101644 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101645 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101646 return storage;
101647 }
101648 EXPORT_SYMBOL(dev_get_stats);
101649 @@ -6574,7 +6574,7 @@ struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
101650 if (!queue)
101651 return NULL;
101652 netdev_init_one_queue(dev, queue, NULL);
101653 - queue->qdisc = &noop_qdisc;
101654 + RCU_INIT_POINTER(queue->qdisc, &noop_qdisc);
101655 queue->qdisc_sleeping = &noop_qdisc;
101656 rcu_assign_pointer(dev->ingress_queue, queue);
101657 #endif
101658 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101659 index 72e899a..79a9409 100644
101660 --- a/net/core/dev_ioctl.c
101661 +++ b/net/core/dev_ioctl.c
101662 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101663 no_module = !dev;
101664 if (no_module && capable(CAP_NET_ADMIN))
101665 no_module = request_module("netdev-%s", name);
101666 - if (no_module && capable(CAP_SYS_MODULE))
101667 + if (no_module && capable(CAP_SYS_MODULE)) {
101668 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101669 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101670 +#else
101671 request_module("%s", name);
101672 +#endif
101673 + }
101674 }
101675 EXPORT_SYMBOL(dev_load);
101676
101677 diff --git a/net/core/filter.c b/net/core/filter.c
101678 index 647b122..18a7ff6 100644
101679 --- a/net/core/filter.c
101680 +++ b/net/core/filter.c
101681 @@ -532,7 +532,11 @@ do_pass:
101682
101683 /* Unkown instruction. */
101684 default:
101685 - goto err;
101686 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101687 + fp->code, fp->jt, fp->jf, fp->k);
101688 + kfree(addrs);
101689 + BUG();
101690 + return -EINVAL;
101691 }
101692
101693 insn++;
101694 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101695 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101696 int pc, ret = 0;
101697
101698 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101699 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101700
101701 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101702 if (!masks)
101703 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101704 if (!fp)
101705 return -ENOMEM;
101706
101707 - memcpy(fp->insns, fprog->filter, fsize);
101708 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101709
101710 fp->len = fprog->len;
101711 /* Since unattached filters are not copied back to user
101712 diff --git a/net/core/flow.c b/net/core/flow.c
101713 index a0348fd..340f65d 100644
101714 --- a/net/core/flow.c
101715 +++ b/net/core/flow.c
101716 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101717 static int flow_entry_valid(struct flow_cache_entry *fle,
101718 struct netns_xfrm *xfrm)
101719 {
101720 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101721 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101722 return 0;
101723 if (fle->object && !fle->object->ops->check(fle->object))
101724 return 0;
101725 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101726 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101727 fcp->hash_count++;
101728 }
101729 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101730 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101731 flo = fle->object;
101732 if (!flo)
101733 goto ret_object;
101734 @@ -263,7 +263,7 @@ nocache:
101735 }
101736 flo = resolver(net, key, family, dir, flo, ctx);
101737 if (fle) {
101738 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101739 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101740 if (!IS_ERR(flo))
101741 fle->object = flo;
101742 else
101743 @@ -379,7 +379,7 @@ done:
101744 static void flow_cache_flush_task(struct work_struct *work)
101745 {
101746 struct netns_xfrm *xfrm = container_of(work, struct netns_xfrm,
101747 - flow_cache_gc_work);
101748 + flow_cache_flush_work);
101749 struct net *net = container_of(xfrm, struct net, xfrm);
101750
101751 flow_cache_flush(net);
101752 diff --git a/net/core/iovec.c b/net/core/iovec.c
101753 index e1ec45a..e5c6f16 100644
101754 --- a/net/core/iovec.c
101755 +++ b/net/core/iovec.c
101756 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101757 if (m->msg_name && m->msg_namelen) {
101758 if (mode == VERIFY_READ) {
101759 void __user *namep;
101760 - namep = (void __user __force *) m->msg_name;
101761 + namep = (void __force_user *) m->msg_name;
101762 err = move_addr_to_kernel(namep, m->msg_namelen,
101763 address);
101764 if (err < 0)
101765 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101766 }
101767
101768 size = m->msg_iovlen * sizeof(struct iovec);
101769 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101770 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101771 return -EFAULT;
101772
101773 m->msg_iov = iov;
101774 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101775 index ef31fef..8be66d9 100644
101776 --- a/net/core/neighbour.c
101777 +++ b/net/core/neighbour.c
101778 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101779 void __user *buffer, size_t *lenp, loff_t *ppos)
101780 {
101781 int size, ret;
101782 - struct ctl_table tmp = *ctl;
101783 + ctl_table_no_const tmp = *ctl;
101784
101785 tmp.extra1 = &zero;
101786 tmp.extra2 = &unres_qlen_max;
101787 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101788 void __user *buffer,
101789 size_t *lenp, loff_t *ppos)
101790 {
101791 - struct ctl_table tmp = *ctl;
101792 + ctl_table_no_const tmp = *ctl;
101793 int ret;
101794
101795 tmp.extra1 = &zero;
101796 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101797 index 2bf8329..2eb1423 100644
101798 --- a/net/core/net-procfs.c
101799 +++ b/net/core/net-procfs.c
101800 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101801 struct rtnl_link_stats64 temp;
101802 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101803
101804 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101805 + if (gr_proc_is_restricted())
101806 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101807 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101808 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101809 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101810 + else
101811 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101812 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101813 dev->name, stats->rx_bytes, stats->rx_packets,
101814 stats->rx_errors,
101815 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101816 return 0;
101817 }
101818
101819 -static const struct seq_operations dev_seq_ops = {
101820 +const struct seq_operations dev_seq_ops = {
101821 .start = dev_seq_start,
101822 .next = dev_seq_next,
101823 .stop = dev_seq_stop,
101824 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101825
101826 static int softnet_seq_open(struct inode *inode, struct file *file)
101827 {
101828 - return seq_open(file, &softnet_seq_ops);
101829 + return seq_open_restrict(file, &softnet_seq_ops);
101830 }
101831
101832 static const struct file_operations softnet_seq_fops = {
101833 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101834 else
101835 seq_printf(seq, "%04x", ntohs(pt->type));
101836
101837 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101838 + seq_printf(seq, " %-8s %pf\n",
101839 + pt->dev ? pt->dev->name : "", NULL);
101840 +#else
101841 seq_printf(seq, " %-8s %pf\n",
101842 pt->dev ? pt->dev->name : "", pt->func);
101843 +#endif
101844 }
101845
101846 return 0;
101847 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101848 index 9dd0669..c52fb1b 100644
101849 --- a/net/core/net-sysfs.c
101850 +++ b/net/core/net-sysfs.c
101851 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101852 {
101853 struct net_device *netdev = to_net_dev(dev);
101854 return sprintf(buf, fmt_dec,
101855 - atomic_read(&netdev->carrier_changes));
101856 + atomic_read_unchecked(&netdev->carrier_changes));
101857 }
101858 static DEVICE_ATTR_RO(carrier_changes);
101859
101860 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101861 index 7f15517..f7d65c0 100644
101862 --- a/net/core/net_namespace.c
101863 +++ b/net/core/net_namespace.c
101864 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101865 int error;
101866 LIST_HEAD(net_exit_list);
101867
101868 - list_add_tail(&ops->list, list);
101869 + pax_list_add_tail((struct list_head *)&ops->list, list);
101870 if (ops->init || (ops->id && ops->size)) {
101871 for_each_net(net) {
101872 error = ops_init(ops, net);
101873 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101874
101875 out_undo:
101876 /* If I have an error cleanup all namespaces I initialized */
101877 - list_del(&ops->list);
101878 + pax_list_del((struct list_head *)&ops->list);
101879 ops_exit_list(ops, &net_exit_list);
101880 ops_free_list(ops, &net_exit_list);
101881 return error;
101882 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101883 struct net *net;
101884 LIST_HEAD(net_exit_list);
101885
101886 - list_del(&ops->list);
101887 + pax_list_del((struct list_head *)&ops->list);
101888 for_each_net(net)
101889 list_add_tail(&net->exit_list, &net_exit_list);
101890 ops_exit_list(ops, &net_exit_list);
101891 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101892 mutex_lock(&net_mutex);
101893 error = register_pernet_operations(&pernet_list, ops);
101894 if (!error && (first_device == &pernet_list))
101895 - first_device = &ops->list;
101896 + first_device = (struct list_head *)&ops->list;
101897 mutex_unlock(&net_mutex);
101898 return error;
101899 }
101900 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101901 index e6645b4..43e1af9 100644
101902 --- a/net/core/netpoll.c
101903 +++ b/net/core/netpoll.c
101904 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101905 struct udphdr *udph;
101906 struct iphdr *iph;
101907 struct ethhdr *eth;
101908 - static atomic_t ip_ident;
101909 + static atomic_unchecked_t ip_ident;
101910 struct ipv6hdr *ip6h;
101911
101912 udp_len = len + sizeof(*udph);
101913 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101914 put_unaligned(0x45, (unsigned char *)iph);
101915 iph->tos = 0;
101916 put_unaligned(htons(ip_len), &(iph->tot_len));
101917 - iph->id = htons(atomic_inc_return(&ip_ident));
101918 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101919 iph->frag_off = 0;
101920 iph->ttl = 64;
101921 iph->protocol = IPPROTO_UDP;
101922 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101923 index 443256b..bbff424 100644
101924 --- a/net/core/pktgen.c
101925 +++ b/net/core/pktgen.c
101926 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101927 pn->net = net;
101928 INIT_LIST_HEAD(&pn->pktgen_threads);
101929 pn->pktgen_exiting = false;
101930 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101931 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101932 if (!pn->proc_dir) {
101933 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101934 return -ENODEV;
101935 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101936 index 76321ea..3129bd6 100644
101937 --- a/net/core/rtnetlink.c
101938 +++ b/net/core/rtnetlink.c
101939 @@ -58,7 +58,7 @@ struct rtnl_link {
101940 rtnl_doit_func doit;
101941 rtnl_dumpit_func dumpit;
101942 rtnl_calcit_func calcit;
101943 -};
101944 +} __no_const;
101945
101946 static DEFINE_MUTEX(rtnl_mutex);
101947
101948 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101949 * to use the ops for creating device. So do not
101950 * fill up dellink as well. That disables rtnl_dellink.
101951 */
101952 - if (ops->setup && !ops->dellink)
101953 - ops->dellink = unregister_netdevice_queue;
101954 + if (ops->setup && !ops->dellink) {
101955 + pax_open_kernel();
101956 + *(void **)&ops->dellink = unregister_netdevice_queue;
101957 + pax_close_kernel();
101958 + }
101959
101960 - list_add_tail(&ops->list, &link_ops);
101961 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101962 return 0;
101963 }
101964 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101965 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101966 for_each_net(net) {
101967 __rtnl_kill_links(net, ops);
101968 }
101969 - list_del(&ops->list);
101970 + pax_list_del((struct list_head *)&ops->list);
101971 }
101972 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101973
101974 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101975 (dev->ifalias &&
101976 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101977 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101978 - atomic_read(&dev->carrier_changes)))
101979 + atomic_read_unchecked(&dev->carrier_changes)))
101980 goto nla_put_failure;
101981
101982 if (1) {
101983 diff --git a/net/core/scm.c b/net/core/scm.c
101984 index b442e7e..6f5b5a2 100644
101985 --- a/net/core/scm.c
101986 +++ b/net/core/scm.c
101987 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101988 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101989 {
101990 struct cmsghdr __user *cm
101991 - = (__force struct cmsghdr __user *)msg->msg_control;
101992 + = (struct cmsghdr __force_user *)msg->msg_control;
101993 struct cmsghdr cmhdr;
101994 int cmlen = CMSG_LEN(len);
101995 int err;
101996 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101997 err = -EFAULT;
101998 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101999 goto out;
102000 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102001 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102002 goto out;
102003 cmlen = CMSG_SPACE(len);
102004 if (msg->msg_controllen < cmlen)
102005 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102006 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102007 {
102008 struct cmsghdr __user *cm
102009 - = (__force struct cmsghdr __user*)msg->msg_control;
102010 + = (struct cmsghdr __force_user *)msg->msg_control;
102011
102012 int fdmax = 0;
102013 int fdnum = scm->fp->count;
102014 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102015 if (fdnum < fdmax)
102016 fdmax = fdnum;
102017
102018 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102019 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102020 i++, cmfptr++)
102021 {
102022 struct socket *sock;
102023 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102024 index d7543d0..ff96aec 100644
102025 --- a/net/core/skbuff.c
102026 +++ b/net/core/skbuff.c
102027 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
102028 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102029 int len, __wsum csum)
102030 {
102031 - const struct skb_checksum_ops ops = {
102032 + static const struct skb_checksum_ops ops = {
102033 .update = csum_partial_ext,
102034 .combine = csum_block_add_ext,
102035 };
102036 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
102037 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102038 sizeof(struct sk_buff),
102039 0,
102040 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102041 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102042 + SLAB_NO_SANITIZE,
102043 NULL);
102044 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102045 sizeof(struct sk_buff_fclones),
102046 0,
102047 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102048 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102049 + SLAB_NO_SANITIZE,
102050 NULL);
102051 }
102052
102053 diff --git a/net/core/sock.c b/net/core/sock.c
102054 index 15e0c67..0310f4a 100644
102055 --- a/net/core/sock.c
102056 +++ b/net/core/sock.c
102057 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102058 struct sk_buff_head *list = &sk->sk_receive_queue;
102059
102060 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102061 - atomic_inc(&sk->sk_drops);
102062 + atomic_inc_unchecked(&sk->sk_drops);
102063 trace_sock_rcvqueue_full(sk, skb);
102064 return -ENOMEM;
102065 }
102066 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102067 return err;
102068
102069 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102070 - atomic_inc(&sk->sk_drops);
102071 + atomic_inc_unchecked(&sk->sk_drops);
102072 return -ENOBUFS;
102073 }
102074
102075 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102076 skb_dst_force(skb);
102077
102078 spin_lock_irqsave(&list->lock, flags);
102079 - skb->dropcount = atomic_read(&sk->sk_drops);
102080 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102081 __skb_queue_tail(list, skb);
102082 spin_unlock_irqrestore(&list->lock, flags);
102083
102084 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102085 skb->dev = NULL;
102086
102087 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102088 - atomic_inc(&sk->sk_drops);
102089 + atomic_inc_unchecked(&sk->sk_drops);
102090 goto discard_and_relse;
102091 }
102092 if (nested)
102093 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102094 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102095 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102096 bh_unlock_sock(sk);
102097 - atomic_inc(&sk->sk_drops);
102098 + atomic_inc_unchecked(&sk->sk_drops);
102099 goto discard_and_relse;
102100 }
102101
102102 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102103 struct timeval tm;
102104 } v;
102105
102106 - int lv = sizeof(int);
102107 - int len;
102108 + unsigned int lv = sizeof(int);
102109 + unsigned int len;
102110
102111 if (get_user(len, optlen))
102112 return -EFAULT;
102113 - if (len < 0)
102114 + if (len > INT_MAX)
102115 return -EINVAL;
102116
102117 memset(&v, 0, sizeof(v));
102118 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102119
102120 case SO_PEERNAME:
102121 {
102122 - char address[128];
102123 + char address[_K_SS_MAXSIZE];
102124
102125 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102126 return -ENOTCONN;
102127 - if (lv < len)
102128 + if (lv < len || sizeof address < len)
102129 return -EINVAL;
102130 if (copy_to_user(optval, address, len))
102131 return -EFAULT;
102132 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102133
102134 if (len > lv)
102135 len = lv;
102136 - if (copy_to_user(optval, &v, len))
102137 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102138 return -EFAULT;
102139 lenout:
102140 if (put_user(len, optlen))
102141 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102142 */
102143 smp_wmb();
102144 atomic_set(&sk->sk_refcnt, 1);
102145 - atomic_set(&sk->sk_drops, 0);
102146 + atomic_set_unchecked(&sk->sk_drops, 0);
102147 }
102148 EXPORT_SYMBOL(sock_init_data);
102149
102150 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102151 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102152 int level, int type)
102153 {
102154 + struct sock_extended_err ee;
102155 struct sock_exterr_skb *serr;
102156 struct sk_buff *skb;
102157 int copied, err;
102158 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102159 sock_recv_timestamp(msg, sk, skb);
102160
102161 serr = SKB_EXT_ERR(skb);
102162 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102163 + ee = serr->ee;
102164 + put_cmsg(msg, level, type, sizeof ee, &ee);
102165
102166 msg->msg_flags |= MSG_ERRQUEUE;
102167 err = copied;
102168 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102169 index ad704c7..ca48aff 100644
102170 --- a/net/core/sock_diag.c
102171 +++ b/net/core/sock_diag.c
102172 @@ -9,26 +9,33 @@
102173 #include <linux/inet_diag.h>
102174 #include <linux/sock_diag.h>
102175
102176 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102177 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102178 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102179 static DEFINE_MUTEX(sock_diag_table_mutex);
102180
102181 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102182 {
102183 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102184 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102185 cookie[1] != INET_DIAG_NOCOOKIE) &&
102186 ((u32)(unsigned long)sk != cookie[0] ||
102187 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102188 return -ESTALE;
102189 else
102190 +#endif
102191 return 0;
102192 }
102193 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102194
102195 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102196 {
102197 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102198 + cookie[0] = 0;
102199 + cookie[1] = 0;
102200 +#else
102201 cookie[0] = (u32)(unsigned long)sk;
102202 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102203 +#endif
102204 }
102205 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102206
102207 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102208 mutex_lock(&sock_diag_table_mutex);
102209 if (sock_diag_handlers[hndl->family])
102210 err = -EBUSY;
102211 - else
102212 + else {
102213 + pax_open_kernel();
102214 sock_diag_handlers[hndl->family] = hndl;
102215 + pax_close_kernel();
102216 + }
102217 mutex_unlock(&sock_diag_table_mutex);
102218
102219 return err;
102220 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102221
102222 mutex_lock(&sock_diag_table_mutex);
102223 BUG_ON(sock_diag_handlers[family] != hnld);
102224 + pax_open_kernel();
102225 sock_diag_handlers[family] = NULL;
102226 + pax_close_kernel();
102227 mutex_unlock(&sock_diag_table_mutex);
102228 }
102229 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102230 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102231 index cf9cd13..50683950 100644
102232 --- a/net/core/sysctl_net_core.c
102233 +++ b/net/core/sysctl_net_core.c
102234 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102235 {
102236 unsigned int orig_size, size;
102237 int ret, i;
102238 - struct ctl_table tmp = {
102239 + ctl_table_no_const tmp = {
102240 .data = &size,
102241 .maxlen = sizeof(size),
102242 .mode = table->mode
102243 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102244 void __user *buffer, size_t *lenp, loff_t *ppos)
102245 {
102246 char id[IFNAMSIZ];
102247 - struct ctl_table tbl = {
102248 + ctl_table_no_const tbl = {
102249 .data = id,
102250 .maxlen = IFNAMSIZ,
102251 };
102252 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102253 .mode = 0644,
102254 .proc_handler = proc_dointvec
102255 },
102256 -#ifdef CONFIG_BPF_JIT
102257 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102258 {
102259 .procname = "bpf_jit_enable",
102260 .data = &bpf_jit_enable,
102261 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102262
102263 static __net_init int sysctl_core_net_init(struct net *net)
102264 {
102265 - struct ctl_table *tbl;
102266 + ctl_table_no_const *tbl = NULL;
102267
102268 net->core.sysctl_somaxconn = SOMAXCONN;
102269
102270 - tbl = netns_core_table;
102271 if (!net_eq(net, &init_net)) {
102272 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102273 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102274 if (tbl == NULL)
102275 goto err_dup;
102276
102277 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102278 if (net->user_ns != &init_user_ns) {
102279 tbl[0].procname = NULL;
102280 }
102281 - }
102282 -
102283 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102284 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102285 + } else
102286 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102287 if (net->core.sysctl_hdr == NULL)
102288 goto err_reg;
102289
102290 return 0;
102291
102292 err_reg:
102293 - if (tbl != netns_core_table)
102294 - kfree(tbl);
102295 + kfree(tbl);
102296 err_dup:
102297 return -ENOMEM;
102298 }
102299 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102300 kfree(tbl);
102301 }
102302
102303 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102304 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102305 .init = sysctl_core_net_init,
102306 .exit = sysctl_core_net_exit,
102307 };
102308 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102309 index 25733d5..b9360f0 100644
102310 --- a/net/decnet/af_decnet.c
102311 +++ b/net/decnet/af_decnet.c
102312 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
102313 .sysctl_rmem = sysctl_decnet_rmem,
102314 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102315 .obj_size = sizeof(struct dn_sock),
102316 + .slab_flags = SLAB_USERCOPY,
102317 };
102318
102319 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102320 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102321 index 4400da7..3429972 100644
102322 --- a/net/decnet/dn_dev.c
102323 +++ b/net/decnet/dn_dev.c
102324 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
102325 .extra1 = &min_t3,
102326 .extra2 = &max_t3
102327 },
102328 - {0}
102329 + { }
102330 },
102331 };
102332
102333 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102334 index 5325b54..a0d4d69 100644
102335 --- a/net/decnet/sysctl_net_decnet.c
102336 +++ b/net/decnet/sysctl_net_decnet.c
102337 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102338
102339 if (len > *lenp) len = *lenp;
102340
102341 - if (copy_to_user(buffer, addr, len))
102342 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102343 return -EFAULT;
102344
102345 *lenp = len;
102346 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102347
102348 if (len > *lenp) len = *lenp;
102349
102350 - if (copy_to_user(buffer, devname, len))
102351 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102352 return -EFAULT;
102353
102354 *lenp = len;
102355 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102356 index a2c7e4c..3dc9f67 100644
102357 --- a/net/hsr/hsr_netlink.c
102358 +++ b/net/hsr/hsr_netlink.c
102359 @@ -102,7 +102,7 @@ nla_put_failure:
102360 return -EMSGSIZE;
102361 }
102362
102363 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102364 +static struct rtnl_link_ops hsr_link_ops = {
102365 .kind = "hsr",
102366 .maxtype = IFLA_HSR_MAX,
102367 .policy = hsr_policy,
102368 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102369 index 4413629..dea596a 100644
102370 --- a/net/ieee802154/6lowpan_rtnl.c
102371 +++ b/net/ieee802154/6lowpan_rtnl.c
102372 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102373 dev_put(real_dev);
102374 }
102375
102376 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102377 +static struct rtnl_link_ops lowpan_link_ops = {
102378 .kind = "lowpan",
102379 .priv_size = sizeof(struct lowpan_dev_info),
102380 .setup = lowpan_setup,
102381 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102382 index 7cfcd68..84ca5b7 100644
102383 --- a/net/ieee802154/reassembly.c
102384 +++ b/net/ieee802154/reassembly.c
102385 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102386
102387 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102388 {
102389 - struct ctl_table *table;
102390 + ctl_table_no_const *table = NULL;
102391 struct ctl_table_header *hdr;
102392 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102393 net_ieee802154_lowpan(net);
102394
102395 - table = lowpan_frags_ns_ctl_table;
102396 if (!net_eq(net, &init_net)) {
102397 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102398 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102399 GFP_KERNEL);
102400 if (table == NULL)
102401 goto err_alloc;
102402 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102403 /* Don't export sysctls to unprivileged users */
102404 if (net->user_ns != &init_user_ns)
102405 table[0].procname = NULL;
102406 - }
102407 -
102408 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102409 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102410 + } else
102411 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102412 if (hdr == NULL)
102413 goto err_reg;
102414
102415 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102416 return 0;
102417
102418 err_reg:
102419 - if (!net_eq(net, &init_net))
102420 - kfree(table);
102421 + kfree(table);
102422 err_alloc:
102423 return -ENOMEM;
102424 }
102425 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102426 index e67da4e..da217942 100644
102427 --- a/net/ipv4/af_inet.c
102428 +++ b/net/ipv4/af_inet.c
102429 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102430 return ip_recv_error(sk, msg, len, addr_len);
102431 #if IS_ENABLED(CONFIG_IPV6)
102432 if (sk->sk_family == AF_INET6)
102433 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102434 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102435 #endif
102436 return -EINVAL;
102437 }
102438 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102439 index 214882e..ec032f6 100644
102440 --- a/net/ipv4/devinet.c
102441 +++ b/net/ipv4/devinet.c
102442 @@ -69,7 +69,8 @@
102443
102444 static struct ipv4_devconf ipv4_devconf = {
102445 .data = {
102446 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102447 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102448 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102449 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102450 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102451 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102452 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102453
102454 static struct ipv4_devconf ipv4_devconf_dflt = {
102455 .data = {
102456 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102457 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102458 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102459 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102460 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102461 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102462 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102463 idx = 0;
102464 head = &net->dev_index_head[h];
102465 rcu_read_lock();
102466 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102467 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102468 net->dev_base_seq;
102469 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102470 if (idx < s_idx)
102471 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102472 idx = 0;
102473 head = &net->dev_index_head[h];
102474 rcu_read_lock();
102475 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102476 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102477 net->dev_base_seq;
102478 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102479 if (idx < s_idx)
102480 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102481 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102482 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102483
102484 -static struct devinet_sysctl_table {
102485 +static const struct devinet_sysctl_table {
102486 struct ctl_table_header *sysctl_header;
102487 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102488 } devinet_sysctl = {
102489 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102490 int err;
102491 struct ipv4_devconf *all, *dflt;
102492 #ifdef CONFIG_SYSCTL
102493 - struct ctl_table *tbl = ctl_forward_entry;
102494 + ctl_table_no_const *tbl = NULL;
102495 struct ctl_table_header *forw_hdr;
102496 #endif
102497
102498 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102499 goto err_alloc_dflt;
102500
102501 #ifdef CONFIG_SYSCTL
102502 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102503 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102504 if (tbl == NULL)
102505 goto err_alloc_ctl;
102506
102507 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102508 goto err_reg_dflt;
102509
102510 err = -ENOMEM;
102511 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102512 + if (!net_eq(net, &init_net))
102513 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102514 + else
102515 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102516 if (forw_hdr == NULL)
102517 goto err_reg_ctl;
102518 net->ipv4.forw_hdr = forw_hdr;
102519 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102520 err_reg_dflt:
102521 __devinet_sysctl_unregister(all);
102522 err_reg_all:
102523 - if (tbl != ctl_forward_entry)
102524 - kfree(tbl);
102525 + kfree(tbl);
102526 err_alloc_ctl:
102527 #endif
102528 if (dflt != &ipv4_devconf_dflt)
102529 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102530 index 23104a3..9f5570b 100644
102531 --- a/net/ipv4/fib_frontend.c
102532 +++ b/net/ipv4/fib_frontend.c
102533 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102534 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102535 fib_sync_up(dev);
102536 #endif
102537 - atomic_inc(&net->ipv4.dev_addr_genid);
102538 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102539 rt_cache_flush(dev_net(dev));
102540 break;
102541 case NETDEV_DOWN:
102542 fib_del_ifaddr(ifa, NULL);
102543 - atomic_inc(&net->ipv4.dev_addr_genid);
102544 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102545 if (ifa->ifa_dev->ifa_list == NULL) {
102546 /* Last address was deleted from this interface.
102547 * Disable IP.
102548 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102549 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102550 fib_sync_up(dev);
102551 #endif
102552 - atomic_inc(&net->ipv4.dev_addr_genid);
102553 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102554 rt_cache_flush(net);
102555 break;
102556 case NETDEV_DOWN:
102557 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102558 index f99f41b..1879da9 100644
102559 --- a/net/ipv4/fib_semantics.c
102560 +++ b/net/ipv4/fib_semantics.c
102561 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102562 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102563 nh->nh_gw,
102564 nh->nh_parent->fib_scope);
102565 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102566 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102567
102568 return nh->nh_saddr;
102569 }
102570 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102571 index 9111a4e..3576905 100644
102572 --- a/net/ipv4/inet_hashtables.c
102573 +++ b/net/ipv4/inet_hashtables.c
102574 @@ -18,6 +18,7 @@
102575 #include <linux/sched.h>
102576 #include <linux/slab.h>
102577 #include <linux/wait.h>
102578 +#include <linux/security.h>
102579
102580 #include <net/inet_connection_sock.h>
102581 #include <net/inet_hashtables.h>
102582 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102583 return inet_ehashfn(net, laddr, lport, faddr, fport);
102584 }
102585
102586 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102587 +
102588 /*
102589 * Allocate and initialize a new local port bind bucket.
102590 * The bindhash mutex for snum's hash chain must be held here.
102591 @@ -554,6 +557,8 @@ ok:
102592 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102593 spin_unlock(&head->lock);
102594
102595 + gr_update_task_in_ip_table(inet_sk(sk));
102596 +
102597 if (tw) {
102598 inet_twsk_deschedule(tw, death_row);
102599 while (twrefcnt) {
102600 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102601 index 241afd7..31b95d5 100644
102602 --- a/net/ipv4/inetpeer.c
102603 +++ b/net/ipv4/inetpeer.c
102604 @@ -461,7 +461,7 @@ relookup:
102605 if (p) {
102606 p->daddr = *daddr;
102607 atomic_set(&p->refcnt, 1);
102608 - atomic_set(&p->rid, 0);
102609 + atomic_set_unchecked(&p->rid, 0);
102610 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102611 p->rate_tokens = 0;
102612 /* 60*HZ is arbitrary, but chosen enough high so that the first
102613 diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
102614 index 3a83ce5..787b3c2 100644
102615 --- a/net/ipv4/ip_forward.c
102616 +++ b/net/ipv4/ip_forward.c
102617 @@ -129,7 +129,8 @@ int ip_forward(struct sk_buff *skb)
102618 * We now generate an ICMP HOST REDIRECT giving the route
102619 * we calculated.
102620 */
102621 - if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb))
102622 + if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
102623 + !skb_sec_path(skb))
102624 ip_rt_send_redirect(skb);
102625
102626 skb->priority = rt_tos2priority(iph->tos);
102627 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102628 index 2811cc1..ad5a534 100644
102629 --- a/net/ipv4/ip_fragment.c
102630 +++ b/net/ipv4/ip_fragment.c
102631 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102632 return 0;
102633
102634 start = qp->rid;
102635 - end = atomic_inc_return(&peer->rid);
102636 + end = atomic_inc_return_unchecked(&peer->rid);
102637 qp->rid = end;
102638
102639 rc = qp->q.fragments && (end - start) > max;
102640 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102641
102642 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102643 {
102644 - struct ctl_table *table;
102645 + ctl_table_no_const *table = NULL;
102646 struct ctl_table_header *hdr;
102647
102648 - table = ip4_frags_ns_ctl_table;
102649 if (!net_eq(net, &init_net)) {
102650 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102651 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102652 if (table == NULL)
102653 goto err_alloc;
102654
102655 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102656 /* Don't export sysctls to unprivileged users */
102657 if (net->user_ns != &init_user_ns)
102658 table[0].procname = NULL;
102659 - }
102660 + hdr = register_net_sysctl(net, "net/ipv4", table);
102661 + } else
102662 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102663
102664 - hdr = register_net_sysctl(net, "net/ipv4", table);
102665 if (hdr == NULL)
102666 goto err_reg;
102667
102668 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102669 return 0;
102670
102671 err_reg:
102672 - if (!net_eq(net, &init_net))
102673 - kfree(table);
102674 + kfree(table);
102675 err_alloc:
102676 return -ENOMEM;
102677 }
102678 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102679 index 69aaf0a..8298c029 100644
102680 --- a/net/ipv4/ip_gre.c
102681 +++ b/net/ipv4/ip_gre.c
102682 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102683 module_param(log_ecn_error, bool, 0644);
102684 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102685
102686 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102687 +static struct rtnl_link_ops ipgre_link_ops;
102688 static int ipgre_tunnel_init(struct net_device *dev);
102689
102690 static int ipgre_net_id __read_mostly;
102691 @@ -816,7 +816,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102692 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102693 };
102694
102695 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102696 +static struct rtnl_link_ops ipgre_link_ops = {
102697 .kind = "gre",
102698 .maxtype = IFLA_GRE_MAX,
102699 .policy = ipgre_policy,
102700 @@ -830,7 +830,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102701 .fill_info = ipgre_fill_info,
102702 };
102703
102704 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102705 +static struct rtnl_link_ops ipgre_tap_ops = {
102706 .kind = "gretap",
102707 .maxtype = IFLA_GRE_MAX,
102708 .policy = ipgre_policy,
102709 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102710 index 3d4da2c..40f9c29 100644
102711 --- a/net/ipv4/ip_input.c
102712 +++ b/net/ipv4/ip_input.c
102713 @@ -147,6 +147,10 @@
102714 #include <linux/mroute.h>
102715 #include <linux/netlink.h>
102716
102717 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102718 +extern int grsec_enable_blackhole;
102719 +#endif
102720 +
102721 /*
102722 * Process Router Attention IP option (RFC 2113)
102723 */
102724 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102725 if (!raw) {
102726 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102727 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102728 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102729 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102730 +#endif
102731 icmp_send(skb, ICMP_DEST_UNREACH,
102732 ICMP_PROT_UNREACH, 0);
102733 }
102734 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102735 index bc6471d..c5e8a0c 100644
102736 --- a/net/ipv4/ip_output.c
102737 +++ b/net/ipv4/ip_output.c
102738 @@ -1517,6 +1517,7 @@ static DEFINE_PER_CPU(struct inet_sock, unicast_sock) = {
102739 .sk_wmem_alloc = ATOMIC_INIT(1),
102740 .sk_allocation = GFP_ATOMIC,
102741 .sk_flags = (1UL << SOCK_USE_WRITE_QUEUE),
102742 + .sk_pacing_rate = ~0U,
102743 },
102744 .pmtudisc = IP_PMTUDISC_WANT,
102745 .uc_ttl = -1,
102746 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102747 index 9daf217..373d454 100644
102748 --- a/net/ipv4/ip_sockglue.c
102749 +++ b/net/ipv4/ip_sockglue.c
102750 @@ -443,15 +443,12 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102751
102752 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
102753 sin = &errhdr.offender;
102754 - sin->sin_family = AF_UNSPEC;
102755 + memset(sin, 0, sizeof(*sin));
102756 +
102757 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
102758 - struct inet_sock *inet = inet_sk(sk);
102759 -
102760 sin->sin_family = AF_INET;
102761 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
102762 - sin->sin_port = 0;
102763 - memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
102764 - if (inet->cmsg_flags)
102765 + if (inet_sk(sk)->cmsg_flags)
102766 ip_cmsg_recv(msg, skb);
102767 }
102768
102769 @@ -1177,7 +1174,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102770 len = min_t(unsigned int, len, opt->optlen);
102771 if (put_user(len, optlen))
102772 return -EFAULT;
102773 - if (copy_to_user(optval, opt->__data, len))
102774 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102775 + copy_to_user(optval, opt->__data, len))
102776 return -EFAULT;
102777 return 0;
102778 }
102779 @@ -1308,7 +1306,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102780 if (sk->sk_type != SOCK_STREAM)
102781 return -ENOPROTOOPT;
102782
102783 - msg.msg_control = (__force void *) optval;
102784 + msg.msg_control = (__force_kernel void *) optval;
102785 msg.msg_controllen = len;
102786 msg.msg_flags = flags;
102787
102788 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102789 index 1a7e979..fd05aa4 100644
102790 --- a/net/ipv4/ip_vti.c
102791 +++ b/net/ipv4/ip_vti.c
102792 @@ -45,7 +45,7 @@
102793 #include <net/net_namespace.h>
102794 #include <net/netns/generic.h>
102795
102796 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102797 +static struct rtnl_link_ops vti_link_ops;
102798
102799 static int vti_net_id __read_mostly;
102800 static int vti_tunnel_init(struct net_device *dev);
102801 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102802 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102803 };
102804
102805 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102806 +static struct rtnl_link_ops vti_link_ops = {
102807 .kind = "vti",
102808 .maxtype = IFLA_VTI_MAX,
102809 .policy = vti_policy,
102810 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102811 index 648fa14..97864d0 100644
102812 --- a/net/ipv4/ipconfig.c
102813 +++ b/net/ipv4/ipconfig.c
102814 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102815
102816 mm_segment_t oldfs = get_fs();
102817 set_fs(get_ds());
102818 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102819 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102820 set_fs(oldfs);
102821 return res;
102822 }
102823 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102824
102825 mm_segment_t oldfs = get_fs();
102826 set_fs(get_ds());
102827 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102828 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102829 set_fs(oldfs);
102830 return res;
102831 }
102832 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102833
102834 mm_segment_t oldfs = get_fs();
102835 set_fs(get_ds());
102836 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102837 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102838 set_fs(oldfs);
102839 return res;
102840 }
102841 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102842 index 37096d6..86abb03 100644
102843 --- a/net/ipv4/ipip.c
102844 +++ b/net/ipv4/ipip.c
102845 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102846 static int ipip_net_id __read_mostly;
102847
102848 static int ipip_tunnel_init(struct net_device *dev);
102849 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102850 +static struct rtnl_link_ops ipip_link_ops;
102851
102852 static int ipip_err(struct sk_buff *skb, u32 info)
102853 {
102854 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102855 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102856 };
102857
102858 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102859 +static struct rtnl_link_ops ipip_link_ops = {
102860 .kind = "ipip",
102861 .maxtype = IFLA_IPTUN_MAX,
102862 .policy = ipip_policy,
102863 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102864 index f95b6f9..2ee2097 100644
102865 --- a/net/ipv4/netfilter/arp_tables.c
102866 +++ b/net/ipv4/netfilter/arp_tables.c
102867 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102868 #endif
102869
102870 static int get_info(struct net *net, void __user *user,
102871 - const int *len, int compat)
102872 + int len, int compat)
102873 {
102874 char name[XT_TABLE_MAXNAMELEN];
102875 struct xt_table *t;
102876 int ret;
102877
102878 - if (*len != sizeof(struct arpt_getinfo)) {
102879 - duprintf("length %u != %Zu\n", *len,
102880 + if (len != sizeof(struct arpt_getinfo)) {
102881 + duprintf("length %u != %Zu\n", len,
102882 sizeof(struct arpt_getinfo));
102883 return -EINVAL;
102884 }
102885 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102886 info.size = private->size;
102887 strcpy(info.name, name);
102888
102889 - if (copy_to_user(user, &info, *len) != 0)
102890 + if (copy_to_user(user, &info, len) != 0)
102891 ret = -EFAULT;
102892 else
102893 ret = 0;
102894 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102895
102896 switch (cmd) {
102897 case ARPT_SO_GET_INFO:
102898 - ret = get_info(sock_net(sk), user, len, 1);
102899 + ret = get_info(sock_net(sk), user, *len, 1);
102900 break;
102901 case ARPT_SO_GET_ENTRIES:
102902 ret = compat_get_entries(sock_net(sk), user, len);
102903 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102904
102905 switch (cmd) {
102906 case ARPT_SO_GET_INFO:
102907 - ret = get_info(sock_net(sk), user, len, 0);
102908 + ret = get_info(sock_net(sk), user, *len, 0);
102909 break;
102910
102911 case ARPT_SO_GET_ENTRIES:
102912 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102913 index 99e810f..3711b81 100644
102914 --- a/net/ipv4/netfilter/ip_tables.c
102915 +++ b/net/ipv4/netfilter/ip_tables.c
102916 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102917 #endif
102918
102919 static int get_info(struct net *net, void __user *user,
102920 - const int *len, int compat)
102921 + int len, int compat)
102922 {
102923 char name[XT_TABLE_MAXNAMELEN];
102924 struct xt_table *t;
102925 int ret;
102926
102927 - if (*len != sizeof(struct ipt_getinfo)) {
102928 - duprintf("length %u != %zu\n", *len,
102929 + if (len != sizeof(struct ipt_getinfo)) {
102930 + duprintf("length %u != %zu\n", len,
102931 sizeof(struct ipt_getinfo));
102932 return -EINVAL;
102933 }
102934 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102935 info.size = private->size;
102936 strcpy(info.name, name);
102937
102938 - if (copy_to_user(user, &info, *len) != 0)
102939 + if (copy_to_user(user, &info, len) != 0)
102940 ret = -EFAULT;
102941 else
102942 ret = 0;
102943 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102944
102945 switch (cmd) {
102946 case IPT_SO_GET_INFO:
102947 - ret = get_info(sock_net(sk), user, len, 1);
102948 + ret = get_info(sock_net(sk), user, *len, 1);
102949 break;
102950 case IPT_SO_GET_ENTRIES:
102951 ret = compat_get_entries(sock_net(sk), user, len);
102952 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102953
102954 switch (cmd) {
102955 case IPT_SO_GET_INFO:
102956 - ret = get_info(sock_net(sk), user, len, 0);
102957 + ret = get_info(sock_net(sk), user, *len, 0);
102958 break;
102959
102960 case IPT_SO_GET_ENTRIES:
102961 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102962 index e90f83a..3e6acca 100644
102963 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102964 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102965 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102966 spin_lock_init(&cn->lock);
102967
102968 #ifdef CONFIG_PROC_FS
102969 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102970 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102971 if (!cn->procdir) {
102972 pr_err("Unable to proc dir entry\n");
102973 return -ENOMEM;
102974 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102975 index 5d740cc..22c8e65 100644
102976 --- a/net/ipv4/ping.c
102977 +++ b/net/ipv4/ping.c
102978 @@ -59,7 +59,7 @@ struct ping_table {
102979 };
102980
102981 static struct ping_table ping_table;
102982 -struct pingv6_ops pingv6_ops;
102983 +struct pingv6_ops *pingv6_ops;
102984 EXPORT_SYMBOL_GPL(pingv6_ops);
102985
102986 static u16 ping_port_rover;
102987 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102988 return -ENODEV;
102989 }
102990 }
102991 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102992 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102993 scoped);
102994 rcu_read_unlock();
102995
102996 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102997 }
102998 #if IS_ENABLED(CONFIG_IPV6)
102999 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103000 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103001 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103002 #endif
103003 }
103004
103005 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103006 info, (u8 *)icmph);
103007 #if IS_ENABLED(CONFIG_IPV6)
103008 } else if (family == AF_INET6) {
103009 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103010 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103011 info, (u8 *)icmph);
103012 #endif
103013 }
103014 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103015 }
103016
103017 if (inet6_sk(sk)->rxopt.all)
103018 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103019 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103020 if (skb->protocol == htons(ETH_P_IPV6) &&
103021 inet6_sk(sk)->rxopt.all)
103022 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103023 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103024 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103025 ip_cmsg_recv(msg, skb);
103026 #endif
103027 @@ -965,8 +965,11 @@ void ping_rcv(struct sk_buff *skb)
103028
103029 sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
103030 if (sk != NULL) {
103031 + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
103032 +
103033 pr_debug("rcv on socket %p\n", sk);
103034 - ping_queue_rcv_skb(sk, skb_get(skb));
103035 + if (skb2)
103036 + ping_queue_rcv_skb(sk, skb2);
103037 sock_put(sk);
103038 return;
103039 }
103040 @@ -1105,7 +1108,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103041 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103042 0, sock_i_ino(sp),
103043 atomic_read(&sp->sk_refcnt), sp,
103044 - atomic_read(&sp->sk_drops));
103045 + atomic_read_unchecked(&sp->sk_drops));
103046 }
103047
103048 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103049 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103050 index 739db31..74f0210 100644
103051 --- a/net/ipv4/raw.c
103052 +++ b/net/ipv4/raw.c
103053 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103054 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103055 {
103056 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103057 - atomic_inc(&sk->sk_drops);
103058 + atomic_inc_unchecked(&sk->sk_drops);
103059 kfree_skb(skb);
103060 return NET_RX_DROP;
103061 }
103062 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103063
103064 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103065 {
103066 + struct icmp_filter filter;
103067 +
103068 if (optlen > sizeof(struct icmp_filter))
103069 optlen = sizeof(struct icmp_filter);
103070 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103071 + if (copy_from_user(&filter, optval, optlen))
103072 return -EFAULT;
103073 + raw_sk(sk)->filter = filter;
103074 return 0;
103075 }
103076
103077 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103078 {
103079 int len, ret = -EFAULT;
103080 + struct icmp_filter filter;
103081
103082 if (get_user(len, optlen))
103083 goto out;
103084 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103085 if (len > sizeof(struct icmp_filter))
103086 len = sizeof(struct icmp_filter);
103087 ret = -EFAULT;
103088 - if (put_user(len, optlen) ||
103089 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103090 + filter = raw_sk(sk)->filter;
103091 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103092 goto out;
103093 ret = 0;
103094 out: return ret;
103095 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103096 0, 0L, 0,
103097 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103098 0, sock_i_ino(sp),
103099 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103100 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103101 }
103102
103103 static int raw_seq_show(struct seq_file *seq, void *v)
103104 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103105 index 6a2155b..47de388 100644
103106 --- a/net/ipv4/route.c
103107 +++ b/net/ipv4/route.c
103108 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103109
103110 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103111 {
103112 - return seq_open(file, &rt_cache_seq_ops);
103113 + return seq_open_restrict(file, &rt_cache_seq_ops);
103114 }
103115
103116 static const struct file_operations rt_cache_seq_fops = {
103117 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103118
103119 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103120 {
103121 - return seq_open(file, &rt_cpu_seq_ops);
103122 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103123 }
103124
103125 static const struct file_operations rt_cpu_seq_fops = {
103126 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103127
103128 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103129 {
103130 - return single_open(file, rt_acct_proc_show, NULL);
103131 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103132 }
103133
103134 static const struct file_operations rt_acct_proc_fops = {
103135 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103136
103137 #define IP_IDENTS_SZ 2048u
103138 struct ip_ident_bucket {
103139 - atomic_t id;
103140 + atomic_unchecked_t id;
103141 u32 stamp32;
103142 };
103143
103144 -static struct ip_ident_bucket *ip_idents __read_mostly;
103145 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103146
103147 /* In order to protect privacy, we add a perturbation to identifiers
103148 * if one generator is seldom used. This makes hard for an attacker
103149 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103150 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103151 delta = prandom_u32_max(now - old);
103152
103153 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103154 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103155 }
103156 EXPORT_SYMBOL(ip_idents_reserve);
103157
103158 @@ -1554,11 +1554,10 @@ static int __mkroute_input(struct sk_buff *skb,
103159
103160 do_cache = res->fi && !itag;
103161 if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
103162 + skb->protocol == htons(ETH_P_IP) &&
103163 (IN_DEV_SHARED_MEDIA(out_dev) ||
103164 - inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res)))) {
103165 - flags |= RTCF_DOREDIRECT;
103166 - do_cache = false;
103167 - }
103168 + inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
103169 + IPCB(skb)->flags |= IPSKB_DOREDIRECT;
103170
103171 if (skb->protocol != htons(ETH_P_IP)) {
103172 /* Not IP (i.e. ARP). Do not create route, if it is
103173 @@ -2303,6 +2302,8 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
103174 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
103175 if (rt->rt_flags & RTCF_NOTIFY)
103176 r->rtm_flags |= RTM_F_NOTIFY;
103177 + if (IPCB(skb)->flags & IPSKB_DOREDIRECT)
103178 + r->rtm_flags |= RTCF_DOREDIRECT;
103179
103180 if (nla_put_be32(skb, RTA_DST, dst))
103181 goto nla_put_failure;
103182 @@ -2624,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103183 .maxlen = sizeof(int),
103184 .mode = 0200,
103185 .proc_handler = ipv4_sysctl_rtcache_flush,
103186 + .extra1 = &init_net,
103187 },
103188 { },
103189 };
103190
103191 static __net_init int sysctl_route_net_init(struct net *net)
103192 {
103193 - struct ctl_table *tbl;
103194 + ctl_table_no_const *tbl = NULL;
103195
103196 - tbl = ipv4_route_flush_table;
103197 if (!net_eq(net, &init_net)) {
103198 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103199 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103200 if (tbl == NULL)
103201 goto err_dup;
103202
103203 /* Don't export sysctls to unprivileged users */
103204 if (net->user_ns != &init_user_ns)
103205 tbl[0].procname = NULL;
103206 - }
103207 - tbl[0].extra1 = net;
103208 + tbl[0].extra1 = net;
103209 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103210 + } else
103211 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103212
103213 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103214 if (net->ipv4.route_hdr == NULL)
103215 goto err_reg;
103216 return 0;
103217
103218 err_reg:
103219 - if (tbl != ipv4_route_flush_table)
103220 - kfree(tbl);
103221 + kfree(tbl);
103222 err_dup:
103223 return -ENOMEM;
103224 }
103225 @@ -2674,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103226
103227 static __net_init int rt_genid_init(struct net *net)
103228 {
103229 - atomic_set(&net->ipv4.rt_genid, 0);
103230 - atomic_set(&net->fnhe_genid, 0);
103231 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103232 + atomic_set_unchecked(&net->fnhe_genid, 0);
103233 get_random_bytes(&net->ipv4.dev_addr_genid,
103234 sizeof(net->ipv4.dev_addr_genid));
103235 return 0;
103236 @@ -2718,11 +2719,7 @@ int __init ip_rt_init(void)
103237 {
103238 int rc = 0;
103239
103240 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103241 - if (!ip_idents)
103242 - panic("IP: failed to allocate ip_idents\n");
103243 -
103244 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103245 + prandom_bytes(ip_idents, sizeof(ip_idents));
103246
103247 #ifdef CONFIG_IP_ROUTE_CLASSID
103248 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103249 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103250 index b3c53c8..35cc18d 100644
103251 --- a/net/ipv4/sysctl_net_ipv4.c
103252 +++ b/net/ipv4/sysctl_net_ipv4.c
103253 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103254 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103255 int ret;
103256 int range[2];
103257 - struct ctl_table tmp = {
103258 + ctl_table_no_const tmp = {
103259 .data = &range,
103260 .maxlen = sizeof(range),
103261 .mode = table->mode,
103262 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103263 int ret;
103264 gid_t urange[2];
103265 kgid_t low, high;
103266 - struct ctl_table tmp = {
103267 + ctl_table_no_const tmp = {
103268 .data = &urange,
103269 .maxlen = sizeof(urange),
103270 .mode = table->mode,
103271 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103272 void __user *buffer, size_t *lenp, loff_t *ppos)
103273 {
103274 char val[TCP_CA_NAME_MAX];
103275 - struct ctl_table tbl = {
103276 + ctl_table_no_const tbl = {
103277 .data = val,
103278 .maxlen = TCP_CA_NAME_MAX,
103279 };
103280 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103281 void __user *buffer, size_t *lenp,
103282 loff_t *ppos)
103283 {
103284 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103285 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103286 int ret;
103287
103288 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103289 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103290 void __user *buffer, size_t *lenp,
103291 loff_t *ppos)
103292 {
103293 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103294 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103295 int ret;
103296
103297 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103298 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103299 void __user *buffer, size_t *lenp,
103300 loff_t *ppos)
103301 {
103302 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103303 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103304 struct tcp_fastopen_context *ctxt;
103305 int ret;
103306 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103307 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
103308
103309 static __net_init int ipv4_sysctl_init_net(struct net *net)
103310 {
103311 - struct ctl_table *table;
103312 + ctl_table_no_const *table = NULL;
103313
103314 - table = ipv4_net_table;
103315 if (!net_eq(net, &init_net)) {
103316 int i;
103317
103318 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103319 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103320 if (table == NULL)
103321 goto err_alloc;
103322
103323 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103324 table[i].data += (void *)net - (void *)&init_net;
103325 }
103326
103327 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103328 + if (!net_eq(net, &init_net))
103329 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103330 + else
103331 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103332 if (net->ipv4.ipv4_hdr == NULL)
103333 goto err_reg;
103334
103335 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103336 index d107ee2..bcebf11 100644
103337 --- a/net/ipv4/tcp_input.c
103338 +++ b/net/ipv4/tcp_input.c
103339 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103340 * without any lock. We want to make sure compiler wont store
103341 * intermediate values in this location.
103342 */
103343 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103344 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103345 sk->sk_max_pacing_rate);
103346 }
103347
103348 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103349 * simplifies code)
103350 */
103351 static void
103352 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103353 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103354 struct sk_buff *head, struct sk_buff *tail,
103355 u32 start, u32 end)
103356 {
103357 @@ -5506,6 +5506,7 @@ discard:
103358 tcp_paws_reject(&tp->rx_opt, 0))
103359 goto discard_and_undo;
103360
103361 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103362 if (th->syn) {
103363 /* We see SYN without ACK. It is attempt of
103364 * simultaneous connect with crossed SYNs.
103365 @@ -5556,6 +5557,7 @@ discard:
103366 goto discard;
103367 #endif
103368 }
103369 +#endif
103370 /* "fifth, if neither of the SYN or RST bits is set then
103371 * drop the segment and return."
103372 */
103373 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103374 goto discard;
103375
103376 if (th->syn) {
103377 - if (th->fin)
103378 + if (th->fin || th->urg || th->psh)
103379 goto discard;
103380 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103381 return 1;
103382 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103383 index ef7089c..a3e65fb 100644
103384 --- a/net/ipv4/tcp_ipv4.c
103385 +++ b/net/ipv4/tcp_ipv4.c
103386 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
103387 int sysctl_tcp_low_latency __read_mostly;
103388 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103389
103390 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103391 +extern int grsec_enable_blackhole;
103392 +#endif
103393 +
103394 #ifdef CONFIG_TCP_MD5SIG
103395 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103396 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103397 @@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103398 return 0;
103399
103400 reset:
103401 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103402 + if (!grsec_enable_blackhole)
103403 +#endif
103404 tcp_v4_send_reset(rsk, skb);
103405 discard:
103406 kfree_skb(skb);
103407 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103408 TCP_SKB_CB(skb)->sacked = 0;
103409
103410 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103411 - if (!sk)
103412 + if (!sk) {
103413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103414 + ret = 1;
103415 +#endif
103416 goto no_tcp_socket;
103417 -
103418 + }
103419 process:
103420 - if (sk->sk_state == TCP_TIME_WAIT)
103421 + if (sk->sk_state == TCP_TIME_WAIT) {
103422 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103423 + ret = 2;
103424 +#endif
103425 goto do_time_wait;
103426 + }
103427
103428 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103429 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103430 @@ -1694,6 +1708,10 @@ csum_error:
103431 bad_packet:
103432 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103433 } else {
103434 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103435 + if (!grsec_enable_blackhole || (ret == 1 &&
103436 + (skb->dev->flags & IFF_LOOPBACK)))
103437 +#endif
103438 tcp_v4_send_reset(NULL, skb);
103439 }
103440
103441 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103442 index 63d2680..2db9d6b 100644
103443 --- a/net/ipv4/tcp_minisocks.c
103444 +++ b/net/ipv4/tcp_minisocks.c
103445 @@ -27,6 +27,10 @@
103446 #include <net/inet_common.h>
103447 #include <net/xfrm.h>
103448
103449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103450 +extern int grsec_enable_blackhole;
103451 +#endif
103452 +
103453 int sysctl_tcp_syncookies __read_mostly = 1;
103454 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103455
103456 @@ -739,7 +743,10 @@ embryonic_reset:
103457 * avoid becoming vulnerable to outside attack aiming at
103458 * resetting legit local connections.
103459 */
103460 - req->rsk_ops->send_reset(sk, skb);
103461 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103462 + if (!grsec_enable_blackhole)
103463 +#endif
103464 + req->rsk_ops->send_reset(sk, skb);
103465 } else if (fastopen) { /* received a valid RST pkt */
103466 reqsk_fastopen_remove(sk, req, true);
103467 tcp_reset(sk);
103468 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103469 index ebf5ff5..4d1ff32 100644
103470 --- a/net/ipv4/tcp_probe.c
103471 +++ b/net/ipv4/tcp_probe.c
103472 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103473 if (cnt + width >= len)
103474 break;
103475
103476 - if (copy_to_user(buf + cnt, tbuf, width))
103477 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103478 return -EFAULT;
103479 cnt += width;
103480 }
103481 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103482 index 9b21ae8..4eb67df 100644
103483 --- a/net/ipv4/tcp_timer.c
103484 +++ b/net/ipv4/tcp_timer.c
103485 @@ -22,6 +22,10 @@
103486 #include <linux/gfp.h>
103487 #include <net/tcp.h>
103488
103489 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103490 +extern int grsec_lastack_retries;
103491 +#endif
103492 +
103493 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103494 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103495 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103496 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103497 }
103498 }
103499
103500 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103501 + if ((sk->sk_state == TCP_LAST_ACK) &&
103502 + (grsec_lastack_retries > 0) &&
103503 + (grsec_lastack_retries < retry_until))
103504 + retry_until = grsec_lastack_retries;
103505 +#endif
103506 +
103507 if (retransmits_timed_out(sk, retry_until,
103508 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103509 /* Has it gone just too far? */
103510 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103511 index cd0db54..93a6518 100644
103512 --- a/net/ipv4/udp.c
103513 +++ b/net/ipv4/udp.c
103514 @@ -87,6 +87,7 @@
103515 #include <linux/types.h>
103516 #include <linux/fcntl.h>
103517 #include <linux/module.h>
103518 +#include <linux/security.h>
103519 #include <linux/socket.h>
103520 #include <linux/sockios.h>
103521 #include <linux/igmp.h>
103522 @@ -114,6 +115,10 @@
103523 #include <net/busy_poll.h>
103524 #include "udp_impl.h"
103525
103526 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103527 +extern int grsec_enable_blackhole;
103528 +#endif
103529 +
103530 struct udp_table udp_table __read_mostly;
103531 EXPORT_SYMBOL(udp_table);
103532
103533 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103534 return true;
103535 }
103536
103537 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103538 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103539 +
103540 /*
103541 * This routine is called by the ICMP module when it gets some
103542 * sort of error condition. If err < 0 then the socket should
103543 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103544 dport = usin->sin_port;
103545 if (dport == 0)
103546 return -EINVAL;
103547 +
103548 + err = gr_search_udp_sendmsg(sk, usin);
103549 + if (err)
103550 + return err;
103551 } else {
103552 if (sk->sk_state != TCP_ESTABLISHED)
103553 return -EDESTADDRREQ;
103554 +
103555 + err = gr_search_udp_sendmsg(sk, NULL);
103556 + if (err)
103557 + return err;
103558 +
103559 daddr = inet->inet_daddr;
103560 dport = inet->inet_dport;
103561 /* Open fast path for connected socket.
103562 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103563 IS_UDPLITE(sk));
103564 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103565 IS_UDPLITE(sk));
103566 - atomic_inc(&sk->sk_drops);
103567 + atomic_inc_unchecked(&sk->sk_drops);
103568 __skb_unlink(skb, rcvq);
103569 __skb_queue_tail(&list_kill, skb);
103570 }
103571 @@ -1262,6 +1279,10 @@ try_again:
103572 if (!skb)
103573 goto out;
103574
103575 + err = gr_search_udp_recvmsg(sk, skb);
103576 + if (err)
103577 + goto out_free;
103578 +
103579 ulen = skb->len - sizeof(struct udphdr);
103580 copied = len;
103581 if (copied > ulen)
103582 @@ -1295,7 +1316,7 @@ try_again:
103583 if (unlikely(err)) {
103584 trace_kfree_skb(skb, udp_recvmsg);
103585 if (!peeked) {
103586 - atomic_inc(&sk->sk_drops);
103587 + atomic_inc_unchecked(&sk->sk_drops);
103588 UDP_INC_STATS_USER(sock_net(sk),
103589 UDP_MIB_INERRORS, is_udplite);
103590 }
103591 @@ -1592,7 +1613,7 @@ csum_error:
103592 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103593 drop:
103594 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103595 - atomic_inc(&sk->sk_drops);
103596 + atomic_inc_unchecked(&sk->sk_drops);
103597 kfree_skb(skb);
103598 return -1;
103599 }
103600 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103601 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103602
103603 if (!skb1) {
103604 - atomic_inc(&sk->sk_drops);
103605 + atomic_inc_unchecked(&sk->sk_drops);
103606 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103607 IS_UDPLITE(sk));
103608 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103609 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103610 goto csum_error;
103611
103612 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103613 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103614 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103615 +#endif
103616 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103617
103618 /*
103619 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103620 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103621 0, sock_i_ino(sp),
103622 atomic_read(&sp->sk_refcnt), sp,
103623 - atomic_read(&sp->sk_drops));
103624 + atomic_read_unchecked(&sp->sk_drops));
103625 }
103626
103627 int udp4_seq_show(struct seq_file *seq, void *v)
103628 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103629 index 6156f68..d6ab46d 100644
103630 --- a/net/ipv4/xfrm4_policy.c
103631 +++ b/net/ipv4/xfrm4_policy.c
103632 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103633 fl4->flowi4_tos = iph->tos;
103634 }
103635
103636 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103637 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103638 {
103639 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103640
103641 - xfrm4_policy_afinfo.garbage_collect(net);
103642 + xfrm_garbage_collect_deferred(net);
103643 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103644 }
103645
103646 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103647
103648 static int __net_init xfrm4_net_init(struct net *net)
103649 {
103650 - struct ctl_table *table;
103651 + ctl_table_no_const *table = NULL;
103652 struct ctl_table_header *hdr;
103653
103654 - table = xfrm4_policy_table;
103655 if (!net_eq(net, &init_net)) {
103656 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103657 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103658 if (!table)
103659 goto err_alloc;
103660
103661 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103662 - }
103663 -
103664 - hdr = register_net_sysctl(net, "net/ipv4", table);
103665 + hdr = register_net_sysctl(net, "net/ipv4", table);
103666 + } else
103667 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103668 if (!hdr)
103669 goto err_reg;
103670
103671 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103672 return 0;
103673
103674 err_reg:
103675 - if (!net_eq(net, &init_net))
103676 - kfree(table);
103677 + kfree(table);
103678 err_alloc:
103679 return -ENOMEM;
103680 }
103681 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103682 index 0169ccf..6f14338 100644
103683 --- a/net/ipv6/addrconf.c
103684 +++ b/net/ipv6/addrconf.c
103685 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103686 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103687 .mtu6 = IPV6_MIN_MTU,
103688 .accept_ra = 1,
103689 - .accept_redirects = 1,
103690 + .accept_redirects = 0,
103691 .autoconf = 1,
103692 .force_mld_version = 0,
103693 .mldv1_unsolicited_report_interval = 10 * HZ,
103694 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103695 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103696 .mtu6 = IPV6_MIN_MTU,
103697 .accept_ra = 1,
103698 - .accept_redirects = 1,
103699 + .accept_redirects = 0,
103700 .autoconf = 1,
103701 .force_mld_version = 0,
103702 .mldv1_unsolicited_report_interval = 10 * HZ,
103703 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103704 idx = 0;
103705 head = &net->dev_index_head[h];
103706 rcu_read_lock();
103707 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103708 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103709 net->dev_base_seq;
103710 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103711 if (idx < s_idx)
103712 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103713 p.iph.ihl = 5;
103714 p.iph.protocol = IPPROTO_IPV6;
103715 p.iph.ttl = 64;
103716 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103717 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103718
103719 if (ops->ndo_do_ioctl) {
103720 mm_segment_t oldfs = get_fs();
103721 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103722 .release = seq_release_net,
103723 };
103724
103725 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103726 +extern void unregister_ipv6_seq_ops_addr(void);
103727 +
103728 static int __net_init if6_proc_net_init(struct net *net)
103729 {
103730 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103731 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103732 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103733 + unregister_ipv6_seq_ops_addr();
103734 return -ENOMEM;
103735 + }
103736 return 0;
103737 }
103738
103739 static void __net_exit if6_proc_net_exit(struct net *net)
103740 {
103741 remove_proc_entry("if_inet6", net->proc_net);
103742 + unregister_ipv6_seq_ops_addr();
103743 }
103744
103745 static struct pernet_operations if6_proc_net_ops = {
103746 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103747 s_ip_idx = ip_idx = cb->args[2];
103748
103749 rcu_read_lock();
103750 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103751 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103752 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103753 idx = 0;
103754 head = &net->dev_index_head[h];
103755 @@ -4536,6 +4543,22 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
103756 return 0;
103757 }
103758
103759 +static const struct nla_policy inet6_af_policy[IFLA_INET6_MAX + 1] = {
103760 + [IFLA_INET6_ADDR_GEN_MODE] = { .type = NLA_U8 },
103761 + [IFLA_INET6_TOKEN] = { .len = sizeof(struct in6_addr) },
103762 +};
103763 +
103764 +static int inet6_validate_link_af(const struct net_device *dev,
103765 + const struct nlattr *nla)
103766 +{
103767 + struct nlattr *tb[IFLA_INET6_MAX + 1];
103768 +
103769 + if (dev && !__in6_dev_get(dev))
103770 + return -EAFNOSUPPORT;
103771 +
103772 + return nla_parse_nested(tb, IFLA_INET6_MAX, nla, inet6_af_policy);
103773 +}
103774 +
103775 static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
103776 {
103777 int err = -EINVAL;
103778 @@ -4788,7 +4811,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103779 rt_genid_bump_ipv6(net);
103780 break;
103781 }
103782 - atomic_inc(&net->ipv6.dev_addr_genid);
103783 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103784 }
103785
103786 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103787 @@ -4808,7 +4831,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103788 int *valp = ctl->data;
103789 int val = *valp;
103790 loff_t pos = *ppos;
103791 - struct ctl_table lctl;
103792 + ctl_table_no_const lctl;
103793 int ret;
103794
103795 /*
103796 @@ -4893,7 +4916,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103797 int *valp = ctl->data;
103798 int val = *valp;
103799 loff_t pos = *ppos;
103800 - struct ctl_table lctl;
103801 + ctl_table_no_const lctl;
103802 int ret;
103803
103804 /*
103805 @@ -5351,6 +5374,7 @@ static struct rtnl_af_ops inet6_ops = {
103806 .family = AF_INET6,
103807 .fill_link_af = inet6_fill_link_af,
103808 .get_link_af_size = inet6_get_link_af_size,
103809 + .validate_link_af = inet6_validate_link_af,
103810 .set_link_af = inet6_set_link_af,
103811 };
103812
103813 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103814 index e8c4400..a4cd5da 100644
103815 --- a/net/ipv6/af_inet6.c
103816 +++ b/net/ipv6/af_inet6.c
103817 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103818 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103819 net->ipv6.sysctl.flowlabel_consistency = 1;
103820 net->ipv6.sysctl.auto_flowlabels = 0;
103821 - atomic_set(&net->ipv6.fib6_sernum, 1);
103822 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103823
103824 err = ipv6_init_mibs(net);
103825 if (err)
103826 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103827 index 2cdc383..4f1b785 100644
103828 --- a/net/ipv6/datagram.c
103829 +++ b/net/ipv6/datagram.c
103830 @@ -383,11 +383,10 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103831
103832 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
103833 sin = &errhdr.offender;
103834 - sin->sin6_family = AF_UNSPEC;
103835 + memset(sin, 0, sizeof(*sin));
103836 +
103837 if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
103838 sin->sin6_family = AF_INET6;
103839 - sin->sin6_flowinfo = 0;
103840 - sin->sin6_port = 0;
103841 if (np->rxopt.all)
103842 ip6_datagram_recv_common_ctl(sk, msg, skb);
103843 if (skb->protocol == htons(ETH_P_IPV6)) {
103844 @@ -398,12 +397,9 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103845 ipv6_iface_scope_id(&sin->sin6_addr,
103846 IP6CB(skb)->iif);
103847 } else {
103848 - struct inet_sock *inet = inet_sk(sk);
103849 -
103850 ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
103851 &sin->sin6_addr);
103852 - sin->sin6_scope_id = 0;
103853 - if (inet->cmsg_flags)
103854 + if (inet_sk(sk)->cmsg_flags)
103855 ip_cmsg_recv(msg, skb);
103856 }
103857 }
103858 @@ -928,5 +924,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103859 0,
103860 sock_i_ino(sp),
103861 atomic_read(&sp->sk_refcnt), sp,
103862 - atomic_read(&sp->sk_drops));
103863 + atomic_read_unchecked(&sp->sk_drops));
103864 }
103865 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103866 index 97ae700..18dcae0 100644
103867 --- a/net/ipv6/icmp.c
103868 +++ b/net/ipv6/icmp.c
103869 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103870
103871 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103872 {
103873 - struct ctl_table *table;
103874 + ctl_table_no_const *table;
103875
103876 table = kmemdup(ipv6_icmp_table_template,
103877 sizeof(ipv6_icmp_table_template),
103878 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103879 index b2d1838..0194c04 100644
103880 --- a/net/ipv6/ip6_fib.c
103881 +++ b/net/ipv6/ip6_fib.c
103882 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103883 int new, old;
103884
103885 do {
103886 - old = atomic_read(&net->ipv6.fib6_sernum);
103887 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103888 new = old < INT_MAX ? old + 1 : 1;
103889 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103890 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103891 old, new) != old);
103892 return new;
103893 }
103894 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103895 index 0e32d2e..dd45cdc 100644
103896 --- a/net/ipv6/ip6_gre.c
103897 +++ b/net/ipv6/ip6_gre.c
103898 @@ -71,8 +71,8 @@ struct ip6gre_net {
103899 struct net_device *fb_tunnel_dev;
103900 };
103901
103902 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103903 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103904 +static struct rtnl_link_ops ip6gre_link_ops;
103905 +static struct rtnl_link_ops ip6gre_tap_ops;
103906 static int ip6gre_tunnel_init(struct net_device *dev);
103907 static void ip6gre_tunnel_setup(struct net_device *dev);
103908 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103909 @@ -417,7 +417,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103910 if (code == ICMPV6_HDR_FIELD)
103911 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
103912
103913 - if (teli && teli == info - 2) {
103914 + if (teli && teli == be32_to_cpu(info) - 2) {
103915 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
103916 if (tel->encap_limit == 0) {
103917 net_warn_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
103918 @@ -429,7 +429,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103919 }
103920 break;
103921 case ICMPV6_PKT_TOOBIG:
103922 - mtu = info - offset;
103923 + mtu = be32_to_cpu(info) - offset;
103924 if (mtu < IPV6_MIN_MTU)
103925 mtu = IPV6_MIN_MTU;
103926 t->dev->mtu = mtu;
103927 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103928 }
103929
103930
103931 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103932 +static struct inet6_protocol ip6gre_protocol = {
103933 .handler = ip6gre_rcv,
103934 .err_handler = ip6gre_err,
103935 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103936 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103937 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103938 };
103939
103940 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103941 +static struct rtnl_link_ops ip6gre_link_ops = {
103942 .kind = "ip6gre",
103943 .maxtype = IFLA_GRE_MAX,
103944 .policy = ip6gre_policy,
103945 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103946 .fill_info = ip6gre_fill_info,
103947 };
103948
103949 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103950 +static struct rtnl_link_ops ip6gre_tap_ops = {
103951 .kind = "ip6gretap",
103952 .maxtype = IFLA_GRE_MAX,
103953 .policy = ip6gre_policy,
103954 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103955 index 9cb94cf..5678108 100644
103956 --- a/net/ipv6/ip6_tunnel.c
103957 +++ b/net/ipv6/ip6_tunnel.c
103958 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103959
103960 static int ip6_tnl_dev_init(struct net_device *dev);
103961 static void ip6_tnl_dev_setup(struct net_device *dev);
103962 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103963 +static struct rtnl_link_ops ip6_link_ops;
103964
103965 static int ip6_tnl_net_id __read_mostly;
103966 struct ip6_tnl_net {
103967 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103968 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103969 };
103970
103971 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103972 +static struct rtnl_link_ops ip6_link_ops = {
103973 .kind = "ip6tnl",
103974 .maxtype = IFLA_IPTUN_MAX,
103975 .policy = ip6_tnl_policy,
103976 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103977 index bcda14d..49378c9 100644
103978 --- a/net/ipv6/ip6_vti.c
103979 +++ b/net/ipv6/ip6_vti.c
103980 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103981
103982 static int vti6_dev_init(struct net_device *dev);
103983 static void vti6_dev_setup(struct net_device *dev);
103984 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103985 +static struct rtnl_link_ops vti6_link_ops;
103986
103987 static int vti6_net_id __read_mostly;
103988 struct vti6_net {
103989 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103990 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103991 };
103992
103993 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103994 +static struct rtnl_link_ops vti6_link_ops = {
103995 .kind = "vti6",
103996 .maxtype = IFLA_VTI_MAX,
103997 .policy = vti6_policy,
103998 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103999 index e1a9583..7dd8f4d 100644
104000 --- a/net/ipv6/ipv6_sockglue.c
104001 +++ b/net/ipv6/ipv6_sockglue.c
104002 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104003 if (sk->sk_type != SOCK_STREAM)
104004 return -ENOPROTOOPT;
104005
104006 - msg.msg_control = optval;
104007 + msg.msg_control = (void __force_kernel *)optval;
104008 msg.msg_controllen = len;
104009 msg.msg_flags = flags;
104010
104011 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104012 index e080fbb..412b3cf 100644
104013 --- a/net/ipv6/netfilter/ip6_tables.c
104014 +++ b/net/ipv6/netfilter/ip6_tables.c
104015 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104016 #endif
104017
104018 static int get_info(struct net *net, void __user *user,
104019 - const int *len, int compat)
104020 + int len, int compat)
104021 {
104022 char name[XT_TABLE_MAXNAMELEN];
104023 struct xt_table *t;
104024 int ret;
104025
104026 - if (*len != sizeof(struct ip6t_getinfo)) {
104027 - duprintf("length %u != %zu\n", *len,
104028 + if (len != sizeof(struct ip6t_getinfo)) {
104029 + duprintf("length %u != %zu\n", len,
104030 sizeof(struct ip6t_getinfo));
104031 return -EINVAL;
104032 }
104033 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104034 info.size = private->size;
104035 strcpy(info.name, name);
104036
104037 - if (copy_to_user(user, &info, *len) != 0)
104038 + if (copy_to_user(user, &info, len) != 0)
104039 ret = -EFAULT;
104040 else
104041 ret = 0;
104042 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104043
104044 switch (cmd) {
104045 case IP6T_SO_GET_INFO:
104046 - ret = get_info(sock_net(sk), user, len, 1);
104047 + ret = get_info(sock_net(sk), user, *len, 1);
104048 break;
104049 case IP6T_SO_GET_ENTRIES:
104050 ret = compat_get_entries(sock_net(sk), user, len);
104051 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104052
104053 switch (cmd) {
104054 case IP6T_SO_GET_INFO:
104055 - ret = get_info(sock_net(sk), user, len, 0);
104056 + ret = get_info(sock_net(sk), user, *len, 0);
104057 break;
104058
104059 case IP6T_SO_GET_ENTRIES:
104060 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104061 index 6f187c8..34b367f 100644
104062 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104063 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104064 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104065
104066 static int nf_ct_frag6_sysctl_register(struct net *net)
104067 {
104068 - struct ctl_table *table;
104069 + ctl_table_no_const *table = NULL;
104070 struct ctl_table_header *hdr;
104071
104072 - table = nf_ct_frag6_sysctl_table;
104073 if (!net_eq(net, &init_net)) {
104074 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104075 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104076 GFP_KERNEL);
104077 if (table == NULL)
104078 goto err_alloc;
104079 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104080 table[2].data = &net->nf_frag.frags.high_thresh;
104081 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104082 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104083 - }
104084 -
104085 - hdr = register_net_sysctl(net, "net/netfilter", table);
104086 + hdr = register_net_sysctl(net, "net/netfilter", table);
104087 + } else
104088 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104089 if (hdr == NULL)
104090 goto err_reg;
104091
104092 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104093 return 0;
104094
104095 err_reg:
104096 - if (!net_eq(net, &init_net))
104097 - kfree(table);
104098 + kfree(table);
104099 err_alloc:
104100 return -ENOMEM;
104101 }
104102 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104103 index 5b7a1ed..d9da205 100644
104104 --- a/net/ipv6/ping.c
104105 +++ b/net/ipv6/ping.c
104106 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104107 };
104108 #endif
104109
104110 +static struct pingv6_ops real_pingv6_ops = {
104111 + .ipv6_recv_error = ipv6_recv_error,
104112 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104113 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104114 + .icmpv6_err_convert = icmpv6_err_convert,
104115 + .ipv6_icmp_error = ipv6_icmp_error,
104116 + .ipv6_chk_addr = ipv6_chk_addr,
104117 +};
104118 +
104119 +static struct pingv6_ops dummy_pingv6_ops = {
104120 + .ipv6_recv_error = dummy_ipv6_recv_error,
104121 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104122 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104123 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104124 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104125 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104126 +};
104127 +
104128 int __init pingv6_init(void)
104129 {
104130 #ifdef CONFIG_PROC_FS
104131 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104132 if (ret)
104133 return ret;
104134 #endif
104135 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104136 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104137 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104138 - ip6_datagram_recv_specific_ctl;
104139 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104140 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104141 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104142 + pingv6_ops = &real_pingv6_ops;
104143 return inet6_register_protosw(&pingv6_protosw);
104144 }
104145
104146 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104147 */
104148 void pingv6_exit(void)
104149 {
104150 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104151 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104152 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104153 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104154 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104155 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104156 #ifdef CONFIG_PROC_FS
104157 unregister_pernet_subsys(&ping_v6_net_ops);
104158 #endif
104159 + pingv6_ops = &dummy_pingv6_ops;
104160 inet6_unregister_protosw(&pingv6_protosw);
104161 }
104162 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104163 index 1752cd0..3c6af41 100644
104164 --- a/net/ipv6/proc.c
104165 +++ b/net/ipv6/proc.c
104166 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104167 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104168 goto proc_snmp6_fail;
104169
104170 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104171 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104172 if (!net->mib.proc_net_devsnmp6)
104173 goto proc_dev_snmp6_fail;
104174 return 0;
104175 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104176 index 896af88..6e2ba628 100644
104177 --- a/net/ipv6/raw.c
104178 +++ b/net/ipv6/raw.c
104179 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104180 {
104181 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104182 skb_checksum_complete(skb)) {
104183 - atomic_inc(&sk->sk_drops);
104184 + atomic_inc_unchecked(&sk->sk_drops);
104185 kfree_skb(skb);
104186 return NET_RX_DROP;
104187 }
104188 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104189 struct raw6_sock *rp = raw6_sk(sk);
104190
104191 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104192 - atomic_inc(&sk->sk_drops);
104193 + atomic_inc_unchecked(&sk->sk_drops);
104194 kfree_skb(skb);
104195 return NET_RX_DROP;
104196 }
104197 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104198
104199 if (inet->hdrincl) {
104200 if (skb_checksum_complete(skb)) {
104201 - atomic_inc(&sk->sk_drops);
104202 + atomic_inc_unchecked(&sk->sk_drops);
104203 kfree_skb(skb);
104204 return NET_RX_DROP;
104205 }
104206 @@ -608,7 +608,7 @@ out:
104207 return err;
104208 }
104209
104210 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104211 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104212 struct flowi6 *fl6, struct dst_entry **dstp,
104213 unsigned int flags)
104214 {
104215 @@ -914,12 +914,15 @@ do_confirm:
104216 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104217 char __user *optval, int optlen)
104218 {
104219 + struct icmp6_filter filter;
104220 +
104221 switch (optname) {
104222 case ICMPV6_FILTER:
104223 if (optlen > sizeof(struct icmp6_filter))
104224 optlen = sizeof(struct icmp6_filter);
104225 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104226 + if (copy_from_user(&filter, optval, optlen))
104227 return -EFAULT;
104228 + raw6_sk(sk)->filter = filter;
104229 return 0;
104230 default:
104231 return -ENOPROTOOPT;
104232 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104233 char __user *optval, int __user *optlen)
104234 {
104235 int len;
104236 + struct icmp6_filter filter;
104237
104238 switch (optname) {
104239 case ICMPV6_FILTER:
104240 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104241 len = sizeof(struct icmp6_filter);
104242 if (put_user(len, optlen))
104243 return -EFAULT;
104244 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104245 + filter = raw6_sk(sk)->filter;
104246 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104247 return -EFAULT;
104248 return 0;
104249 default:
104250 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104251 index 1a157ca..9fc05f4 100644
104252 --- a/net/ipv6/reassembly.c
104253 +++ b/net/ipv6/reassembly.c
104254 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104255
104256 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104257 {
104258 - struct ctl_table *table;
104259 + ctl_table_no_const *table = NULL;
104260 struct ctl_table_header *hdr;
104261
104262 - table = ip6_frags_ns_ctl_table;
104263 if (!net_eq(net, &init_net)) {
104264 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104265 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104266 if (table == NULL)
104267 goto err_alloc;
104268
104269 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104270 /* Don't export sysctls to unprivileged users */
104271 if (net->user_ns != &init_user_ns)
104272 table[0].procname = NULL;
104273 - }
104274 + hdr = register_net_sysctl(net, "net/ipv6", table);
104275 + } else
104276 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104277
104278 - hdr = register_net_sysctl(net, "net/ipv6", table);
104279 if (hdr == NULL)
104280 goto err_reg;
104281
104282 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104283 return 0;
104284
104285 err_reg:
104286 - if (!net_eq(net, &init_net))
104287 - kfree(table);
104288 + kfree(table);
104289 err_alloc:
104290 return -ENOMEM;
104291 }
104292 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104293 index a318dd89..42a612c 100644
104294 --- a/net/ipv6/route.c
104295 +++ b/net/ipv6/route.c
104296 @@ -1150,12 +1150,9 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
104297 struct net *net = dev_net(dst->dev);
104298
104299 rt6->rt6i_flags |= RTF_MODIFIED;
104300 - if (mtu < IPV6_MIN_MTU) {
104301 - u32 features = dst_metric(dst, RTAX_FEATURES);
104302 + if (mtu < IPV6_MIN_MTU)
104303 mtu = IPV6_MIN_MTU;
104304 - features |= RTAX_FEATURE_ALLFRAG;
104305 - dst_metric_set(dst, RTAX_FEATURES, features);
104306 - }
104307 +
104308 dst_metric_set(dst, RTAX_MTU, mtu);
104309 rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
104310 }
104311 @@ -2965,7 +2962,7 @@ struct ctl_table ipv6_route_table_template[] = {
104312
104313 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104314 {
104315 - struct ctl_table *table;
104316 + ctl_table_no_const *table;
104317
104318 table = kmemdup(ipv6_route_table_template,
104319 sizeof(ipv6_route_table_template),
104320 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104321 index a24557a..ade77d3 100644
104322 --- a/net/ipv6/sit.c
104323 +++ b/net/ipv6/sit.c
104324 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104325 static void ipip6_dev_free(struct net_device *dev);
104326 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104327 __be32 *v4dst);
104328 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104329 +static struct rtnl_link_ops sit_link_ops;
104330
104331 static int sit_net_id __read_mostly;
104332 struct sit_net {
104333 @@ -1505,12 +1505,12 @@ static bool ipip6_netlink_encap_parms(struct nlattr *data[],
104334
104335 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
104336 ret = true;
104337 - ipencap->sport = nla_get_u16(data[IFLA_IPTUN_ENCAP_SPORT]);
104338 + ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
104339 }
104340
104341 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
104342 ret = true;
104343 - ipencap->dport = nla_get_u16(data[IFLA_IPTUN_ENCAP_DPORT]);
104344 + ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
104345 }
104346
104347 return ret;
104348 @@ -1706,9 +1706,9 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
104349
104350 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE,
104351 tunnel->encap.type) ||
104352 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_SPORT,
104353 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT,
104354 tunnel->encap.sport) ||
104355 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_DPORT,
104356 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT,
104357 tunnel->encap.dport) ||
104358 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS,
104359 tunnel->encap.dport))
104360 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104361 unregister_netdevice_queue(dev, head);
104362 }
104363
104364 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104365 +static struct rtnl_link_ops sit_link_ops = {
104366 .kind = "sit",
104367 .maxtype = IFLA_IPTUN_MAX,
104368 .policy = ipip6_policy,
104369 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104370 index c5c10fa..2577d51 100644
104371 --- a/net/ipv6/sysctl_net_ipv6.c
104372 +++ b/net/ipv6/sysctl_net_ipv6.c
104373 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
104374
104375 static int __net_init ipv6_sysctl_net_init(struct net *net)
104376 {
104377 - struct ctl_table *ipv6_table;
104378 + ctl_table_no_const *ipv6_table;
104379 struct ctl_table *ipv6_route_table;
104380 struct ctl_table *ipv6_icmp_table;
104381 int err;
104382 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104383 index c113602..0cccb46 100644
104384 --- a/net/ipv6/tcp_ipv6.c
104385 +++ b/net/ipv6/tcp_ipv6.c
104386 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104387 }
104388 }
104389
104390 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104391 +extern int grsec_enable_blackhole;
104392 +#endif
104393 +
104394 static void tcp_v6_hash(struct sock *sk)
104395 {
104396 if (sk->sk_state != TCP_CLOSE) {
104397 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104398 return 0;
104399
104400 reset:
104401 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104402 + if (!grsec_enable_blackhole)
104403 +#endif
104404 tcp_v6_send_reset(sk, skb);
104405 discard:
104406 if (opt_skb)
104407 @@ -1441,12 +1448,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104408
104409 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
104410 inet6_iif(skb));
104411 - if (!sk)
104412 + if (!sk) {
104413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104414 + ret = 1;
104415 +#endif
104416 goto no_tcp_socket;
104417 + }
104418
104419 process:
104420 - if (sk->sk_state == TCP_TIME_WAIT)
104421 + if (sk->sk_state == TCP_TIME_WAIT) {
104422 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104423 + ret = 2;
104424 +#endif
104425 goto do_time_wait;
104426 + }
104427
104428 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104429 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104430 @@ -1497,6 +1512,10 @@ csum_error:
104431 bad_packet:
104432 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104433 } else {
104434 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104435 + if (!grsec_enable_blackhole || (ret == 1 &&
104436 + (skb->dev->flags & IFF_LOOPBACK)))
104437 +#endif
104438 tcp_v6_send_reset(NULL, skb);
104439 }
104440
104441 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104442 index f6ba535..b41033f 100644
104443 --- a/net/ipv6/udp.c
104444 +++ b/net/ipv6/udp.c
104445 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104446 udp_ipv6_hash_secret + net_hash_mix(net));
104447 }
104448
104449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104450 +extern int grsec_enable_blackhole;
104451 +#endif
104452 +
104453 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104454 {
104455 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104456 @@ -434,7 +438,7 @@ try_again:
104457 if (unlikely(err)) {
104458 trace_kfree_skb(skb, udpv6_recvmsg);
104459 if (!peeked) {
104460 - atomic_inc(&sk->sk_drops);
104461 + atomic_inc_unchecked(&sk->sk_drops);
104462 if (is_udp4)
104463 UDP_INC_STATS_USER(sock_net(sk),
104464 UDP_MIB_INERRORS,
104465 @@ -701,7 +705,7 @@ csum_error:
104466 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104467 drop:
104468 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104469 - atomic_inc(&sk->sk_drops);
104470 + atomic_inc_unchecked(&sk->sk_drops);
104471 kfree_skb(skb);
104472 return -1;
104473 }
104474 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104475 if (likely(skb1 == NULL))
104476 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104477 if (!skb1) {
104478 - atomic_inc(&sk->sk_drops);
104479 + atomic_inc_unchecked(&sk->sk_drops);
104480 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104481 IS_UDPLITE(sk));
104482 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104483 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104484 goto csum_error;
104485
104486 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104487 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104488 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104489 +#endif
104490 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104491
104492 kfree_skb(skb);
104493 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104494 index 5f98364..691985a 100644
104495 --- a/net/ipv6/xfrm6_policy.c
104496 +++ b/net/ipv6/xfrm6_policy.c
104497 @@ -130,12 +130,18 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104498 {
104499 struct flowi6 *fl6 = &fl->u.ip6;
104500 int onlyproto = 0;
104501 - u16 offset = skb_network_header_len(skb);
104502 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104503 + u16 offset = sizeof(*hdr);
104504 struct ipv6_opt_hdr *exthdr;
104505 const unsigned char *nh = skb_network_header(skb);
104506 - u8 nexthdr = nh[IP6CB(skb)->nhoff];
104507 + u16 nhoff = IP6CB(skb)->nhoff;
104508 int oif = 0;
104509 + u8 nexthdr;
104510 +
104511 + if (!nhoff)
104512 + nhoff = offsetof(struct ipv6hdr, nexthdr);
104513 +
104514 + nexthdr = nh[nhoff];
104515
104516 if (skb_dst(skb))
104517 oif = skb_dst(skb)->dev->ifindex;
104518 @@ -217,11 +223,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104519 }
104520 }
104521
104522 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104523 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104524 {
104525 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104526
104527 - xfrm6_policy_afinfo.garbage_collect(net);
104528 + xfrm_garbage_collect_deferred(net);
104529 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104530 }
104531
104532 @@ -334,19 +340,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104533
104534 static int __net_init xfrm6_net_init(struct net *net)
104535 {
104536 - struct ctl_table *table;
104537 + ctl_table_no_const *table = NULL;
104538 struct ctl_table_header *hdr;
104539
104540 - table = xfrm6_policy_table;
104541 if (!net_eq(net, &init_net)) {
104542 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104543 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104544 if (!table)
104545 goto err_alloc;
104546
104547 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104548 - }
104549 + hdr = register_net_sysctl(net, "net/ipv6", table);
104550 + } else
104551 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104552
104553 - hdr = register_net_sysctl(net, "net/ipv6", table);
104554 if (!hdr)
104555 goto err_reg;
104556
104557 @@ -354,8 +360,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104558 return 0;
104559
104560 err_reg:
104561 - if (!net_eq(net, &init_net))
104562 - kfree(table);
104563 + kfree(table);
104564 err_alloc:
104565 return -ENOMEM;
104566 }
104567 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104568 index e15c16a..7cf07aa 100644
104569 --- a/net/ipx/ipx_proc.c
104570 +++ b/net/ipx/ipx_proc.c
104571 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104572 struct proc_dir_entry *p;
104573 int rc = -ENOMEM;
104574
104575 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104576 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104577
104578 if (!ipx_proc_dir)
104579 goto out;
104580 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104581 index 61ceb4c..e788eb8 100644
104582 --- a/net/irda/ircomm/ircomm_tty.c
104583 +++ b/net/irda/ircomm/ircomm_tty.c
104584 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104585 add_wait_queue(&port->open_wait, &wait);
104586
104587 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104588 - __FILE__, __LINE__, tty->driver->name, port->count);
104589 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104590
104591 spin_lock_irqsave(&port->lock, flags);
104592 - port->count--;
104593 + atomic_dec(&port->count);
104594 port->blocked_open++;
104595 spin_unlock_irqrestore(&port->lock, flags);
104596
104597 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104598 }
104599
104600 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104601 - __FILE__, __LINE__, tty->driver->name, port->count);
104602 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104603
104604 schedule();
104605 }
104606 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104607
104608 spin_lock_irqsave(&port->lock, flags);
104609 if (!tty_hung_up_p(filp))
104610 - port->count++;
104611 + atomic_inc(&port->count);
104612 port->blocked_open--;
104613 spin_unlock_irqrestore(&port->lock, flags);
104614
104615 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104616 - __FILE__, __LINE__, tty->driver->name, port->count);
104617 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104618
104619 if (!retval)
104620 port->flags |= ASYNC_NORMAL_ACTIVE;
104621 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104622
104623 /* ++ is not atomic, so this should be protected - Jean II */
104624 spin_lock_irqsave(&self->port.lock, flags);
104625 - self->port.count++;
104626 + atomic_inc(&self->port.count);
104627 spin_unlock_irqrestore(&self->port.lock, flags);
104628 tty_port_tty_set(&self->port, tty);
104629
104630 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104631 - self->line, self->port.count);
104632 + self->line, atomic_read(&self->port.count));
104633
104634 /* Not really used by us, but lets do it anyway */
104635 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104636 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104637 tty_kref_put(port->tty);
104638 }
104639 port->tty = NULL;
104640 - port->count = 0;
104641 + atomic_set(&port->count, 0);
104642 spin_unlock_irqrestore(&port->lock, flags);
104643
104644 wake_up_interruptible(&port->open_wait);
104645 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104646 seq_putc(m, '\n');
104647
104648 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104649 - seq_printf(m, "Open count: %d\n", self->port.count);
104650 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104651 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104652 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104653
104654 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104655 index b9ac598..f88cc56 100644
104656 --- a/net/irda/irproc.c
104657 +++ b/net/irda/irproc.c
104658 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104659 {
104660 int i;
104661
104662 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104663 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104664 if (proc_irda == NULL)
104665 return;
104666
104667 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104668 index a089b6b..3ca3b60 100644
104669 --- a/net/iucv/af_iucv.c
104670 +++ b/net/iucv/af_iucv.c
104671 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104672 {
104673 char name[12];
104674
104675 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104676 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104677 while (__iucv_get_sock_by_name(name)) {
104678 sprintf(name, "%08x",
104679 - atomic_inc_return(&iucv_sk_list.autobind_name));
104680 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104681 }
104682 memcpy(iucv->src_name, name, 8);
104683 }
104684 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104685 index 2a6a1fd..6c112b0 100644
104686 --- a/net/iucv/iucv.c
104687 +++ b/net/iucv/iucv.c
104688 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104689 return NOTIFY_OK;
104690 }
104691
104692 -static struct notifier_block __refdata iucv_cpu_notifier = {
104693 +static struct notifier_block iucv_cpu_notifier = {
104694 .notifier_call = iucv_cpu_notify,
104695 };
104696
104697 diff --git a/net/key/af_key.c b/net/key/af_key.c
104698 index 1847ec4..26ef732 100644
104699 --- a/net/key/af_key.c
104700 +++ b/net/key/af_key.c
104701 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104702 static u32 get_acqseq(void)
104703 {
104704 u32 res;
104705 - static atomic_t acqseq;
104706 + static atomic_unchecked_t acqseq;
104707
104708 do {
104709 - res = atomic_inc_return(&acqseq);
104710 + res = atomic_inc_return_unchecked(&acqseq);
104711 } while (!res);
104712 return res;
104713 }
104714 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104715 index edb78e6..8dc654a 100644
104716 --- a/net/l2tp/l2tp_eth.c
104717 +++ b/net/l2tp/l2tp_eth.c
104718 @@ -42,12 +42,12 @@ struct l2tp_eth {
104719 struct sock *tunnel_sock;
104720 struct l2tp_session *session;
104721 struct list_head list;
104722 - atomic_long_t tx_bytes;
104723 - atomic_long_t tx_packets;
104724 - atomic_long_t tx_dropped;
104725 - atomic_long_t rx_bytes;
104726 - atomic_long_t rx_packets;
104727 - atomic_long_t rx_errors;
104728 + atomic_long_unchecked_t tx_bytes;
104729 + atomic_long_unchecked_t tx_packets;
104730 + atomic_long_unchecked_t tx_dropped;
104731 + atomic_long_unchecked_t rx_bytes;
104732 + atomic_long_unchecked_t rx_packets;
104733 + atomic_long_unchecked_t rx_errors;
104734 };
104735
104736 /* via l2tp_session_priv() */
104737 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104738 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104739
104740 if (likely(ret == NET_XMIT_SUCCESS)) {
104741 - atomic_long_add(len, &priv->tx_bytes);
104742 - atomic_long_inc(&priv->tx_packets);
104743 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104744 + atomic_long_inc_unchecked(&priv->tx_packets);
104745 } else {
104746 - atomic_long_inc(&priv->tx_dropped);
104747 + atomic_long_inc_unchecked(&priv->tx_dropped);
104748 }
104749 return NETDEV_TX_OK;
104750 }
104751 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104752 {
104753 struct l2tp_eth *priv = netdev_priv(dev);
104754
104755 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104756 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104757 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104758 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104759 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104760 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104761 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104762 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104763 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104764 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104765 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104766 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104767 return stats;
104768 }
104769
104770 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104771 nf_reset(skb);
104772
104773 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104774 - atomic_long_inc(&priv->rx_packets);
104775 - atomic_long_add(data_len, &priv->rx_bytes);
104776 + atomic_long_inc_unchecked(&priv->rx_packets);
104777 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104778 } else {
104779 - atomic_long_inc(&priv->rx_errors);
104780 + atomic_long_inc_unchecked(&priv->rx_errors);
104781 }
104782 return;
104783
104784 error:
104785 - atomic_long_inc(&priv->rx_errors);
104786 + atomic_long_inc_unchecked(&priv->rx_errors);
104787 kfree_skb(skb);
104788 }
104789
104790 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104791 index 1a3c7e0..80f8b0c 100644
104792 --- a/net/llc/llc_proc.c
104793 +++ b/net/llc/llc_proc.c
104794 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104795 int rc = -ENOMEM;
104796 struct proc_dir_entry *p;
104797
104798 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104799 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104800 if (!llc_proc_dir)
104801 goto out;
104802
104803 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104804 index 343da1e..509873f 100644
104805 --- a/net/mac80211/cfg.c
104806 +++ b/net/mac80211/cfg.c
104807 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104808 ret = ieee80211_vif_use_channel(sdata, chandef,
104809 IEEE80211_CHANCTX_EXCLUSIVE);
104810 }
104811 - } else if (local->open_count == local->monitors) {
104812 + } else if (local_read(&local->open_count) == local->monitors) {
104813 local->_oper_chandef = *chandef;
104814 ieee80211_hw_config(local, 0);
104815 }
104816 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104817 else
104818 local->probe_req_reg--;
104819
104820 - if (!local->open_count)
104821 + if (!local_read(&local->open_count))
104822 break;
104823
104824 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104825 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104826 if (chanctx_conf) {
104827 *chandef = sdata->vif.bss_conf.chandef;
104828 ret = 0;
104829 - } else if (local->open_count > 0 &&
104830 - local->open_count == local->monitors &&
104831 + } else if (local_read(&local->open_count) > 0 &&
104832 + local_read(&local->open_count) == local->monitors &&
104833 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104834 if (local->use_chanctx)
104835 *chandef = local->monitor_chandef;
104836 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104837 index 8c68da3..0695016 100644
104838 --- a/net/mac80211/ieee80211_i.h
104839 +++ b/net/mac80211/ieee80211_i.h
104840 @@ -29,6 +29,7 @@
104841 #include <net/ieee80211_radiotap.h>
104842 #include <net/cfg80211.h>
104843 #include <net/mac80211.h>
104844 +#include <asm/local.h>
104845 #include "key.h"
104846 #include "sta_info.h"
104847 #include "debug.h"
104848 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
104849 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104850 spinlock_t queue_stop_reason_lock;
104851
104852 - int open_count;
104853 + local_t open_count;
104854 int monitors, cooked_mntrs;
104855 /* number of interfaces with corresponding FIF_ flags */
104856 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104857 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104858 index eeae0ab..0f24585 100644
104859 --- a/net/mac80211/iface.c
104860 +++ b/net/mac80211/iface.c
104861 @@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104862 break;
104863 }
104864
104865 - if (local->open_count == 0) {
104866 + if (local_read(&local->open_count) == 0) {
104867 res = drv_start(local);
104868 if (res)
104869 goto err_del_bss;
104870 @@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104871 res = drv_add_interface(local, sdata);
104872 if (res)
104873 goto err_stop;
104874 - } else if (local->monitors == 0 && local->open_count == 0) {
104875 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104876 res = ieee80211_add_virtual_monitor(local);
104877 if (res)
104878 goto err_stop;
104879 @@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104880 atomic_inc(&local->iff_promiscs);
104881
104882 if (coming_up)
104883 - local->open_count++;
104884 + local_inc(&local->open_count);
104885
104886 if (hw_reconf_flags)
104887 ieee80211_hw_config(local, hw_reconf_flags);
104888 @@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104889 err_del_interface:
104890 drv_remove_interface(local, sdata);
104891 err_stop:
104892 - if (!local->open_count)
104893 + if (!local_read(&local->open_count))
104894 drv_stop(local);
104895 err_del_bss:
104896 sdata->bss = NULL;
104897 @@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104898 }
104899
104900 if (going_down)
104901 - local->open_count--;
104902 + local_dec(&local->open_count);
104903
104904 switch (sdata->vif.type) {
104905 case NL80211_IFTYPE_AP_VLAN:
104906 @@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104907 }
104908 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104909
104910 - if (local->open_count == 0)
104911 + if (local_read(&local->open_count) == 0)
104912 ieee80211_clear_tx_pending(local);
104913
104914 /*
104915 @@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104916 if (cancel_scan)
104917 flush_delayed_work(&local->scan_work);
104918
104919 - if (local->open_count == 0) {
104920 + if (local_read(&local->open_count) == 0) {
104921 ieee80211_stop_device(local);
104922
104923 /* no reconfiguring after stop! */
104924 @@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104925 ieee80211_configure_filter(local);
104926 ieee80211_hw_config(local, hw_reconf_flags);
104927
104928 - if (local->monitors == local->open_count)
104929 + if (local->monitors == local_read(&local->open_count))
104930 ieee80211_add_virtual_monitor(local);
104931 }
104932
104933 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104934 index 0de7c93..884b2ca 100644
104935 --- a/net/mac80211/main.c
104936 +++ b/net/mac80211/main.c
104937 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104938 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104939 IEEE80211_CONF_CHANGE_POWER);
104940
104941 - if (changed && local->open_count) {
104942 + if (changed && local_read(&local->open_count)) {
104943 ret = drv_config(local, changed);
104944 /*
104945 * Goal:
104946 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104947 index 4a95fe3..0bfd713 100644
104948 --- a/net/mac80211/pm.c
104949 +++ b/net/mac80211/pm.c
104950 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104951 struct ieee80211_sub_if_data *sdata;
104952 struct sta_info *sta;
104953
104954 - if (!local->open_count)
104955 + if (!local_read(&local->open_count))
104956 goto suspend;
104957
104958 ieee80211_scan_cancel(local);
104959 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104960 cancel_work_sync(&local->dynamic_ps_enable_work);
104961 del_timer_sync(&local->dynamic_ps_timer);
104962
104963 - local->wowlan = wowlan && local->open_count;
104964 + local->wowlan = wowlan && local_read(&local->open_count);
104965 if (local->wowlan) {
104966 int err = drv_suspend(local, wowlan);
104967 if (err < 0) {
104968 @@ -126,7 +126,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104969 WARN_ON(!list_empty(&local->chanctx_list));
104970
104971 /* stop hardware - this must stop RX */
104972 - if (local->open_count)
104973 + if (local_read(&local->open_count))
104974 ieee80211_stop_device(local);
104975
104976 suspend:
104977 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104978 index 6081329..ab23834 100644
104979 --- a/net/mac80211/rate.c
104980 +++ b/net/mac80211/rate.c
104981 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104982
104983 ASSERT_RTNL();
104984
104985 - if (local->open_count)
104986 + if (local_read(&local->open_count))
104987 return -EBUSY;
104988
104989 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104990 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104991 index 3c61060..7bed2e3 100644
104992 --- a/net/mac80211/util.c
104993 +++ b/net/mac80211/util.c
104994 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104995 }
104996 #endif
104997 /* everything else happens only if HW was up & running */
104998 - if (!local->open_count)
104999 + if (!local_read(&local->open_count))
105000 goto wake_up;
105001
105002 /*
105003 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105004 local->in_reconfig = false;
105005 barrier();
105006
105007 - if (local->monitors == local->open_count && local->monitors > 0)
105008 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105009 ieee80211_add_virtual_monitor(local);
105010
105011 /*
105012 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105013 index ae5096ab..e5aa70a 100644
105014 --- a/net/netfilter/Kconfig
105015 +++ b/net/netfilter/Kconfig
105016 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
105017
105018 To compile it as a module, choose M here. If unsure, say N.
105019
105020 +config NETFILTER_XT_MATCH_GRADM
105021 + tristate '"gradm" match support'
105022 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105023 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105024 + ---help---
105025 + The gradm match allows to match on grsecurity RBAC being enabled.
105026 + It is useful when iptables rules are applied early on bootup to
105027 + prevent connections to the machine (except from a trusted host)
105028 + while the RBAC system is disabled.
105029 +
105030 config NETFILTER_XT_MATCH_HASHLIMIT
105031 tristate '"hashlimit" match support'
105032 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105033 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105034 index a9571be..c59e173 100644
105035 --- a/net/netfilter/Makefile
105036 +++ b/net/netfilter/Makefile
105037 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105038 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105039 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105040 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105041 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105042 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105043 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105044 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105045 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105046 index d259da3..6a32b2c 100644
105047 --- a/net/netfilter/ipset/ip_set_core.c
105048 +++ b/net/netfilter/ipset/ip_set_core.c
105049 @@ -1952,7 +1952,7 @@ done:
105050 return ret;
105051 }
105052
105053 -static struct nf_sockopt_ops so_set __read_mostly = {
105054 +static struct nf_sockopt_ops so_set = {
105055 .pf = PF_INET,
105056 .get_optmin = SO_IP_SET,
105057 .get_optmax = SO_IP_SET + 1,
105058 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105059 index b0f7b62..0541842 100644
105060 --- a/net/netfilter/ipvs/ip_vs_conn.c
105061 +++ b/net/netfilter/ipvs/ip_vs_conn.c
105062 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105063 /* Increase the refcnt counter of the dest */
105064 ip_vs_dest_hold(dest);
105065
105066 - conn_flags = atomic_read(&dest->conn_flags);
105067 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
105068 if (cp->protocol != IPPROTO_UDP)
105069 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105070 flags = cp->flags;
105071 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
105072
105073 cp->control = NULL;
105074 atomic_set(&cp->n_control, 0);
105075 - atomic_set(&cp->in_pkts, 0);
105076 + atomic_set_unchecked(&cp->in_pkts, 0);
105077
105078 cp->packet_xmit = NULL;
105079 cp->app = NULL;
105080 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105081
105082 /* Don't drop the entry if its number of incoming packets is not
105083 located in [0, 8] */
105084 - i = atomic_read(&cp->in_pkts);
105085 + i = atomic_read_unchecked(&cp->in_pkts);
105086 if (i > 8 || i < 0) return 0;
105087
105088 if (!todrop_rate[i]) return 0;
105089 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105090 index 990decb..5075248 100644
105091 --- a/net/netfilter/ipvs/ip_vs_core.c
105092 +++ b/net/netfilter/ipvs/ip_vs_core.c
105093 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105094 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105095 /* do not touch skb anymore */
105096
105097 - atomic_inc(&cp->in_pkts);
105098 + atomic_inc_unchecked(&cp->in_pkts);
105099 ip_vs_conn_put(cp);
105100 return ret;
105101 }
105102 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105103 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105104 pkts = sysctl_sync_threshold(ipvs);
105105 else
105106 - pkts = atomic_add_return(1, &cp->in_pkts);
105107 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105108
105109 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105110 ip_vs_sync_conn(net, cp, pkts);
105111 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105112 index ac7ba68..9735acb9 100644
105113 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105114 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105115 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105116 */
105117 ip_vs_rs_hash(ipvs, dest);
105118 }
105119 - atomic_set(&dest->conn_flags, conn_flags);
105120 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105121
105122 /* bind the service */
105123 old_svc = rcu_dereference_protected(dest->svc, 1);
105124 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105125 * align with netns init in ip_vs_control_net_init()
105126 */
105127
105128 -static struct ctl_table vs_vars[] = {
105129 +static ctl_table_no_const vs_vars[] __read_only = {
105130 {
105131 .procname = "amemthresh",
105132 .maxlen = sizeof(int),
105133 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105134 " %-7s %-6d %-10d %-10d\n",
105135 &dest->addr.in6,
105136 ntohs(dest->port),
105137 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105138 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105139 atomic_read(&dest->weight),
105140 atomic_read(&dest->activeconns),
105141 atomic_read(&dest->inactconns));
105142 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105143 "%-7s %-6d %-10d %-10d\n",
105144 ntohl(dest->addr.ip),
105145 ntohs(dest->port),
105146 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105147 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105148 atomic_read(&dest->weight),
105149 atomic_read(&dest->activeconns),
105150 atomic_read(&dest->inactconns));
105151 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105152
105153 entry.addr = dest->addr.ip;
105154 entry.port = dest->port;
105155 - entry.conn_flags = atomic_read(&dest->conn_flags);
105156 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105157 entry.weight = atomic_read(&dest->weight);
105158 entry.u_threshold = dest->u_threshold;
105159 entry.l_threshold = dest->l_threshold;
105160 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105161 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105162 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105163 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105164 - (atomic_read(&dest->conn_flags) &
105165 + (atomic_read_unchecked(&dest->conn_flags) &
105166 IP_VS_CONN_F_FWD_MASK)) ||
105167 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105168 atomic_read(&dest->weight)) ||
105169 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105170 {
105171 int idx;
105172 struct netns_ipvs *ipvs = net_ipvs(net);
105173 - struct ctl_table *tbl;
105174 + ctl_table_no_const *tbl;
105175
105176 atomic_set(&ipvs->dropentry, 0);
105177 spin_lock_init(&ipvs->dropentry_lock);
105178 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105179 index 127f140..553d652 100644
105180 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105181 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105182 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105183 * IPVS LBLC sysctl table
105184 */
105185 #ifdef CONFIG_SYSCTL
105186 -static struct ctl_table vs_vars_table[] = {
105187 +static ctl_table_no_const vs_vars_table[] __read_only = {
105188 {
105189 .procname = "lblc_expiration",
105190 .data = NULL,
105191 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105192 index 2229d2d..b32b785 100644
105193 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105194 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105195 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105196 * IPVS LBLCR sysctl table
105197 */
105198
105199 -static struct ctl_table vs_vars_table[] = {
105200 +static ctl_table_no_const vs_vars_table[] __read_only = {
105201 {
105202 .procname = "lblcr_expiration",
105203 .data = NULL,
105204 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105205 index 7162c86..9eeb60e 100644
105206 --- a/net/netfilter/ipvs/ip_vs_sync.c
105207 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105208 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105209 cp = cp->control;
105210 if (cp) {
105211 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105212 - pkts = atomic_add_return(1, &cp->in_pkts);
105213 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105214 else
105215 pkts = sysctl_sync_threshold(ipvs);
105216 ip_vs_sync_conn(net, cp->control, pkts);
105217 @@ -771,7 +771,7 @@ control:
105218 if (!cp)
105219 return;
105220 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105221 - pkts = atomic_add_return(1, &cp->in_pkts);
105222 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105223 else
105224 pkts = sysctl_sync_threshold(ipvs);
105225 goto sloop;
105226 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105227
105228 if (opt)
105229 memcpy(&cp->in_seq, opt, sizeof(*opt));
105230 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105231 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105232 cp->state = state;
105233 cp->old_state = cp->state;
105234 /*
105235 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105236 index bd90bf8..816a020d 100644
105237 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105238 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105239 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105240 else
105241 rc = NF_ACCEPT;
105242 /* do not touch skb anymore */
105243 - atomic_inc(&cp->in_pkts);
105244 + atomic_inc_unchecked(&cp->in_pkts);
105245 goto out;
105246 }
105247
105248 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105249 else
105250 rc = NF_ACCEPT;
105251 /* do not touch skb anymore */
105252 - atomic_inc(&cp->in_pkts);
105253 + atomic_inc_unchecked(&cp->in_pkts);
105254 goto out;
105255 }
105256
105257 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105258 index a4b5e2a..13b1de3 100644
105259 --- a/net/netfilter/nf_conntrack_acct.c
105260 +++ b/net/netfilter/nf_conntrack_acct.c
105261 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105262 #ifdef CONFIG_SYSCTL
105263 static int nf_conntrack_acct_init_sysctl(struct net *net)
105264 {
105265 - struct ctl_table *table;
105266 + ctl_table_no_const *table;
105267
105268 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105269 GFP_KERNEL);
105270 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105271 index c588012..b0d4ef8 100644
105272 --- a/net/netfilter/nf_conntrack_core.c
105273 +++ b/net/netfilter/nf_conntrack_core.c
105274 @@ -1737,6 +1737,10 @@ void nf_conntrack_init_end(void)
105275 #define DYING_NULLS_VAL ((1<<30)+1)
105276 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105277
105278 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105279 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105280 +#endif
105281 +
105282 int nf_conntrack_init_net(struct net *net)
105283 {
105284 int ret = -ENOMEM;
105285 @@ -1762,7 +1766,11 @@ int nf_conntrack_init_net(struct net *net)
105286 if (!net->ct.stat)
105287 goto err_pcpu_lists;
105288
105289 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105290 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105291 +#else
105292 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105293 +#endif
105294 if (!net->ct.slabname)
105295 goto err_slabname;
105296
105297 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105298 index 4e78c57..ec8fb74 100644
105299 --- a/net/netfilter/nf_conntrack_ecache.c
105300 +++ b/net/netfilter/nf_conntrack_ecache.c
105301 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105302 #ifdef CONFIG_SYSCTL
105303 static int nf_conntrack_event_init_sysctl(struct net *net)
105304 {
105305 - struct ctl_table *table;
105306 + ctl_table_no_const *table;
105307
105308 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105309 GFP_KERNEL);
105310 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105311 index 5b3eae7..dd4b8fe 100644
105312 --- a/net/netfilter/nf_conntrack_helper.c
105313 +++ b/net/netfilter/nf_conntrack_helper.c
105314 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105315
105316 static int nf_conntrack_helper_init_sysctl(struct net *net)
105317 {
105318 - struct ctl_table *table;
105319 + ctl_table_no_const *table;
105320
105321 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105322 GFP_KERNEL);
105323 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105324 index b65d586..beec902 100644
105325 --- a/net/netfilter/nf_conntrack_proto.c
105326 +++ b/net/netfilter/nf_conntrack_proto.c
105327 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105328
105329 static void
105330 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105331 - struct ctl_table **table,
105332 + ctl_table_no_const **table,
105333 unsigned int users)
105334 {
105335 if (users > 0)
105336 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105337 index cf65a1e..2f291e9 100644
105338 --- a/net/netfilter/nf_conntrack_standalone.c
105339 +++ b/net/netfilter/nf_conntrack_standalone.c
105340 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105341
105342 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105343 {
105344 - struct ctl_table *table;
105345 + ctl_table_no_const *table;
105346
105347 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105348 GFP_KERNEL);
105349 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105350 index 7a394df..bd91a8a 100644
105351 --- a/net/netfilter/nf_conntrack_timestamp.c
105352 +++ b/net/netfilter/nf_conntrack_timestamp.c
105353 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105354 #ifdef CONFIG_SYSCTL
105355 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105356 {
105357 - struct ctl_table *table;
105358 + ctl_table_no_const *table;
105359
105360 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105361 GFP_KERNEL);
105362 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105363 index d719764..311bc60 100644
105364 --- a/net/netfilter/nf_log.c
105365 +++ b/net/netfilter/nf_log.c
105366 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105367
105368 #ifdef CONFIG_SYSCTL
105369 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105370 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105371 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105372
105373 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105374 void __user *buffer, size_t *lenp, loff_t *ppos)
105375 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105376 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105377 mutex_unlock(&nf_log_mutex);
105378 } else {
105379 + ctl_table_no_const nf_log_table = *table;
105380 +
105381 mutex_lock(&nf_log_mutex);
105382 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105383 lockdep_is_held(&nf_log_mutex));
105384 if (!logger)
105385 - table->data = "NONE";
105386 + nf_log_table.data = "NONE";
105387 else
105388 - table->data = logger->name;
105389 - r = proc_dostring(table, write, buffer, lenp, ppos);
105390 + nf_log_table.data = logger->name;
105391 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105392 mutex_unlock(&nf_log_mutex);
105393 }
105394
105395 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105396 index c68c1e5..8b5d670 100644
105397 --- a/net/netfilter/nf_sockopt.c
105398 +++ b/net/netfilter/nf_sockopt.c
105399 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105400 }
105401 }
105402
105403 - list_add(&reg->list, &nf_sockopts);
105404 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105405 out:
105406 mutex_unlock(&nf_sockopt_mutex);
105407 return ret;
105408 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105409 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105410 {
105411 mutex_lock(&nf_sockopt_mutex);
105412 - list_del(&reg->list);
105413 + pax_list_del((struct list_head *)&reg->list);
105414 mutex_unlock(&nf_sockopt_mutex);
105415 }
105416 EXPORT_SYMBOL(nf_unregister_sockopt);
105417 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
105418 index 71b574c..d319e8b 100644
105419 --- a/net/netfilter/nf_tables_api.c
105420 +++ b/net/netfilter/nf_tables_api.c
105421 @@ -1134,9 +1134,11 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr)
105422 /* Restore old counters on this cpu, no problem. Per-cpu statistics
105423 * are not exposed to userspace.
105424 */
105425 + preempt_disable();
105426 stats = this_cpu_ptr(newstats);
105427 stats->bytes = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
105428 stats->pkts = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
105429 + preempt_enable();
105430
105431 return newstats;
105432 }
105433 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105434 index 5f1be5b..2cba8cd 100644
105435 --- a/net/netfilter/nfnetlink_log.c
105436 +++ b/net/netfilter/nfnetlink_log.c
105437 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105438 struct nfnl_log_net {
105439 spinlock_t instances_lock;
105440 struct hlist_head instance_table[INSTANCE_BUCKETS];
105441 - atomic_t global_seq;
105442 + atomic_unchecked_t global_seq;
105443 };
105444
105445 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105446 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105447 /* global sequence number */
105448 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105449 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105450 - htonl(atomic_inc_return(&log->global_seq))))
105451 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105452 goto nla_put_failure;
105453
105454 if (data_len) {
105455 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105456 new file mode 100644
105457 index 0000000..c566332
105458 --- /dev/null
105459 +++ b/net/netfilter/xt_gradm.c
105460 @@ -0,0 +1,51 @@
105461 +/*
105462 + * gradm match for netfilter
105463 + * Copyright © Zbigniew Krzystolik, 2010
105464 + *
105465 + * This program is free software; you can redistribute it and/or modify
105466 + * it under the terms of the GNU General Public License; either version
105467 + * 2 or 3 as published by the Free Software Foundation.
105468 + */
105469 +#include <linux/module.h>
105470 +#include <linux/moduleparam.h>
105471 +#include <linux/skbuff.h>
105472 +#include <linux/netfilter/x_tables.h>
105473 +#include <linux/grsecurity.h>
105474 +#include <linux/netfilter/xt_gradm.h>
105475 +
105476 +static bool
105477 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105478 +{
105479 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105480 + bool retval = false;
105481 + if (gr_acl_is_enabled())
105482 + retval = true;
105483 + return retval ^ info->invflags;
105484 +}
105485 +
105486 +static struct xt_match gradm_mt_reg __read_mostly = {
105487 + .name = "gradm",
105488 + .revision = 0,
105489 + .family = NFPROTO_UNSPEC,
105490 + .match = gradm_mt,
105491 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105492 + .me = THIS_MODULE,
105493 +};
105494 +
105495 +static int __init gradm_mt_init(void)
105496 +{
105497 + return xt_register_match(&gradm_mt_reg);
105498 +}
105499 +
105500 +static void __exit gradm_mt_exit(void)
105501 +{
105502 + xt_unregister_match(&gradm_mt_reg);
105503 +}
105504 +
105505 +module_init(gradm_mt_init);
105506 +module_exit(gradm_mt_exit);
105507 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105508 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105509 +MODULE_LICENSE("GPL");
105510 +MODULE_ALIAS("ipt_gradm");
105511 +MODULE_ALIAS("ip6t_gradm");
105512 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105513 index 05fbc2a..4424b5c 100644
105514 --- a/net/netfilter/xt_hashlimit.c
105515 +++ b/net/netfilter/xt_hashlimit.c
105516 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105517 {
105518 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105519
105520 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105521 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105522 if (!hashlimit_net->ipt_hashlimit)
105523 return -ENOMEM;
105524 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105525 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105526 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105527 if (!hashlimit_net->ip6t_hashlimit) {
105528 remove_proc_entry("ipt_hashlimit", net->proc_net);
105529 return -ENOMEM;
105530 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105531 index a9faae8..1ea30e0 100644
105532 --- a/net/netfilter/xt_recent.c
105533 +++ b/net/netfilter/xt_recent.c
105534 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105535 {
105536 struct recent_net *recent_net = recent_pernet(net);
105537
105538 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105539 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105540 if (!recent_net->xt_recent)
105541 return -ENOMEM;
105542 return 0;
105543 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105544 index 11de55e..f25e448 100644
105545 --- a/net/netfilter/xt_statistic.c
105546 +++ b/net/netfilter/xt_statistic.c
105547 @@ -19,7 +19,7 @@
105548 #include <linux/module.h>
105549
105550 struct xt_statistic_priv {
105551 - atomic_t count;
105552 + atomic_unchecked_t count;
105553 } ____cacheline_aligned_in_smp;
105554
105555 MODULE_LICENSE("GPL");
105556 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105557 break;
105558 case XT_STATISTIC_MODE_NTH:
105559 do {
105560 - oval = atomic_read(&info->master->count);
105561 + oval = atomic_read_unchecked(&info->master->count);
105562 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105563 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105564 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105565 if (nval == 0)
105566 ret = !ret;
105567 break;
105568 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105569 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105570 if (info->master == NULL)
105571 return -ENOMEM;
105572 - atomic_set(&info->master->count, info->u.nth.count);
105573 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105574
105575 return 0;
105576 }
105577 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105578 index 79c965a..ee2b76d 100644
105579 --- a/net/netlink/af_netlink.c
105580 +++ b/net/netlink/af_netlink.c
105581 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105582 sk->sk_error_report(sk);
105583 }
105584 }
105585 - atomic_inc(&sk->sk_drops);
105586 + atomic_inc_unchecked(&sk->sk_drops);
105587 }
105588
105589 static void netlink_rcv_wake(struct sock *sk)
105590 @@ -2990,7 +2990,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105591 sk_wmem_alloc_get(s),
105592 nlk->cb_running,
105593 atomic_read(&s->sk_refcnt),
105594 - atomic_read(&s->sk_drops),
105595 + atomic_read_unchecked(&s->sk_drops),
105596 sock_i_ino(s)
105597 );
105598
105599 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105600 index 8451612..c8872bc 100644
105601 --- a/net/openvswitch/vport-internal_dev.c
105602 +++ b/net/openvswitch/vport-internal_dev.c
105603 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105604 .ndo_get_stats64 = internal_dev_get_stats,
105605 };
105606
105607 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105608 +static struct rtnl_link_ops internal_dev_link_ops = {
105609 .kind = "openvswitch",
105610 };
105611
105612 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
105613 index 6015802..e81e8bf 100644
105614 --- a/net/openvswitch/vport.c
105615 +++ b/net/openvswitch/vport.c
105616 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
105617 * netdev-stats can be directly read over netlink-ioctl.
105618 */
105619
105620 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
105621 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
105622 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
105623 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
105624 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
105625 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
105626 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
105627 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
105628
105629 for_each_possible_cpu(i) {
105630 const struct pcpu_sw_netstats *percpu_stats;
105631 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
105632 {
105633 switch (err_type) {
105634 case VPORT_E_RX_DROPPED:
105635 - atomic_long_inc(&vport->err_stats.rx_dropped);
105636 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
105637 break;
105638
105639 case VPORT_E_RX_ERROR:
105640 - atomic_long_inc(&vport->err_stats.rx_errors);
105641 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
105642 break;
105643
105644 case VPORT_E_TX_DROPPED:
105645 - atomic_long_inc(&vport->err_stats.tx_dropped);
105646 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
105647 break;
105648
105649 case VPORT_E_TX_ERROR:
105650 - atomic_long_inc(&vport->err_stats.tx_errors);
105651 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
105652 break;
105653 }
105654
105655 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
105656 index 8942125..03ed887 100644
105657 --- a/net/openvswitch/vport.h
105658 +++ b/net/openvswitch/vport.h
105659 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
105660 /* The following definitions are for implementers of vport devices: */
105661
105662 struct vport_err_stats {
105663 - atomic_long_t rx_dropped;
105664 - atomic_long_t rx_errors;
105665 - atomic_long_t tx_dropped;
105666 - atomic_long_t tx_errors;
105667 + atomic_long_unchecked_t rx_dropped;
105668 + atomic_long_unchecked_t rx_errors;
105669 + atomic_long_unchecked_t tx_dropped;
105670 + atomic_long_unchecked_t tx_errors;
105671 };
105672 /**
105673 * struct vport_portids - array of netlink portids of a vport.
105674 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105675 index 07c04a8..3ca11eb 100644
105676 --- a/net/packet/af_packet.c
105677 +++ b/net/packet/af_packet.c
105678 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105679
105680 return ret;
105681 drop:
105682 - atomic_long_inc(&dev->tx_dropped);
105683 + atomic_long_inc_unchecked(&dev->tx_dropped);
105684 kfree_skb(skb);
105685 return NET_XMIT_DROP;
105686 }
105687 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105688
105689 spin_lock(&sk->sk_receive_queue.lock);
105690 po->stats.stats1.tp_packets++;
105691 - skb->dropcount = atomic_read(&sk->sk_drops);
105692 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105693 __skb_queue_tail(&sk->sk_receive_queue, skb);
105694 spin_unlock(&sk->sk_receive_queue.lock);
105695 sk->sk_data_ready(sk);
105696 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105697 drop_n_acct:
105698 spin_lock(&sk->sk_receive_queue.lock);
105699 po->stats.stats1.tp_drops++;
105700 - atomic_inc(&sk->sk_drops);
105701 + atomic_inc_unchecked(&sk->sk_drops);
105702 spin_unlock(&sk->sk_receive_queue.lock);
105703
105704 drop_n_restore:
105705 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105706 case PACKET_HDRLEN:
105707 if (len > sizeof(int))
105708 len = sizeof(int);
105709 - if (copy_from_user(&val, optval, len))
105710 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105711 return -EFAULT;
105712 switch (val) {
105713 case TPACKET_V1:
105714 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105715 len = lv;
105716 if (put_user(len, optlen))
105717 return -EFAULT;
105718 - if (copy_to_user(optval, data, len))
105719 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105720 return -EFAULT;
105721 return 0;
105722 }
105723 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105724 index 70a547e..23477fe 100644
105725 --- a/net/phonet/pep.c
105726 +++ b/net/phonet/pep.c
105727 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105728
105729 case PNS_PEP_CTRL_REQ:
105730 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105731 - atomic_inc(&sk->sk_drops);
105732 + atomic_inc_unchecked(&sk->sk_drops);
105733 break;
105734 }
105735 __skb_pull(skb, 4);
105736 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105737 }
105738
105739 if (pn->rx_credits == 0) {
105740 - atomic_inc(&sk->sk_drops);
105741 + atomic_inc_unchecked(&sk->sk_drops);
105742 err = -ENOBUFS;
105743 break;
105744 }
105745 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105746 }
105747
105748 if (pn->rx_credits == 0) {
105749 - atomic_inc(&sk->sk_drops);
105750 + atomic_inc_unchecked(&sk->sk_drops);
105751 err = NET_RX_DROP;
105752 break;
105753 }
105754 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105755 index 008214a..bb68240 100644
105756 --- a/net/phonet/socket.c
105757 +++ b/net/phonet/socket.c
105758 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105759 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105760 sock_i_ino(sk),
105761 atomic_read(&sk->sk_refcnt), sk,
105762 - atomic_read(&sk->sk_drops));
105763 + atomic_read_unchecked(&sk->sk_drops));
105764 }
105765 seq_pad(seq, '\n');
105766 return 0;
105767 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105768 index c02a8c4..3c5b600 100644
105769 --- a/net/phonet/sysctl.c
105770 +++ b/net/phonet/sysctl.c
105771 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105772 {
105773 int ret;
105774 int range[2] = {local_port_range[0], local_port_range[1]};
105775 - struct ctl_table tmp = {
105776 + ctl_table_no_const tmp = {
105777 .data = &range,
105778 .maxlen = sizeof(range),
105779 .mode = table->mode,
105780 diff --git a/net/rds/cong.c b/net/rds/cong.c
105781 index e5b65ac..f3b6fb7 100644
105782 --- a/net/rds/cong.c
105783 +++ b/net/rds/cong.c
105784 @@ -78,7 +78,7 @@
105785 * finds that the saved generation number is smaller than the global generation
105786 * number, it wakes up the process.
105787 */
105788 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105789 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105790
105791 /*
105792 * Congestion monitoring
105793 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105794 rdsdebug("waking map %p for %pI4\n",
105795 map, &map->m_addr);
105796 rds_stats_inc(s_cong_update_received);
105797 - atomic_inc(&rds_cong_generation);
105798 + atomic_inc_unchecked(&rds_cong_generation);
105799 if (waitqueue_active(&map->m_waitq))
105800 wake_up(&map->m_waitq);
105801 if (waitqueue_active(&rds_poll_waitq))
105802 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105803
105804 int rds_cong_updated_since(unsigned long *recent)
105805 {
105806 - unsigned long gen = atomic_read(&rds_cong_generation);
105807 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105808
105809 if (likely(*recent == gen))
105810 return 0;
105811 diff --git a/net/rds/ib.h b/net/rds/ib.h
105812 index 7280ab8..e04f4ea 100644
105813 --- a/net/rds/ib.h
105814 +++ b/net/rds/ib.h
105815 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105816 /* sending acks */
105817 unsigned long i_ack_flags;
105818 #ifdef KERNEL_HAS_ATOMIC64
105819 - atomic64_t i_ack_next; /* next ACK to send */
105820 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105821 #else
105822 spinlock_t i_ack_lock; /* protect i_ack_next */
105823 u64 i_ack_next; /* next ACK to send */
105824 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105825 index 31b74f5..dc1fbfa 100644
105826 --- a/net/rds/ib_cm.c
105827 +++ b/net/rds/ib_cm.c
105828 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105829 /* Clear the ACK state */
105830 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105831 #ifdef KERNEL_HAS_ATOMIC64
105832 - atomic64_set(&ic->i_ack_next, 0);
105833 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105834 #else
105835 ic->i_ack_next = 0;
105836 #endif
105837 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105838 index d67de45..73dbf51 100644
105839 --- a/net/rds/ib_recv.c
105840 +++ b/net/rds/ib_recv.c
105841 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105842 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105843 int ack_required)
105844 {
105845 - atomic64_set(&ic->i_ack_next, seq);
105846 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105847 if (ack_required) {
105848 smp_mb__before_atomic();
105849 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105850 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105851 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105852 smp_mb__after_atomic();
105853
105854 - return atomic64_read(&ic->i_ack_next);
105855 + return atomic64_read_unchecked(&ic->i_ack_next);
105856 }
105857 #endif
105858
105859 diff --git a/net/rds/iw.h b/net/rds/iw.h
105860 index 04ce3b1..48119a6 100644
105861 --- a/net/rds/iw.h
105862 +++ b/net/rds/iw.h
105863 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105864 /* sending acks */
105865 unsigned long i_ack_flags;
105866 #ifdef KERNEL_HAS_ATOMIC64
105867 - atomic64_t i_ack_next; /* next ACK to send */
105868 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105869 #else
105870 spinlock_t i_ack_lock; /* protect i_ack_next */
105871 u64 i_ack_next; /* next ACK to send */
105872 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105873 index a91e1db..cf3053f 100644
105874 --- a/net/rds/iw_cm.c
105875 +++ b/net/rds/iw_cm.c
105876 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105877 /* Clear the ACK state */
105878 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105879 #ifdef KERNEL_HAS_ATOMIC64
105880 - atomic64_set(&ic->i_ack_next, 0);
105881 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105882 #else
105883 ic->i_ack_next = 0;
105884 #endif
105885 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105886 index aa8bf67..b70133c 100644
105887 --- a/net/rds/iw_recv.c
105888 +++ b/net/rds/iw_recv.c
105889 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105890 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105891 int ack_required)
105892 {
105893 - atomic64_set(&ic->i_ack_next, seq);
105894 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105895 if (ack_required) {
105896 smp_mb__before_atomic();
105897 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105898 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105899 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105900 smp_mb__after_atomic();
105901
105902 - return atomic64_read(&ic->i_ack_next);
105903 + return atomic64_read_unchecked(&ic->i_ack_next);
105904 }
105905 #endif
105906
105907 diff --git a/net/rds/rds.h b/net/rds/rds.h
105908 index 48f8ffc..0ef3eec 100644
105909 --- a/net/rds/rds.h
105910 +++ b/net/rds/rds.h
105911 @@ -449,7 +449,7 @@ struct rds_transport {
105912 void (*sync_mr)(void *trans_private, int direction);
105913 void (*free_mr)(void *trans_private, int invalidate);
105914 void (*flush_mrs)(void);
105915 -};
105916 +} __do_const;
105917
105918 struct rds_sock {
105919 struct sock rs_sk;
105920 diff --git a/net/rds/sysctl.c b/net/rds/sysctl.c
105921 index c3b0cd4..c173f69 100644
105922 --- a/net/rds/sysctl.c
105923 +++ b/net/rds/sysctl.c
105924 @@ -71,14 +71,14 @@ static struct ctl_table rds_sysctl_rds_table[] = {
105925 {
105926 .procname = "max_unacked_packets",
105927 .data = &rds_sysctl_max_unacked_packets,
105928 - .maxlen = sizeof(unsigned long),
105929 + .maxlen = sizeof(int),
105930 .mode = 0644,
105931 .proc_handler = proc_dointvec,
105932 },
105933 {
105934 .procname = "max_unacked_bytes",
105935 .data = &rds_sysctl_max_unacked_bytes,
105936 - .maxlen = sizeof(unsigned long),
105937 + .maxlen = sizeof(int),
105938 .mode = 0644,
105939 .proc_handler = proc_dointvec,
105940 },
105941 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105942 index edac9ef..16bcb98 100644
105943 --- a/net/rds/tcp.c
105944 +++ b/net/rds/tcp.c
105945 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105946 int val = 1;
105947
105948 set_fs(KERNEL_DS);
105949 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105950 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105951 sizeof(val));
105952 set_fs(oldfs);
105953 }
105954 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105955 index 53b17ca..45463e7 100644
105956 --- a/net/rds/tcp_send.c
105957 +++ b/net/rds/tcp_send.c
105958 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105959
105960 oldfs = get_fs();
105961 set_fs(KERNEL_DS);
105962 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105963 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105964 sizeof(val));
105965 set_fs(oldfs);
105966 }
105967 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105968 index 7b16704..9628ec6 100644
105969 --- a/net/rxrpc/af_rxrpc.c
105970 +++ b/net/rxrpc/af_rxrpc.c
105971 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105972 __be32 rxrpc_epoch;
105973
105974 /* current debugging ID */
105975 -atomic_t rxrpc_debug_id;
105976 +atomic_unchecked_t rxrpc_debug_id;
105977
105978 /* count of skbs currently in use */
105979 atomic_t rxrpc_n_skbs;
105980 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105981 index c6be17a..2a6200a 100644
105982 --- a/net/rxrpc/ar-ack.c
105983 +++ b/net/rxrpc/ar-ack.c
105984 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105985
105986 _enter("{%d,%d,%d,%d},",
105987 call->acks_hard, call->acks_unacked,
105988 - atomic_read(&call->sequence),
105989 + atomic_read_unchecked(&call->sequence),
105990 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105991
105992 stop = 0;
105993 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105994
105995 /* each Tx packet has a new serial number */
105996 sp->hdr.serial =
105997 - htonl(atomic_inc_return(&call->conn->serial));
105998 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105999
106000 hdr = (struct rxrpc_header *) txb->head;
106001 hdr->serial = sp->hdr.serial;
106002 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
106003 */
106004 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
106005 {
106006 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
106007 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
106008 }
106009
106010 /*
106011 @@ -677,7 +677,7 @@ process_further:
106012
106013 latest = ntohl(sp->hdr.serial);
106014 hard = ntohl(ack.firstPacket);
106015 - tx = atomic_read(&call->sequence);
106016 + tx = atomic_read_unchecked(&call->sequence);
106017
106018 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106019 latest,
106020 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
106021 goto maybe_reschedule;
106022
106023 send_ACK_with_skew:
106024 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
106025 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
106026 ntohl(ack.serial));
106027 send_ACK:
106028 mtu = call->conn->trans->peer->if_mtu;
106029 @@ -1221,7 +1221,7 @@ send_ACK:
106030 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
106031 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
106032
106033 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106034 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106035 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106036 ntohl(hdr.serial),
106037 ntohs(ack.maxSkew),
106038 @@ -1239,7 +1239,7 @@ send_ACK:
106039 send_message:
106040 _debug("send message");
106041
106042 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106043 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106044 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
106045 send_message_2:
106046
106047 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
106048 index a9e05db..194e793 100644
106049 --- a/net/rxrpc/ar-call.c
106050 +++ b/net/rxrpc/ar-call.c
106051 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
106052 spin_lock_init(&call->lock);
106053 rwlock_init(&call->state_lock);
106054 atomic_set(&call->usage, 1);
106055 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
106056 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106057 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
106058
106059 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
106060 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
106061 index 6631f4f..bfdf056 100644
106062 --- a/net/rxrpc/ar-connection.c
106063 +++ b/net/rxrpc/ar-connection.c
106064 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
106065 rwlock_init(&conn->lock);
106066 spin_lock_init(&conn->state_lock);
106067 atomic_set(&conn->usage, 1);
106068 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
106069 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106070 conn->avail_calls = RXRPC_MAXCALLS;
106071 conn->size_align = 4;
106072 conn->header_size = sizeof(struct rxrpc_header);
106073 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
106074 index e7ed43a..6afa140 100644
106075 --- a/net/rxrpc/ar-connevent.c
106076 +++ b/net/rxrpc/ar-connevent.c
106077 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
106078
106079 len = iov[0].iov_len + iov[1].iov_len;
106080
106081 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106082 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106083 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106084
106085 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106086 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106087 index 481f89f..ceeaf8d 100644
106088 --- a/net/rxrpc/ar-input.c
106089 +++ b/net/rxrpc/ar-input.c
106090 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106091 /* track the latest serial number on this connection for ACK packet
106092 * information */
106093 serial = ntohl(sp->hdr.serial);
106094 - hi_serial = atomic_read(&call->conn->hi_serial);
106095 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106096 while (serial > hi_serial)
106097 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106098 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106099 serial);
106100
106101 /* request ACK generation for any ACK or DATA packet that requests
106102 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106103 index ba9fd36..9bbfe01 100644
106104 --- a/net/rxrpc/ar-internal.h
106105 +++ b/net/rxrpc/ar-internal.h
106106 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106107 int error; /* error code for local abort */
106108 int debug_id; /* debug ID for printks */
106109 unsigned int call_counter; /* call ID counter */
106110 - atomic_t serial; /* packet serial number counter */
106111 - atomic_t hi_serial; /* highest serial number received */
106112 + atomic_unchecked_t serial; /* packet serial number counter */
106113 + atomic_unchecked_t hi_serial; /* highest serial number received */
106114 u8 avail_calls; /* number of calls available */
106115 u8 size_align; /* data size alignment (for security) */
106116 u8 header_size; /* rxrpc + security header size */
106117 @@ -346,7 +346,7 @@ struct rxrpc_call {
106118 spinlock_t lock;
106119 rwlock_t state_lock; /* lock for state transition */
106120 atomic_t usage;
106121 - atomic_t sequence; /* Tx data packet sequence counter */
106122 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106123 u32 abort_code; /* local/remote abort code */
106124 enum { /* current state of call */
106125 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106126 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106127 */
106128 extern atomic_t rxrpc_n_skbs;
106129 extern __be32 rxrpc_epoch;
106130 -extern atomic_t rxrpc_debug_id;
106131 +extern atomic_unchecked_t rxrpc_debug_id;
106132 extern struct workqueue_struct *rxrpc_workqueue;
106133
106134 /*
106135 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106136 index 87f7135..74d3703 100644
106137 --- a/net/rxrpc/ar-local.c
106138 +++ b/net/rxrpc/ar-local.c
106139 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106140 spin_lock_init(&local->lock);
106141 rwlock_init(&local->services_lock);
106142 atomic_set(&local->usage, 1);
106143 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106144 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106145 memcpy(&local->srx, srx, sizeof(*srx));
106146 }
106147
106148 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106149 index 0b4b9a7..966ffbb 100644
106150 --- a/net/rxrpc/ar-output.c
106151 +++ b/net/rxrpc/ar-output.c
106152 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106153 memset(skb_put(skb, pad), 0, pad);
106154 }
106155
106156 - seq = atomic_inc_return(&call->sequence);
106157 + seq = atomic_inc_return_unchecked(&call->sequence);
106158
106159 sp->hdr.epoch = conn->epoch;
106160 sp->hdr.cid = call->cid;
106161 sp->hdr.callNumber = call->call_id;
106162 sp->hdr.seq = htonl(seq);
106163 sp->hdr.serial =
106164 - htonl(atomic_inc_return(&conn->serial));
106165 + htonl(atomic_inc_return_unchecked(&conn->serial));
106166 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106167 sp->hdr.userStatus = 0;
106168 sp->hdr.securityIndex = conn->security_ix;
106169 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106170 index bebaa43..2644591 100644
106171 --- a/net/rxrpc/ar-peer.c
106172 +++ b/net/rxrpc/ar-peer.c
106173 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106174 INIT_LIST_HEAD(&peer->error_targets);
106175 spin_lock_init(&peer->lock);
106176 atomic_set(&peer->usage, 1);
106177 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106178 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106179 memcpy(&peer->srx, srx, sizeof(*srx));
106180
106181 rxrpc_assess_MTU_size(peer);
106182 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106183 index 38047f7..9f48511 100644
106184 --- a/net/rxrpc/ar-proc.c
106185 +++ b/net/rxrpc/ar-proc.c
106186 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106187 atomic_read(&conn->usage),
106188 rxrpc_conn_states[conn->state],
106189 key_serial(conn->key),
106190 - atomic_read(&conn->serial),
106191 - atomic_read(&conn->hi_serial));
106192 + atomic_read_unchecked(&conn->serial),
106193 + atomic_read_unchecked(&conn->hi_serial));
106194
106195 return 0;
106196 }
106197 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106198 index 1976dec..aa70be5 100644
106199 --- a/net/rxrpc/ar-transport.c
106200 +++ b/net/rxrpc/ar-transport.c
106201 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106202 spin_lock_init(&trans->client_lock);
106203 rwlock_init(&trans->conn_lock);
106204 atomic_set(&trans->usage, 1);
106205 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106206 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106207
106208 if (peer->srx.transport.family == AF_INET) {
106209 switch (peer->srx.transport_type) {
106210 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106211 index f226709..0e735a8 100644
106212 --- a/net/rxrpc/rxkad.c
106213 +++ b/net/rxrpc/rxkad.c
106214 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106215
106216 len = iov[0].iov_len + iov[1].iov_len;
106217
106218 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106219 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106220 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106221
106222 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106223 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106224
106225 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106226
106227 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106228 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106229 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106230
106231 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106232 diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
106233 index aad6a67..baef987 100644
106234 --- a/net/sched/cls_api.c
106235 +++ b/net/sched/cls_api.c
106236 @@ -556,8 +556,9 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
106237 }
106238 EXPORT_SYMBOL(tcf_exts_change);
106239
106240 -#define tcf_exts_first_act(ext) \
106241 - list_first_entry(&(exts)->actions, struct tc_action, list)
106242 +#define tcf_exts_first_act(ext) \
106243 + list_first_entry_or_null(&(exts)->actions, \
106244 + struct tc_action, list)
106245
106246 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
106247 {
106248 @@ -603,7 +604,7 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
106249 {
106250 #ifdef CONFIG_NET_CLS_ACT
106251 struct tc_action *a = tcf_exts_first_act(exts);
106252 - if (tcf_action_copy_stats(skb, a, 1) < 0)
106253 + if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
106254 return -1;
106255 #endif
106256 return 0;
106257 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
106258 index eed49d1..ce22514 100644
106259 --- a/net/sched/cls_bpf.c
106260 +++ b/net/sched/cls_bpf.c
106261 @@ -191,6 +191,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
106262 }
106263
106264 bpf_size = bpf_len * sizeof(*bpf_ops);
106265 + if (bpf_size != nla_len(tb[TCA_BPF_OPS])) {
106266 + ret = -EINVAL;
106267 + goto errout;
106268 + }
106269 +
106270 bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
106271 if (bpf_ops == NULL) {
106272 ret = -ENOMEM;
106273 @@ -226,15 +231,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
106274 struct cls_bpf_head *head)
106275 {
106276 unsigned int i = 0x80000000;
106277 + u32 handle;
106278
106279 do {
106280 if (++head->hgen == 0x7FFFFFFF)
106281 head->hgen = 1;
106282 } while (--i > 0 && cls_bpf_get(tp, head->hgen));
106283 - if (i == 0)
106284 +
106285 + if (unlikely(i == 0)) {
106286 pr_err("Insufficient number of handles\n");
106287 + handle = 0;
106288 + } else {
106289 + handle = head->hgen;
106290 + }
106291
106292 - return i;
106293 + return handle;
106294 }
106295
106296 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
106297 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106298 index 6efca30..1259f82 100644
106299 --- a/net/sched/sch_generic.c
106300 +++ b/net/sched/sch_generic.c
106301 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
106302 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106303 if (dev->reg_state == NETREG_UNINITIALIZED)
106304 return;
106305 - atomic_inc(&dev->carrier_changes);
106306 + atomic_inc_unchecked(&dev->carrier_changes);
106307 linkwatch_fire_event(dev);
106308 if (netif_running(dev))
106309 __netdev_watchdog_up(dev);
106310 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
106311 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106312 if (dev->reg_state == NETREG_UNINITIALIZED)
106313 return;
106314 - atomic_inc(&dev->carrier_changes);
106315 + atomic_inc_unchecked(&dev->carrier_changes);
106316 linkwatch_fire_event(dev);
106317 }
106318 }
106319 diff --git a/net/sctp/associola.c b/net/sctp/associola.c
106320 index f791edd..26d06db 100644
106321 --- a/net/sctp/associola.c
106322 +++ b/net/sctp/associola.c
106323 @@ -1182,7 +1182,6 @@ void sctp_assoc_update(struct sctp_association *asoc,
106324 asoc->peer.peer_hmacs = new->peer.peer_hmacs;
106325 new->peer.peer_hmacs = NULL;
106326
106327 - sctp_auth_key_put(asoc->asoc_shared_key);
106328 sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
106329 }
106330
106331 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106332 index 0e4198e..f94193e 100644
106333 --- a/net/sctp/ipv6.c
106334 +++ b/net/sctp/ipv6.c
106335 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106336 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106337 };
106338
106339 -static struct sctp_af sctp_af_inet6 = {
106340 +static struct sctp_af sctp_af_inet6 __read_only = {
106341 .sa_family = AF_INET6,
106342 .sctp_xmit = sctp_v6_xmit,
106343 .setsockopt = ipv6_setsockopt,
106344 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106345 #endif
106346 };
106347
106348 -static struct sctp_pf sctp_pf_inet6 = {
106349 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106350 .event_msgname = sctp_inet6_event_msgname,
106351 .skb_msgname = sctp_inet6_skb_msgname,
106352 .af_supported = sctp_inet6_af_supported,
106353 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106354
106355 void sctp_v6_pf_exit(void)
106356 {
106357 - list_del(&sctp_af_inet6.list);
106358 + pax_list_del(&sctp_af_inet6.list);
106359 }
106360
106361 /* Initialize IPv6 support and register with socket layer. */
106362 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106363 index 8f34b27..b105385 100644
106364 --- a/net/sctp/protocol.c
106365 +++ b/net/sctp/protocol.c
106366 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106367 return 0;
106368 }
106369
106370 + pax_open_kernel();
106371 INIT_LIST_HEAD(&af->list);
106372 - list_add_tail(&af->list, &sctp_address_families);
106373 + pax_close_kernel();
106374 + pax_list_add_tail(&af->list, &sctp_address_families);
106375 return 1;
106376 }
106377
106378 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106379
106380 static struct sctp_af sctp_af_inet;
106381
106382 -static struct sctp_pf sctp_pf_inet = {
106383 +static struct sctp_pf sctp_pf_inet __read_only = {
106384 .event_msgname = sctp_inet_event_msgname,
106385 .skb_msgname = sctp_inet_skb_msgname,
106386 .af_supported = sctp_inet_af_supported,
106387 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106388 };
106389
106390 /* IPv4 address related functions. */
106391 -static struct sctp_af sctp_af_inet = {
106392 +static struct sctp_af sctp_af_inet __read_only = {
106393 .sa_family = AF_INET,
106394 .sctp_xmit = sctp_v4_xmit,
106395 .setsockopt = ip_setsockopt,
106396 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106397
106398 static void sctp_v4_pf_exit(void)
106399 {
106400 - list_del(&sctp_af_inet.list);
106401 + pax_list_del(&sctp_af_inet.list);
106402 }
106403
106404 static int sctp_v4_protosw_init(void)
106405 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106406 index fef2acd..c705c4f 100644
106407 --- a/net/sctp/sm_sideeffect.c
106408 +++ b/net/sctp/sm_sideeffect.c
106409 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106410 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106411 }
106412
106413 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106414 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106415 NULL,
106416 sctp_generate_t1_cookie_event,
106417 sctp_generate_t1_init_event,
106418 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106419 index 634a2ab..dfdaf9b 100644
106420 --- a/net/sctp/socket.c
106421 +++ b/net/sctp/socket.c
106422 @@ -1603,7 +1603,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106423 sctp_assoc_t associd = 0;
106424 sctp_cmsgs_t cmsgs = { NULL };
106425 sctp_scope_t scope;
106426 - bool fill_sinfo_ttl = false;
106427 + bool fill_sinfo_ttl = false, wait_connect = false;
106428 struct sctp_datamsg *datamsg;
106429 int msg_flags = msg->msg_flags;
106430 __u16 sinfo_flags = 0;
106431 @@ -1943,6 +1943,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106432 if (err < 0)
106433 goto out_free;
106434
106435 + wait_connect = true;
106436 pr_debug("%s: we associated primitively\n", __func__);
106437 }
106438
106439 @@ -1980,6 +1981,11 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106440 sctp_datamsg_put(datamsg);
106441 err = msg_len;
106442
106443 + if (unlikely(wait_connect)) {
106444 + timeo = sock_sndtimeo(sk, msg_flags & MSG_DONTWAIT);
106445 + sctp_wait_for_connect(asoc, &timeo);
106446 + }
106447 +
106448 /* If we are already past ASSOCIATE, the lower
106449 * layers are responsible for association cleanup.
106450 */
106451 @@ -2199,11 +2205,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106452 {
106453 struct sctp_association *asoc;
106454 struct sctp_ulpevent *event;
106455 + struct sctp_event_subscribe subscribe;
106456
106457 if (optlen > sizeof(struct sctp_event_subscribe))
106458 return -EINVAL;
106459 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106460 + if (copy_from_user(&subscribe, optval, optlen))
106461 return -EFAULT;
106462 + sctp_sk(sk)->subscribe = subscribe;
106463
106464 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106465 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106466 @@ -4372,13 +4380,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106467 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106468 int __user *optlen)
106469 {
106470 + struct sctp_event_subscribe subscribe;
106471 +
106472 if (len <= 0)
106473 return -EINVAL;
106474 if (len > sizeof(struct sctp_event_subscribe))
106475 len = sizeof(struct sctp_event_subscribe);
106476 if (put_user(len, optlen))
106477 return -EFAULT;
106478 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106479 + subscribe = sctp_sk(sk)->subscribe;
106480 + if (copy_to_user(optval, &subscribe, len))
106481 return -EFAULT;
106482 return 0;
106483 }
106484 @@ -4396,6 +4407,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106485 */
106486 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106487 {
106488 + __u32 autoclose;
106489 +
106490 /* Applicable to UDP-style socket only */
106491 if (sctp_style(sk, TCP))
106492 return -EOPNOTSUPP;
106493 @@ -4404,7 +4417,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106494 len = sizeof(int);
106495 if (put_user(len, optlen))
106496 return -EFAULT;
106497 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106498 + autoclose = sctp_sk(sk)->autoclose;
106499 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106500 return -EFAULT;
106501 return 0;
106502 }
106503 @@ -4778,12 +4792,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106504 */
106505 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106506 {
106507 + struct sctp_initmsg initmsg;
106508 +
106509 if (len < sizeof(struct sctp_initmsg))
106510 return -EINVAL;
106511 len = sizeof(struct sctp_initmsg);
106512 if (put_user(len, optlen))
106513 return -EFAULT;
106514 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106515 + initmsg = sctp_sk(sk)->initmsg;
106516 + if (copy_to_user(optval, &initmsg, len))
106517 return -EFAULT;
106518 return 0;
106519 }
106520 @@ -4824,6 +4841,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106521 ->addr_to_user(sp, &temp);
106522 if (space_left < addrlen)
106523 return -ENOMEM;
106524 + if (addrlen > sizeof(temp) || addrlen < 0)
106525 + return -EFAULT;
106526 if (copy_to_user(to, &temp, addrlen))
106527 return -EFAULT;
106528 to += addrlen;
106529 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106530 index 2e9ada1..40f425d 100644
106531 --- a/net/sctp/sysctl.c
106532 +++ b/net/sctp/sysctl.c
106533 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106534 loff_t *ppos)
106535 {
106536 struct net *net = current->nsproxy->net_ns;
106537 - struct ctl_table tbl;
106538 + ctl_table_no_const tbl;
106539 bool changed = false;
106540 char *none = "none";
106541 char tmp[8];
106542 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106543 struct net *net = current->nsproxy->net_ns;
106544 unsigned int min = *(unsigned int *) ctl->extra1;
106545 unsigned int max = *(unsigned int *) ctl->extra2;
106546 - struct ctl_table tbl;
106547 + ctl_table_no_const tbl;
106548 int ret, new_value;
106549
106550 memset(&tbl, 0, sizeof(struct ctl_table));
106551 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106552 struct net *net = current->nsproxy->net_ns;
106553 unsigned int min = *(unsigned int *) ctl->extra1;
106554 unsigned int max = *(unsigned int *) ctl->extra2;
106555 - struct ctl_table tbl;
106556 + ctl_table_no_const tbl;
106557 int ret, new_value;
106558
106559 memset(&tbl, 0, sizeof(struct ctl_table));
106560 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106561 loff_t *ppos)
106562 {
106563 struct net *net = current->nsproxy->net_ns;
106564 - struct ctl_table tbl;
106565 + ctl_table_no_const tbl;
106566 int new_value, ret;
106567
106568 memset(&tbl, 0, sizeof(struct ctl_table));
106569 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106570
106571 int sctp_sysctl_net_register(struct net *net)
106572 {
106573 - struct ctl_table *table;
106574 + ctl_table_no_const *table;
106575 int i;
106576
106577 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106578 diff --git a/net/socket.c b/net/socket.c
106579 index fe20c31..83a0ed6 100644
106580 --- a/net/socket.c
106581 +++ b/net/socket.c
106582 @@ -89,6 +89,7 @@
106583 #include <linux/magic.h>
106584 #include <linux/slab.h>
106585 #include <linux/xattr.h>
106586 +#include <linux/in.h>
106587
106588 #include <asm/uaccess.h>
106589 #include <asm/unistd.h>
106590 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106591 unsigned int sysctl_net_busy_poll __read_mostly;
106592 #endif
106593
106594 +#include <linux/grsock.h>
106595 +
106596 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106597 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106598 unsigned long nr_segs, loff_t pos);
106599 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106600 */
106601
106602 static DEFINE_SPINLOCK(net_family_lock);
106603 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106604 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106605
106606 /*
106607 * Statistics counters of the socket lists
106608 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106609 &sockfs_dentry_operations, SOCKFS_MAGIC);
106610 }
106611
106612 -static struct vfsmount *sock_mnt __read_mostly;
106613 +struct vfsmount *sock_mnt __read_mostly;
106614
106615 static struct file_system_type sock_fs_type = {
106616 .name = "sockfs",
106617 @@ -1263,6 +1266,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106618 return -EAFNOSUPPORT;
106619 if (type < 0 || type >= SOCK_MAX)
106620 return -EINVAL;
106621 + if (protocol < 0)
106622 + return -EINVAL;
106623
106624 /* Compatibility.
106625
106626 @@ -1283,6 +1288,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106627 if (err)
106628 return err;
106629
106630 + if(!kern && !gr_search_socket(family, type, protocol)) {
106631 + if (rcu_access_pointer(net_families[family]) == NULL)
106632 + return -EAFNOSUPPORT;
106633 + else
106634 + return -EACCES;
106635 + }
106636 +
106637 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106638 + if (rcu_access_pointer(net_families[family]) == NULL)
106639 + return -EAFNOSUPPORT;
106640 + else
106641 + return -EACCES;
106642 + }
106643 +
106644 /*
106645 * Allocate the socket and allow the family to set things up. if
106646 * the protocol is 0, the family is instructed to select an appropriate
106647 @@ -1534,6 +1553,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106648 if (sock) {
106649 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106650 if (err >= 0) {
106651 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106652 + err = -EACCES;
106653 + goto error;
106654 + }
106655 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106656 + if (err)
106657 + goto error;
106658 +
106659 err = security_socket_bind(sock,
106660 (struct sockaddr *)&address,
106661 addrlen);
106662 @@ -1542,6 +1569,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106663 (struct sockaddr *)
106664 &address, addrlen);
106665 }
106666 +error:
106667 fput_light(sock->file, fput_needed);
106668 }
106669 return err;
106670 @@ -1565,10 +1593,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106671 if ((unsigned int)backlog > somaxconn)
106672 backlog = somaxconn;
106673
106674 + if (gr_handle_sock_server_other(sock->sk)) {
106675 + err = -EPERM;
106676 + goto error;
106677 + }
106678 +
106679 + err = gr_search_listen(sock);
106680 + if (err)
106681 + goto error;
106682 +
106683 err = security_socket_listen(sock, backlog);
106684 if (!err)
106685 err = sock->ops->listen(sock, backlog);
106686
106687 +error:
106688 fput_light(sock->file, fput_needed);
106689 }
106690 return err;
106691 @@ -1612,6 +1650,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106692 newsock->type = sock->type;
106693 newsock->ops = sock->ops;
106694
106695 + if (gr_handle_sock_server_other(sock->sk)) {
106696 + err = -EPERM;
106697 + sock_release(newsock);
106698 + goto out_put;
106699 + }
106700 +
106701 + err = gr_search_accept(sock);
106702 + if (err) {
106703 + sock_release(newsock);
106704 + goto out_put;
106705 + }
106706 +
106707 /*
106708 * We don't need try_module_get here, as the listening socket (sock)
106709 * has the protocol module (sock->ops->owner) held.
106710 @@ -1657,6 +1707,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106711 fd_install(newfd, newfile);
106712 err = newfd;
106713
106714 + gr_attach_curr_ip(newsock->sk);
106715 +
106716 out_put:
106717 fput_light(sock->file, fput_needed);
106718 out:
106719 @@ -1689,6 +1741,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106720 int, addrlen)
106721 {
106722 struct socket *sock;
106723 + struct sockaddr *sck;
106724 struct sockaddr_storage address;
106725 int err, fput_needed;
106726
106727 @@ -1699,6 +1752,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106728 if (err < 0)
106729 goto out_put;
106730
106731 + sck = (struct sockaddr *)&address;
106732 +
106733 + if (gr_handle_sock_client(sck)) {
106734 + err = -EACCES;
106735 + goto out_put;
106736 + }
106737 +
106738 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106739 + if (err)
106740 + goto out_put;
106741 +
106742 err =
106743 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106744 if (err)
106745 @@ -1780,6 +1844,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106746 * the protocol.
106747 */
106748
106749 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106750 +
106751 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106752 unsigned int, flags, struct sockaddr __user *, addr,
106753 int, addr_len)
106754 @@ -1846,7 +1912,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106755 struct socket *sock;
106756 struct iovec iov;
106757 struct msghdr msg;
106758 - struct sockaddr_storage address;
106759 + struct sockaddr_storage address = { };
106760 int err, err2;
106761 int fput_needed;
106762
106763 @@ -2075,7 +2141,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106764 * checking falls down on this.
106765 */
106766 if (copy_from_user(ctl_buf,
106767 - (void __user __force *)msg_sys->msg_control,
106768 + (void __force_user *)msg_sys->msg_control,
106769 ctl_len))
106770 goto out_freectl;
106771 msg_sys->msg_control = ctl_buf;
106772 @@ -2226,7 +2292,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106773 int err, total_len, len;
106774
106775 /* kernel mode address */
106776 - struct sockaddr_storage addr;
106777 + struct sockaddr_storage addr = { };
106778
106779 /* user mode address pointers */
106780 struct sockaddr __user *uaddr;
106781 @@ -2255,7 +2321,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106782 /* Save the user-mode address (verify_iovec will change the
106783 * kernel msghdr to use the kernel address space)
106784 */
106785 - uaddr = (__force void __user *)msg_sys->msg_name;
106786 + uaddr = (void __force_user *)msg_sys->msg_name;
106787 uaddr_len = COMPAT_NAMELEN(msg);
106788 if (MSG_CMSG_COMPAT & flags)
106789 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106790 @@ -2896,7 +2962,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106791 ifr = compat_alloc_user_space(buf_size);
106792 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106793
106794 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106795 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106796 return -EFAULT;
106797
106798 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106799 @@ -3007,7 +3073,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106800 old_fs = get_fs();
106801 set_fs(KERNEL_DS);
106802 err = dev_ioctl(net, cmd,
106803 - (struct ifreq __user __force *) &kifr);
106804 + (struct ifreq __force_user *) &kifr);
106805 set_fs(old_fs);
106806
106807 return err;
106808 @@ -3100,7 +3166,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106809
106810 old_fs = get_fs();
106811 set_fs(KERNEL_DS);
106812 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106813 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106814 set_fs(old_fs);
106815
106816 if (cmd == SIOCGIFMAP && !err) {
106817 @@ -3184,7 +3250,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106818 ret |= get_user(rtdev, &(ur4->rt_dev));
106819 if (rtdev) {
106820 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106821 - r4.rt_dev = (char __user __force *)devname;
106822 + r4.rt_dev = (char __force_user *)devname;
106823 devname[15] = 0;
106824 } else
106825 r4.rt_dev = NULL;
106826 @@ -3411,8 +3477,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106827 int __user *uoptlen;
106828 int err;
106829
106830 - uoptval = (char __user __force *) optval;
106831 - uoptlen = (int __user __force *) optlen;
106832 + uoptval = (char __force_user *) optval;
106833 + uoptlen = (int __force_user *) optlen;
106834
106835 set_fs(KERNEL_DS);
106836 if (level == SOL_SOCKET)
106837 @@ -3432,7 +3498,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106838 char __user *uoptval;
106839 int err;
106840
106841 - uoptval = (char __user __force *) optval;
106842 + uoptval = (char __force_user *) optval;
106843
106844 set_fs(KERNEL_DS);
106845 if (level == SOL_SOCKET)
106846 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106847 index c548ab2..4e1b68b 100644
106848 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106849 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106850 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106851 uint64_t *handle)
106852 {
106853 struct rsc rsci, *rscp = NULL;
106854 - static atomic64_t ctxhctr;
106855 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106856 long long ctxh;
106857 struct gss_api_mech *gm = NULL;
106858 time_t expiry;
106859 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106860 status = -ENOMEM;
106861 /* the handle needs to be just a unique id,
106862 * use a static counter */
106863 - ctxh = atomic64_inc_return(&ctxhctr);
106864 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106865
106866 /* make a copy for the caller */
106867 *handle = ctxh;
106868 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106869 index 0663621..c4928d4 100644
106870 --- a/net/sunrpc/cache.c
106871 +++ b/net/sunrpc/cache.c
106872 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106873 struct sunrpc_net *sn;
106874
106875 sn = net_generic(net, sunrpc_net_id);
106876 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106877 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106878 if (cd->u.procfs.proc_ent == NULL)
106879 goto out_nomem;
106880 cd->u.procfs.channel_ent = NULL;
106881 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106882 index 9acd6ce..4353a72 100644
106883 --- a/net/sunrpc/clnt.c
106884 +++ b/net/sunrpc/clnt.c
106885 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106886 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106887
106888 /* Increment call count */
106889 - task->tk_msg.rpc_proc->p_count++;
106890 + pax_open_kernel();
106891 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106892 + pax_close_kernel();
106893 clnt->cl_stats->rpccnt++;
106894 task->tk_action = call_reserve;
106895 }
106896 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106897 index fe3441a..922c29e 100644
106898 --- a/net/sunrpc/sched.c
106899 +++ b/net/sunrpc/sched.c
106900 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106901 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106902 static void rpc_task_set_debuginfo(struct rpc_task *task)
106903 {
106904 - static atomic_t rpc_pid;
106905 + static atomic_unchecked_t rpc_pid;
106906
106907 - task->tk_pid = atomic_inc_return(&rpc_pid);
106908 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106909 }
106910 #else
106911 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106912 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106913 index 5453049..465669a 100644
106914 --- a/net/sunrpc/stats.c
106915 +++ b/net/sunrpc/stats.c
106916 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106917
106918 dprintk("RPC: registering /proc/net/rpc\n");
106919 sn = net_generic(net, sunrpc_net_id);
106920 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106921 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106922 if (sn->proc_net_rpc == NULL)
106923 return -ENOMEM;
106924
106925 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106926 index ca8a795..ddfc41b 100644
106927 --- a/net/sunrpc/svc.c
106928 +++ b/net/sunrpc/svc.c
106929 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106930 svc_putnl(resv, RPC_SUCCESS);
106931
106932 /* Bump per-procedure stats counter */
106933 - procp->pc_count++;
106934 + pax_open_kernel();
106935 + (*(unsigned int *)&procp->pc_count)++;
106936 + pax_close_kernel();
106937
106938 /* Initialize storage for argp and resp */
106939 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106940 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106941 index 621ca7b..59421dd 100644
106942 --- a/net/sunrpc/svcauth_unix.c
106943 +++ b/net/sunrpc/svcauth_unix.c
106944 @@ -414,7 +414,7 @@ struct unix_gid {
106945 struct group_info *gi;
106946 };
106947
106948 -static int unix_gid_hash(kuid_t uid)
106949 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106950 {
106951 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106952 }
106953 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106954 (*bpp)[-1] = '\n';
106955 }
106956
106957 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106958 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106959
106960 static int unix_gid_parse(struct cache_detail *cd,
106961 char *mesg, int mlen)
106962 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106963 index c1b6270..05089c1 100644
106964 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106965 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106966 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106967 static unsigned int min_max_inline = 4096;
106968 static unsigned int max_max_inline = 65536;
106969
106970 -atomic_t rdma_stat_recv;
106971 -atomic_t rdma_stat_read;
106972 -atomic_t rdma_stat_write;
106973 -atomic_t rdma_stat_sq_starve;
106974 -atomic_t rdma_stat_rq_starve;
106975 -atomic_t rdma_stat_rq_poll;
106976 -atomic_t rdma_stat_rq_prod;
106977 -atomic_t rdma_stat_sq_poll;
106978 -atomic_t rdma_stat_sq_prod;
106979 +atomic_unchecked_t rdma_stat_recv;
106980 +atomic_unchecked_t rdma_stat_read;
106981 +atomic_unchecked_t rdma_stat_write;
106982 +atomic_unchecked_t rdma_stat_sq_starve;
106983 +atomic_unchecked_t rdma_stat_rq_starve;
106984 +atomic_unchecked_t rdma_stat_rq_poll;
106985 +atomic_unchecked_t rdma_stat_rq_prod;
106986 +atomic_unchecked_t rdma_stat_sq_poll;
106987 +atomic_unchecked_t rdma_stat_sq_prod;
106988
106989 /* Temporary NFS request map and context caches */
106990 struct kmem_cache *svc_rdma_map_cachep;
106991 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106992 len -= *ppos;
106993 if (len > *lenp)
106994 len = *lenp;
106995 - if (len && copy_to_user(buffer, str_buf, len))
106996 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106997 return -EFAULT;
106998 *lenp = len;
106999 *ppos += len;
107000 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
107001 {
107002 .procname = "rdma_stat_read",
107003 .data = &rdma_stat_read,
107004 - .maxlen = sizeof(atomic_t),
107005 + .maxlen = sizeof(atomic_unchecked_t),
107006 .mode = 0644,
107007 .proc_handler = read_reset_stat,
107008 },
107009 {
107010 .procname = "rdma_stat_recv",
107011 .data = &rdma_stat_recv,
107012 - .maxlen = sizeof(atomic_t),
107013 + .maxlen = sizeof(atomic_unchecked_t),
107014 .mode = 0644,
107015 .proc_handler = read_reset_stat,
107016 },
107017 {
107018 .procname = "rdma_stat_write",
107019 .data = &rdma_stat_write,
107020 - .maxlen = sizeof(atomic_t),
107021 + .maxlen = sizeof(atomic_unchecked_t),
107022 .mode = 0644,
107023 .proc_handler = read_reset_stat,
107024 },
107025 {
107026 .procname = "rdma_stat_sq_starve",
107027 .data = &rdma_stat_sq_starve,
107028 - .maxlen = sizeof(atomic_t),
107029 + .maxlen = sizeof(atomic_unchecked_t),
107030 .mode = 0644,
107031 .proc_handler = read_reset_stat,
107032 },
107033 {
107034 .procname = "rdma_stat_rq_starve",
107035 .data = &rdma_stat_rq_starve,
107036 - .maxlen = sizeof(atomic_t),
107037 + .maxlen = sizeof(atomic_unchecked_t),
107038 .mode = 0644,
107039 .proc_handler = read_reset_stat,
107040 },
107041 {
107042 .procname = "rdma_stat_rq_poll",
107043 .data = &rdma_stat_rq_poll,
107044 - .maxlen = sizeof(atomic_t),
107045 + .maxlen = sizeof(atomic_unchecked_t),
107046 .mode = 0644,
107047 .proc_handler = read_reset_stat,
107048 },
107049 {
107050 .procname = "rdma_stat_rq_prod",
107051 .data = &rdma_stat_rq_prod,
107052 - .maxlen = sizeof(atomic_t),
107053 + .maxlen = sizeof(atomic_unchecked_t),
107054 .mode = 0644,
107055 .proc_handler = read_reset_stat,
107056 },
107057 {
107058 .procname = "rdma_stat_sq_poll",
107059 .data = &rdma_stat_sq_poll,
107060 - .maxlen = sizeof(atomic_t),
107061 + .maxlen = sizeof(atomic_unchecked_t),
107062 .mode = 0644,
107063 .proc_handler = read_reset_stat,
107064 },
107065 {
107066 .procname = "rdma_stat_sq_prod",
107067 .data = &rdma_stat_sq_prod,
107068 - .maxlen = sizeof(atomic_t),
107069 + .maxlen = sizeof(atomic_unchecked_t),
107070 .mode = 0644,
107071 .proc_handler = read_reset_stat,
107072 },
107073 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107074 index e011027..9d3c4e1 100644
107075 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107076 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107077 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
107078 *page_no = pg_no;
107079 *page_offset = pg_off;
107080 ret = read;
107081 - atomic_inc(&rdma_stat_read);
107082 + atomic_inc_unchecked(&rdma_stat_read);
107083 return ret;
107084 err:
107085 svc_rdma_unmap_dma(ctxt);
107086 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107087 *page_no = pg_no;
107088 *page_offset = pg_off;
107089 ret = read;
107090 - atomic_inc(&rdma_stat_read);
107091 + atomic_inc_unchecked(&rdma_stat_read);
107092 return ret;
107093 err:
107094 svc_rdma_unmap_dma(ctxt);
107095 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107096 dto_q);
107097 list_del_init(&ctxt->dto_q);
107098 } else {
107099 - atomic_inc(&rdma_stat_rq_starve);
107100 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107101 clear_bit(XPT_DATA, &xprt->xpt_flags);
107102 ctxt = NULL;
107103 }
107104 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107105 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107106 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107107 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107108 - atomic_inc(&rdma_stat_recv);
107109 + atomic_inc_unchecked(&rdma_stat_recv);
107110
107111 /* Build up the XDR from the receive buffers. */
107112 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107113 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107114 index 9f1b506..2e0b321 100644
107115 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107116 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107117 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107118 write_wr.wr.rdma.remote_addr = to;
107119
107120 /* Post It */
107121 - atomic_inc(&rdma_stat_write);
107122 + atomic_inc_unchecked(&rdma_stat_write);
107123 if (svc_rdma_send(xprt, &write_wr))
107124 goto err;
107125 return write_len - bc;
107126 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107127 index 4e61880..1f0d963 100644
107128 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107129 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107130 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107131 return;
107132
107133 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107134 - atomic_inc(&rdma_stat_rq_poll);
107135 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107136
107137 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107138 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107139 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107140 }
107141
107142 if (ctxt)
107143 - atomic_inc(&rdma_stat_rq_prod);
107144 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107145
107146 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107147 /*
107148 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107149 return;
107150
107151 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107152 - atomic_inc(&rdma_stat_sq_poll);
107153 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107154 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107155 int i;
107156
107157 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107158 }
107159
107160 if (ctxt)
107161 - atomic_inc(&rdma_stat_sq_prod);
107162 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107163 }
107164
107165 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107166 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107167 spin_lock_bh(&xprt->sc_lock);
107168 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107169 spin_unlock_bh(&xprt->sc_lock);
107170 - atomic_inc(&rdma_stat_sq_starve);
107171 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107172
107173 /* See if we can opportunistically reap SQ WR to make room */
107174 sq_cq_reap(xprt);
107175 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107176 index e7000be..e3b0ba7 100644
107177 --- a/net/sysctl_net.c
107178 +++ b/net/sysctl_net.c
107179 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107180 kgid_t root_gid = make_kgid(net->user_ns, 0);
107181
107182 /* Allow network administrator to have same access as root. */
107183 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107184 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107185 uid_eq(root_uid, current_euid())) {
107186 int mode = (table->mode >> 6) & 7;
107187 return (mode << 6) | (mode << 3) | mode;
107188 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107189 index 31b5cb2..566ff01 100644
107190 --- a/net/tipc/subscr.c
107191 +++ b/net/tipc/subscr.c
107192 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107193 struct tipc_subscriber *subscriber = sub->subscriber;
107194 struct kvec msg_sect;
107195
107196 - msg_sect.iov_base = (void *)&sub->evt;
107197 + msg_sect.iov_base = &sub->evt;
107198 msg_sect.iov_len = sizeof(struct tipc_event);
107199 sub->evt.event = htohl(event, sub->swap);
107200 sub->evt.found_lower = htohl(found_lower, sub->swap);
107201 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107202 index e968843..bc95776 100644
107203 --- a/net/unix/af_unix.c
107204 +++ b/net/unix/af_unix.c
107205 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107206 err = -ECONNREFUSED;
107207 if (!S_ISSOCK(inode->i_mode))
107208 goto put_fail;
107209 +
107210 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107211 + err = -EACCES;
107212 + goto put_fail;
107213 + }
107214 +
107215 u = unix_find_socket_byinode(inode);
107216 if (!u)
107217 goto put_fail;
107218 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107219 if (u) {
107220 struct dentry *dentry;
107221 dentry = unix_sk(u)->path.dentry;
107222 +
107223 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107224 + err = -EPERM;
107225 + sock_put(u);
107226 + goto fail;
107227 + }
107228 +
107229 if (dentry)
107230 touch_atime(&unix_sk(u)->path);
107231 } else
107232 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107233 */
107234 err = security_path_mknod(&path, dentry, mode, 0);
107235 if (!err) {
107236 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107237 + err = -EACCES;
107238 + goto out;
107239 + }
107240 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107241 if (!err) {
107242 res->mnt = mntget(path.mnt);
107243 res->dentry = dget(dentry);
107244 + gr_handle_create(dentry, path.mnt);
107245 }
107246 }
107247 +out:
107248 done_path_create(&path, dentry);
107249 return err;
107250 }
107251 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107252 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107253 "Inode Path\n");
107254 else {
107255 - struct sock *s = v;
107256 + struct sock *s = v, *peer;
107257 struct unix_sock *u = unix_sk(s);
107258 unix_state_lock(s);
107259 + peer = unix_peer(s);
107260 + unix_state_unlock(s);
107261 +
107262 + unix_state_double_lock(s, peer);
107263
107264 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107265 s,
107266 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107267 }
107268 for ( ; i < len; i++)
107269 seq_putc(seq, u->addr->name->sun_path[i]);
107270 - }
107271 - unix_state_unlock(s);
107272 + } else if (peer)
107273 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107274 +
107275 + unix_state_double_unlock(s, peer);
107276 seq_putc(seq, '\n');
107277 }
107278
107279 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107280 index b3d5150..ff3a837 100644
107281 --- a/net/unix/sysctl_net_unix.c
107282 +++ b/net/unix/sysctl_net_unix.c
107283 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107284
107285 int __net_init unix_sysctl_register(struct net *net)
107286 {
107287 - struct ctl_table *table;
107288 + ctl_table_no_const *table;
107289
107290 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107291 if (table == NULL)
107292 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107293 index 9b7f207..2596621 100644
107294 --- a/net/vmw_vsock/vmci_transport_notify.c
107295 +++ b/net/vmw_vsock/vmci_transport_notify.c
107296 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107297
107298 /* Socket control packet based operations. */
107299 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107300 - vmci_transport_notify_pkt_socket_init,
107301 - vmci_transport_notify_pkt_socket_destruct,
107302 - vmci_transport_notify_pkt_poll_in,
107303 - vmci_transport_notify_pkt_poll_out,
107304 - vmci_transport_notify_pkt_handle_pkt,
107305 - vmci_transport_notify_pkt_recv_init,
107306 - vmci_transport_notify_pkt_recv_pre_block,
107307 - vmci_transport_notify_pkt_recv_pre_dequeue,
107308 - vmci_transport_notify_pkt_recv_post_dequeue,
107309 - vmci_transport_notify_pkt_send_init,
107310 - vmci_transport_notify_pkt_send_pre_block,
107311 - vmci_transport_notify_pkt_send_pre_enqueue,
107312 - vmci_transport_notify_pkt_send_post_enqueue,
107313 - vmci_transport_notify_pkt_process_request,
107314 - vmci_transport_notify_pkt_process_negotiate,
107315 + .socket_init = vmci_transport_notify_pkt_socket_init,
107316 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107317 + .poll_in = vmci_transport_notify_pkt_poll_in,
107318 + .poll_out = vmci_transport_notify_pkt_poll_out,
107319 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107320 + .recv_init = vmci_transport_notify_pkt_recv_init,
107321 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107322 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107323 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107324 + .send_init = vmci_transport_notify_pkt_send_init,
107325 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107326 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107327 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107328 + .process_request = vmci_transport_notify_pkt_process_request,
107329 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107330 };
107331 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107332 index dc9c792..3089de0 100644
107333 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107334 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107335 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107336
107337 /* Socket always on control packet based operations. */
107338 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107339 - vmci_transport_notify_pkt_socket_init,
107340 - vmci_transport_notify_pkt_socket_destruct,
107341 - vmci_transport_notify_pkt_poll_in,
107342 - vmci_transport_notify_pkt_poll_out,
107343 - vmci_transport_notify_pkt_handle_pkt,
107344 - vmci_transport_notify_pkt_recv_init,
107345 - vmci_transport_notify_pkt_recv_pre_block,
107346 - vmci_transport_notify_pkt_recv_pre_dequeue,
107347 - vmci_transport_notify_pkt_recv_post_dequeue,
107348 - vmci_transport_notify_pkt_send_init,
107349 - vmci_transport_notify_pkt_send_pre_block,
107350 - vmci_transport_notify_pkt_send_pre_enqueue,
107351 - vmci_transport_notify_pkt_send_post_enqueue,
107352 - vmci_transport_notify_pkt_process_request,
107353 - vmci_transport_notify_pkt_process_negotiate,
107354 + .socket_init = vmci_transport_notify_pkt_socket_init,
107355 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107356 + .poll_in = vmci_transport_notify_pkt_poll_in,
107357 + .poll_out = vmci_transport_notify_pkt_poll_out,
107358 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107359 + .recv_init = vmci_transport_notify_pkt_recv_init,
107360 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107361 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107362 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107363 + .send_init = vmci_transport_notify_pkt_send_init,
107364 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107365 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107366 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107367 + .process_request = vmci_transport_notify_pkt_process_request,
107368 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107369 };
107370 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107371 index c8717c1..08539f5 100644
107372 --- a/net/wireless/wext-core.c
107373 +++ b/net/wireless/wext-core.c
107374 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107375 */
107376
107377 /* Support for very large requests */
107378 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107379 - (user_length > descr->max_tokens)) {
107380 + if (user_length > descr->max_tokens) {
107381 /* Allow userspace to GET more than max so
107382 * we can support any size GET requests.
107383 * There is still a limit : -ENOMEM.
107384 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107385 }
107386 }
107387
107388 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107389 - /*
107390 - * If this is a GET, but not NOMAX, it means that the extra
107391 - * data is not bounded by userspace, but by max_tokens. Thus
107392 - * set the length to max_tokens. This matches the extra data
107393 - * allocation.
107394 - * The driver should fill it with the number of tokens it
107395 - * provided, and it may check iwp->length rather than having
107396 - * knowledge of max_tokens. If the driver doesn't change the
107397 - * iwp->length, this ioctl just copies back max_token tokens
107398 - * filled with zeroes. Hopefully the driver isn't claiming
107399 - * them to be valid data.
107400 - */
107401 - iwp->length = descr->max_tokens;
107402 - }
107403 -
107404 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107405
107406 iwp->length += essid_compat;
107407 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107408 index 4323952..a06dfe1 100644
107409 --- a/net/x25/sysctl_net_x25.c
107410 +++ b/net/x25/sysctl_net_x25.c
107411 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107412 .mode = 0644,
107413 .proc_handler = proc_dointvec,
107414 },
107415 - { 0, },
107416 + { },
107417 };
107418
107419 void __init x25_register_sysctl(void)
107420 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107421 index 0917f04..f4e3d8c 100644
107422 --- a/net/x25/x25_proc.c
107423 +++ b/net/x25/x25_proc.c
107424 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107425
107426 int __init x25_proc_init(void)
107427 {
107428 - if (!proc_mkdir("x25", init_net.proc_net))
107429 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107430 return -ENOMEM;
107431
107432 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107433 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107434 index 88bf289..7b0741b 100644
107435 --- a/net/xfrm/xfrm_policy.c
107436 +++ b/net/xfrm/xfrm_policy.c
107437 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107438 {
107439 policy->walk.dead = 1;
107440
107441 - atomic_inc(&policy->genid);
107442 + atomic_inc_unchecked(&policy->genid);
107443
107444 if (del_timer(&policy->polq.hold_timer))
107445 xfrm_pol_put(policy);
107446 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107447 hlist_add_head(&policy->bydst, chain);
107448 xfrm_pol_hold(policy);
107449 net->xfrm.policy_count[dir]++;
107450 - atomic_inc(&net->xfrm.flow_cache_genid);
107451 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107452
107453 /* After previous checking, family can either be AF_INET or AF_INET6 */
107454 if (policy->family == AF_INET)
107455 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107456
107457 xdst->num_pols = num_pols;
107458 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107459 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107460 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107461
107462 return xdst;
107463 }
107464 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
107465 }
107466 EXPORT_SYMBOL(xfrm_garbage_collect);
107467
107468 -static void xfrm_garbage_collect_deferred(struct net *net)
107469 +void xfrm_garbage_collect_deferred(struct net *net)
107470 {
107471 flow_cache_flush_deferred(net);
107472 }
107473 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107474
107475 static void xfrm_init_pmtu(struct dst_entry *dst)
107476 {
107477 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107478 if (xdst->xfrm_genid != dst->xfrm->genid)
107479 return 0;
107480 if (xdst->num_pols > 0 &&
107481 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107482 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107483 return 0;
107484
107485 mtu = dst_mtu(dst->child);
107486 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107487 dst_ops->link_failure = xfrm_link_failure;
107488 if (likely(dst_ops->neigh_lookup == NULL))
107489 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107490 - if (likely(afinfo->garbage_collect == NULL))
107491 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107492 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107493 }
107494 spin_unlock(&xfrm_policy_afinfo_lock);
107495 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107496 dst_ops->check = NULL;
107497 dst_ops->negative_advice = NULL;
107498 dst_ops->link_failure = NULL;
107499 - afinfo->garbage_collect = NULL;
107500 }
107501 return err;
107502 }
107503 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107504 sizeof(pol->xfrm_vec[i].saddr));
107505 pol->xfrm_vec[i].encap_family = mp->new_family;
107506 /* flush bundles */
107507 - atomic_inc(&pol->genid);
107508 + atomic_inc_unchecked(&pol->genid);
107509 }
107510 }
107511
107512 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107513 index de971b6..b843409 100644
107514 --- a/net/xfrm/xfrm_state.c
107515 +++ b/net/xfrm/xfrm_state.c
107516 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107517
107518 if (unlikely(afinfo == NULL))
107519 return -EAFNOSUPPORT;
107520 - typemap = afinfo->type_map;
107521 + typemap = (const struct xfrm_type **)afinfo->type_map;
107522 spin_lock_bh(&xfrm_type_lock);
107523
107524 - if (likely(typemap[type->proto] == NULL))
107525 + if (likely(typemap[type->proto] == NULL)) {
107526 + pax_open_kernel();
107527 typemap[type->proto] = type;
107528 - else
107529 + pax_close_kernel();
107530 + } else
107531 err = -EEXIST;
107532 spin_unlock_bh(&xfrm_type_lock);
107533 xfrm_state_put_afinfo(afinfo);
107534 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107535
107536 if (unlikely(afinfo == NULL))
107537 return -EAFNOSUPPORT;
107538 - typemap = afinfo->type_map;
107539 + typemap = (const struct xfrm_type **)afinfo->type_map;
107540 spin_lock_bh(&xfrm_type_lock);
107541
107542 if (unlikely(typemap[type->proto] != type))
107543 err = -ENOENT;
107544 - else
107545 + else {
107546 + pax_open_kernel();
107547 typemap[type->proto] = NULL;
107548 + pax_close_kernel();
107549 + }
107550 spin_unlock_bh(&xfrm_type_lock);
107551 xfrm_state_put_afinfo(afinfo);
107552 return err;
107553 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107554 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107555 {
107556 struct xfrm_state_afinfo *afinfo;
107557 - const struct xfrm_type **typemap;
107558 const struct xfrm_type *type;
107559 int modload_attempted = 0;
107560
107561 @@ -211,9 +215,8 @@ retry:
107562 afinfo = xfrm_state_get_afinfo(family);
107563 if (unlikely(afinfo == NULL))
107564 return NULL;
107565 - typemap = afinfo->type_map;
107566
107567 - type = typemap[proto];
107568 + type = afinfo->type_map[proto];
107569 if (unlikely(type && !try_module_get(type->owner)))
107570 type = NULL;
107571 if (!type && !modload_attempted) {
107572 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107573 return -EAFNOSUPPORT;
107574
107575 err = -EEXIST;
107576 - modemap = afinfo->mode_map;
107577 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107578 spin_lock_bh(&xfrm_mode_lock);
107579 if (modemap[mode->encap])
107580 goto out;
107581 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107582 if (!try_module_get(afinfo->owner))
107583 goto out;
107584
107585 - mode->afinfo = afinfo;
107586 + pax_open_kernel();
107587 + *(const void **)&mode->afinfo = afinfo;
107588 modemap[mode->encap] = mode;
107589 + pax_close_kernel();
107590 err = 0;
107591
107592 out:
107593 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107594 return -EAFNOSUPPORT;
107595
107596 err = -ENOENT;
107597 - modemap = afinfo->mode_map;
107598 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107599 spin_lock_bh(&xfrm_mode_lock);
107600 if (likely(modemap[mode->encap] == mode)) {
107601 + pax_open_kernel();
107602 modemap[mode->encap] = NULL;
107603 + pax_close_kernel();
107604 module_put(mode->afinfo->owner);
107605 err = 0;
107606 }
107607 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107608 u32 xfrm_get_acqseq(void)
107609 {
107610 u32 res;
107611 - static atomic_t acqseq;
107612 + static atomic_unchecked_t acqseq;
107613
107614 do {
107615 - res = atomic_inc_return(&acqseq);
107616 + res = atomic_inc_return_unchecked(&acqseq);
107617 } while (!res);
107618
107619 return res;
107620 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107621 index 05a6e3d..6716ec9 100644
107622 --- a/net/xfrm/xfrm_sysctl.c
107623 +++ b/net/xfrm/xfrm_sysctl.c
107624 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107625
107626 int __net_init xfrm_sysctl_init(struct net *net)
107627 {
107628 - struct ctl_table *table;
107629 + ctl_table_no_const *table;
107630
107631 __xfrm_sysctl_init(net);
107632
107633 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
107634 index 65e7b08..1b868d5 100644
107635 --- a/scripts/Kbuild.include
107636 +++ b/scripts/Kbuild.include
107637 @@ -144,7 +144,7 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
107638 # cc-ldoption
107639 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
107640 cc-ldoption = $(call try-run,\
107641 - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107642 + $(CC) $(1) -Wl,-r -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107643
107644 # ld-option
107645 # Usage: LDFLAGS += $(call ld-option, -X)
107646 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107647 index 649ce68..f6bc05c 100644
107648 --- a/scripts/Makefile.build
107649 +++ b/scripts/Makefile.build
107650 @@ -60,7 +60,7 @@ endif
107651 endif
107652
107653 # Do not include host rules unless needed
107654 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107655 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107656 include scripts/Makefile.host
107657 endif
107658
107659 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107660 index a609552..fde19cd 100644
107661 --- a/scripts/Makefile.clean
107662 +++ b/scripts/Makefile.clean
107663 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107664 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107665 $(always) $(targets) $(clean-files) \
107666 $(host-progs) \
107667 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107668 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107669 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107670
107671 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107672
107673 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107674 index 133edfa..c9aa07f 100644
107675 --- a/scripts/Makefile.host
107676 +++ b/scripts/Makefile.host
107677 @@ -20,7 +20,19 @@
107678 # Will compile qconf as a C++ program, and menu as a C program.
107679 # They are linked as C++ code to the executable qconf
107680
107681 +# hostprogs-y := conf
107682 +# conf-objs := conf.o libkconfig.so
107683 +# libkconfig-objs := expr.o type.o
107684 +# Will create a shared library named libkconfig.so that consists of
107685 +# expr.o and type.o (they are both compiled as C code and the object files
107686 +# are made as position independent code).
107687 +# conf.c is compiled as a C program, and conf.o is linked together with
107688 +# libkconfig.so as the executable conf.
107689 +# Note: Shared libraries consisting of C++ files are not supported
107690 +
107691 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107692 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107693 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107694
107695 # C code
107696 # Executables compiled from a single .c file
107697 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107698 # C++ Object (.o) files compiled from .cc files
107699 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107700
107701 +# Shared libaries (only .c supported)
107702 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107703 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107704 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107705 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107706 +# Remove .so files from "xxx-objs"
107707 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107708 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107709 +
107710 +# Object (.o) files used by the shared libaries
107711 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107712 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107713 +
107714 # output directory for programs/.o files
107715 # hostprogs-y := tools/build may have been specified.
107716 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107717 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107718 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107719 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107720 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107721 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107722 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107723 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107724 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107725 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107726
107727 obj-dirs += $(host-objdirs)
107728 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107729 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107730 $(call if_changed_dep,host-cxxobjs)
107731
107732 +# Compile .c file, create position independent .o file
107733 +# host-cshobjs -> .o
107734 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107735 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107736 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107737 + $(call if_changed_dep,host-cshobjs)
107738 +
107739 +# Compile .c file, create position independent .o file
107740 +# host-cxxshobjs -> .o
107741 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107742 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107743 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107744 + $(call if_changed_dep,host-cxxshobjs)
107745 +
107746 +# Link a shared library, based on position independent .o files
107747 +# *.o -> .so shared library (host-cshlib)
107748 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107749 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107750 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107751 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107752 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107753 + $(call if_changed,host-cshlib)
107754 +
107755 +# Link a shared library, based on position independent .o files
107756 +# *.o -> .so shared library (host-cxxshlib)
107757 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107758 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107759 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107760 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107761 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107762 + $(call if_changed,host-cxxshlib)
107763 +
107764 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107765 - $(host-cxxmulti) $(host-cxxobjs)
107766 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107767 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107768 index b304068..462d24e 100644
107769 --- a/scripts/basic/fixdep.c
107770 +++ b/scripts/basic/fixdep.c
107771 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107772 /*
107773 * Lookup a value in the configuration string.
107774 */
107775 -static int is_defined_config(const char *name, int len, unsigned int hash)
107776 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107777 {
107778 struct item *aux;
107779
107780 @@ -211,10 +211,10 @@ static void clear_config(void)
107781 /*
107782 * Record the use of a CONFIG_* word.
107783 */
107784 -static void use_config(const char *m, int slen)
107785 +static void use_config(const char *m, unsigned int slen)
107786 {
107787 unsigned int hash = strhash(m, slen);
107788 - int c, i;
107789 + unsigned int c, i;
107790
107791 if (is_defined_config(m, slen, hash))
107792 return;
107793 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107794
107795 static void parse_config_file(const char *map, size_t len)
107796 {
107797 - const int *end = (const int *) (map + len);
107798 + const unsigned int *end = (const unsigned int *) (map + len);
107799 /* start at +1, so that p can never be < map */
107800 - const int *m = (const int *) map + 1;
107801 + const unsigned int *m = (const unsigned int *) map + 1;
107802 const char *p, *q;
107803
107804 for (; m < end; m++) {
107805 @@ -435,7 +435,7 @@ static void print_deps(void)
107806 static void traps(void)
107807 {
107808 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107809 - int *p = (int *)test;
107810 + unsigned int *p = (unsigned int *)test;
107811
107812 if (*p != INT_CONF) {
107813 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107814 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107815 new file mode 100644
107816 index 0000000..822fa9e
107817 --- /dev/null
107818 +++ b/scripts/gcc-plugin.sh
107819 @@ -0,0 +1,51 @@
107820 +#!/bin/sh
107821 +srctree=$(dirname "$0")
107822 +gccplugins_dir=$($3 -print-file-name=plugin)
107823 +plugincc=$($1 -E - -o /dev/null -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
107824 +#include "gcc-common.h"
107825 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107826 +#warning $2 CXX
107827 +#else
107828 +#warning $1 CC
107829 +#endif
107830 +EOF
107831 +)
107832 +
107833 +if [ $? -ne 0 ]
107834 +then
107835 + exit 1
107836 +fi
107837 +
107838 +case "$plugincc" in
107839 + *"$1 CC"*)
107840 + echo "$1"
107841 + exit 0
107842 + ;;
107843 +
107844 + *"$2 CXX"*)
107845 + # the c++ compiler needs another test, see below
107846 + ;;
107847 +
107848 + *)
107849 + exit 1
107850 + ;;
107851 +esac
107852 +
107853 +# we need a c++ compiler that supports the designated initializer GNU extension
107854 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
107855 +#include "gcc-common.h"
107856 +class test {
107857 +public:
107858 + int test;
107859 +} test = {
107860 + .test = 1
107861 +};
107862 +EOF
107863 +)
107864 +
107865 +if [ $? -eq 0 ]
107866 +then
107867 + echo "$2"
107868 + exit 0
107869 +fi
107870 +exit 1
107871 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107872 index fdebd66..a349e33 100755
107873 --- a/scripts/headers_install.sh
107874 +++ b/scripts/headers_install.sh
107875 @@ -32,6 +32,7 @@ do
107876 FILE="$(basename "$i")"
107877 sed -r \
107878 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107879 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107880 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107881 -e 's@^#include <linux/compiler.h>@@' \
107882 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107883 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107884 index 86a4fe7..99e91f9 100755
107885 --- a/scripts/link-vmlinux.sh
107886 +++ b/scripts/link-vmlinux.sh
107887 @@ -166,7 +166,7 @@ else
107888 fi;
107889
107890 # final build of init/
107891 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107892 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107893
107894 kallsymso=""
107895 kallsyms_vmlinux=""
107896 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107897 index e614ef6..d9d2b01 100644
107898 --- a/scripts/mod/file2alias.c
107899 +++ b/scripts/mod/file2alias.c
107900 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107901 unsigned long size, unsigned long id_size,
107902 void *symval)
107903 {
107904 - int i;
107905 + unsigned int i;
107906
107907 if (size % id_size || size < id_size) {
107908 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107909 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107910 /* USB is special because the bcdDevice can be matched against a numeric range */
107911 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107912 static void do_usb_entry(void *symval,
107913 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107914 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107915 unsigned char range_lo, unsigned char range_hi,
107916 unsigned char max, struct module *mod)
107917 {
107918 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107919 {
107920 unsigned int devlo, devhi;
107921 unsigned char chi, clo, max;
107922 - int ndigits;
107923 + unsigned int ndigits;
107924
107925 DEF_FIELD(symval, usb_device_id, match_flags);
107926 DEF_FIELD(symval, usb_device_id, idVendor);
107927 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107928 for (i = 0; i < count; i++) {
107929 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107930 char acpi_id[sizeof(*id)];
107931 - int j;
107932 + unsigned int j;
107933
107934 buf_printf(&mod->dev_table_buf,
107935 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107936 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107937
107938 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107939 const char *id = (char *)(*devs)[j].id;
107940 - int i2, j2;
107941 + unsigned int i2, j2;
107942 int dup = 0;
107943
107944 if (!id[0])
107945 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107946 /* add an individual alias for every device entry */
107947 if (!dup) {
107948 char acpi_id[PNP_ID_LEN];
107949 - int k;
107950 + unsigned int k;
107951
107952 buf_printf(&mod->dev_table_buf,
107953 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107954 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107955 static int do_dmi_entry(const char *filename, void *symval,
107956 char *alias)
107957 {
107958 - int i, j;
107959 + unsigned int i, j;
107960 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107961 sprintf(alias, "dmi*");
107962
107963 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107964 index d439856..10c1eac 100644
107965 --- a/scripts/mod/modpost.c
107966 +++ b/scripts/mod/modpost.c
107967 @@ -921,6 +921,7 @@ enum mismatch {
107968 ANY_INIT_TO_ANY_EXIT,
107969 ANY_EXIT_TO_ANY_INIT,
107970 EXPORT_TO_INIT_EXIT,
107971 + DATA_TO_TEXT
107972 };
107973
107974 struct sectioncheck {
107975 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
107976 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107977 .mismatch = EXPORT_TO_INIT_EXIT,
107978 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107979 +},
107980 +/* Do not reference code from writable data */
107981 +{
107982 + .fromsec = { DATA_SECTIONS, NULL },
107983 + .tosec = { TEXT_SECTIONS, NULL },
107984 + .mismatch = DATA_TO_TEXT
107985 }
107986 };
107987
107988 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107989 continue;
107990 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107991 continue;
107992 - if (sym->st_value == addr)
107993 - return sym;
107994 /* Find a symbol nearby - addr are maybe negative */
107995 d = sym->st_value - addr;
107996 + if (d == 0)
107997 + return sym;
107998 if (d < 0)
107999 d = addr - sym->st_value;
108000 if (d < distance) {
108001 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
108002 tosym, prl_to, prl_to, tosym);
108003 free(prl_to);
108004 break;
108005 + case DATA_TO_TEXT:
108006 +#if 0
108007 + fprintf(stderr,
108008 + "The %s %s:%s references\n"
108009 + "the %s %s:%s%s\n",
108010 + from, fromsec, fromsym, to, tosec, tosym, to_p);
108011 +#endif
108012 + break;
108013 }
108014 fprintf(stderr, "\n");
108015 }
108016 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
108017 static void check_sec_ref(struct module *mod, const char *modname,
108018 struct elf_info *elf)
108019 {
108020 - int i;
108021 + unsigned int i;
108022 Elf_Shdr *sechdrs = elf->sechdrs;
108023
108024 /* Walk through all sections */
108025 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
108026 va_end(ap);
108027 }
108028
108029 -void buf_write(struct buffer *buf, const char *s, int len)
108030 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
108031 {
108032 if (buf->size - buf->pos < len) {
108033 buf->size += len + SZ;
108034 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
108035 if (fstat(fileno(file), &st) < 0)
108036 goto close_write;
108037
108038 - if (st.st_size != b->pos)
108039 + if (st.st_size != (off_t)b->pos)
108040 goto close_write;
108041
108042 tmp = NOFAIL(malloc(b->pos));
108043 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
108044 index 168b43d..77914bf 100644
108045 --- a/scripts/mod/modpost.h
108046 +++ b/scripts/mod/modpost.h
108047 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
108048
108049 struct buffer {
108050 char *p;
108051 - int pos;
108052 - int size;
108053 + unsigned int pos;
108054 + unsigned int size;
108055 };
108056
108057 void __attribute__((format(printf, 2, 3)))
108058 buf_printf(struct buffer *buf, const char *fmt, ...);
108059
108060 void
108061 -buf_write(struct buffer *buf, const char *s, int len);
108062 +buf_write(struct buffer *buf, const char *s, unsigned int len);
108063
108064 struct module {
108065 struct module *next;
108066 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
108067 index 944418d..15291e4 100644
108068 --- a/scripts/mod/sumversion.c
108069 +++ b/scripts/mod/sumversion.c
108070 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
108071 goto out;
108072 }
108073
108074 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
108075 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
108076 warn("writing sum in %s failed: %s\n",
108077 filename, strerror(errno));
108078 goto out;
108079 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
108080 index 0865b3e..7235dd4 100644
108081 --- a/scripts/module-common.lds
108082 +++ b/scripts/module-common.lds
108083 @@ -6,6 +6,10 @@
108084 SECTIONS {
108085 /DISCARD/ : { *(.discard) }
108086
108087 + .rodata : {
108088 + *(.rodata) *(.rodata.*)
108089 + *(.data..read_only)
108090 + }
108091 __ksymtab : { *(SORT(___ksymtab+*)) }
108092 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108093 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108094 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108095 index 99ca6e7..3a1a1a1 100644
108096 --- a/scripts/package/Makefile
108097 +++ b/scripts/package/Makefile
108098 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108099 ln -sf $(srctree) $(KERNELPATH)
108100 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108101 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108102 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108103 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108104 rm $(KERNELPATH)
108105 rm -f $(objtree)/.scmversion
108106 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108107 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108108 index 5972624..4028795 100755
108109 --- a/scripts/package/builddeb
108110 +++ b/scripts/package/builddeb
108111 @@ -293,6 +293,7 @@ fi
108112 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108113 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108114 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108115 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108116 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108117 mkdir -p "$destdir"
108118 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108119 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108120 index 1395760..bca2734 100755
108121 --- a/scripts/package/mkspec
108122 +++ b/scripts/package/mkspec
108123 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108124 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108125 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\""
108126 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108127 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108128 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108129 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108130
108131 echo ""
108132 echo "%clean"
108133 echo 'rm -rf $RPM_BUILD_ROOT'
108134 echo ""
108135 +echo "%pre"
108136 +echo 'chmod -f 0500 /boot'
108137 +echo 'if [ -d /lib/modules ]; then'
108138 +echo 'chmod -f 0500 /lib/modules'
108139 +echo 'fi'
108140 +echo 'if [ -d /lib32/modules ]; then'
108141 +echo 'chmod -f 0500 /lib32/modules'
108142 +echo 'fi'
108143 +echo 'if [ -d /lib64/modules ]; then'
108144 +echo 'chmod -f 0500 /lib64/modules'
108145 +echo 'fi'
108146 +echo ""
108147 +echo "%post devel"
108148 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108149 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108150 +echo ""
108151 echo "%post"
108152 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108153 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108154 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
108155 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
108156 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108157 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108158 +echo "if [ -x /sbin/dracut ]; then"
108159 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108160 +echo "else"
108161 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108162 echo "fi"
108163 echo ""
108164 echo "%files"
108165 -echo '%defattr (-, root, root)'
108166 +echo '%defattr (400, root, root, 500)'
108167 echo "%dir /lib/modules"
108168 -echo "/lib/modules/$KERNELRELEASE"
108169 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108170 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108171 +echo "/lib/modules/$KERNELRELEASE"
108172 echo "/lib/firmware/$KERNELRELEASE"
108173 echo "/boot/*"
108174 echo ""
108175 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
108176 echo "/usr/include"
108177 echo ""
108178 echo "%files devel"
108179 -echo '%defattr (-, root, root)'
108180 +echo '%defattr (400, root, root, 500)'
108181 +echo "%dir /lib/modules/$KERNELRELEASE"
108182 echo "/usr/src/kernels/$KERNELRELEASE"
108183 -echo "/lib/modules/$KERNELRELEASE/build"
108184 -echo "/lib/modules/$KERNELRELEASE/source"
108185 echo ""
108186 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108187 index 4718d78..9220d58 100644
108188 --- a/scripts/pnmtologo.c
108189 +++ b/scripts/pnmtologo.c
108190 @@ -244,14 +244,14 @@ static void write_header(void)
108191 fprintf(out, " * Linux logo %s\n", logoname);
108192 fputs(" */\n\n", out);
108193 fputs("#include <linux/linux_logo.h>\n\n", out);
108194 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108195 + fprintf(out, "static unsigned char %s_data[] = {\n",
108196 logoname);
108197 }
108198
108199 static void write_footer(void)
108200 {
108201 fputs("\n};\n\n", out);
108202 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108203 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108204 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108205 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108206 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108207 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108208 fputs("\n};\n\n", out);
108209
108210 /* write logo clut */
108211 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108212 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108213 logoname);
108214 write_hex_cnt = 0;
108215 for (i = 0; i < logo_clutsize; i++) {
108216 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108217 index ba87004..3f4852c 100644
108218 --- a/scripts/sortextable.h
108219 +++ b/scripts/sortextable.h
108220 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108221 const char *secstrtab;
108222 const char *strtab;
108223 char *extab_image;
108224 - int extab_index = 0;
108225 - int i;
108226 - int idx;
108227 + unsigned int extab_index = 0;
108228 + unsigned int i;
108229 + unsigned int idx;
108230 unsigned int num_sections;
108231 unsigned int secindex_strings;
108232
108233 diff --git a/scripts/tags.sh b/scripts/tags.sh
108234 index cdb491d..8d32bfc 100755
108235 --- a/scripts/tags.sh
108236 +++ b/scripts/tags.sh
108237 @@ -26,7 +26,7 @@ else
108238 fi
108239
108240 # ignore userspace tools
108241 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108242 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108243
108244 # Find all available archs
108245 find_all_archs()
108246 diff --git a/security/Kconfig b/security/Kconfig
108247 index beb86b5..1a953b1 100644
108248 --- a/security/Kconfig
108249 +++ b/security/Kconfig
108250 @@ -4,6 +4,974 @@
108251
108252 menu "Security options"
108253
108254 +menu "Grsecurity"
108255 +
108256 + config ARCH_TRACK_EXEC_LIMIT
108257 + bool
108258 +
108259 + config PAX_KERNEXEC_PLUGIN
108260 + bool
108261 +
108262 + config PAX_PER_CPU_PGD
108263 + bool
108264 +
108265 + config TASK_SIZE_MAX_SHIFT
108266 + int
108267 + depends on X86_64
108268 + default 47 if !PAX_PER_CPU_PGD
108269 + default 42 if PAX_PER_CPU_PGD
108270 +
108271 + config PAX_ENABLE_PAE
108272 + bool
108273 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108274 +
108275 + config PAX_USERCOPY_SLABS
108276 + bool
108277 +
108278 +config GRKERNSEC
108279 + bool "Grsecurity"
108280 + select CRYPTO
108281 + select CRYPTO_SHA256
108282 + select PROC_FS
108283 + select STOP_MACHINE
108284 + select TTY
108285 + select DEBUG_KERNEL
108286 + select DEBUG_LIST
108287 + help
108288 + If you say Y here, you will be able to configure many features
108289 + that will enhance the security of your system. It is highly
108290 + recommended that you say Y here and read through the help
108291 + for each option so that you fully understand the features and
108292 + can evaluate their usefulness for your machine.
108293 +
108294 +choice
108295 + prompt "Configuration Method"
108296 + depends on GRKERNSEC
108297 + default GRKERNSEC_CONFIG_CUSTOM
108298 + help
108299 +
108300 +config GRKERNSEC_CONFIG_AUTO
108301 + bool "Automatic"
108302 + help
108303 + If you choose this configuration method, you'll be able to answer a small
108304 + number of simple questions about how you plan to use this kernel.
108305 + The settings of grsecurity and PaX will be automatically configured for
108306 + the highest commonly-used settings within the provided constraints.
108307 +
108308 + If you require additional configuration, custom changes can still be made
108309 + from the "custom configuration" menu.
108310 +
108311 +config GRKERNSEC_CONFIG_CUSTOM
108312 + bool "Custom"
108313 + help
108314 + If you choose this configuration method, you'll be able to configure all
108315 + grsecurity and PaX settings manually. Via this method, no options are
108316 + automatically enabled.
108317 +
108318 +endchoice
108319 +
108320 +choice
108321 + prompt "Usage Type"
108322 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108323 + default GRKERNSEC_CONFIG_SERVER
108324 + help
108325 +
108326 +config GRKERNSEC_CONFIG_SERVER
108327 + bool "Server"
108328 + help
108329 + Choose this option if you plan to use this kernel on a server.
108330 +
108331 +config GRKERNSEC_CONFIG_DESKTOP
108332 + bool "Desktop"
108333 + help
108334 + Choose this option if you plan to use this kernel on a desktop.
108335 +
108336 +endchoice
108337 +
108338 +choice
108339 + prompt "Virtualization Type"
108340 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108341 + default GRKERNSEC_CONFIG_VIRT_NONE
108342 + help
108343 +
108344 +config GRKERNSEC_CONFIG_VIRT_NONE
108345 + bool "None"
108346 + help
108347 + Choose this option if this kernel will be run on bare metal.
108348 +
108349 +config GRKERNSEC_CONFIG_VIRT_GUEST
108350 + bool "Guest"
108351 + help
108352 + Choose this option if this kernel will be run as a VM guest.
108353 +
108354 +config GRKERNSEC_CONFIG_VIRT_HOST
108355 + bool "Host"
108356 + help
108357 + Choose this option if this kernel will be run as a VM host.
108358 +
108359 +endchoice
108360 +
108361 +choice
108362 + prompt "Virtualization Hardware"
108363 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108364 + help
108365 +
108366 +config GRKERNSEC_CONFIG_VIRT_EPT
108367 + bool "EPT/RVI Processor Support"
108368 + depends on X86
108369 + help
108370 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108371 + hardware virtualization. This allows for additional kernel hardening protections
108372 + to operate without additional performance impact.
108373 +
108374 + To see if your Intel processor supports EPT, see:
108375 + http://ark.intel.com/Products/VirtualizationTechnology
108376 + (Most Core i3/5/7 support EPT)
108377 +
108378 + To see if your AMD processor supports RVI, see:
108379 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108380 +
108381 +config GRKERNSEC_CONFIG_VIRT_SOFT
108382 + bool "First-gen/No Hardware Virtualization"
108383 + help
108384 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108385 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108386 +
108387 +endchoice
108388 +
108389 +choice
108390 + prompt "Virtualization Software"
108391 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108392 + help
108393 +
108394 +config GRKERNSEC_CONFIG_VIRT_XEN
108395 + bool "Xen"
108396 + help
108397 + Choose this option if this kernel is running as a Xen guest or host.
108398 +
108399 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108400 + bool "VMWare"
108401 + help
108402 + Choose this option if this kernel is running as a VMWare guest or host.
108403 +
108404 +config GRKERNSEC_CONFIG_VIRT_KVM
108405 + bool "KVM"
108406 + help
108407 + Choose this option if this kernel is running as a KVM guest or host.
108408 +
108409 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108410 + bool "VirtualBox"
108411 + help
108412 + Choose this option if this kernel is running as a VirtualBox guest or host.
108413 +
108414 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108415 + bool "Hyper-V"
108416 + help
108417 + Choose this option if this kernel is running as a Hyper-V guest.
108418 +
108419 +endchoice
108420 +
108421 +choice
108422 + prompt "Required Priorities"
108423 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108424 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108425 + help
108426 +
108427 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108428 + bool "Performance"
108429 + help
108430 + Choose this option if performance is of highest priority for this deployment
108431 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108432 + clearing of structures intended for userland, and freed memory sanitizing will
108433 + be disabled.
108434 +
108435 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108436 + bool "Security"
108437 + help
108438 + Choose this option if security is of highest priority for this deployment of
108439 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108440 + for userland, and freed memory sanitizing will be enabled for this kernel.
108441 + In a worst-case scenario, these features can introduce a 20% performance hit
108442 + (UDEREF on x64 contributing half of this hit).
108443 +
108444 +endchoice
108445 +
108446 +menu "Default Special Groups"
108447 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108448 +
108449 +config GRKERNSEC_PROC_GID
108450 + int "GID exempted from /proc restrictions"
108451 + default 1001
108452 + help
108453 + Setting this GID determines which group will be exempted from
108454 + grsecurity's /proc restrictions, allowing users of the specified
108455 + group to view network statistics and the existence of other users'
108456 + processes on the system. This GID may also be chosen at boot time
108457 + via "grsec_proc_gid=" on the kernel commandline.
108458 +
108459 +config GRKERNSEC_TPE_UNTRUSTED_GID
108460 + int "GID for TPE-untrusted users"
108461 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108462 + default 1005
108463 + help
108464 + Setting this GID determines which group untrusted users should
108465 + be added to. These users will be placed under grsecurity's Trusted Path
108466 + Execution mechanism, preventing them from executing their own binaries.
108467 + The users will only be able to execute binaries in directories owned and
108468 + writable only by the root user. If the sysctl option is enabled, a sysctl
108469 + option with name "tpe_gid" is created.
108470 +
108471 +config GRKERNSEC_TPE_TRUSTED_GID
108472 + int "GID for TPE-trusted users"
108473 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108474 + default 1005
108475 + help
108476 + Setting this GID determines what group TPE restrictions will be
108477 + *disabled* for. If the sysctl option is enabled, a sysctl option
108478 + with name "tpe_gid" is created.
108479 +
108480 +config GRKERNSEC_SYMLINKOWN_GID
108481 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108482 + depends on GRKERNSEC_CONFIG_SERVER
108483 + default 1006
108484 + help
108485 + Setting this GID determines what group kernel-enforced
108486 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108487 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108488 +
108489 +
108490 +endmenu
108491 +
108492 +menu "Customize Configuration"
108493 +depends on GRKERNSEC
108494 +
108495 +menu "PaX"
108496 +
108497 +config PAX
108498 + bool "Enable various PaX features"
108499 + default y if GRKERNSEC_CONFIG_AUTO
108500 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108501 + help
108502 + This allows you to enable various PaX features. PaX adds
108503 + intrusion prevention mechanisms to the kernel that reduce
108504 + the risks posed by exploitable memory corruption bugs.
108505 +
108506 +menu "PaX Control"
108507 + depends on PAX
108508 +
108509 +config PAX_SOFTMODE
108510 + bool 'Support soft mode'
108511 + help
108512 + Enabling this option will allow you to run PaX in soft mode, that
108513 + is, PaX features will not be enforced by default, only on executables
108514 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108515 + support as they are the only way to mark executables for soft mode use.
108516 +
108517 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108518 + line option on boot. Furthermore you can control various PaX features
108519 + at runtime via the entries in /proc/sys/kernel/pax.
108520 +
108521 +config PAX_EI_PAX
108522 + bool 'Use legacy ELF header marking'
108523 + default y if GRKERNSEC_CONFIG_AUTO
108524 + help
108525 + Enabling this option will allow you to control PaX features on
108526 + a per executable basis via the 'chpax' utility available at
108527 + http://pax.grsecurity.net/. The control flags will be read from
108528 + an otherwise reserved part of the ELF header. This marking has
108529 + numerous drawbacks (no support for soft-mode, toolchain does not
108530 + know about the non-standard use of the ELF header) therefore it
108531 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108532 + support.
108533 +
108534 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108535 + support as well, they will override the legacy EI_PAX marks.
108536 +
108537 + If you enable none of the marking options then all applications
108538 + will run with PaX enabled on them by default.
108539 +
108540 +config PAX_PT_PAX_FLAGS
108541 + bool 'Use ELF program header marking'
108542 + default y if GRKERNSEC_CONFIG_AUTO
108543 + help
108544 + Enabling this option will allow you to control PaX features on
108545 + a per executable basis via the 'paxctl' utility available at
108546 + http://pax.grsecurity.net/. The control flags will be read from
108547 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108548 + has the benefits of supporting both soft mode and being fully
108549 + integrated into the toolchain (the binutils patch is available
108550 + from http://pax.grsecurity.net).
108551 +
108552 + Note that if you enable the legacy EI_PAX marking support as well,
108553 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108554 +
108555 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108556 + must make sure that the marks are the same if a binary has both marks.
108557 +
108558 + If you enable none of the marking options then all applications
108559 + will run with PaX enabled on them by default.
108560 +
108561 +config PAX_XATTR_PAX_FLAGS
108562 + bool 'Use filesystem extended attributes marking'
108563 + default y if GRKERNSEC_CONFIG_AUTO
108564 + select CIFS_XATTR if CIFS
108565 + select F2FS_FS_XATTR if F2FS_FS
108566 + select EXT2_FS_XATTR if EXT2_FS
108567 + select EXT3_FS_XATTR if EXT3_FS
108568 + select JFFS2_FS_XATTR if JFFS2_FS
108569 + select REISERFS_FS_XATTR if REISERFS_FS
108570 + select SQUASHFS_XATTR if SQUASHFS
108571 + select TMPFS_XATTR if TMPFS
108572 + help
108573 + Enabling this option will allow you to control PaX features on
108574 + a per executable basis via the 'setfattr' utility. The control
108575 + flags will be read from the user.pax.flags extended attribute of
108576 + the file. This marking has the benefit of supporting binary-only
108577 + applications that self-check themselves (e.g., skype) and would
108578 + not tolerate chpax/paxctl changes. The main drawback is that
108579 + extended attributes are not supported by some filesystems (e.g.,
108580 + isofs, udf, vfat) so copying files through such filesystems will
108581 + lose the extended attributes and these PaX markings.
108582 +
108583 + Note that if you enable the legacy EI_PAX marking support as well,
108584 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108585 +
108586 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108587 + must make sure that the marks are the same if a binary has both marks.
108588 +
108589 + If you enable none of the marking options then all applications
108590 + will run with PaX enabled on them by default.
108591 +
108592 +choice
108593 + prompt 'MAC system integration'
108594 + default PAX_HAVE_ACL_FLAGS
108595 + help
108596 + Mandatory Access Control systems have the option of controlling
108597 + PaX flags on a per executable basis, choose the method supported
108598 + by your particular system.
108599 +
108600 + - "none": if your MAC system does not interact with PaX,
108601 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108602 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108603 +
108604 + NOTE: this option is for developers/integrators only.
108605 +
108606 + config PAX_NO_ACL_FLAGS
108607 + bool 'none'
108608 +
108609 + config PAX_HAVE_ACL_FLAGS
108610 + bool 'direct'
108611 +
108612 + config PAX_HOOK_ACL_FLAGS
108613 + bool 'hook'
108614 +endchoice
108615 +
108616 +endmenu
108617 +
108618 +menu "Non-executable pages"
108619 + depends on PAX
108620 +
108621 +config PAX_NOEXEC
108622 + bool "Enforce non-executable pages"
108623 + default y if GRKERNSEC_CONFIG_AUTO
108624 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108625 + help
108626 + By design some architectures do not allow for protecting memory
108627 + pages against execution or even if they do, Linux does not make
108628 + use of this feature. In practice this means that if a page is
108629 + readable (such as the stack or heap) it is also executable.
108630 +
108631 + There is a well known exploit technique that makes use of this
108632 + fact and a common programming mistake where an attacker can
108633 + introduce code of his choice somewhere in the attacked program's
108634 + memory (typically the stack or the heap) and then execute it.
108635 +
108636 + If the attacked program was running with different (typically
108637 + higher) privileges than that of the attacker, then he can elevate
108638 + his own privilege level (e.g. get a root shell, write to files for
108639 + which he does not have write access to, etc).
108640 +
108641 + Enabling this option will let you choose from various features
108642 + that prevent the injection and execution of 'foreign' code in
108643 + a program.
108644 +
108645 + This will also break programs that rely on the old behaviour and
108646 + expect that dynamically allocated memory via the malloc() family
108647 + of functions is executable (which it is not). Notable examples
108648 + are the XFree86 4.x server, the java runtime and wine.
108649 +
108650 +config PAX_PAGEEXEC
108651 + bool "Paging based non-executable pages"
108652 + default y if GRKERNSEC_CONFIG_AUTO
108653 + 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)
108654 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108655 + help
108656 + This implementation is based on the paging feature of the CPU.
108657 + On i386 without hardware non-executable bit support there is a
108658 + variable but usually low performance impact, however on Intel's
108659 + P4 core based CPUs it is very high so you should not enable this
108660 + for kernels meant to be used on such CPUs.
108661 +
108662 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108663 + with hardware non-executable bit support there is no performance
108664 + impact, on ppc the impact is negligible.
108665 +
108666 + Note that several architectures require various emulations due to
108667 + badly designed userland ABIs, this will cause a performance impact
108668 + but will disappear as soon as userland is fixed. For example, ppc
108669 + userland MUST have been built with secure-plt by a recent toolchain.
108670 +
108671 +config PAX_SEGMEXEC
108672 + bool "Segmentation based non-executable pages"
108673 + default y if GRKERNSEC_CONFIG_AUTO
108674 + depends on PAX_NOEXEC && X86_32
108675 + help
108676 + This implementation is based on the segmentation feature of the
108677 + CPU and has a very small performance impact, however applications
108678 + will be limited to a 1.5 GB address space instead of the normal
108679 + 3 GB.
108680 +
108681 +config PAX_EMUTRAMP
108682 + bool "Emulate trampolines"
108683 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108684 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108685 + help
108686 + There are some programs and libraries that for one reason or
108687 + another attempt to execute special small code snippets from
108688 + non-executable memory pages. Most notable examples are the
108689 + signal handler return code generated by the kernel itself and
108690 + the GCC trampolines.
108691 +
108692 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108693 + such programs will no longer work under your kernel.
108694 +
108695 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108696 + utilities to enable trampoline emulation for the affected programs
108697 + yet still have the protection provided by the non-executable pages.
108698 +
108699 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108700 + your system will not even boot.
108701 +
108702 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108703 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108704 + for the affected files.
108705 +
108706 + NOTE: enabling this feature *may* open up a loophole in the
108707 + protection provided by non-executable pages that an attacker
108708 + could abuse. Therefore the best solution is to not have any
108709 + files on your system that would require this option. This can
108710 + be achieved by not using libc5 (which relies on the kernel
108711 + signal handler return code) and not using or rewriting programs
108712 + that make use of the nested function implementation of GCC.
108713 + Skilled users can just fix GCC itself so that it implements
108714 + nested function calls in a way that does not interfere with PaX.
108715 +
108716 +config PAX_EMUSIGRT
108717 + bool "Automatically emulate sigreturn trampolines"
108718 + depends on PAX_EMUTRAMP && PARISC
108719 + default y
108720 + help
108721 + Enabling this option will have the kernel automatically detect
108722 + and emulate signal return trampolines executing on the stack
108723 + that would otherwise lead to task termination.
108724 +
108725 + This solution is intended as a temporary one for users with
108726 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108727 + Modula-3 runtime, etc) or executables linked to such, basically
108728 + everything that does not specify its own SA_RESTORER function in
108729 + normal executable memory like glibc 2.1+ does.
108730 +
108731 + On parisc you MUST enable this option, otherwise your system will
108732 + not even boot.
108733 +
108734 + NOTE: this feature cannot be disabled on a per executable basis
108735 + and since it *does* open up a loophole in the protection provided
108736 + by non-executable pages, the best solution is to not have any
108737 + files on your system that would require this option.
108738 +
108739 +config PAX_MPROTECT
108740 + bool "Restrict mprotect()"
108741 + default y if GRKERNSEC_CONFIG_AUTO
108742 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108743 + help
108744 + Enabling this option will prevent programs from
108745 + - changing the executable status of memory pages that were
108746 + not originally created as executable,
108747 + - making read-only executable pages writable again,
108748 + - creating executable pages from anonymous memory,
108749 + - making read-only-after-relocations (RELRO) data pages writable again.
108750 +
108751 + You should say Y here to complete the protection provided by
108752 + the enforcement of non-executable pages.
108753 +
108754 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108755 + this feature on a per file basis.
108756 +
108757 +config PAX_MPROTECT_COMPAT
108758 + bool "Use legacy/compat protection demoting (read help)"
108759 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108760 + depends on PAX_MPROTECT
108761 + help
108762 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108763 + by sending the proper error code to the application. For some broken
108764 + userland, this can cause problems with Python or other applications. The
108765 + current implementation however allows for applications like clamav to
108766 + detect if JIT compilation/execution is allowed and to fall back gracefully
108767 + to an interpreter-based mode if it does not. While we encourage everyone
108768 + to use the current implementation as-is and push upstream to fix broken
108769 + userland (note that the RWX logging option can assist with this), in some
108770 + environments this may not be possible. Having to disable MPROTECT
108771 + completely on certain binaries reduces the security benefit of PaX,
108772 + so this option is provided for those environments to revert to the old
108773 + behavior.
108774 +
108775 +config PAX_ELFRELOCS
108776 + bool "Allow ELF text relocations (read help)"
108777 + depends on PAX_MPROTECT
108778 + default n
108779 + help
108780 + Non-executable pages and mprotect() restrictions are effective
108781 + in preventing the introduction of new executable code into an
108782 + attacked task's address space. There remain only two venues
108783 + for this kind of attack: if the attacker can execute already
108784 + existing code in the attacked task then he can either have it
108785 + create and mmap() a file containing his code or have it mmap()
108786 + an already existing ELF library that does not have position
108787 + independent code in it and use mprotect() on it to make it
108788 + writable and copy his code there. While protecting against
108789 + the former approach is beyond PaX, the latter can be prevented
108790 + by having only PIC ELF libraries on one's system (which do not
108791 + need to relocate their code). If you are sure this is your case,
108792 + as is the case with all modern Linux distributions, then leave
108793 + this option disabled. You should say 'n' here.
108794 +
108795 +config PAX_ETEXECRELOCS
108796 + bool "Allow ELF ET_EXEC text relocations"
108797 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108798 + select PAX_ELFRELOCS
108799 + default y
108800 + help
108801 + On some architectures there are incorrectly created applications
108802 + that require text relocations and would not work without enabling
108803 + this option. If you are an alpha, ia64 or parisc user, you should
108804 + enable this option and disable it once you have made sure that
108805 + none of your applications need it.
108806 +
108807 +config PAX_EMUPLT
108808 + bool "Automatically emulate ELF PLT"
108809 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108810 + default y
108811 + help
108812 + Enabling this option will have the kernel automatically detect
108813 + and emulate the Procedure Linkage Table entries in ELF files.
108814 + On some architectures such entries are in writable memory, and
108815 + become non-executable leading to task termination. Therefore
108816 + it is mandatory that you enable this option on alpha, parisc,
108817 + sparc and sparc64, otherwise your system would not even boot.
108818 +
108819 + NOTE: this feature *does* open up a loophole in the protection
108820 + provided by the non-executable pages, therefore the proper
108821 + solution is to modify the toolchain to produce a PLT that does
108822 + not need to be writable.
108823 +
108824 +config PAX_DLRESOLVE
108825 + bool 'Emulate old glibc resolver stub'
108826 + depends on PAX_EMUPLT && SPARC
108827 + default n
108828 + help
108829 + This option is needed if userland has an old glibc (before 2.4)
108830 + that puts a 'save' instruction into the runtime generated resolver
108831 + stub that needs special emulation.
108832 +
108833 +config PAX_KERNEXEC
108834 + bool "Enforce non-executable kernel pages"
108835 + 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))
108836 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108837 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108838 + select PAX_KERNEXEC_PLUGIN if X86_64
108839 + help
108840 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108841 + that is, enabling this option will make it harder to inject
108842 + and execute 'foreign' code in kernel memory itself.
108843 +
108844 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108845 + the kernel command-line will result in an RWX physical map.
108846 +
108847 + Likewise, the EFI runtime services are necessarily mapped as
108848 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108849 + is recommended that you boot with "noefi" on the kernel
108850 + command-line if possible to eliminate the mapping.
108851 +
108852 +choice
108853 + prompt "Return Address Instrumentation Method"
108854 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108855 + depends on PAX_KERNEXEC_PLUGIN
108856 + help
108857 + Select the method used to instrument function pointer dereferences.
108858 + Note that binary modules cannot be instrumented by this approach.
108859 +
108860 + Note that the implementation requires a gcc with plugin support,
108861 + i.e., gcc 4.5 or newer. You may need to install the supporting
108862 + headers explicitly in addition to the normal gcc package.
108863 +
108864 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108865 + bool "bts"
108866 + help
108867 + This method is compatible with binary only modules but has
108868 + a higher runtime overhead.
108869 +
108870 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108871 + bool "or"
108872 + depends on !PARAVIRT
108873 + help
108874 + This method is incompatible with binary only modules but has
108875 + a lower runtime overhead.
108876 +endchoice
108877 +
108878 +config PAX_KERNEXEC_PLUGIN_METHOD
108879 + string
108880 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108881 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108882 + default ""
108883 +
108884 +config PAX_KERNEXEC_MODULE_TEXT
108885 + int "Minimum amount of memory reserved for module code"
108886 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108887 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108888 + depends on PAX_KERNEXEC && X86_32
108889 + help
108890 + Due to implementation details the kernel must reserve a fixed
108891 + amount of memory for runtime allocated code (such as modules)
108892 + at compile time that cannot be changed at runtime. Here you
108893 + can specify the minimum amount in MB that will be reserved.
108894 + Due to the same implementation details this size will always
108895 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108896 + the actually available memory for runtime allocated code will
108897 + usually be more than this minimum.
108898 +
108899 + The default 4 MB should be enough for most users but if you have
108900 + an excessive number of modules (e.g., most distribution configs
108901 + compile many drivers as modules) or use huge modules such as
108902 + nvidia's kernel driver, you will need to adjust this amount.
108903 + A good rule of thumb is to look at your currently loaded kernel
108904 + modules and add up their sizes.
108905 +
108906 +endmenu
108907 +
108908 +menu "Address Space Layout Randomization"
108909 + depends on PAX
108910 +
108911 +config PAX_ASLR
108912 + bool "Address Space Layout Randomization"
108913 + default y if GRKERNSEC_CONFIG_AUTO
108914 + help
108915 + Many if not most exploit techniques rely on the knowledge of
108916 + certain addresses in the attacked program. The following options
108917 + will allow the kernel to apply a certain amount of randomization
108918 + to specific parts of the program thereby forcing an attacker to
108919 + guess them in most cases. Any failed guess will most likely crash
108920 + the attacked program which allows the kernel to detect such attempts
108921 + and react on them. PaX itself provides no reaction mechanisms,
108922 + instead it is strongly encouraged that you make use of grsecurity's
108923 + (http://www.grsecurity.net/) built-in crash detection features or
108924 + develop one yourself.
108925 +
108926 + By saying Y here you can choose to randomize the following areas:
108927 + - top of the task's kernel stack
108928 + - top of the task's userland stack
108929 + - base address for mmap() requests that do not specify one
108930 + (this includes all libraries)
108931 + - base address of the main executable
108932 +
108933 + It is strongly recommended to say Y here as address space layout
108934 + randomization has negligible impact on performance yet it provides
108935 + a very effective protection.
108936 +
108937 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108938 + this feature on a per file basis.
108939 +
108940 +config PAX_RANDKSTACK
108941 + bool "Randomize kernel stack base"
108942 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108943 + depends on X86_TSC && X86
108944 + help
108945 + By saying Y here the kernel will randomize every task's kernel
108946 + stack on every system call. This will not only force an attacker
108947 + to guess it but also prevent him from making use of possible
108948 + leaked information about it.
108949 +
108950 + Since the kernel stack is a rather scarce resource, randomization
108951 + may cause unexpected stack overflows, therefore you should very
108952 + carefully test your system. Note that once enabled in the kernel
108953 + configuration, this feature cannot be disabled on a per file basis.
108954 +
108955 +config PAX_RANDUSTACK
108956 + bool
108957 +
108958 +config PAX_RANDMMAP
108959 + bool "Randomize user stack and mmap() bases"
108960 + default y if GRKERNSEC_CONFIG_AUTO
108961 + depends on PAX_ASLR
108962 + select PAX_RANDUSTACK
108963 + help
108964 + By saying Y here the kernel will randomize every task's userland
108965 + stack and use a randomized base address for mmap() requests that
108966 + do not specify one themselves.
108967 +
108968 + The stack randomization is done in two steps where the second
108969 + one may apply a big amount of shift to the top of the stack and
108970 + cause problems for programs that want to use lots of memory (more
108971 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108972 +
108973 + As a result of mmap randomization all dynamically loaded libraries
108974 + will appear at random addresses and therefore be harder to exploit
108975 + by a technique where an attacker attempts to execute library code
108976 + for his purposes (e.g. spawn a shell from an exploited program that
108977 + is running at an elevated privilege level).
108978 +
108979 + Furthermore, if a program is relinked as a dynamic ELF file, its
108980 + base address will be randomized as well, completing the full
108981 + randomization of the address space layout. Attacking such programs
108982 + becomes a guess game. You can find an example of doing this at
108983 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108984 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108985 +
108986 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108987 + feature on a per file basis.
108988 +
108989 +endmenu
108990 +
108991 +menu "Miscellaneous hardening features"
108992 +
108993 +config PAX_MEMORY_SANITIZE
108994 + bool "Sanitize all freed memory"
108995 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108996 + help
108997 + By saying Y here the kernel will erase memory pages and slab objects
108998 + as soon as they are freed. This in turn reduces the lifetime of data
108999 + stored in them, making it less likely that sensitive information such
109000 + as passwords, cryptographic secrets, etc stay in memory for too long.
109001 +
109002 + This is especially useful for programs whose runtime is short, long
109003 + lived processes and the kernel itself benefit from this as long as
109004 + they ensure timely freeing of memory that may hold sensitive
109005 + information.
109006 +
109007 + A nice side effect of the sanitization of slab objects is the
109008 + reduction of possible info leaks caused by padding bytes within the
109009 + leaky structures. Use-after-free bugs for structures containing
109010 + pointers can also be detected as dereferencing the sanitized pointer
109011 + will generate an access violation.
109012 +
109013 + The tradeoff is performance impact, on a single CPU system kernel
109014 + compilation sees a 3% slowdown, other systems and workloads may vary
109015 + and you are advised to test this feature on your expected workload
109016 + before deploying it.
109017 +
109018 + The slab sanitization feature excludes a few slab caches per default
109019 + for performance reasons. To extend the feature to cover those as
109020 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
109021 +
109022 + To reduce the performance penalty by sanitizing pages only, albeit
109023 + limiting the effectiveness of this feature at the same time, slab
109024 + sanitization can be disabled with the kernel command line parameter
109025 + "pax_sanitize_slab=off".
109026 +
109027 + Note that this feature does not protect data stored in live pages,
109028 + e.g., process memory swapped to disk may stay there for a long time.
109029 +
109030 +config PAX_MEMORY_STACKLEAK
109031 + bool "Sanitize kernel stack"
109032 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109033 + depends on X86
109034 + help
109035 + By saying Y here the kernel will erase the kernel stack before it
109036 + returns from a system call. This in turn reduces the information
109037 + that a kernel stack leak bug can reveal.
109038 +
109039 + Note that such a bug can still leak information that was put on
109040 + the stack by the current system call (the one eventually triggering
109041 + the bug) but traces of earlier system calls on the kernel stack
109042 + cannot leak anymore.
109043 +
109044 + The tradeoff is performance impact: on a single CPU system kernel
109045 + compilation sees a 1% slowdown, other systems and workloads may vary
109046 + and you are advised to test this feature on your expected workload
109047 + before deploying it.
109048 +
109049 + Note that the full feature requires a gcc with plugin support,
109050 + i.e., gcc 4.5 or newer. You may need to install the supporting
109051 + headers explicitly in addition to the normal gcc package. Using
109052 + older gcc versions means that functions with large enough stack
109053 + frames may leave uninitialized memory behind that may be exposed
109054 + to a later syscall leaking the stack.
109055 +
109056 +config PAX_MEMORY_STRUCTLEAK
109057 + bool "Forcibly initialize local variables copied to userland"
109058 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109059 + help
109060 + By saying Y here the kernel will zero initialize some local
109061 + variables that are going to be copied to userland. This in
109062 + turn prevents unintended information leakage from the kernel
109063 + stack should later code forget to explicitly set all parts of
109064 + the copied variable.
109065 +
109066 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
109067 + at a much smaller coverage.
109068 +
109069 + Note that the implementation requires a gcc with plugin support,
109070 + i.e., gcc 4.5 or newer. You may need to install the supporting
109071 + headers explicitly in addition to the normal gcc package.
109072 +
109073 +config PAX_MEMORY_UDEREF
109074 + bool "Prevent invalid userland pointer dereference"
109075 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
109076 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
109077 + select PAX_PER_CPU_PGD if X86_64
109078 + help
109079 + By saying Y here the kernel will be prevented from dereferencing
109080 + userland pointers in contexts where the kernel expects only kernel
109081 + pointers. This is both a useful runtime debugging feature and a
109082 + security measure that prevents exploiting a class of kernel bugs.
109083 +
109084 + The tradeoff is that some virtualization solutions may experience
109085 + a huge slowdown and therefore you should not enable this feature
109086 + for kernels meant to run in such environments. Whether a given VM
109087 + solution is affected or not is best determined by simply trying it
109088 + out, the performance impact will be obvious right on boot as this
109089 + mechanism engages from very early on. A good rule of thumb is that
109090 + VMs running on CPUs without hardware virtualization support (i.e.,
109091 + the majority of IA-32 CPUs) will likely experience the slowdown.
109092 +
109093 + On X86_64 the kernel will make use of PCID support when available
109094 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109095 + or performance impact. Pass pax_weakuderef on the kernel command
109096 + line to choose the latter.
109097 +
109098 +config PAX_REFCOUNT
109099 + bool "Prevent various kernel object reference counter overflows"
109100 + default y if GRKERNSEC_CONFIG_AUTO
109101 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109102 + help
109103 + By saying Y here the kernel will detect and prevent overflowing
109104 + various (but not all) kinds of object reference counters. Such
109105 + overflows can normally occur due to bugs only and are often, if
109106 + not always, exploitable.
109107 +
109108 + The tradeoff is that data structures protected by an overflowed
109109 + refcount will never be freed and therefore will leak memory. Note
109110 + that this leak also happens even without this protection but in
109111 + that case the overflow can eventually trigger the freeing of the
109112 + data structure while it is still being used elsewhere, resulting
109113 + in the exploitable situation that this feature prevents.
109114 +
109115 + Since this has a negligible performance impact, you should enable
109116 + this feature.
109117 +
109118 +config PAX_CONSTIFY_PLUGIN
109119 + bool "Automatically constify eligible structures"
109120 + default y
109121 + depends on !UML && PAX_KERNEXEC
109122 + help
109123 + By saying Y here the compiler will automatically constify a class
109124 + of types that contain only function pointers. This reduces the
109125 + kernel's attack surface and also produces a better memory layout.
109126 +
109127 + Note that the implementation requires a gcc with plugin support,
109128 + i.e., gcc 4.5 or newer. You may need to install the supporting
109129 + headers explicitly in addition to the normal gcc package.
109130 +
109131 + Note that if some code really has to modify constified variables
109132 + then the source code will have to be patched to allow it. Examples
109133 + can be found in PaX itself (the no_const attribute) and for some
109134 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109135 +
109136 +config PAX_USERCOPY
109137 + bool "Harden heap object copies between kernel and userland"
109138 + default y if GRKERNSEC_CONFIG_AUTO
109139 + depends on ARM || IA64 || PPC || SPARC || X86
109140 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109141 + select PAX_USERCOPY_SLABS
109142 + help
109143 + By saying Y here the kernel will enforce the size of heap objects
109144 + when they are copied in either direction between the kernel and
109145 + userland, even if only a part of the heap object is copied.
109146 +
109147 + Specifically, this checking prevents information leaking from the
109148 + kernel heap during kernel to userland copies (if the kernel heap
109149 + object is otherwise fully initialized) and prevents kernel heap
109150 + overflows during userland to kernel copies.
109151 +
109152 + Note that the current implementation provides the strictest bounds
109153 + checks for the SLUB allocator.
109154 +
109155 + Enabling this option also enables per-slab cache protection against
109156 + data in a given cache being copied into/out of via userland
109157 + accessors. Though the whitelist of regions will be reduced over
109158 + time, it notably protects important data structures like task structs.
109159 +
109160 + If frame pointers are enabled on x86, this option will also restrict
109161 + copies into and out of the kernel stack to local variables within a
109162 + single frame.
109163 +
109164 + Since this has a negligible performance impact, you should enable
109165 + this feature.
109166 +
109167 +config PAX_USERCOPY_DEBUG
109168 + bool
109169 + depends on X86 && PAX_USERCOPY
109170 + default n
109171 +
109172 +config PAX_SIZE_OVERFLOW
109173 + bool "Prevent various integer overflows in function size parameters"
109174 + default y if GRKERNSEC_CONFIG_AUTO
109175 + depends on X86
109176 + help
109177 + By saying Y here the kernel recomputes expressions of function
109178 + arguments marked by a size_overflow attribute with double integer
109179 + precision (DImode/TImode for 32/64 bit integer types).
109180 +
109181 + The recomputed argument is checked against TYPE_MAX and an event
109182 + is logged on overflow and the triggering process is killed.
109183 +
109184 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109185 +
109186 + Note that the implementation requires a gcc with plugin support,
109187 + i.e., gcc 4.5 or newer. You may need to install the supporting
109188 + headers explicitly in addition to the normal gcc package.
109189 +
109190 +config PAX_LATENT_ENTROPY
109191 + bool "Generate some entropy during boot and runtime"
109192 + default y if GRKERNSEC_CONFIG_AUTO
109193 + help
109194 + By saying Y here the kernel will instrument some kernel code to
109195 + extract some entropy from both original and artificially created
109196 + program state. This will help especially embedded systems where
109197 + there is little 'natural' source of entropy normally. The cost
109198 + is some slowdown of the boot process and fork and irq processing.
109199 +
109200 + When pax_extra_latent_entropy is passed on the kernel command line,
109201 + entropy will be extracted from up to the first 4GB of RAM while the
109202 + runtime memory allocator is being initialized. This costs even more
109203 + slowdown of the boot process.
109204 +
109205 + Note that the implementation requires a gcc with plugin support,
109206 + i.e., gcc 4.5 or newer. You may need to install the supporting
109207 + headers explicitly in addition to the normal gcc package.
109208 +
109209 + Note that entropy extracted this way is not cryptographically
109210 + secure!
109211 +
109212 +endmenu
109213 +
109214 +endmenu
109215 +
109216 +source grsecurity/Kconfig
109217 +
109218 +endmenu
109219 +
109220 +endmenu
109221 +
109222 source security/keys/Kconfig
109223
109224 config SECURITY_DMESG_RESTRICT
109225 @@ -103,7 +1071,7 @@ config INTEL_TXT
109226 config LSM_MMAP_MIN_ADDR
109227 int "Low address space for LSM to protect from user allocation"
109228 depends on SECURITY && SECURITY_SELINUX
109229 - default 32768 if ARM || (ARM64 && COMPAT)
109230 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109231 default 65536
109232 help
109233 This is the portion of low virtual memory which should be protected
109234 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109235 index fdaa50c..2761dcb 100644
109236 --- a/security/apparmor/file.c
109237 +++ b/security/apparmor/file.c
109238 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109239 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109240 struct path *new_dir, struct dentry *new_dentry)
109241 {
109242 - struct path link = { new_dir->mnt, new_dentry };
109243 - struct path target = { new_dir->mnt, old_dentry };
109244 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109245 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109246 struct path_cond cond = {
109247 old_dentry->d_inode->i_uid,
109248 old_dentry->d_inode->i_mode
109249 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109250 index 65ca451..ad6f22d 100644
109251 --- a/security/apparmor/lsm.c
109252 +++ b/security/apparmor/lsm.c
109253 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109254 struct dentry *dentry, u32 mask,
109255 struct path_cond *cond)
109256 {
109257 - struct path path = { dir->mnt, dentry };
109258 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109259
109260 return common_perm(op, &path, mask, cond);
109261 }
109262 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109263 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109264 struct dentry *dentry, u32 mask)
109265 {
109266 - struct path path = { mnt, dentry };
109267 + struct path path = { .mnt = mnt, .dentry = dentry };
109268 struct path_cond cond = { dentry->d_inode->i_uid,
109269 dentry->d_inode->i_mode
109270 };
109271 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109272
109273 profile = aa_current_profile();
109274 if (!unconfined(profile)) {
109275 - struct path old_path = { old_dir->mnt, old_dentry };
109276 - struct path new_path = { new_dir->mnt, new_dentry };
109277 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109278 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109279 struct path_cond cond = { old_dentry->d_inode->i_uid,
109280 old_dentry->d_inode->i_mode
109281 };
109282 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109283 return error;
109284 }
109285
109286 -static struct security_operations apparmor_ops = {
109287 +static struct security_operations apparmor_ops __read_only = {
109288 .name = "apparmor",
109289
109290 .ptrace_access_check = apparmor_ptrace_access_check,
109291 diff --git a/security/commoncap.c b/security/commoncap.c
109292 index bab0611..f9a0ff5 100644
109293 --- a/security/commoncap.c
109294 +++ b/security/commoncap.c
109295 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109296 return 0;
109297 }
109298
109299 +/* returns:
109300 + 1 for suid privilege
109301 + 2 for sgid privilege
109302 + 3 for fscap privilege
109303 +*/
109304 +int is_privileged_binary(const struct dentry *dentry)
109305 +{
109306 + struct cpu_vfs_cap_data capdata;
109307 + struct inode *inode = dentry->d_inode;
109308 +
109309 + if (!inode || S_ISDIR(inode->i_mode))
109310 + return 0;
109311 +
109312 + if (inode->i_mode & S_ISUID)
109313 + return 1;
109314 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109315 + return 2;
109316 +
109317 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109318 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109319 + return 3;
109320 + }
109321 +
109322 + return 0;
109323 +}
109324 +
109325 /*
109326 * Attempt to get the on-exec apply capability sets for an executable file from
109327 * its xattrs and, if present, apply them to the proposed credentials being
109328 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109329 const struct cred *cred = current_cred();
109330 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109331
109332 + if (gr_acl_enable_at_secure())
109333 + return 1;
109334 +
109335 if (!uid_eq(cred->uid, root_uid)) {
109336 if (bprm->cap_effective)
109337 return 1;
109338 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109339 index 8ee997d..24c174b 100644
109340 --- a/security/integrity/ima/ima.h
109341 +++ b/security/integrity/ima/ima.h
109342 @@ -116,8 +116,8 @@ int ima_init_template(void);
109343 extern spinlock_t ima_queue_lock;
109344
109345 struct ima_h_table {
109346 - atomic_long_t len; /* number of stored measurements in the list */
109347 - atomic_long_t violations;
109348 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109349 + atomic_long_unchecked_t violations;
109350 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109351 };
109352 extern struct ima_h_table ima_htable;
109353 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109354 index 8688597..9fa80d2 100644
109355 --- a/security/integrity/ima/ima_api.c
109356 +++ b/security/integrity/ima/ima_api.c
109357 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109358 int result;
109359
109360 /* can overflow, only indicator */
109361 - atomic_long_inc(&ima_htable.violations);
109362 + atomic_long_inc_unchecked(&ima_htable.violations);
109363
109364 result = ima_alloc_init_template(NULL, file, filename,
109365 NULL, 0, &entry);
109366 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109367 index da92fcc..8a5d390 100644
109368 --- a/security/integrity/ima/ima_fs.c
109369 +++ b/security/integrity/ima/ima_fs.c
109370 @@ -28,12 +28,12 @@
109371 static int valid_policy = 1;
109372 #define TMPBUFLEN 12
109373 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109374 - loff_t *ppos, atomic_long_t *val)
109375 + loff_t *ppos, atomic_long_unchecked_t *val)
109376 {
109377 char tmpbuf[TMPBUFLEN];
109378 ssize_t len;
109379
109380 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109381 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109382 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109383 }
109384
109385 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109386 index 552705d..9920f4fb 100644
109387 --- a/security/integrity/ima/ima_queue.c
109388 +++ b/security/integrity/ima/ima_queue.c
109389 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109390 INIT_LIST_HEAD(&qe->later);
109391 list_add_tail_rcu(&qe->later, &ima_measurements);
109392
109393 - atomic_long_inc(&ima_htable.len);
109394 + atomic_long_inc_unchecked(&ima_htable.len);
109395 key = ima_hash_key(entry->digest);
109396 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109397 return 0;
109398 diff --git a/security/keys/compat.c b/security/keys/compat.c
109399 index 3478965..ec7bb9e 100644
109400 --- a/security/keys/compat.c
109401 +++ b/security/keys/compat.c
109402 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109403 if (ret == 0)
109404 goto no_payload_free;
109405
109406 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109407 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109408 err:
109409 if (iov != iovstack)
109410 kfree(iov);
109411 diff --git a/security/keys/internal.h b/security/keys/internal.h
109412 index 200e378..cdc74b5 100644
109413 --- a/security/keys/internal.h
109414 +++ b/security/keys/internal.h
109415 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109416 extern long keyctl_invalidate_key(key_serial_t);
109417
109418 extern long keyctl_instantiate_key_common(key_serial_t,
109419 - const struct iovec *,
109420 + const struct iovec __user *,
109421 unsigned, size_t, key_serial_t);
109422 #ifdef CONFIG_PERSISTENT_KEYRINGS
109423 extern long keyctl_get_persistent(uid_t, key_serial_t);
109424 diff --git a/security/keys/key.c b/security/keys/key.c
109425 index e17ba6a..2cc04a6 100644
109426 --- a/security/keys/key.c
109427 +++ b/security/keys/key.c
109428 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109429
109430 atomic_set(&key->usage, 1);
109431 init_rwsem(&key->sem);
109432 - lockdep_set_class(&key->sem, &type->lock_class);
109433 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109434 key->index_key.type = type;
109435 key->user = user;
109436 key->quotalen = quotalen;
109437 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109438 struct key_type *p;
109439 int ret;
109440
109441 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109442 + pax_open_kernel();
109443 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109444 + pax_close_kernel();
109445
109446 ret = -EEXIST;
109447 down_write(&key_types_sem);
109448 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109449 }
109450
109451 /* store the type */
109452 - list_add(&ktype->link, &key_types_list);
109453 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109454
109455 pr_notice("Key type %s registered\n", ktype->name);
109456 ret = 0;
109457 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109458 void unregister_key_type(struct key_type *ktype)
109459 {
109460 down_write(&key_types_sem);
109461 - list_del_init(&ktype->link);
109462 + pax_list_del_init((struct list_head *)&ktype->link);
109463 downgrade_write(&key_types_sem);
109464 key_gc_keytype(ktype);
109465 pr_notice("Key type %s unregistered\n", ktype->name);
109466 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109467 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109468
109469 /* add the special key types */
109470 - list_add_tail(&key_type_keyring.link, &key_types_list);
109471 - list_add_tail(&key_type_dead.link, &key_types_list);
109472 - list_add_tail(&key_type_user.link, &key_types_list);
109473 - list_add_tail(&key_type_logon.link, &key_types_list);
109474 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109475 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109476 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109477 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109478
109479 /* record the root user tracking */
109480 rb_link_node(&root_key_user.node,
109481 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109482 index 4743d71..170a185 100644
109483 --- a/security/keys/keyctl.c
109484 +++ b/security/keys/keyctl.c
109485 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109486 /*
109487 * Copy the iovec data from userspace
109488 */
109489 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109490 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109491 unsigned ioc)
109492 {
109493 for (; ioc > 0; ioc--) {
109494 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109495 * If successful, 0 will be returned.
109496 */
109497 long keyctl_instantiate_key_common(key_serial_t id,
109498 - const struct iovec *payload_iov,
109499 + const struct iovec __user *payload_iov,
109500 unsigned ioc,
109501 size_t plen,
109502 key_serial_t ringid)
109503 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
109504 [0].iov_len = plen
109505 };
109506
109507 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109508 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109509 }
109510
109511 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109512 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109513 if (ret == 0)
109514 goto no_payload_free;
109515
109516 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109517 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109518 err:
109519 if (iov != iovstack)
109520 kfree(iov);
109521 diff --git a/security/keys/request_key.c b/security/keys/request_key.c
109522 index 0c7aea4..486ef6f 100644
109523 --- a/security/keys/request_key.c
109524 +++ b/security/keys/request_key.c
109525 @@ -414,6 +414,7 @@ link_check_failed:
109526
109527 link_prealloc_failed:
109528 mutex_unlock(&user->cons_lock);
109529 + key_put(key);
109530 kleave(" = %d [prelink]", ret);
109531 return ret;
109532
109533 diff --git a/security/min_addr.c b/security/min_addr.c
109534 index f728728..6457a0c 100644
109535 --- a/security/min_addr.c
109536 +++ b/security/min_addr.c
109537 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109538 */
109539 static void update_mmap_min_addr(void)
109540 {
109541 +#ifndef SPARC
109542 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109543 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109544 mmap_min_addr = dac_mmap_min_addr;
109545 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109546 #else
109547 mmap_min_addr = dac_mmap_min_addr;
109548 #endif
109549 +#endif
109550 }
109551
109552 /*
109553 diff --git a/security/security.c b/security/security.c
109554 index 18b35c6..c9fbc92 100644
109555 --- a/security/security.c
109556 +++ b/security/security.c
109557 @@ -33,8 +33,8 @@
109558 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109559 CONFIG_DEFAULT_SECURITY;
109560
109561 -static struct security_operations *security_ops;
109562 -static struct security_operations default_security_ops = {
109563 +struct security_operations *security_ops __read_only;
109564 +struct security_operations default_security_ops __read_only = {
109565 .name = "default",
109566 };
109567
109568 @@ -73,11 +73,6 @@ int __init security_init(void)
109569 return 0;
109570 }
109571
109572 -void reset_security_ops(void)
109573 -{
109574 - security_ops = &default_security_ops;
109575 -}
109576 -
109577 /* Save user chosen LSM */
109578 static int __init choose_lsm(char *str)
109579 {
109580 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109581 index a18f1fa..c9b9fc4 100644
109582 --- a/security/selinux/avc.c
109583 +++ b/security/selinux/avc.c
109584 @@ -59,7 +59,7 @@ struct avc_node {
109585 struct avc_cache {
109586 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109587 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109588 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109589 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109590 atomic_t active_nodes;
109591 u32 latest_notif; /* latest revocation notification */
109592 };
109593 @@ -167,7 +167,7 @@ void __init avc_init(void)
109594 spin_lock_init(&avc_cache.slots_lock[i]);
109595 }
109596 atomic_set(&avc_cache.active_nodes, 0);
109597 - atomic_set(&avc_cache.lru_hint, 0);
109598 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109599
109600 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109601 0, SLAB_PANIC, NULL);
109602 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109603 spinlock_t *lock;
109604
109605 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109606 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109607 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109608 head = &avc_cache.slots[hvalue];
109609 lock = &avc_cache.slots_lock[hvalue];
109610
109611 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109612 index c603b20..8716ec9 100644
109613 --- a/security/selinux/hooks.c
109614 +++ b/security/selinux/hooks.c
109615 @@ -95,8 +95,6 @@
109616 #include "audit.h"
109617 #include "avc_ss.h"
109618
109619 -extern struct security_operations *security_ops;
109620 -
109621 /* SECMARK reference count */
109622 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109623
109624 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109625
109626 #endif
109627
109628 -static struct security_operations selinux_ops = {
109629 +static struct security_operations selinux_ops __read_only = {
109630 .name = "selinux",
109631
109632 .ptrace_access_check = selinux_ptrace_access_check,
109633 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
109634 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109635 static int selinux_disabled;
109636
109637 +extern struct security_operations *security_ops;
109638 +extern struct security_operations default_security_ops;
109639 +
109640 int selinux_disable(void)
109641 {
109642 if (ss_initialized) {
109643 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
109644 selinux_disabled = 1;
109645 selinux_enabled = 0;
109646
109647 - reset_security_ops();
109648 + pax_open_kernel();
109649 + security_ops = &default_security_ops;
109650 + pax_close_kernel();
109651
109652 /* Try to destroy the avc node cache */
109653 avc_disable();
109654 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109655 index 1450f85..a91e0bc 100644
109656 --- a/security/selinux/include/xfrm.h
109657 +++ b/security/selinux/include/xfrm.h
109658 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109659
109660 rtnl_lock();
109661 for_each_net(net) {
109662 - atomic_inc(&net->xfrm.flow_cache_genid);
109663 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109664 rt_genid_bump_all(net);
109665 }
109666 rtnl_unlock();
109667 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109668 index d515ec2..8a4ca71 100644
109669 --- a/security/smack/smack_lsm.c
109670 +++ b/security/smack/smack_lsm.c
109671 @@ -4079,7 +4079,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109672 return 0;
109673 }
109674
109675 -struct security_operations smack_ops = {
109676 +struct security_operations smack_ops __read_only = {
109677 .name = "smack",
109678
109679 .ptrace_access_check = smack_ptrace_access_check,
109680 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109681 index 4003907..13a2b55 100644
109682 --- a/security/tomoyo/file.c
109683 +++ b/security/tomoyo/file.c
109684 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109685 {
109686 struct tomoyo_request_info r;
109687 struct tomoyo_obj_info obj = {
109688 - .path1 = *path,
109689 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109690 };
109691 int error = -ENOMEM;
109692 struct tomoyo_path_info buf;
109693 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109694 struct tomoyo_path_info buf;
109695 struct tomoyo_request_info r;
109696 struct tomoyo_obj_info obj = {
109697 - .path1 = *path,
109698 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109699 };
109700 int idx;
109701
109702 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109703 {
109704 struct tomoyo_request_info r;
109705 struct tomoyo_obj_info obj = {
109706 - .path1 = *path,
109707 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109708 };
109709 int error;
109710 struct tomoyo_path_info buf;
109711 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109712 {
109713 struct tomoyo_request_info r;
109714 struct tomoyo_obj_info obj = {
109715 - .path1 = *path,
109716 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109717 };
109718 int error = -ENOMEM;
109719 struct tomoyo_path_info buf;
109720 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109721 struct tomoyo_path_info buf2;
109722 struct tomoyo_request_info r;
109723 struct tomoyo_obj_info obj = {
109724 - .path1 = *path1,
109725 - .path2 = *path2,
109726 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109727 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109728 };
109729 int idx;
109730
109731 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109732 index 390c646..f2f8db3 100644
109733 --- a/security/tomoyo/mount.c
109734 +++ b/security/tomoyo/mount.c
109735 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109736 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109737 need_dev = -1; /* dev_name is a directory */
109738 } else {
109739 + if (!capable(CAP_SYS_ADMIN)) {
109740 + error = -EPERM;
109741 + goto out;
109742 + }
109743 fstype = get_fs_type(type);
109744 if (!fstype) {
109745 error = -ENODEV;
109746 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109747 index f0b756e..8aa497b 100644
109748 --- a/security/tomoyo/tomoyo.c
109749 +++ b/security/tomoyo/tomoyo.c
109750 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109751 */
109752 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109753 {
109754 - struct path path = { mnt, dentry };
109755 + struct path path = { .mnt = mnt, .dentry = dentry };
109756 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109757 }
109758
109759 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109760 */
109761 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109762 {
109763 - struct path path = { parent->mnt, dentry };
109764 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109765 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109766 }
109767
109768 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109769 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109770 umode_t mode)
109771 {
109772 - struct path path = { parent->mnt, dentry };
109773 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109774 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109775 mode & S_IALLUGO);
109776 }
109777 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109778 */
109779 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109780 {
109781 - struct path path = { parent->mnt, dentry };
109782 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109783 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109784 }
109785
109786 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109787 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109788 const char *old_name)
109789 {
109790 - struct path path = { parent->mnt, dentry };
109791 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109792 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109793 }
109794
109795 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109796 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109797 umode_t mode, unsigned int dev)
109798 {
109799 - struct path path = { parent->mnt, dentry };
109800 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109801 int type = TOMOYO_TYPE_CREATE;
109802 const unsigned int perm = mode & S_IALLUGO;
109803
109804 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109805 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109806 struct dentry *new_dentry)
109807 {
109808 - struct path path1 = { new_dir->mnt, old_dentry };
109809 - struct path path2 = { new_dir->mnt, new_dentry };
109810 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109811 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109812 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109813 }
109814
109815 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109816 struct path *new_parent,
109817 struct dentry *new_dentry)
109818 {
109819 - struct path path1 = { old_parent->mnt, old_dentry };
109820 - struct path path2 = { new_parent->mnt, new_dentry };
109821 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109822 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109823 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109824 }
109825
109826 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109827 */
109828 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109829 {
109830 - struct path path = { mnt, mnt->mnt_root };
109831 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109832 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109833 }
109834
109835 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109836 * tomoyo_security_ops is a "struct security_operations" which is used for
109837 * registering TOMOYO.
109838 */
109839 -static struct security_operations tomoyo_security_ops = {
109840 +static struct security_operations tomoyo_security_ops __read_only = {
109841 .name = "tomoyo",
109842 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109843 .cred_prepare = tomoyo_cred_prepare,
109844 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109845 index 20ef514..4182bed 100644
109846 --- a/security/yama/Kconfig
109847 +++ b/security/yama/Kconfig
109848 @@ -1,6 +1,6 @@
109849 config SECURITY_YAMA
109850 bool "Yama support"
109851 - depends on SECURITY
109852 + depends on SECURITY && !GRKERNSEC
109853 select SECURITYFS
109854 select SECURITY_PATH
109855 default n
109856 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109857 index 13c88fbc..f8c115e 100644
109858 --- a/security/yama/yama_lsm.c
109859 +++ b/security/yama/yama_lsm.c
109860 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109861 }
109862
109863 #ifndef CONFIG_SECURITY_YAMA_STACKED
109864 -static struct security_operations yama_ops = {
109865 +static struct security_operations yama_ops __read_only = {
109866 .name = "yama",
109867
109868 .ptrace_access_check = yama_ptrace_access_check,
109869 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109870 #endif
109871
109872 #ifdef CONFIG_SYSCTL
109873 +static int zero __read_only;
109874 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109875 +
109876 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109877 void __user *buffer, size_t *lenp, loff_t *ppos)
109878 {
109879 - int rc;
109880 + ctl_table_no_const yama_table;
109881
109882 if (write && !capable(CAP_SYS_PTRACE))
109883 return -EPERM;
109884
109885 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109886 - if (rc)
109887 - return rc;
109888 -
109889 + yama_table = *table;
109890 /* Lock the max value if it ever gets set. */
109891 - if (write && *(int *)table->data == *(int *)table->extra2)
109892 - table->extra1 = table->extra2;
109893 -
109894 - return rc;
109895 + if (ptrace_scope == max_scope)
109896 + yama_table.extra1 = &max_scope;
109897 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109898 }
109899
109900 -static int zero;
109901 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109902 -
109903 struct ctl_path yama_sysctl_path[] = {
109904 { .procname = "kernel", },
109905 { .procname = "yama", },
109906 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109907 index 401107b..b9c47c6 100644
109908 --- a/sound/aoa/codecs/onyx.c
109909 +++ b/sound/aoa/codecs/onyx.c
109910 @@ -54,7 +54,7 @@ struct onyx {
109911 spdif_locked:1,
109912 analog_locked:1,
109913 original_mute:2;
109914 - int open_count;
109915 + local_t open_count;
109916 struct codec_info *codec_info;
109917
109918 /* mutex serializes concurrent access to the device
109919 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109920 struct onyx *onyx = cii->codec_data;
109921
109922 mutex_lock(&onyx->mutex);
109923 - onyx->open_count++;
109924 + local_inc(&onyx->open_count);
109925 mutex_unlock(&onyx->mutex);
109926
109927 return 0;
109928 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109929 struct onyx *onyx = cii->codec_data;
109930
109931 mutex_lock(&onyx->mutex);
109932 - onyx->open_count--;
109933 - if (!onyx->open_count)
109934 + if (local_dec_and_test(&onyx->open_count))
109935 onyx->spdif_locked = onyx->analog_locked = 0;
109936 mutex_unlock(&onyx->mutex);
109937
109938 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109939 index ffd2025..df062c9 100644
109940 --- a/sound/aoa/codecs/onyx.h
109941 +++ b/sound/aoa/codecs/onyx.h
109942 @@ -11,6 +11,7 @@
109943 #include <linux/i2c.h>
109944 #include <asm/pmac_low_i2c.h>
109945 #include <asm/prom.h>
109946 +#include <asm/local.h>
109947
109948 /* PCM3052 register definitions */
109949
109950 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109951 index ada69d7..5f65386 100644
109952 --- a/sound/core/oss/pcm_oss.c
109953 +++ b/sound/core/oss/pcm_oss.c
109954 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109955 if (in_kernel) {
109956 mm_segment_t fs;
109957 fs = snd_enter_user();
109958 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109959 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109960 snd_leave_user(fs);
109961 } else {
109962 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109963 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109964 }
109965 if (ret != -EPIPE && ret != -ESTRPIPE)
109966 break;
109967 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109968 if (in_kernel) {
109969 mm_segment_t fs;
109970 fs = snd_enter_user();
109971 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109972 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109973 snd_leave_user(fs);
109974 } else {
109975 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109976 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109977 }
109978 if (ret == -EPIPE) {
109979 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109980 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109981 struct snd_pcm_plugin_channel *channels;
109982 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109983 if (!in_kernel) {
109984 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109985 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109986 return -EFAULT;
109987 buf = runtime->oss.buffer;
109988 }
109989 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109990 }
109991 } else {
109992 tmp = snd_pcm_oss_write2(substream,
109993 - (const char __force *)buf,
109994 + (const char __force_kernel *)buf,
109995 runtime->oss.period_bytes, 0);
109996 if (tmp <= 0)
109997 goto err;
109998 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109999 struct snd_pcm_runtime *runtime = substream->runtime;
110000 snd_pcm_sframes_t frames, frames1;
110001 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
110002 - char __user *final_dst = (char __force __user *)buf;
110003 + char __user *final_dst = (char __force_user *)buf;
110004 if (runtime->oss.plugin_first) {
110005 struct snd_pcm_plugin_channel *channels;
110006 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
110007 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
110008 xfer += tmp;
110009 runtime->oss.buffer_used -= tmp;
110010 } else {
110011 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
110012 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
110013 runtime->oss.period_bytes, 0);
110014 if (tmp <= 0)
110015 goto err;
110016 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
110017 size1);
110018 size1 /= runtime->channels; /* frames */
110019 fs = snd_enter_user();
110020 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
110021 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
110022 snd_leave_user(fs);
110023 }
110024 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
110025 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
110026 index 2d957ba..fda022c 100644
110027 --- a/sound/core/pcm_compat.c
110028 +++ b/sound/core/pcm_compat.c
110029 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
110030 int err;
110031
110032 fs = snd_enter_user();
110033 - err = snd_pcm_delay(substream, &delay);
110034 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
110035 snd_leave_user(fs);
110036 if (err < 0)
110037 return err;
110038 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
110039 index 166d59c..89e3889 100644
110040 --- a/sound/core/pcm_native.c
110041 +++ b/sound/core/pcm_native.c
110042 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
110043 switch (substream->stream) {
110044 case SNDRV_PCM_STREAM_PLAYBACK:
110045 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
110046 - (void __user *)arg);
110047 + (void __force_user *)arg);
110048 break;
110049 case SNDRV_PCM_STREAM_CAPTURE:
110050 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
110051 - (void __user *)arg);
110052 + (void __force_user *)arg);
110053 break;
110054 default:
110055 result = -EINVAL;
110056 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
110057 index 16d4267..fe8b49b 100644
110058 --- a/sound/core/seq/oss/seq_oss.c
110059 +++ b/sound/core/seq/oss/seq_oss.c
110060 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
110061 {
110062 int rc;
110063 static struct snd_seq_dev_ops ops = {
110064 - snd_seq_oss_synth_register,
110065 - snd_seq_oss_synth_unregister,
110066 + .init_device = snd_seq_oss_synth_register,
110067 + .free_device = snd_seq_oss_synth_unregister,
110068 };
110069
110070 snd_seq_autoload_lock();
110071 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
110072 index 91a786a..4c07ed4 100644
110073 --- a/sound/core/seq/seq_device.c
110074 +++ b/sound/core/seq/seq_device.c
110075 @@ -64,7 +64,7 @@ struct ops_list {
110076 int argsize; /* argument size */
110077
110078 /* operators */
110079 - struct snd_seq_dev_ops ops;
110080 + struct snd_seq_dev_ops *ops;
110081
110082 /* registered devices */
110083 struct list_head dev_list; /* list of devices */
110084 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
110085
110086 mutex_lock(&ops->reg_mutex);
110087 /* copy driver operators */
110088 - ops->ops = *entry;
110089 + ops->ops = entry;
110090 ops->driver |= DRIVER_LOADED;
110091 ops->argsize = argsize;
110092
110093 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110094 dev->name, ops->id, ops->argsize, dev->argsize);
110095 return -EINVAL;
110096 }
110097 - if (ops->ops.init_device(dev) >= 0) {
110098 + if (ops->ops->init_device(dev) >= 0) {
110099 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110100 ops->num_init_devices++;
110101 } else {
110102 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110103 dev->name, ops->id, ops->argsize, dev->argsize);
110104 return -EINVAL;
110105 }
110106 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110107 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110108 dev->status = SNDRV_SEQ_DEVICE_FREE;
110109 dev->driver_data = NULL;
110110 ops->num_init_devices--;
110111 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110112 index a1fd77a..69cd659 100644
110113 --- a/sound/core/seq/seq_midi.c
110114 +++ b/sound/core/seq/seq_midi.c
110115 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110116 static int __init alsa_seq_midi_init(void)
110117 {
110118 static struct snd_seq_dev_ops ops = {
110119 - snd_seq_midisynth_register_port,
110120 - snd_seq_midisynth_unregister_port,
110121 + .init_device = snd_seq_midisynth_register_port,
110122 + .free_device = snd_seq_midisynth_unregister_port,
110123 };
110124 memset(&synths, 0, sizeof(synths));
110125 snd_seq_autoload_lock();
110126 diff --git a/sound/core/sound.c b/sound/core/sound.c
110127 index 38ad1a0..5010a40 100644
110128 --- a/sound/core/sound.c
110129 +++ b/sound/core/sound.c
110130 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110131 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110132 default: return;
110133 }
110134 - request_module(str);
110135 + request_module("%s", str);
110136 }
110137
110138 #endif /* modular kernel */
110139 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110140 index f5fd448..6ae276da 100644
110141 --- a/sound/drivers/mts64.c
110142 +++ b/sound/drivers/mts64.c
110143 @@ -29,6 +29,7 @@
110144 #include <sound/initval.h>
110145 #include <sound/rawmidi.h>
110146 #include <sound/control.h>
110147 +#include <asm/local.h>
110148
110149 #define CARD_NAME "Miditerminal 4140"
110150 #define DRIVER_NAME "MTS64"
110151 @@ -67,7 +68,7 @@ struct mts64 {
110152 struct pardevice *pardev;
110153 int pardev_claimed;
110154
110155 - int open_count;
110156 + local_t open_count;
110157 int current_midi_output_port;
110158 int current_midi_input_port;
110159 u8 mode[MTS64_NUM_INPUT_PORTS];
110160 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110161 {
110162 struct mts64 *mts = substream->rmidi->private_data;
110163
110164 - if (mts->open_count == 0) {
110165 + if (local_read(&mts->open_count) == 0) {
110166 /* We don't need a spinlock here, because this is just called
110167 if the device has not been opened before.
110168 So there aren't any IRQs from the device */
110169 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110170
110171 msleep(50);
110172 }
110173 - ++(mts->open_count);
110174 + local_inc(&mts->open_count);
110175
110176 return 0;
110177 }
110178 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110179 struct mts64 *mts = substream->rmidi->private_data;
110180 unsigned long flags;
110181
110182 - --(mts->open_count);
110183 - if (mts->open_count == 0) {
110184 + if (local_dec_return(&mts->open_count) == 0) {
110185 /* We need the spinlock_irqsave here because we can still
110186 have IRQs at this point */
110187 spin_lock_irqsave(&mts->lock, flags);
110188 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110189
110190 msleep(500);
110191
110192 - } else if (mts->open_count < 0)
110193 - mts->open_count = 0;
110194 + } else if (local_read(&mts->open_count) < 0)
110195 + local_set(&mts->open_count, 0);
110196
110197 return 0;
110198 }
110199 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110200 index 6839953..7a0f4b9 100644
110201 --- a/sound/drivers/opl3/opl3_seq.c
110202 +++ b/sound/drivers/opl3/opl3_seq.c
110203 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110204 {
110205 static struct snd_seq_dev_ops ops =
110206 {
110207 - snd_opl3_seq_new_device,
110208 - snd_opl3_seq_delete_device
110209 + .init_device = snd_opl3_seq_new_device,
110210 + .free_device = snd_opl3_seq_delete_device
110211 };
110212
110213 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110214 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110215 index b953fb4..1999c01 100644
110216 --- a/sound/drivers/opl4/opl4_lib.c
110217 +++ b/sound/drivers/opl4/opl4_lib.c
110218 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110219 MODULE_DESCRIPTION("OPL4 driver");
110220 MODULE_LICENSE("GPL");
110221
110222 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110223 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110224 {
110225 int timeout = 10;
110226 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110227 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110228 index 9919769..d7de36c 100644
110229 --- a/sound/drivers/opl4/opl4_seq.c
110230 +++ b/sound/drivers/opl4/opl4_seq.c
110231 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110232 static int __init alsa_opl4_synth_init(void)
110233 {
110234 static struct snd_seq_dev_ops ops = {
110235 - snd_opl4_seq_new_device,
110236 - snd_opl4_seq_delete_device
110237 + .init_device = snd_opl4_seq_new_device,
110238 + .free_device = snd_opl4_seq_delete_device
110239 };
110240
110241 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110242 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110243 index 78ccfa4..7a0857b 100644
110244 --- a/sound/drivers/portman2x4.c
110245 +++ b/sound/drivers/portman2x4.c
110246 @@ -48,6 +48,7 @@
110247 #include <sound/initval.h>
110248 #include <sound/rawmidi.h>
110249 #include <sound/control.h>
110250 +#include <asm/local.h>
110251
110252 #define CARD_NAME "Portman 2x4"
110253 #define DRIVER_NAME "portman"
110254 @@ -85,7 +86,7 @@ struct portman {
110255 struct pardevice *pardev;
110256 int pardev_claimed;
110257
110258 - int open_count;
110259 + local_t open_count;
110260 int mode[PORTMAN_NUM_INPUT_PORTS];
110261 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110262 };
110263 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110264 index 95fc2eaf..ea5d6a7 100644
110265 --- a/sound/firewire/amdtp.c
110266 +++ b/sound/firewire/amdtp.c
110267 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110268 ptr = s->pcm_buffer_pointer + frames;
110269 if (ptr >= pcm->runtime->buffer_size)
110270 ptr -= pcm->runtime->buffer_size;
110271 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110272 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110273
110274 s->pcm_period_pointer += frames;
110275 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110276 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110277 */
110278 void amdtp_stream_update(struct amdtp_stream *s)
110279 {
110280 - ACCESS_ONCE(s->source_node_id_field) =
110281 + ACCESS_ONCE_RW(s->source_node_id_field) =
110282 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110283 }
110284 EXPORT_SYMBOL(amdtp_stream_update);
110285 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110286 index 4823c08..47a5f7c 100644
110287 --- a/sound/firewire/amdtp.h
110288 +++ b/sound/firewire/amdtp.h
110289 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110290 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110291 struct snd_pcm_substream *pcm)
110292 {
110293 - ACCESS_ONCE(s->pcm) = pcm;
110294 + ACCESS_ONCE_RW(s->pcm) = pcm;
110295 }
110296
110297 /**
110298 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110299 struct snd_rawmidi_substream *midi)
110300 {
110301 if (port < s->midi_ports)
110302 - ACCESS_ONCE(s->midi[port]) = midi;
110303 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110304 }
110305
110306 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110307 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110308 index 7ac9443..0ec6274 100644
110309 --- a/sound/firewire/isight.c
110310 +++ b/sound/firewire/isight.c
110311 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110312 ptr += count;
110313 if (ptr >= runtime->buffer_size)
110314 ptr -= runtime->buffer_size;
110315 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110316 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110317
110318 isight->period_counter += count;
110319 if (isight->period_counter >= runtime->period_size) {
110320 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110321 if (err < 0)
110322 return err;
110323
110324 - ACCESS_ONCE(isight->pcm_active) = true;
110325 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110326
110327 return 0;
110328 }
110329 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110330 {
110331 struct isight *isight = substream->private_data;
110332
110333 - ACCESS_ONCE(isight->pcm_active) = false;
110334 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110335
110336 mutex_lock(&isight->mutex);
110337 isight_stop_streaming(isight);
110338 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110339
110340 switch (cmd) {
110341 case SNDRV_PCM_TRIGGER_START:
110342 - ACCESS_ONCE(isight->pcm_running) = true;
110343 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110344 break;
110345 case SNDRV_PCM_TRIGGER_STOP:
110346 - ACCESS_ONCE(isight->pcm_running) = false;
110347 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110348 break;
110349 default:
110350 return -EINVAL;
110351 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110352 index 2dba848..c682aef 100644
110353 --- a/sound/firewire/scs1x.c
110354 +++ b/sound/firewire/scs1x.c
110355 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110356 {
110357 struct scs *scs = stream->rmidi->private_data;
110358
110359 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110360 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110361 if (up) {
110362 scs->output_idle = false;
110363 tasklet_schedule(&scs->tasklet);
110364 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110365 {
110366 struct scs *scs = stream->rmidi->private_data;
110367
110368 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110369 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110370 }
110371
110372 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110373 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110374
110375 snd_card_disconnect(scs->card);
110376
110377 - ACCESS_ONCE(scs->output) = NULL;
110378 - ACCESS_ONCE(scs->input) = NULL;
110379 + ACCESS_ONCE_RW(scs->output) = NULL;
110380 + ACCESS_ONCE_RW(scs->input) = NULL;
110381
110382 wait_event(scs->idle_wait, scs->output_idle);
110383
110384 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110385 index 4e3fcfb..ab45a9d 100644
110386 --- a/sound/isa/sb/emu8000_synth.c
110387 +++ b/sound/isa/sb/emu8000_synth.c
110388 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110389 {
110390
110391 static struct snd_seq_dev_ops ops = {
110392 - snd_emu8000_new_device,
110393 - snd_emu8000_delete_device,
110394 + .init_device = snd_emu8000_new_device,
110395 + .free_device = snd_emu8000_delete_device,
110396 };
110397 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110398 sizeof(struct snd_emu8000*));
110399 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110400 index 048439a..3be9f6f 100644
110401 --- a/sound/oss/sb_audio.c
110402 +++ b/sound/oss/sb_audio.c
110403 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110404 buf16 = (signed short *)(localbuf + localoffs);
110405 while (c)
110406 {
110407 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110408 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110409 if (copy_from_user(lbuf8,
110410 userbuf+useroffs + p,
110411 locallen))
110412 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110413 index a33e8ce..2262303 100644
110414 --- a/sound/oss/swarm_cs4297a.c
110415 +++ b/sound/oss/swarm_cs4297a.c
110416 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110417 {
110418 struct cs4297a_state *s;
110419 u32 pwr, id;
110420 - mm_segment_t fs;
110421 int rval;
110422 u64 cfg;
110423 int mdio_val;
110424 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110425 if (!rval) {
110426 char *sb1250_duart_present;
110427
110428 +#if 0
110429 + mm_segment_t fs;
110430 fs = get_fs();
110431 set_fs(KERNEL_DS);
110432 -#if 0
110433 val = SOUND_MASK_LINE;
110434 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110435 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110436 val = initvol[i].vol;
110437 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110438 }
110439 + set_fs(fs);
110440 // cs4297a_write_ac97(s, 0x18, 0x0808);
110441 #else
110442 // cs4297a_write_ac97(s, 0x5e, 0x180);
110443 cs4297a_write_ac97(s, 0x02, 0x0808);
110444 cs4297a_write_ac97(s, 0x18, 0x0808);
110445 #endif
110446 - set_fs(fs);
110447
110448 list_add(&s->list, &cs4297a_devs);
110449
110450 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110451 index 4c41c90..37f3631 100644
110452 --- a/sound/pci/emu10k1/emu10k1_synth.c
110453 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110454 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110455 {
110456
110457 static struct snd_seq_dev_ops ops = {
110458 - snd_emu10k1_synth_new_device,
110459 - snd_emu10k1_synth_delete_device,
110460 + .init_device = snd_emu10k1_synth_new_device,
110461 + .free_device = snd_emu10k1_synth_delete_device,
110462 };
110463 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110464 sizeof(struct snd_emu10k1_synth_arg));
110465 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110466 index e708368..764dffe 100644
110467 --- a/sound/pci/hda/hda_codec.c
110468 +++ b/sound/pci/hda/hda_codec.c
110469 @@ -968,14 +968,10 @@ find_codec_preset(struct hda_codec *codec)
110470 mutex_unlock(&preset_mutex);
110471
110472 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110473 - char name[32];
110474 if (!mod_requested)
110475 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110476 - codec->vendor_id);
110477 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110478 else
110479 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110480 - (codec->vendor_id >> 16) & 0xffff);
110481 - request_module(name);
110482 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110483 mod_requested++;
110484 goto again;
110485 }
110486 @@ -2802,7 +2798,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110487 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110488 mm_segment_t fs = get_fs();
110489 set_fs(get_ds());
110490 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110491 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110492 tlv = _tlv;
110493 set_fs(fs);
110494 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110495 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110496 index 4631a23..001ae57 100644
110497 --- a/sound/pci/ymfpci/ymfpci.h
110498 +++ b/sound/pci/ymfpci/ymfpci.h
110499 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110500 spinlock_t reg_lock;
110501 spinlock_t voice_lock;
110502 wait_queue_head_t interrupt_sleep;
110503 - atomic_t interrupt_sleep_count;
110504 + atomic_unchecked_t interrupt_sleep_count;
110505 struct snd_info_entry *proc_entry;
110506 const struct firmware *dsp_microcode;
110507 const struct firmware *controller_microcode;
110508 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110509 index 81c916a..516f0bf 100644
110510 --- a/sound/pci/ymfpci/ymfpci_main.c
110511 +++ b/sound/pci/ymfpci/ymfpci_main.c
110512 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110513 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110514 break;
110515 }
110516 - if (atomic_read(&chip->interrupt_sleep_count)) {
110517 - atomic_set(&chip->interrupt_sleep_count, 0);
110518 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110519 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110520 wake_up(&chip->interrupt_sleep);
110521 }
110522 __end:
110523 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110524 continue;
110525 init_waitqueue_entry(&wait, current);
110526 add_wait_queue(&chip->interrupt_sleep, &wait);
110527 - atomic_inc(&chip->interrupt_sleep_count);
110528 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110529 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110530 remove_wait_queue(&chip->interrupt_sleep, &wait);
110531 }
110532 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110533 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110534 spin_unlock(&chip->reg_lock);
110535
110536 - if (atomic_read(&chip->interrupt_sleep_count)) {
110537 - atomic_set(&chip->interrupt_sleep_count, 0);
110538 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110539 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110540 wake_up(&chip->interrupt_sleep);
110541 }
110542 }
110543 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110544 spin_lock_init(&chip->reg_lock);
110545 spin_lock_init(&chip->voice_lock);
110546 init_waitqueue_head(&chip->interrupt_sleep);
110547 - atomic_set(&chip->interrupt_sleep_count, 0);
110548 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110549 chip->card = card;
110550 chip->pci = pci;
110551 chip->irq = -1;
110552 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110553 index b60ff56..7307f0f 100644
110554 --- a/sound/soc/soc-core.c
110555 +++ b/sound/soc/soc-core.c
110556 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110557 if (ret)
110558 return ret;
110559
110560 - ops->warm_reset = snd_soc_ac97_warm_reset;
110561 - ops->reset = snd_soc_ac97_reset;
110562 + pax_open_kernel();
110563 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110564 + *(void **)&ops->reset = snd_soc_ac97_reset;
110565 + pax_close_kernel();
110566
110567 snd_ac97_rst_cfg = cfg;
110568 return 0;
110569 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110570 index 7778b8e..3d619fc 100644
110571 --- a/sound/synth/emux/emux_seq.c
110572 +++ b/sound/synth/emux/emux_seq.c
110573 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110574 * MIDI emulation operators
110575 */
110576 static struct snd_midi_op emux_ops = {
110577 - snd_emux_note_on,
110578 - snd_emux_note_off,
110579 - snd_emux_key_press,
110580 - snd_emux_terminate_note,
110581 - snd_emux_control,
110582 - snd_emux_nrpn,
110583 - snd_emux_sysex,
110584 + .note_on = snd_emux_note_on,
110585 + .note_off = snd_emux_note_off,
110586 + .key_press = snd_emux_key_press,
110587 + .note_terminate = snd_emux_terminate_note,
110588 + .control = snd_emux_control,
110589 + .nrpn = snd_emux_nrpn,
110590 + .sysex = snd_emux_sysex,
110591 };
110592
110593
110594 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110595 new file mode 100644
110596 index 0000000..de92ed9
110597 --- /dev/null
110598 +++ b/tools/gcc/.gitignore
110599 @@ -0,0 +1 @@
110600 +randomize_layout_seed.h
110601 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110602 new file mode 100644
110603 index 0000000..7b8921f
110604 --- /dev/null
110605 +++ b/tools/gcc/Makefile
110606 @@ -0,0 +1,52 @@
110607 +#CC := gcc
110608 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110609 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110610 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110611 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110612 +
110613 +ifeq ($(PLUGINCC),$(HOSTCC))
110614 +HOSTLIBS := hostlibs
110615 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110616 +export HOST_EXTRACFLAGS
110617 +else
110618 +HOSTLIBS := hostcxxlibs
110619 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110620 +export HOST_EXTRACXXFLAGS
110621 +endif
110622 +
110623 +export GCCPLUGINS_DIR HOSTLIBS
110624 +
110625 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110626 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110627 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110628 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110629 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110630 +$(HOSTLIBS)-y += colorize_plugin.so
110631 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110632 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110633 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110634 +
110635 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110636 +subdir- += size_overflow_plugin
110637 +
110638 +always := $($(HOSTLIBS)-y)
110639 +
110640 +constify_plugin-objs := constify_plugin.o
110641 +stackleak_plugin-objs := stackleak_plugin.o
110642 +kallocstat_plugin-objs := kallocstat_plugin.o
110643 +kernexec_plugin-objs := kernexec_plugin.o
110644 +checker_plugin-objs := checker_plugin.o
110645 +colorize_plugin-objs := colorize_plugin.o
110646 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110647 +structleak_plugin-objs := structleak_plugin.o
110648 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110649 +
110650 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110651 +
110652 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110653 + cmd_create_randomize_layout_seed = \
110654 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110655 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110656 + $(call if_changed,create_randomize_layout_seed)
110657 +
110658 +targets += randomize_layout_seed.h randomize_layout_hash.h
110659 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110660 new file mode 100644
110661 index 0000000..5452feea
110662 --- /dev/null
110663 +++ b/tools/gcc/checker_plugin.c
110664 @@ -0,0 +1,150 @@
110665 +/*
110666 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110667 + * Licensed under the GPL v2
110668 + *
110669 + * Note: the choice of the license means that the compilation process is
110670 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110671 + * but for the kernel it doesn't matter since it doesn't link against
110672 + * any of the gcc libraries
110673 + *
110674 + * gcc plugin to implement various sparse (source code checker) features
110675 + *
110676 + * TODO:
110677 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110678 + *
110679 + * BUGS:
110680 + * - none known
110681 + */
110682 +
110683 +#include "gcc-common.h"
110684 +
110685 +extern void c_register_addr_space (const char *str, addr_space_t as);
110686 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110687 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110688 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110689 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110690 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110691 +
110692 +int plugin_is_GPL_compatible;
110693 +
110694 +static struct plugin_info checker_plugin_info = {
110695 + .version = "201304082245",
110696 + .help = NULL,
110697 +};
110698 +
110699 +#define ADDR_SPACE_KERNEL 0
110700 +#define ADDR_SPACE_FORCE_KERNEL 1
110701 +#define ADDR_SPACE_USER 2
110702 +#define ADDR_SPACE_FORCE_USER 3
110703 +#define ADDR_SPACE_IOMEM 0
110704 +#define ADDR_SPACE_FORCE_IOMEM 0
110705 +#define ADDR_SPACE_PERCPU 0
110706 +#define ADDR_SPACE_FORCE_PERCPU 0
110707 +#define ADDR_SPACE_RCU 0
110708 +#define ADDR_SPACE_FORCE_RCU 0
110709 +
110710 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110711 +{
110712 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110713 +}
110714 +
110715 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110716 +{
110717 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110718 +}
110719 +
110720 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110721 +{
110722 + return default_addr_space_valid_pointer_mode(mode, as);
110723 +}
110724 +
110725 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110726 +{
110727 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110728 +}
110729 +
110730 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110731 +{
110732 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110733 +}
110734 +
110735 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110736 +{
110737 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110738 + return true;
110739 +
110740 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110741 + return true;
110742 +
110743 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110744 + return true;
110745 +
110746 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110747 + return true;
110748 +
110749 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110750 + return true;
110751 +
110752 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110753 + return true;
110754 +
110755 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110756 + return true;
110757 +
110758 + return subset == superset;
110759 +}
110760 +
110761 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110762 +{
110763 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110764 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110765 +
110766 + return op;
110767 +}
110768 +
110769 +static void register_checker_address_spaces(void *event_data, void *data)
110770 +{
110771 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110772 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110773 + c_register_addr_space("__user", ADDR_SPACE_USER);
110774 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110775 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110776 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110777 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110778 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110779 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110780 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110781 +
110782 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110783 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110784 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110785 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110786 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110787 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110788 + targetm.addr_space.convert = checker_addr_space_convert;
110789 +}
110790 +
110791 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110792 +{
110793 + const char * const plugin_name = plugin_info->base_name;
110794 + const int argc = plugin_info->argc;
110795 + const struct plugin_argument * const argv = plugin_info->argv;
110796 + int i;
110797 +
110798 + if (!plugin_default_version_check(version, &gcc_version)) {
110799 + error(G_("incompatible gcc/plugin versions"));
110800 + return 1;
110801 + }
110802 +
110803 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110804 +
110805 + for (i = 0; i < argc; ++i)
110806 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110807 +
110808 + if (TARGET_64BIT == 0)
110809 + return 0;
110810 +
110811 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110812 +
110813 + return 0;
110814 +}
110815 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110816 new file mode 100644
110817 index 0000000..54461af
110818 --- /dev/null
110819 +++ b/tools/gcc/colorize_plugin.c
110820 @@ -0,0 +1,210 @@
110821 +/*
110822 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110823 + * Licensed under the GPL v2
110824 + *
110825 + * Note: the choice of the license means that the compilation process is
110826 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110827 + * but for the kernel it doesn't matter since it doesn't link against
110828 + * any of the gcc libraries
110829 + *
110830 + * gcc plugin to colorize diagnostic output
110831 + *
110832 + */
110833 +
110834 +#include "gcc-common.h"
110835 +
110836 +int plugin_is_GPL_compatible;
110837 +
110838 +static struct plugin_info colorize_plugin_info = {
110839 + .version = "201404202350",
110840 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110841 +};
110842 +
110843 +#define GREEN "\033[32m\033[K"
110844 +#define LIGHTGREEN "\033[1;32m\033[K"
110845 +#define YELLOW "\033[33m\033[K"
110846 +#define LIGHTYELLOW "\033[1;33m\033[K"
110847 +#define RED "\033[31m\033[K"
110848 +#define LIGHTRED "\033[1;31m\033[K"
110849 +#define BLUE "\033[34m\033[K"
110850 +#define LIGHTBLUE "\033[1;34m\033[K"
110851 +#define BRIGHT "\033[1;m\033[K"
110852 +#define NORMAL "\033[m\033[K"
110853 +
110854 +static diagnostic_starter_fn old_starter;
110855 +static diagnostic_finalizer_fn old_finalizer;
110856 +
110857 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110858 +{
110859 + const char *color;
110860 + char *newprefix;
110861 +
110862 + switch (diagnostic->kind) {
110863 + case DK_NOTE:
110864 + color = LIGHTBLUE;
110865 + break;
110866 +
110867 + case DK_PEDWARN:
110868 + case DK_WARNING:
110869 + color = LIGHTYELLOW;
110870 + break;
110871 +
110872 + case DK_ERROR:
110873 + case DK_FATAL:
110874 + case DK_ICE:
110875 + case DK_PERMERROR:
110876 + case DK_SORRY:
110877 + color = LIGHTRED;
110878 + break;
110879 +
110880 + default:
110881 + color = NORMAL;
110882 + }
110883 +
110884 + old_starter(context, diagnostic);
110885 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110886 + return;
110887 + pp_destroy_prefix(context->printer);
110888 + pp_set_prefix(context->printer, newprefix);
110889 +}
110890 +
110891 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110892 +{
110893 + old_finalizer(context, diagnostic);
110894 +}
110895 +
110896 +static void colorize_arm(void)
110897 +{
110898 + old_starter = diagnostic_starter(global_dc);
110899 + old_finalizer = diagnostic_finalizer(global_dc);
110900 +
110901 + diagnostic_starter(global_dc) = start_colorize;
110902 + diagnostic_finalizer(global_dc) = finalize_colorize;
110903 +}
110904 +
110905 +static unsigned int execute_colorize_rearm(void)
110906 +{
110907 + if (diagnostic_starter(global_dc) == start_colorize)
110908 + return 0;
110909 +
110910 + colorize_arm();
110911 + return 0;
110912 +}
110913 +
110914 +#if BUILDING_GCC_VERSION >= 4009
110915 +static const struct pass_data colorize_rearm_pass_data = {
110916 +#else
110917 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110918 + .pass = {
110919 +#endif
110920 + .type = SIMPLE_IPA_PASS,
110921 + .name = "colorize_rearm",
110922 +#if BUILDING_GCC_VERSION >= 4008
110923 + .optinfo_flags = OPTGROUP_NONE,
110924 +#endif
110925 +#if BUILDING_GCC_VERSION >= 4009
110926 + .has_gate = false,
110927 + .has_execute = true,
110928 +#else
110929 + .gate = NULL,
110930 + .execute = execute_colorize_rearm,
110931 + .sub = NULL,
110932 + .next = NULL,
110933 + .static_pass_number = 0,
110934 +#endif
110935 + .tv_id = TV_NONE,
110936 + .properties_required = 0,
110937 + .properties_provided = 0,
110938 + .properties_destroyed = 0,
110939 + .todo_flags_start = 0,
110940 + .todo_flags_finish = 0
110941 +#if BUILDING_GCC_VERSION < 4009
110942 + }
110943 +#endif
110944 +};
110945 +
110946 +#if BUILDING_GCC_VERSION >= 4009
110947 +namespace {
110948 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110949 +public:
110950 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110951 + unsigned int execute() { return execute_colorize_rearm(); }
110952 +};
110953 +}
110954 +
110955 +static opt_pass *make_colorize_rearm_pass(void)
110956 +{
110957 + return new colorize_rearm_pass();
110958 +}
110959 +#else
110960 +static struct opt_pass *make_colorize_rearm_pass(void)
110961 +{
110962 + return &colorize_rearm_pass.pass;
110963 +}
110964 +#endif
110965 +
110966 +static void colorize_start_unit(void *gcc_data, void *user_data)
110967 +{
110968 + colorize_arm();
110969 +}
110970 +
110971 +static bool should_colorize(void)
110972 +{
110973 +#if BUILDING_GCC_VERSION >= 4009
110974 + return false;
110975 +#else
110976 + char const *t = getenv("TERM");
110977 +
110978 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110979 +#endif
110980 +}
110981 +
110982 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110983 +{
110984 + const char * const plugin_name = plugin_info->base_name;
110985 + const int argc = plugin_info->argc;
110986 + const struct plugin_argument * const argv = plugin_info->argv;
110987 + int i;
110988 + struct register_pass_info colorize_rearm_pass_info;
110989 + bool colorize;
110990 +
110991 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110992 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110993 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110994 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110995 +
110996 + if (!plugin_default_version_check(version, &gcc_version)) {
110997 + error(G_("incompatible gcc/plugin versions"));
110998 + return 1;
110999 + }
111000 +
111001 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
111002 +
111003 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
111004 +
111005 + for (i = 0; i < argc; ++i) {
111006 + if (!strcmp(argv[i].key, "color")) {
111007 + if (!argv[i].value) {
111008 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111009 + continue;
111010 + }
111011 + if (!strcmp(argv[i].value, "always"))
111012 + colorize = true;
111013 + else if (!strcmp(argv[i].value, "never"))
111014 + colorize = false;
111015 + else if (!strcmp(argv[i].value, "auto"))
111016 + colorize = should_colorize();
111017 + else
111018 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111019 + continue;
111020 + }
111021 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111022 + }
111023 +
111024 + if (colorize) {
111025 + // TODO: parse GCC_COLORS as used by gcc 4.9+
111026 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
111027 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
111028 + }
111029 + return 0;
111030 +}
111031 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
111032 new file mode 100644
111033 index 0000000..3b5af59
111034 --- /dev/null
111035 +++ b/tools/gcc/constify_plugin.c
111036 @@ -0,0 +1,558 @@
111037 +/*
111038 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
111039 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
111040 + * Licensed under the GPL v2, or (at your option) v3
111041 + *
111042 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
111043 + *
111044 + * Homepage:
111045 + * http://www.grsecurity.net/~ephox/const_plugin/
111046 + *
111047 + * Usage:
111048 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
111049 + * $ gcc -fplugin=constify_plugin.so test.c -O2
111050 + */
111051 +
111052 +#include "gcc-common.h"
111053 +
111054 +// unused C type flag in all versions 4.5-4.9
111055 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
111056 +
111057 +int plugin_is_GPL_compatible;
111058 +
111059 +static struct plugin_info const_plugin_info = {
111060 + .version = "201401270210",
111061 + .help = "no-constify\tturn off constification\n",
111062 +};
111063 +
111064 +typedef struct {
111065 + bool has_fptr_field;
111066 + bool has_writable_field;
111067 + bool has_do_const_field;
111068 + bool has_no_const_field;
111069 +} constify_info;
111070 +
111071 +static const_tree get_field_type(const_tree field)
111072 +{
111073 + return strip_array_types(TREE_TYPE(field));
111074 +}
111075 +
111076 +static bool is_fptr(const_tree field)
111077 +{
111078 + const_tree ptr = get_field_type(field);
111079 +
111080 + if (TREE_CODE(ptr) != POINTER_TYPE)
111081 + return false;
111082 +
111083 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
111084 +}
111085 +
111086 +/*
111087 + * determine whether the given structure type meets the requirements for automatic constification,
111088 + * including the constification attributes on nested structure types
111089 + */
111090 +static void constifiable(const_tree node, constify_info *cinfo)
111091 +{
111092 + const_tree field;
111093 +
111094 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111095 +
111096 + // e.g., pointer to structure fields while still constructing the structure type
111097 + if (TYPE_FIELDS(node) == NULL_TREE)
111098 + return;
111099 +
111100 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111101 + const_tree type = get_field_type(field);
111102 + enum tree_code code = TREE_CODE(type);
111103 +
111104 + if (node == type)
111105 + continue;
111106 +
111107 + if (is_fptr(field))
111108 + cinfo->has_fptr_field = true;
111109 + else if (!TREE_READONLY(field))
111110 + cinfo->has_writable_field = true;
111111 +
111112 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111113 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111114 + cinfo->has_do_const_field = true;
111115 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111116 + cinfo->has_no_const_field = true;
111117 + else
111118 + constifiable(type, cinfo);
111119 + }
111120 + }
111121 +}
111122 +
111123 +static bool constified(const_tree node)
111124 +{
111125 + constify_info cinfo = {
111126 + .has_fptr_field = false,
111127 + .has_writable_field = false,
111128 + .has_do_const_field = false,
111129 + .has_no_const_field = false
111130 + };
111131 +
111132 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111133 +
111134 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111135 +// gcc_assert(!TYPE_READONLY(node));
111136 + return false;
111137 + }
111138 +
111139 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111140 + gcc_assert(TYPE_READONLY(node));
111141 + return true;
111142 + }
111143 +
111144 + constifiable(node, &cinfo);
111145 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111146 + return false;
111147 +
111148 + return TYPE_READONLY(node);
111149 +}
111150 +
111151 +static void deconstify_tree(tree node);
111152 +
111153 +static void deconstify_type(tree type)
111154 +{
111155 + tree field;
111156 +
111157 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111158 +
111159 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111160 + const_tree fieldtype = get_field_type(field);
111161 +
111162 + // special case handling of simple ptr-to-same-array-type members
111163 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111164 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111165 +
111166 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111167 + continue;
111168 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111169 + continue;
111170 + if (!constified(ptrtype))
111171 + continue;
111172 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111173 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111174 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111175 + }
111176 + continue;
111177 + }
111178 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111179 + continue;
111180 + if (!constified(fieldtype))
111181 + continue;
111182 +
111183 + deconstify_tree(field);
111184 + TREE_READONLY(field) = 0;
111185 + }
111186 + TYPE_READONLY(type) = 0;
111187 + C_TYPE_FIELDS_READONLY(type) = 0;
111188 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111189 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111190 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111191 + }
111192 +}
111193 +
111194 +static void deconstify_tree(tree node)
111195 +{
111196 + tree old_type, new_type, field;
111197 +
111198 + old_type = TREE_TYPE(node);
111199 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111200 + node = TREE_TYPE(node) = copy_node(old_type);
111201 + old_type = TREE_TYPE(old_type);
111202 + }
111203 +
111204 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111205 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111206 +
111207 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111208 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111209 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111210 + DECL_FIELD_CONTEXT(field) = new_type;
111211 +
111212 + deconstify_type(new_type);
111213 +
111214 + TREE_TYPE(node) = new_type;
111215 +}
111216 +
111217 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111218 +{
111219 + tree type;
111220 + constify_info cinfo = {
111221 + .has_fptr_field = false,
111222 + .has_writable_field = false,
111223 + .has_do_const_field = false,
111224 + .has_no_const_field = false
111225 + };
111226 +
111227 + *no_add_attrs = true;
111228 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111229 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111230 + return NULL_TREE;
111231 + }
111232 +
111233 + if (TREE_CODE(*node) == PARM_DECL) {
111234 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111235 + return NULL_TREE;
111236 + }
111237 +
111238 + if (TREE_CODE(*node) == VAR_DECL) {
111239 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111240 + return NULL_TREE;
111241 + }
111242 +
111243 + if (TYPE_P(*node)) {
111244 + type = *node;
111245 + } else {
111246 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111247 + type = TREE_TYPE(*node);
111248 + }
111249 +
111250 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111251 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111252 + return NULL_TREE;
111253 + }
111254 +
111255 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111256 + error("%qE attribute is already applied to the type %qT", name, type);
111257 + return NULL_TREE;
111258 + }
111259 +
111260 + if (TYPE_P(*node)) {
111261 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111262 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111263 + else
111264 + *no_add_attrs = false;
111265 + return NULL_TREE;
111266 + }
111267 +
111268 + constifiable(type, &cinfo);
111269 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111270 + deconstify_tree(*node);
111271 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111272 + return NULL_TREE;
111273 + }
111274 +
111275 + error("%qE attribute used on type %qT that is not constified", name, type);
111276 + return NULL_TREE;
111277 +}
111278 +
111279 +static void constify_type(tree type)
111280 +{
111281 + TYPE_READONLY(type) = 1;
111282 + C_TYPE_FIELDS_READONLY(type) = 1;
111283 + TYPE_CONSTIFY_VISITED(type) = 1;
111284 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111285 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111286 +}
111287 +
111288 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111289 +{
111290 + *no_add_attrs = true;
111291 + if (!TYPE_P(*node)) {
111292 + error("%qE attribute applies to types only (%qD)", name, *node);
111293 + return NULL_TREE;
111294 + }
111295 +
111296 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111297 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111298 + return NULL_TREE;
111299 + }
111300 +
111301 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111302 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111303 + return NULL_TREE;
111304 + }
111305 +
111306 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111307 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111308 + return NULL_TREE;
111309 + }
111310 +
111311 + *no_add_attrs = false;
111312 + return NULL_TREE;
111313 +}
111314 +
111315 +static struct attribute_spec no_const_attr = {
111316 + .name = "no_const",
111317 + .min_length = 0,
111318 + .max_length = 0,
111319 + .decl_required = false,
111320 + .type_required = false,
111321 + .function_type_required = false,
111322 + .handler = handle_no_const_attribute,
111323 +#if BUILDING_GCC_VERSION >= 4007
111324 + .affects_type_identity = true
111325 +#endif
111326 +};
111327 +
111328 +static struct attribute_spec do_const_attr = {
111329 + .name = "do_const",
111330 + .min_length = 0,
111331 + .max_length = 0,
111332 + .decl_required = false,
111333 + .type_required = false,
111334 + .function_type_required = false,
111335 + .handler = handle_do_const_attribute,
111336 +#if BUILDING_GCC_VERSION >= 4007
111337 + .affects_type_identity = true
111338 +#endif
111339 +};
111340 +
111341 +static void register_attributes(void *event_data, void *data)
111342 +{
111343 + register_attribute(&no_const_attr);
111344 + register_attribute(&do_const_attr);
111345 +}
111346 +
111347 +static void finish_type(void *event_data, void *data)
111348 +{
111349 + tree type = (tree)event_data;
111350 + constify_info cinfo = {
111351 + .has_fptr_field = false,
111352 + .has_writable_field = false,
111353 + .has_do_const_field = false,
111354 + .has_no_const_field = false
111355 + };
111356 +
111357 + if (type == NULL_TREE || type == error_mark_node)
111358 + return;
111359 +
111360 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111361 + return;
111362 +
111363 + constifiable(type, &cinfo);
111364 +
111365 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111366 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111367 + deconstify_type(type);
111368 + TYPE_CONSTIFY_VISITED(type) = 1;
111369 + } else
111370 + error("'no_const' attribute used on type %qT that is not constified", type);
111371 + return;
111372 + }
111373 +
111374 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111375 + if (!cinfo.has_writable_field) {
111376 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111377 + return;
111378 + }
111379 + constify_type(type);
111380 + return;
111381 + }
111382 +
111383 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111384 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111385 + error("'do_const' attribute used on type %qT that is constified", type);
111386 + return;
111387 + }
111388 + constify_type(type);
111389 + return;
111390 + }
111391 +
111392 + deconstify_type(type);
111393 + TYPE_CONSTIFY_VISITED(type) = 1;
111394 +}
111395 +
111396 +static void check_global_variables(void *event_data, void *data)
111397 +{
111398 +#if BUILDING_GCC_VERSION >= 4009
111399 + varpool_node *node;
111400 +#else
111401 + struct varpool_node *node;
111402 +#endif
111403 +
111404 + FOR_EACH_VARIABLE(node) {
111405 + tree var = NODE_DECL(node);
111406 + tree type = TREE_TYPE(var);
111407 +
111408 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111409 + continue;
111410 +
111411 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111412 + continue;
111413 +
111414 + if (!TYPE_CONSTIFY_VISITED(type))
111415 + continue;
111416 +
111417 + if (DECL_EXTERNAL(var))
111418 + continue;
111419 +
111420 + if (DECL_INITIAL(var))
111421 + continue;
111422 +
111423 + // this works around a gcc bug/feature where uninitialized globals
111424 + // are moved into the .bss section regardless of any constification
111425 + DECL_INITIAL(var) = build_constructor(type, NULL);
111426 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111427 + }
111428 +}
111429 +
111430 +static unsigned int check_local_variables(void)
111431 +{
111432 + unsigned int ret = 0;
111433 + tree var;
111434 +
111435 + unsigned int i;
111436 +
111437 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111438 + tree type = TREE_TYPE(var);
111439 +
111440 + gcc_assert(DECL_P(var));
111441 + if (is_global_var(var))
111442 + continue;
111443 +
111444 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111445 + continue;
111446 +
111447 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111448 + continue;
111449 +
111450 + if (!TYPE_CONSTIFY_VISITED(type))
111451 + continue;
111452 +
111453 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111454 + ret = 1;
111455 + }
111456 + return ret;
111457 +}
111458 +
111459 +#if BUILDING_GCC_VERSION >= 4009
111460 +static const struct pass_data check_local_variables_pass_data = {
111461 +#else
111462 +static struct gimple_opt_pass check_local_variables_pass = {
111463 + .pass = {
111464 +#endif
111465 + .type = GIMPLE_PASS,
111466 + .name = "check_local_variables",
111467 +#if BUILDING_GCC_VERSION >= 4008
111468 + .optinfo_flags = OPTGROUP_NONE,
111469 +#endif
111470 +#if BUILDING_GCC_VERSION >= 5000
111471 +#elif BUILDING_GCC_VERSION >= 4009
111472 + .has_gate = false,
111473 + .has_execute = true,
111474 +#else
111475 + .gate = NULL,
111476 + .execute = check_local_variables,
111477 + .sub = NULL,
111478 + .next = NULL,
111479 + .static_pass_number = 0,
111480 +#endif
111481 + .tv_id = TV_NONE,
111482 + .properties_required = 0,
111483 + .properties_provided = 0,
111484 + .properties_destroyed = 0,
111485 + .todo_flags_start = 0,
111486 + .todo_flags_finish = 0
111487 +#if BUILDING_GCC_VERSION < 4009
111488 + }
111489 +#endif
111490 +};
111491 +
111492 +#if BUILDING_GCC_VERSION >= 4009
111493 +namespace {
111494 +class check_local_variables_pass : public gimple_opt_pass {
111495 +public:
111496 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111497 + unsigned int execute() { return check_local_variables(); }
111498 +};
111499 +}
111500 +
111501 +static opt_pass *make_check_local_variables_pass(void)
111502 +{
111503 + return new check_local_variables_pass();
111504 +}
111505 +#else
111506 +static struct opt_pass *make_check_local_variables_pass(void)
111507 +{
111508 + return &check_local_variables_pass.pass;
111509 +}
111510 +#endif
111511 +
111512 +static struct {
111513 + const char *name;
111514 + const char *asm_op;
111515 +} sections[] = {
111516 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111517 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111518 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111519 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111520 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111521 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111522 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111523 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111524 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111525 +};
111526 +
111527 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111528 +
111529 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111530 +{
111531 + size_t i;
111532 +
111533 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111534 + if (!strcmp(sections[i].name, name))
111535 + return 0;
111536 + return old_section_type_flags(decl, name, reloc);
111537 +}
111538 +
111539 +static void constify_start_unit(void *gcc_data, void *user_data)
111540 +{
111541 +// size_t i;
111542 +
111543 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111544 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111545 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111546 +
111547 + old_section_type_flags = targetm.section_type_flags;
111548 + targetm.section_type_flags = constify_section_type_flags;
111549 +}
111550 +
111551 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111552 +{
111553 + const char * const plugin_name = plugin_info->base_name;
111554 + const int argc = plugin_info->argc;
111555 + const struct plugin_argument * const argv = plugin_info->argv;
111556 + int i;
111557 + bool constify = true;
111558 +
111559 + struct register_pass_info check_local_variables_pass_info;
111560 +
111561 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111562 + check_local_variables_pass_info.reference_pass_name = "ssa";
111563 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111564 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111565 +
111566 + if (!plugin_default_version_check(version, &gcc_version)) {
111567 + error(G_("incompatible gcc/plugin versions"));
111568 + return 1;
111569 + }
111570 +
111571 + for (i = 0; i < argc; ++i) {
111572 + if (!(strcmp(argv[i].key, "no-constify"))) {
111573 + constify = false;
111574 + continue;
111575 + }
111576 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111577 + }
111578 +
111579 + if (strncmp(lang_hooks.name, "GNU C", 5) && !strncmp(lang_hooks.name, "GNU C+", 6)) {
111580 + inform(UNKNOWN_LOCATION, G_("%s supports C only, not %s"), plugin_name, lang_hooks.name);
111581 + constify = false;
111582 + }
111583 +
111584 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111585 + if (constify) {
111586 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111587 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111588 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111589 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111590 + }
111591 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111592 +
111593 + return 0;
111594 +}
111595 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111596 new file mode 100644
111597 index 0000000..e90c205
111598 --- /dev/null
111599 +++ b/tools/gcc/gcc-common.h
111600 @@ -0,0 +1,295 @@
111601 +#ifndef GCC_COMMON_H_INCLUDED
111602 +#define GCC_COMMON_H_INCLUDED
111603 +
111604 +#include "plugin.h"
111605 +#include "bversion.h"
111606 +#include "plugin-version.h"
111607 +#include "config.h"
111608 +#include "system.h"
111609 +#include "coretypes.h"
111610 +#include "tm.h"
111611 +#include "line-map.h"
111612 +#include "input.h"
111613 +#include "tree.h"
111614 +
111615 +#include "tree-inline.h"
111616 +#include "version.h"
111617 +#include "rtl.h"
111618 +#include "tm_p.h"
111619 +#include "flags.h"
111620 +//#include "insn-attr.h"
111621 +//#include "insn-config.h"
111622 +//#include "insn-flags.h"
111623 +#include "hard-reg-set.h"
111624 +//#include "recog.h"
111625 +#include "output.h"
111626 +#include "except.h"
111627 +#include "function.h"
111628 +#include "toplev.h"
111629 +//#include "expr.h"
111630 +#include "basic-block.h"
111631 +#include "intl.h"
111632 +#include "ggc.h"
111633 +//#include "regs.h"
111634 +#include "timevar.h"
111635 +
111636 +#include "params.h"
111637 +#include "pointer-set.h"
111638 +#include "emit-rtl.h"
111639 +//#include "reload.h"
111640 +//#include "ira.h"
111641 +//#include "dwarf2asm.h"
111642 +#include "debug.h"
111643 +#include "target.h"
111644 +#include "langhooks.h"
111645 +#include "cfgloop.h"
111646 +//#include "hosthooks.h"
111647 +#include "cgraph.h"
111648 +#include "opts.h"
111649 +//#include "coverage.h"
111650 +//#include "value-prof.h"
111651 +
111652 +#if BUILDING_GCC_VERSION >= 4007
111653 +#include "tree-pretty-print.h"
111654 +#include "gimple-pretty-print.h"
111655 +#include "c-tree.h"
111656 +//#include "alloc-pool.h"
111657 +#endif
111658 +
111659 +#if BUILDING_GCC_VERSION <= 4008
111660 +#include "tree-flow.h"
111661 +#else
111662 +#include "tree-cfgcleanup.h"
111663 +#endif
111664 +
111665 +#include "diagnostic.h"
111666 +//#include "tree-diagnostic.h"
111667 +#include "tree-dump.h"
111668 +#include "tree-pass.h"
111669 +//#include "df.h"
111670 +#include "predict.h"
111671 +#include "ipa-utils.h"
111672 +
111673 +#if BUILDING_GCC_VERSION >= 4009
111674 +#include "varasm.h"
111675 +#include "stor-layout.h"
111676 +#include "internal-fn.h"
111677 +#include "gimple-expr.h"
111678 +//#include "diagnostic-color.h"
111679 +#include "context.h"
111680 +#include "tree-ssa-alias.h"
111681 +#include "stringpool.h"
111682 +#include "tree-ssanames.h"
111683 +#include "print-tree.h"
111684 +#include "tree-eh.h"
111685 +#include "stmt.h"
111686 +#endif
111687 +
111688 +#include "gimple.h"
111689 +
111690 +#if BUILDING_GCC_VERSION >= 4009
111691 +#include "tree-ssa-operands.h"
111692 +#include "tree-phinodes.h"
111693 +#include "tree-cfg.h"
111694 +#include "gimple-iterator.h"
111695 +#include "gimple-ssa.h"
111696 +#include "ssa-iterators.h"
111697 +#endif
111698 +
111699 +//#include "lto/lto.h"
111700 +//#include "data-streamer.h"
111701 +//#include "lto-compress.h"
111702 +
111703 +//#include "expr.h" where are you...
111704 +extern rtx emit_move_insn(rtx x, rtx y);
111705 +
111706 +// missing from basic_block.h...
111707 +extern void debug_dominance_info(enum cdi_direction dir);
111708 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111709 +
111710 +#define __unused __attribute__((__unused__))
111711 +
111712 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111713 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111714 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111715 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111716 +
111717 +#if BUILDING_GCC_VERSION == 4005
111718 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111719 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111720 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111721 +#define TODO_rebuild_cgraph_edges 0
111722 +
111723 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111724 +{
111725 + tree fndecl;
111726 +
111727 + if (!is_gimple_call(stmt))
111728 + return false;
111729 + fndecl = gimple_call_fndecl(stmt);
111730 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111731 + return false;
111732 +// print_node(stderr, "pax", fndecl, 4);
111733 + return DECL_FUNCTION_CODE(fndecl) == code;
111734 +}
111735 +
111736 +static inline bool is_simple_builtin(tree decl)
111737 +{
111738 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111739 + return false;
111740 +
111741 + switch (DECL_FUNCTION_CODE(decl)) {
111742 + /* Builtins that expand to constants. */
111743 + case BUILT_IN_CONSTANT_P:
111744 + case BUILT_IN_EXPECT:
111745 + case BUILT_IN_OBJECT_SIZE:
111746 + case BUILT_IN_UNREACHABLE:
111747 + /* Simple register moves or loads from stack. */
111748 + case BUILT_IN_RETURN_ADDRESS:
111749 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111750 + case BUILT_IN_FROB_RETURN_ADDR:
111751 + case BUILT_IN_RETURN:
111752 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111753 + case BUILT_IN_FRAME_ADDRESS:
111754 + case BUILT_IN_VA_END:
111755 + case BUILT_IN_STACK_SAVE:
111756 + case BUILT_IN_STACK_RESTORE:
111757 + /* Exception state returns or moves registers around. */
111758 + case BUILT_IN_EH_FILTER:
111759 + case BUILT_IN_EH_POINTER:
111760 + case BUILT_IN_EH_COPY_VALUES:
111761 + return true;
111762 +
111763 + default:
111764 + return false;
111765 + }
111766 +}
111767 +#endif
111768 +
111769 +#if BUILDING_GCC_VERSION <= 4006
111770 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111771 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111772 +
111773 +// should come from c-tree.h if only it were installed for gcc 4.5...
111774 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111775 +
111776 +#define get_random_seed(noinit) ({ \
111777 + unsigned HOST_WIDE_INT seed; \
111778 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111779 + seed * seed; })
111780 +
111781 +static inline bool gimple_clobber_p(gimple s)
111782 +{
111783 + return false;
111784 +}
111785 +
111786 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111787 +{
111788 + return implicit_built_in_decls[fncode];
111789 +}
111790 +
111791 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111792 +{
111793 + struct cgraph_node *node = cgraph_get_node(decl);
111794 +
111795 + return node ? node : cgraph_node(decl);
111796 +}
111797 +
111798 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111799 +{
111800 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111801 +}
111802 +
111803 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111804 +{
111805 + struct cgraph_node *node;
111806 +
111807 + for (node = cgraph_nodes; node; node = node->next)
111808 + if (cgraph_function_with_gimple_body_p(node))
111809 + return node;
111810 + return NULL;
111811 +}
111812 +
111813 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111814 +{
111815 + for (node = node->next; node; node = node->next)
111816 + if (cgraph_function_with_gimple_body_p(node))
111817 + return node;
111818 + return NULL;
111819 +}
111820 +
111821 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111822 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111823 + (node) = cgraph_next_function_with_gimple_body(node))
111824 +#endif
111825 +
111826 +#if BUILDING_GCC_VERSION == 4006
111827 +extern void debug_gimple_stmt(gimple);
111828 +extern void debug_gimple_seq(gimple_seq);
111829 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111830 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111831 +extern void print_gimple_expr(FILE *, gimple, int, int);
111832 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111833 +#endif
111834 +
111835 +#if BUILDING_GCC_VERSION <= 4007
111836 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111837 +#define PROP_loops 0
111838 +
111839 +static inline int bb_loop_depth(const_basic_block bb)
111840 +{
111841 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111842 +}
111843 +
111844 +static inline bool gimple_store_p(gimple gs)
111845 +{
111846 + tree lhs = gimple_get_lhs(gs);
111847 + return lhs && !is_gimple_reg(lhs);
111848 +}
111849 +#endif
111850 +
111851 +#if BUILDING_GCC_VERSION >= 4007
111852 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111853 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111854 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111855 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111856 +#endif
111857 +
111858 +#if BUILDING_GCC_VERSION <= 4008
111859 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111860 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111861 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111862 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111863 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111864 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111865 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111866 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111867 +
111868 +static inline const char *get_tree_code_name(enum tree_code code)
111869 +{
111870 + gcc_assert(code < MAX_TREE_CODES);
111871 + return tree_code_name[code];
111872 +}
111873 +
111874 +#define ipa_remove_stmt_references(cnode, stmt)
111875 +#endif
111876 +
111877 +#if BUILDING_GCC_VERSION == 4008
111878 +#define NODE_DECL(node) node->symbol.decl
111879 +#else
111880 +#define NODE_DECL(node) node->decl
111881 +#endif
111882 +
111883 +#if BUILDING_GCC_VERSION >= 4008
111884 +#define add_referenced_var(var)
111885 +#define mark_sym_for_renaming(var)
111886 +#define varpool_mark_needed_node(node)
111887 +#define TODO_dump_func 0
111888 +#define TODO_dump_cgraph 0
111889 +#endif
111890 +
111891 +#if BUILDING_GCC_VERSION >= 4009
111892 +#define TODO_ggc_collect 0
111893 +#endif
111894 +
111895 +#endif
111896 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111897 new file mode 100644
111898 index 0000000..7514850
111899 --- /dev/null
111900 +++ b/tools/gcc/gen-random-seed.sh
111901 @@ -0,0 +1,8 @@
111902 +#!/bin/sh
111903 +
111904 +if [ ! -f "$1" ]; then
111905 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111906 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111907 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111908 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111909 +fi
111910 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111911 new file mode 100644
111912 index 0000000..d81c094
111913 --- /dev/null
111914 +++ b/tools/gcc/kallocstat_plugin.c
111915 @@ -0,0 +1,183 @@
111916 +/*
111917 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111918 + * Licensed under the GPL v2
111919 + *
111920 + * Note: the choice of the license means that the compilation process is
111921 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111922 + * but for the kernel it doesn't matter since it doesn't link against
111923 + * any of the gcc libraries
111924 + *
111925 + * gcc plugin to find the distribution of k*alloc sizes
111926 + *
111927 + * TODO:
111928 + *
111929 + * BUGS:
111930 + * - none known
111931 + */
111932 +
111933 +#include "gcc-common.h"
111934 +
111935 +int plugin_is_GPL_compatible;
111936 +
111937 +static struct plugin_info kallocstat_plugin_info = {
111938 + .version = "201401260140",
111939 + .help = NULL
111940 +};
111941 +
111942 +static const char * const kalloc_functions[] = {
111943 + "__kmalloc",
111944 + "kmalloc",
111945 + "kmalloc_large",
111946 + "kmalloc_node",
111947 + "kmalloc_order",
111948 + "kmalloc_order_trace",
111949 + "kmalloc_slab",
111950 + "kzalloc",
111951 + "kzalloc_node",
111952 +};
111953 +
111954 +static bool is_kalloc(const char *fnname)
111955 +{
111956 + size_t i;
111957 +
111958 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111959 + if (!strcmp(fnname, kalloc_functions[i]))
111960 + return true;
111961 + return false;
111962 +}
111963 +
111964 +static unsigned int execute_kallocstat(void)
111965 +{
111966 + basic_block bb;
111967 +
111968 + // 1. loop through BBs and GIMPLE statements
111969 + FOR_EACH_BB_FN(bb, cfun) {
111970 + gimple_stmt_iterator gsi;
111971 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111972 + // gimple match:
111973 + tree fndecl, size;
111974 + gimple stmt;
111975 + const char *fnname;
111976 +
111977 + // is it a call
111978 + stmt = gsi_stmt(gsi);
111979 + if (!is_gimple_call(stmt))
111980 + continue;
111981 + fndecl = gimple_call_fndecl(stmt);
111982 + if (fndecl == NULL_TREE)
111983 + continue;
111984 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111985 + continue;
111986 +
111987 + // is it a call to k*alloc
111988 + fnname = DECL_NAME_POINTER(fndecl);
111989 + if (!is_kalloc(fnname))
111990 + continue;
111991 +
111992 + // is the size arg const or the result of a simple const assignment
111993 + size = gimple_call_arg(stmt, 0);
111994 + while (true) {
111995 + expanded_location xloc;
111996 + size_t size_val;
111997 +
111998 + if (TREE_CONSTANT(size)) {
111999 + xloc = expand_location(gimple_location(stmt));
112000 + if (!xloc.file)
112001 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112002 + size_val = TREE_INT_CST_LOW(size);
112003 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
112004 + break;
112005 + }
112006 +
112007 + if (TREE_CODE(size) != SSA_NAME)
112008 + break;
112009 + stmt = SSA_NAME_DEF_STMT(size);
112010 +//debug_gimple_stmt(stmt);
112011 +//debug_tree(size);
112012 + if (!stmt || !is_gimple_assign(stmt))
112013 + break;
112014 + if (gimple_num_ops(stmt) != 2)
112015 + break;
112016 + size = gimple_assign_rhs1(stmt);
112017 + }
112018 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112019 +//debug_tree(gimple_call_fn(call_stmt));
112020 +//print_node(stderr, "pax", fndecl, 4);
112021 + }
112022 + }
112023 +
112024 + return 0;
112025 +}
112026 +
112027 +#if BUILDING_GCC_VERSION >= 4009
112028 +static const struct pass_data kallocstat_pass_data = {
112029 +#else
112030 +static struct gimple_opt_pass kallocstat_pass = {
112031 + .pass = {
112032 +#endif
112033 + .type = GIMPLE_PASS,
112034 + .name = "kallocstat",
112035 +#if BUILDING_GCC_VERSION >= 4008
112036 + .optinfo_flags = OPTGROUP_NONE,
112037 +#endif
112038 +#if BUILDING_GCC_VERSION >= 4009
112039 + .has_gate = false,
112040 + .has_execute = true,
112041 +#else
112042 + .gate = NULL,
112043 + .execute = execute_kallocstat,
112044 + .sub = NULL,
112045 + .next = NULL,
112046 + .static_pass_number = 0,
112047 +#endif
112048 + .tv_id = TV_NONE,
112049 + .properties_required = 0,
112050 + .properties_provided = 0,
112051 + .properties_destroyed = 0,
112052 + .todo_flags_start = 0,
112053 + .todo_flags_finish = 0
112054 +#if BUILDING_GCC_VERSION < 4009
112055 + }
112056 +#endif
112057 +};
112058 +
112059 +#if BUILDING_GCC_VERSION >= 4009
112060 +namespace {
112061 +class kallocstat_pass : public gimple_opt_pass {
112062 +public:
112063 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
112064 + unsigned int execute() { return execute_kallocstat(); }
112065 +};
112066 +}
112067 +
112068 +static opt_pass *make_kallocstat_pass(void)
112069 +{
112070 + return new kallocstat_pass();
112071 +}
112072 +#else
112073 +static struct opt_pass *make_kallocstat_pass(void)
112074 +{
112075 + return &kallocstat_pass.pass;
112076 +}
112077 +#endif
112078 +
112079 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112080 +{
112081 + const char * const plugin_name = plugin_info->base_name;
112082 + struct register_pass_info kallocstat_pass_info;
112083 +
112084 + kallocstat_pass_info.pass = make_kallocstat_pass();
112085 + kallocstat_pass_info.reference_pass_name = "ssa";
112086 + kallocstat_pass_info.ref_pass_instance_number = 1;
112087 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112088 +
112089 + if (!plugin_default_version_check(version, &gcc_version)) {
112090 + error(G_("incompatible gcc/plugin versions"));
112091 + return 1;
112092 + }
112093 +
112094 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112095 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112096 +
112097 + return 0;
112098 +}
112099 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112100 new file mode 100644
112101 index 0000000..89f256d
112102 --- /dev/null
112103 +++ b/tools/gcc/kernexec_plugin.c
112104 @@ -0,0 +1,522 @@
112105 +/*
112106 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112107 + * Licensed under the GPL v2
112108 + *
112109 + * Note: the choice of the license means that the compilation process is
112110 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112111 + * but for the kernel it doesn't matter since it doesn't link against
112112 + * any of the gcc libraries
112113 + *
112114 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112115 + *
112116 + * TODO:
112117 + *
112118 + * BUGS:
112119 + * - none known
112120 + */
112121 +
112122 +#include "gcc-common.h"
112123 +
112124 +int plugin_is_GPL_compatible;
112125 +
112126 +static struct plugin_info kernexec_plugin_info = {
112127 + .version = "201401260140",
112128 + .help = "method=[bts|or]\tinstrumentation method\n"
112129 +};
112130 +
112131 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112132 +static void (*kernexec_instrument_retaddr)(rtx);
112133 +
112134 +/*
112135 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112136 + */
112137 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112138 +{
112139 + gimple asm_movabs_stmt;
112140 +
112141 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112142 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112143 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112144 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112145 + update_stmt(asm_movabs_stmt);
112146 +}
112147 +
112148 +/*
112149 + * find all asm() stmts that clobber r12 and add a reload of r12
112150 + */
112151 +static unsigned int execute_kernexec_reload(void)
112152 +{
112153 + basic_block bb;
112154 +
112155 + // 1. loop through BBs and GIMPLE statements
112156 + FOR_EACH_BB_FN(bb, cfun) {
112157 + gimple_stmt_iterator gsi;
112158 +
112159 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112160 + // gimple match: __asm__ ("" : : : "r12");
112161 + gimple asm_stmt;
112162 + size_t nclobbers;
112163 +
112164 + // is it an asm ...
112165 + asm_stmt = gsi_stmt(gsi);
112166 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112167 + continue;
112168 +
112169 + // ... clobbering r12
112170 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112171 + while (nclobbers--) {
112172 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112173 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112174 + continue;
112175 + kernexec_reload_fptr_mask(&gsi);
112176 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112177 + break;
112178 + }
112179 + }
112180 + }
112181 +
112182 + return 0;
112183 +}
112184 +
112185 +/*
112186 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112187 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112188 + */
112189 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112190 +{
112191 + gimple assign_intptr, assign_new_fptr, call_stmt;
112192 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112193 +
112194 + call_stmt = gsi_stmt(*gsi);
112195 + old_fptr = gimple_call_fn(call_stmt);
112196 +
112197 + // create temporary unsigned long variable used for bitops and cast fptr to it
112198 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112199 + add_referenced_var(intptr);
112200 + intptr = make_ssa_name(intptr, NULL);
112201 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112202 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112203 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112204 + update_stmt(assign_intptr);
112205 +
112206 + // apply logical or to temporary unsigned long and bitmask
112207 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112208 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112209 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112210 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112211 + assign_intptr = gimple_build_assign(intptr, orptr);
112212 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112213 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112214 + update_stmt(assign_intptr);
112215 +
112216 + // cast temporary unsigned long back to a temporary fptr variable
112217 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112218 + add_referenced_var(new_fptr);
112219 + new_fptr = make_ssa_name(new_fptr, NULL);
112220 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112221 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112222 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112223 + update_stmt(assign_new_fptr);
112224 +
112225 + // replace call stmt fn with the new fptr
112226 + gimple_call_set_fn(call_stmt, new_fptr);
112227 + update_stmt(call_stmt);
112228 +}
112229 +
112230 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112231 +{
112232 + gimple asm_or_stmt, call_stmt;
112233 + tree old_fptr, new_fptr, input, output;
112234 +#if BUILDING_GCC_VERSION <= 4007
112235 + VEC(tree, gc) *inputs = NULL;
112236 + VEC(tree, gc) *outputs = NULL;
112237 +#else
112238 + vec<tree, va_gc> *inputs = NULL;
112239 + vec<tree, va_gc> *outputs = NULL;
112240 +#endif
112241 +
112242 + call_stmt = gsi_stmt(*gsi);
112243 + old_fptr = gimple_call_fn(call_stmt);
112244 +
112245 + // create temporary fptr variable
112246 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112247 + add_referenced_var(new_fptr);
112248 + new_fptr = make_ssa_name(new_fptr, NULL);
112249 +
112250 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112251 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112252 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112253 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112254 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112255 +#if BUILDING_GCC_VERSION <= 4007
112256 + VEC_safe_push(tree, gc, inputs, input);
112257 + VEC_safe_push(tree, gc, outputs, output);
112258 +#else
112259 + vec_safe_push(inputs, input);
112260 + vec_safe_push(outputs, output);
112261 +#endif
112262 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112263 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112264 + gimple_asm_set_volatile(asm_or_stmt, true);
112265 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112266 + update_stmt(asm_or_stmt);
112267 +
112268 + // replace call stmt fn with the new fptr
112269 + gimple_call_set_fn(call_stmt, new_fptr);
112270 + update_stmt(call_stmt);
112271 +}
112272 +
112273 +/*
112274 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112275 + */
112276 +static unsigned int execute_kernexec_fptr(void)
112277 +{
112278 + basic_block bb;
112279 +
112280 + // 1. loop through BBs and GIMPLE statements
112281 + FOR_EACH_BB_FN(bb, cfun) {
112282 + gimple_stmt_iterator gsi;
112283 +
112284 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112285 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112286 + tree fn;
112287 + gimple call_stmt;
112288 +
112289 + // is it a call ...
112290 + call_stmt = gsi_stmt(gsi);
112291 + if (!is_gimple_call(call_stmt))
112292 + continue;
112293 + fn = gimple_call_fn(call_stmt);
112294 + if (TREE_CODE(fn) == ADDR_EXPR)
112295 + continue;
112296 + if (TREE_CODE(fn) != SSA_NAME)
112297 + gcc_unreachable();
112298 +
112299 + // ... through a function pointer
112300 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112301 + fn = SSA_NAME_VAR(fn);
112302 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112303 + debug_tree(fn);
112304 + gcc_unreachable();
112305 + }
112306 + }
112307 + fn = TREE_TYPE(fn);
112308 + if (TREE_CODE(fn) != POINTER_TYPE)
112309 + continue;
112310 + fn = TREE_TYPE(fn);
112311 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112312 + continue;
112313 +
112314 + kernexec_instrument_fptr(&gsi);
112315 +
112316 +//debug_tree(gimple_call_fn(call_stmt));
112317 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112318 + }
112319 + }
112320 +
112321 + return 0;
112322 +}
112323 +
112324 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112325 +static void kernexec_instrument_retaddr_bts(rtx insn)
112326 +{
112327 + rtx btsq;
112328 + rtvec argvec, constraintvec, labelvec;
112329 + int line;
112330 +
112331 + // create asm volatile("btsq $63,(%%rsp)":::)
112332 + argvec = rtvec_alloc(0);
112333 + constraintvec = rtvec_alloc(0);
112334 + labelvec = rtvec_alloc(0);
112335 + line = expand_location(RTL_LOCATION(insn)).line;
112336 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112337 + MEM_VOLATILE_P(btsq) = 1;
112338 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112339 + emit_insn_before(btsq, insn);
112340 +}
112341 +
112342 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112343 +static void kernexec_instrument_retaddr_or(rtx insn)
112344 +{
112345 + rtx orq;
112346 + rtvec argvec, constraintvec, labelvec;
112347 + int line;
112348 +
112349 + // create asm volatile("orq %%r12,(%%rsp)":::)
112350 + argvec = rtvec_alloc(0);
112351 + constraintvec = rtvec_alloc(0);
112352 + labelvec = rtvec_alloc(0);
112353 + line = expand_location(RTL_LOCATION(insn)).line;
112354 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112355 + MEM_VOLATILE_P(orq) = 1;
112356 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112357 + emit_insn_before(orq, insn);
112358 +}
112359 +
112360 +/*
112361 + * find all asm level function returns and forcibly set the highest bit of the return address
112362 + */
112363 +static unsigned int execute_kernexec_retaddr(void)
112364 +{
112365 + rtx insn;
112366 +
112367 +// if (stack_realign_drap)
112368 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112369 +
112370 + // 1. find function returns
112371 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112372 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112373 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112374 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112375 + rtx body;
112376 +
112377 + // is it a retn
112378 + if (!JUMP_P(insn))
112379 + continue;
112380 + body = PATTERN(insn);
112381 + if (GET_CODE(body) == PARALLEL)
112382 + body = XVECEXP(body, 0, 0);
112383 + if (!ANY_RETURN_P(body))
112384 + continue;
112385 + kernexec_instrument_retaddr(insn);
112386 + }
112387 +
112388 +// print_simple_rtl(stderr, get_insns());
112389 +// print_rtl(stderr, get_insns());
112390 +
112391 + return 0;
112392 +}
112393 +
112394 +static bool kernexec_cmodel_check(void)
112395 +{
112396 + tree section;
112397 +
112398 + if (ix86_cmodel != CM_KERNEL)
112399 + return false;
112400 +
112401 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112402 + if (!section || !TREE_VALUE(section))
112403 + return true;
112404 +
112405 + section = TREE_VALUE(TREE_VALUE(section));
112406 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112407 + return true;
112408 +
112409 + return false;
112410 +}
112411 +
112412 +#if BUILDING_GCC_VERSION >= 4009
112413 +static const struct pass_data kernexec_reload_pass_data = {
112414 +#else
112415 +static struct gimple_opt_pass kernexec_reload_pass = {
112416 + .pass = {
112417 +#endif
112418 + .type = GIMPLE_PASS,
112419 + .name = "kernexec_reload",
112420 +#if BUILDING_GCC_VERSION >= 4008
112421 + .optinfo_flags = OPTGROUP_NONE,
112422 +#endif
112423 +#if BUILDING_GCC_VERSION >= 4009
112424 + .has_gate = true,
112425 + .has_execute = true,
112426 +#else
112427 + .gate = kernexec_cmodel_check,
112428 + .execute = execute_kernexec_reload,
112429 + .sub = NULL,
112430 + .next = NULL,
112431 + .static_pass_number = 0,
112432 +#endif
112433 + .tv_id = TV_NONE,
112434 + .properties_required = 0,
112435 + .properties_provided = 0,
112436 + .properties_destroyed = 0,
112437 + .todo_flags_start = 0,
112438 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112439 +#if BUILDING_GCC_VERSION < 4009
112440 + }
112441 +#endif
112442 +};
112443 +
112444 +#if BUILDING_GCC_VERSION >= 4009
112445 +static const struct pass_data kernexec_fptr_pass_data = {
112446 +#else
112447 +static struct gimple_opt_pass kernexec_fptr_pass = {
112448 + .pass = {
112449 +#endif
112450 + .type = GIMPLE_PASS,
112451 + .name = "kernexec_fptr",
112452 +#if BUILDING_GCC_VERSION >= 4008
112453 + .optinfo_flags = OPTGROUP_NONE,
112454 +#endif
112455 +#if BUILDING_GCC_VERSION >= 4009
112456 + .has_gate = true,
112457 + .has_execute = true,
112458 +#else
112459 + .gate = kernexec_cmodel_check,
112460 + .execute = execute_kernexec_fptr,
112461 + .sub = NULL,
112462 + .next = NULL,
112463 + .static_pass_number = 0,
112464 +#endif
112465 + .tv_id = TV_NONE,
112466 + .properties_required = 0,
112467 + .properties_provided = 0,
112468 + .properties_destroyed = 0,
112469 + .todo_flags_start = 0,
112470 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112471 +#if BUILDING_GCC_VERSION < 4009
112472 + }
112473 +#endif
112474 +};
112475 +
112476 +#if BUILDING_GCC_VERSION >= 4009
112477 +static const struct pass_data kernexec_retaddr_pass_data = {
112478 +#else
112479 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112480 + .pass = {
112481 +#endif
112482 + .type = RTL_PASS,
112483 + .name = "kernexec_retaddr",
112484 +#if BUILDING_GCC_VERSION >= 4008
112485 + .optinfo_flags = OPTGROUP_NONE,
112486 +#endif
112487 +#if BUILDING_GCC_VERSION >= 4009
112488 + .has_gate = true,
112489 + .has_execute = true,
112490 +#else
112491 + .gate = kernexec_cmodel_check,
112492 + .execute = execute_kernexec_retaddr,
112493 + .sub = NULL,
112494 + .next = NULL,
112495 + .static_pass_number = 0,
112496 +#endif
112497 + .tv_id = TV_NONE,
112498 + .properties_required = 0,
112499 + .properties_provided = 0,
112500 + .properties_destroyed = 0,
112501 + .todo_flags_start = 0,
112502 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112503 +#if BUILDING_GCC_VERSION < 4009
112504 + }
112505 +#endif
112506 +};
112507 +
112508 +#if BUILDING_GCC_VERSION >= 4009
112509 +namespace {
112510 +class kernexec_reload_pass : public gimple_opt_pass {
112511 +public:
112512 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112513 + bool gate() { return kernexec_cmodel_check(); }
112514 + unsigned int execute() { return execute_kernexec_reload(); }
112515 +};
112516 +
112517 +class kernexec_fptr_pass : public gimple_opt_pass {
112518 +public:
112519 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112520 + bool gate() { return kernexec_cmodel_check(); }
112521 + unsigned int execute() { return execute_kernexec_fptr(); }
112522 +};
112523 +
112524 +class kernexec_retaddr_pass : public rtl_opt_pass {
112525 +public:
112526 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112527 + bool gate() { return kernexec_cmodel_check(); }
112528 + unsigned int execute() { return execute_kernexec_retaddr(); }
112529 +};
112530 +}
112531 +
112532 +static opt_pass *make_kernexec_reload_pass(void)
112533 +{
112534 + return new kernexec_reload_pass();
112535 +}
112536 +
112537 +static opt_pass *make_kernexec_fptr_pass(void)
112538 +{
112539 + return new kernexec_fptr_pass();
112540 +}
112541 +
112542 +static opt_pass *make_kernexec_retaddr_pass(void)
112543 +{
112544 + return new kernexec_retaddr_pass();
112545 +}
112546 +#else
112547 +static struct opt_pass *make_kernexec_reload_pass(void)
112548 +{
112549 + return &kernexec_reload_pass.pass;
112550 +}
112551 +
112552 +static struct opt_pass *make_kernexec_fptr_pass(void)
112553 +{
112554 + return &kernexec_fptr_pass.pass;
112555 +}
112556 +
112557 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112558 +{
112559 + return &kernexec_retaddr_pass.pass;
112560 +}
112561 +#endif
112562 +
112563 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112564 +{
112565 + const char * const plugin_name = plugin_info->base_name;
112566 + const int argc = plugin_info->argc;
112567 + const struct plugin_argument * const argv = plugin_info->argv;
112568 + int i;
112569 + struct register_pass_info kernexec_reload_pass_info;
112570 + struct register_pass_info kernexec_fptr_pass_info;
112571 + struct register_pass_info kernexec_retaddr_pass_info;
112572 +
112573 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112574 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112575 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112576 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112577 +
112578 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112579 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112580 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112581 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112582 +
112583 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112584 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112585 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112586 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112587 +
112588 + if (!plugin_default_version_check(version, &gcc_version)) {
112589 + error(G_("incompatible gcc/plugin versions"));
112590 + return 1;
112591 + }
112592 +
112593 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112594 +
112595 + if (TARGET_64BIT == 0)
112596 + return 0;
112597 +
112598 + for (i = 0; i < argc; ++i) {
112599 + if (!strcmp(argv[i].key, "method")) {
112600 + if (!argv[i].value) {
112601 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112602 + continue;
112603 + }
112604 + if (!strcmp(argv[i].value, "bts")) {
112605 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112606 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112607 + } else if (!strcmp(argv[i].value, "or")) {
112608 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112609 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112610 + fix_register("r12", 1, 1);
112611 + } else
112612 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112613 + continue;
112614 + }
112615 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112616 + }
112617 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112618 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112619 +
112620 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112621 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112622 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112623 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112624 +
112625 + return 0;
112626 +}
112627 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112628 new file mode 100644
112629 index 0000000..e48b323
112630 --- /dev/null
112631 +++ b/tools/gcc/latent_entropy_plugin.c
112632 @@ -0,0 +1,466 @@
112633 +/*
112634 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112635 + * Licensed under the GPL v2
112636 + *
112637 + * Note: the choice of the license means that the compilation process is
112638 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112639 + * but for the kernel it doesn't matter since it doesn't link against
112640 + * any of the gcc libraries
112641 + *
112642 + * gcc plugin to help generate a little bit of entropy from program state,
112643 + * used throughout the uptime of the kernel
112644 + *
112645 + * TODO:
112646 + * - add ipa pass to identify not explicitly marked candidate functions
112647 + * - mix in more program state (function arguments/return values, loop variables, etc)
112648 + * - more instrumentation control via attribute parameters
112649 + *
112650 + * BUGS:
112651 + * - LTO needs -flto-partition=none for now
112652 + */
112653 +
112654 +#include "gcc-common.h"
112655 +
112656 +int plugin_is_GPL_compatible;
112657 +
112658 +static tree latent_entropy_decl;
112659 +
112660 +static struct plugin_info latent_entropy_plugin_info = {
112661 + .version = "201409101820",
112662 + .help = NULL
112663 +};
112664 +
112665 +static unsigned HOST_WIDE_INT seed;
112666 +static unsigned HOST_WIDE_INT get_random_const(void)
112667 +{
112668 + unsigned int i;
112669 + unsigned HOST_WIDE_INT ret = 0;
112670 +
112671 + for (i = 0; i < 8 * sizeof ret; i++) {
112672 + ret = (ret << 1) | (seed & 1);
112673 + seed >>= 1;
112674 + if (ret & 1)
112675 + seed ^= 0xD800000000000000ULL;
112676 + }
112677 +
112678 + return ret;
112679 +}
112680 +
112681 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112682 +{
112683 + tree type;
112684 + unsigned long long mask;
112685 +#if BUILDING_GCC_VERSION <= 4007
112686 + VEC(constructor_elt, gc) *vals;
112687 +#else
112688 + vec<constructor_elt, va_gc> *vals;
112689 +#endif
112690 +
112691 + switch (TREE_CODE(*node)) {
112692 + default:
112693 + *no_add_attrs = true;
112694 + error("%qE attribute only applies to functions and variables", name);
112695 + break;
112696 +
112697 + case VAR_DECL:
112698 + if (DECL_INITIAL(*node)) {
112699 + *no_add_attrs = true;
112700 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112701 + break;
112702 + }
112703 +
112704 + if (!TREE_STATIC(*node)) {
112705 + *no_add_attrs = true;
112706 + error("variable %qD with %qE attribute must not be local", *node, name);
112707 + break;
112708 + }
112709 +
112710 + type = TREE_TYPE(*node);
112711 + switch (TREE_CODE(type)) {
112712 + default:
112713 + *no_add_attrs = true;
112714 + 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);
112715 + break;
112716 +
112717 + case RECORD_TYPE: {
112718 + tree field;
112719 + unsigned int nelt = 0;
112720 +
112721 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112722 + tree fieldtype;
112723 +
112724 + fieldtype = TREE_TYPE(field);
112725 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112726 + *no_add_attrs = true;
112727 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112728 + break;
112729 + }
112730 + }
112731 +
112732 + if (field)
112733 + break;
112734 +
112735 +#if BUILDING_GCC_VERSION <= 4007
112736 + vals = VEC_alloc(constructor_elt, gc, nelt);
112737 +#else
112738 + vec_alloc(vals, nelt);
112739 +#endif
112740 +
112741 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112742 + tree fieldtype;
112743 +
112744 + fieldtype = TREE_TYPE(field);
112745 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112746 + mask = 2 * (mask - 1) + 1;
112747 +
112748 + if (TYPE_UNSIGNED(fieldtype))
112749 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112750 + else
112751 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112752 + }
112753 +
112754 + DECL_INITIAL(*node) = build_constructor(type, vals);
112755 +//debug_tree(DECL_INITIAL(*node));
112756 + break;
112757 + }
112758 +
112759 + case INTEGER_TYPE:
112760 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112761 + mask = 2 * (mask - 1) + 1;
112762 +
112763 + if (TYPE_UNSIGNED(type))
112764 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112765 + else
112766 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112767 + break;
112768 +
112769 + case ARRAY_TYPE: {
112770 + tree elt_type, array_size, elt_size;
112771 + unsigned int i, nelt;
112772 +
112773 + elt_type = TREE_TYPE(type);
112774 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112775 + array_size = TYPE_SIZE_UNIT(type);
112776 +
112777 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112778 + *no_add_attrs = true;
112779 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112780 + break;
112781 + }
112782 +
112783 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112784 +#if BUILDING_GCC_VERSION <= 4007
112785 + vals = VEC_alloc(constructor_elt, gc, nelt);
112786 +#else
112787 + vec_alloc(vals, nelt);
112788 +#endif
112789 +
112790 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112791 + mask = 2 * (mask - 1) + 1;
112792 +
112793 + for (i = 0; i < nelt; i++)
112794 + if (TYPE_UNSIGNED(elt_type))
112795 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112796 + else
112797 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112798 +
112799 + DECL_INITIAL(*node) = build_constructor(type, vals);
112800 +//debug_tree(DECL_INITIAL(*node));
112801 + break;
112802 + }
112803 + }
112804 + break;
112805 +
112806 + case FUNCTION_DECL:
112807 + break;
112808 + }
112809 +
112810 + return NULL_TREE;
112811 +}
112812 +
112813 +static struct attribute_spec latent_entropy_attr = {
112814 + .name = "latent_entropy",
112815 + .min_length = 0,
112816 + .max_length = 0,
112817 + .decl_required = true,
112818 + .type_required = false,
112819 + .function_type_required = false,
112820 + .handler = handle_latent_entropy_attribute,
112821 +#if BUILDING_GCC_VERSION >= 4007
112822 + .affects_type_identity = false
112823 +#endif
112824 +};
112825 +
112826 +static void register_attributes(void *event_data, void *data)
112827 +{
112828 + register_attribute(&latent_entropy_attr);
112829 +}
112830 +
112831 +static bool gate_latent_entropy(void)
112832 +{
112833 + // don't bother with noreturn functions for now
112834 + if (TREE_THIS_VOLATILE(current_function_decl))
112835 + return false;
112836 +
112837 + // gcc-4.5 doesn't discover some trivial noreturn functions
112838 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112839 + return false;
112840 +
112841 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112842 +}
112843 +
112844 +static enum tree_code get_op(tree *rhs)
112845 +{
112846 + static enum tree_code op;
112847 + unsigned HOST_WIDE_INT random_const;
112848 +
112849 + random_const = get_random_const();
112850 +
112851 + switch (op) {
112852 + case BIT_XOR_EXPR:
112853 + op = PLUS_EXPR;
112854 + break;
112855 +
112856 + case PLUS_EXPR:
112857 + if (rhs) {
112858 + op = LROTATE_EXPR;
112859 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112860 + break;
112861 + }
112862 +
112863 + case LROTATE_EXPR:
112864 + default:
112865 + op = BIT_XOR_EXPR;
112866 + break;
112867 + }
112868 + if (rhs)
112869 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112870 + return op;
112871 +}
112872 +
112873 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112874 +{
112875 + gimple_stmt_iterator gsi;
112876 + gimple assign;
112877 + tree addxorrol, rhs;
112878 + enum tree_code op;
112879 +
112880 + op = get_op(&rhs);
112881 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112882 + assign = gimple_build_assign(local_entropy, addxorrol);
112883 + gsi = gsi_after_labels(bb);
112884 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112885 + update_stmt(assign);
112886 +//debug_bb(bb);
112887 +}
112888 +
112889 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112890 +{
112891 + gimple_stmt_iterator gsi;
112892 + gimple assign;
112893 + tree addxorrol, temp;
112894 +
112895 + // 1. create temporary copy of latent_entropy
112896 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112897 + add_referenced_var(temp);
112898 +
112899 + // 2. read...
112900 + temp = make_ssa_name(temp, NULL);
112901 + assign = gimple_build_assign(temp, latent_entropy_decl);
112902 + SSA_NAME_DEF_STMT(temp) = assign;
112903 + add_referenced_var(latent_entropy_decl);
112904 + gsi = gsi_after_labels(bb);
112905 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112906 + update_stmt(assign);
112907 +
112908 + // 3. ...modify...
112909 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112910 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112911 + assign = gimple_build_assign(temp, addxorrol);
112912 + SSA_NAME_DEF_STMT(temp) = assign;
112913 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112914 + update_stmt(assign);
112915 +
112916 + // 4. ...write latent_entropy
112917 + assign = gimple_build_assign(latent_entropy_decl, temp);
112918 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112919 + update_stmt(assign);
112920 +}
112921 +
112922 +static unsigned int execute_latent_entropy(void)
112923 +{
112924 + basic_block bb;
112925 + gimple assign;
112926 + gimple_stmt_iterator gsi;
112927 + tree local_entropy;
112928 +
112929 + if (!latent_entropy_decl) {
112930 +#if BUILDING_GCC_VERSION >= 4009
112931 + varpool_node *node;
112932 +#else
112933 + struct varpool_node *node;
112934 +#endif
112935 +
112936 + FOR_EACH_VARIABLE(node) {
112937 + tree var = NODE_DECL(node);
112938 +
112939 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112940 + continue;
112941 + latent_entropy_decl = var;
112942 +// debug_tree(var);
112943 + break;
112944 + }
112945 + if (!latent_entropy_decl) {
112946 +// debug_tree(current_function_decl);
112947 + return 0;
112948 + }
112949 + }
112950 +
112951 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112952 +
112953 + // 1. create local entropy variable
112954 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112955 + add_referenced_var(local_entropy);
112956 + mark_sym_for_renaming(local_entropy);
112957 +
112958 + // 2. initialize local entropy variable
112959 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112960 + if (dom_info_available_p(CDI_DOMINATORS))
112961 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112962 + gsi = gsi_start_bb(bb);
112963 +
112964 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112965 +// gimple_set_location(assign, loc);
112966 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112967 + update_stmt(assign);
112968 +//debug_bb(bb);
112969 + gcc_assert(single_succ_p(bb));
112970 + bb = single_succ(bb);
112971 +
112972 + // 3. instrument each BB with an operation on the local entropy variable
112973 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112974 + perturb_local_entropy(bb, local_entropy);
112975 +//debug_bb(bb);
112976 + bb = bb->next_bb;
112977 + };
112978 +
112979 + // 4. mix local entropy into the global entropy variable
112980 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112981 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112982 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112983 + return 0;
112984 +}
112985 +
112986 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112987 +{
112988 + tree latent_entropy_type;
112989 +
112990 + seed = get_random_seed(false);
112991 +
112992 + if (in_lto_p)
112993 + return;
112994 +
112995 + // extern volatile u64 latent_entropy
112996 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112997 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112998 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112999 +
113000 + TREE_STATIC(latent_entropy_decl) = 1;
113001 + TREE_PUBLIC(latent_entropy_decl) = 1;
113002 + TREE_USED(latent_entropy_decl) = 1;
113003 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
113004 + DECL_EXTERNAL(latent_entropy_decl) = 1;
113005 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
113006 + lang_hooks.decls.pushdecl(latent_entropy_decl);
113007 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
113008 +// varpool_finalize_decl(latent_entropy_decl);
113009 +// varpool_mark_needed_node(latent_entropy_decl);
113010 +}
113011 +
113012 +#if BUILDING_GCC_VERSION >= 4009
113013 +static const struct pass_data latent_entropy_pass_data = {
113014 +#else
113015 +static struct gimple_opt_pass latent_entropy_pass = {
113016 + .pass = {
113017 +#endif
113018 + .type = GIMPLE_PASS,
113019 + .name = "latent_entropy",
113020 +#if BUILDING_GCC_VERSION >= 4008
113021 + .optinfo_flags = OPTGROUP_NONE,
113022 +#endif
113023 +#if BUILDING_GCC_VERSION >= 4009
113024 + .has_gate = true,
113025 + .has_execute = true,
113026 +#else
113027 + .gate = gate_latent_entropy,
113028 + .execute = execute_latent_entropy,
113029 + .sub = NULL,
113030 + .next = NULL,
113031 + .static_pass_number = 0,
113032 +#endif
113033 + .tv_id = TV_NONE,
113034 + .properties_required = PROP_gimple_leh | PROP_cfg,
113035 + .properties_provided = 0,
113036 + .properties_destroyed = 0,
113037 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
113038 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
113039 +#if BUILDING_GCC_VERSION < 4009
113040 + }
113041 +#endif
113042 +};
113043 +
113044 +#if BUILDING_GCC_VERSION >= 4009
113045 +namespace {
113046 +class latent_entropy_pass : public gimple_opt_pass {
113047 +public:
113048 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
113049 + bool gate() { return gate_latent_entropy(); }
113050 + unsigned int execute() { return execute_latent_entropy(); }
113051 +};
113052 +}
113053 +
113054 +static opt_pass *make_latent_entropy_pass(void)
113055 +{
113056 + return new latent_entropy_pass();
113057 +}
113058 +#else
113059 +static struct opt_pass *make_latent_entropy_pass(void)
113060 +{
113061 + return &latent_entropy_pass.pass;
113062 +}
113063 +#endif
113064 +
113065 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113066 +{
113067 + const char * const plugin_name = plugin_info->base_name;
113068 + struct register_pass_info latent_entropy_pass_info;
113069 +
113070 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
113071 + latent_entropy_pass_info.reference_pass_name = "optimized";
113072 + latent_entropy_pass_info.ref_pass_instance_number = 1;
113073 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
113074 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
113075 + {
113076 + .base = &latent_entropy_decl,
113077 + .nelt = 1,
113078 + .stride = sizeof(latent_entropy_decl),
113079 + .cb = &gt_ggc_mx_tree_node,
113080 + .pchw = &gt_pch_nx_tree_node
113081 + },
113082 + LAST_GGC_ROOT_TAB
113083 + };
113084 +
113085 + if (!plugin_default_version_check(version, &gcc_version)) {
113086 + error(G_("incompatible gcc/plugin versions"));
113087 + return 1;
113088 + }
113089 +
113090 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
113091 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
113092 + if (!in_lto_p)
113093 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
113094 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113095 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113096 +
113097 + return 0;
113098 +}
113099 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113100 new file mode 100644
113101 index 0000000..a5cb46b
113102 --- /dev/null
113103 +++ b/tools/gcc/randomize_layout_plugin.c
113104 @@ -0,0 +1,915 @@
113105 +/*
113106 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113107 + * and PaX Team <pageexec@freemail.hu>
113108 + * Licensed under the GPL v2
113109 + *
113110 + * Usage:
113111 + * $ # for 4.5/4.6/C based 4.7
113112 + * $ 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
113113 + * $ # for C++ based 4.7/4.8+
113114 + * $ 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
113115 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113116 + */
113117 +
113118 +#include "gcc-common.h"
113119 +#include "randomize_layout_seed.h"
113120 +
113121 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113122 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113123 +#endif
113124 +
113125 +#define ORIG_TYPE_NAME(node) \
113126 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113127 +
113128 +int plugin_is_GPL_compatible;
113129 +
113130 +static int performance_mode;
113131 +
113132 +static struct plugin_info randomize_layout_plugin_info = {
113133 + .version = "201402201816",
113134 + .help = "disable\t\t\tdo not activate plugin\n"
113135 + "performance-mode\tenable cacheline-aware layout randomization\n"
113136 +};
113137 +
113138 +/* from old Linux dcache.h */
113139 +static inline unsigned long
113140 +partial_name_hash(unsigned long c, unsigned long prevhash)
113141 +{
113142 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113143 +}
113144 +static inline unsigned int
113145 +name_hash(const unsigned char *name)
113146 +{
113147 + unsigned long hash = 0;
113148 + unsigned int len = strlen((const char *)name);
113149 + while (len--)
113150 + hash = partial_name_hash(*name++, hash);
113151 + return (unsigned int)hash;
113152 +}
113153 +
113154 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113155 +{
113156 + tree type;
113157 +
113158 + *no_add_attrs = true;
113159 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113160 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113161 + return NULL_TREE;
113162 + }
113163 +
113164 + if (TREE_CODE(*node) == PARM_DECL) {
113165 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113166 + return NULL_TREE;
113167 + }
113168 +
113169 + if (TREE_CODE(*node) == VAR_DECL) {
113170 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113171 + return NULL_TREE;
113172 + }
113173 +
113174 + if (TYPE_P(*node)) {
113175 + type = *node;
113176 + } else {
113177 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113178 + type = TREE_TYPE(*node);
113179 + }
113180 +
113181 + if (TREE_CODE(type) != RECORD_TYPE) {
113182 + error("%qE attribute used on %qT applies to struct types only", name, type);
113183 + return NULL_TREE;
113184 + }
113185 +
113186 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113187 + error("%qE attribute is already applied to the type %qT", name, type);
113188 + return NULL_TREE;
113189 + }
113190 +
113191 + *no_add_attrs = false;
113192 +
113193 + return NULL_TREE;
113194 +}
113195 +
113196 +/* set on complete types that we don't need to inspect further at all */
113197 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113198 +{
113199 + *no_add_attrs = false;
113200 + return NULL_TREE;
113201 +}
113202 +
113203 +/*
113204 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113205 + * this does not preclude us from inspecting its fields for potential shuffles
113206 + */
113207 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113208 +{
113209 + *no_add_attrs = false;
113210 + return NULL_TREE;
113211 +}
113212 +
113213 +/*
113214 + * 64bit variant of Bob Jenkins' public domain PRNG
113215 + * 256 bits of internal state
113216 + */
113217 +
113218 +typedef unsigned long long u64;
113219 +
113220 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113221 +
113222 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113223 +static u64 ranval(ranctx *x) {
113224 + u64 e = x->a - rot(x->b, 7);
113225 + x->a = x->b ^ rot(x->c, 13);
113226 + x->b = x->c + rot(x->d, 37);
113227 + x->c = x->d + e;
113228 + x->d = e + x->a;
113229 + return x->d;
113230 +}
113231 +
113232 +static void raninit(ranctx *x, u64 *seed) {
113233 + int i;
113234 +
113235 + x->a = seed[0];
113236 + x->b = seed[1];
113237 + x->c = seed[2];
113238 + x->d = seed[3];
113239 +
113240 + for (i=0; i < 30; ++i)
113241 + (void)ranval(x);
113242 +}
113243 +
113244 +static u64 shuffle_seed[4];
113245 +
113246 +struct partition_group {
113247 + tree tree_start;
113248 + unsigned long start;
113249 + unsigned long length;
113250 +};
113251 +
113252 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113253 +{
113254 + unsigned long i;
113255 + unsigned long accum_size = 0;
113256 + unsigned long accum_length = 0;
113257 + unsigned long group_idx = 0;
113258 +
113259 + gcc_assert(length < INT_MAX);
113260 +
113261 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113262 +
113263 + for (i = 0; i < length; i++) {
113264 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113265 + size_groups[group_idx].tree_start = fields[i];
113266 + size_groups[group_idx].start = i;
113267 + accum_length = 0;
113268 + accum_size = 0;
113269 + }
113270 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113271 + accum_length++;
113272 + if (accum_size >= 64) {
113273 + size_groups[group_idx].length = accum_length;
113274 + accum_length = 0;
113275 + group_idx++;
113276 + }
113277 + }
113278 +
113279 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113280 + !size_groups[group_idx].length) {
113281 + size_groups[group_idx].length = accum_length;
113282 + group_idx++;
113283 + }
113284 +
113285 + *num_groups = group_idx;
113286 +}
113287 +
113288 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113289 +{
113290 + unsigned long i, x;
113291 + struct partition_group size_group[length];
113292 + unsigned long num_groups = 0;
113293 + unsigned long randnum;
113294 +
113295 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113296 + for (i = num_groups - 1; i > 0; i--) {
113297 + struct partition_group tmp;
113298 + randnum = ranval(prng_state) % (i + 1);
113299 + tmp = size_group[i];
113300 + size_group[i] = size_group[randnum];
113301 + size_group[randnum] = tmp;
113302 + }
113303 +
113304 + for (x = 0; x < num_groups; x++) {
113305 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113306 + tree tmp;
113307 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113308 + continue;
113309 + randnum = ranval(prng_state) % (i + 1);
113310 + // we could handle this case differently if desired
113311 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113312 + continue;
113313 + tmp = newtree[i];
113314 + newtree[i] = newtree[randnum];
113315 + newtree[randnum] = tmp;
113316 + }
113317 + }
113318 +}
113319 +
113320 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113321 +{
113322 + unsigned long i, randnum;
113323 +
113324 + for (i = length - 1; i > 0; i--) {
113325 + tree tmp;
113326 + randnum = ranval(prng_state) % (i + 1);
113327 + tmp = newtree[i];
113328 + newtree[i] = newtree[randnum];
113329 + newtree[randnum] = tmp;
113330 + }
113331 +}
113332 +
113333 +/* modern in-place Fisher-Yates shuffle */
113334 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113335 +{
113336 + unsigned long i;
113337 + u64 seed[4];
113338 + ranctx prng_state;
113339 + const unsigned char *structname;
113340 +
113341 + if (length == 0)
113342 + return;
113343 +
113344 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113345 +
113346 + structname = ORIG_TYPE_NAME(type);
113347 +
113348 +#ifdef __DEBUG_PLUGIN
113349 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113350 +#ifdef __DEBUG_VERBOSE
113351 + debug_tree((tree)type);
113352 +#endif
113353 +#endif
113354 +
113355 + for (i = 0; i < 4; i++) {
113356 + seed[i] = shuffle_seed[i];
113357 + seed[i] ^= name_hash(structname);
113358 + }
113359 +
113360 + raninit(&prng_state, (u64 *)&seed);
113361 +
113362 + if (performance_mode)
113363 + performance_shuffle(newtree, length, &prng_state);
113364 + else
113365 + full_shuffle(newtree, length, &prng_state);
113366 +}
113367 +
113368 +static bool is_flexible_array(const_tree field)
113369 +{
113370 + const_tree fieldtype;
113371 + const_tree typesize;
113372 + const_tree elemtype;
113373 + const_tree elemsize;
113374 +
113375 + fieldtype = TREE_TYPE(field);
113376 + typesize = TYPE_SIZE(fieldtype);
113377 +
113378 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113379 + return false;
113380 +
113381 + elemtype = TREE_TYPE(fieldtype);
113382 + elemsize = TYPE_SIZE(elemtype);
113383 +
113384 + /* size of type is represented in bits */
113385 +
113386 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113387 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113388 + return true;
113389 +
113390 + if (typesize != NULL_TREE &&
113391 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113392 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113393 + return true;
113394 +
113395 + return false;
113396 +}
113397 +
113398 +static int relayout_struct(tree type)
113399 +{
113400 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113401 + unsigned long shuffle_length = num_fields;
113402 + tree field;
113403 + tree newtree[num_fields];
113404 + unsigned long i;
113405 + tree list;
113406 + tree variant;
113407 + expanded_location xloc;
113408 +
113409 + if (TYPE_FIELDS(type) == NULL_TREE)
113410 + return 0;
113411 +
113412 + if (num_fields < 2)
113413 + return 0;
113414 +
113415 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113416 +
113417 + gcc_assert(num_fields < INT_MAX);
113418 +
113419 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113420 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113421 + return 0;
113422 +
113423 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113424 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113425 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113426 + return 0;
113427 +
113428 + /* throw out any structs in uapi */
113429 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113430 +
113431 + if (strstr(xloc.file, "/uapi/"))
113432 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113433 +
113434 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113435 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113436 + newtree[i] = field;
113437 + }
113438 +
113439 + /*
113440 + * enforce that we don't randomize the layout of the last
113441 + * element of a struct if it's a 0 or 1-length array
113442 + * or a proper flexible array
113443 + */
113444 + if (is_flexible_array(newtree[num_fields - 1]))
113445 + shuffle_length--;
113446 +
113447 + shuffle(type, (tree *)newtree, shuffle_length);
113448 +
113449 + /*
113450 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113451 + * as gcc provides no other way to detect such code
113452 + */
113453 + list = make_node(FIELD_DECL);
113454 + TREE_CHAIN(list) = newtree[0];
113455 + TREE_TYPE(list) = void_type_node;
113456 + DECL_SIZE(list) = bitsize_zero_node;
113457 + DECL_NONADDRESSABLE_P(list) = 1;
113458 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113459 + DECL_SIZE_UNIT(list) = size_zero_node;
113460 + DECL_FIELD_OFFSET(list) = size_zero_node;
113461 + // to satisfy the constify plugin
113462 + TREE_READONLY(list) = 1;
113463 +
113464 + for (i = 0; i < num_fields - 1; i++)
113465 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113466 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113467 +
113468 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113469 + TYPE_FIELDS(variant) = list;
113470 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113471 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113472 + // force a re-layout
113473 + TYPE_SIZE(variant) = NULL_TREE;
113474 + layout_type(variant);
113475 + }
113476 +
113477 + return 1;
113478 +}
113479 +
113480 +/* from constify plugin */
113481 +static const_tree get_field_type(const_tree field)
113482 +{
113483 + return strip_array_types(TREE_TYPE(field));
113484 +}
113485 +
113486 +/* from constify plugin */
113487 +static bool is_fptr(const_tree fieldtype)
113488 +{
113489 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113490 + return false;
113491 +
113492 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113493 +}
113494 +
113495 +/* derived from constify plugin */
113496 +static int is_pure_ops_struct(const_tree node)
113497 +{
113498 + const_tree field;
113499 +
113500 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113501 +
113502 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113503 + const_tree fieldtype = get_field_type(field);
113504 + enum tree_code code = TREE_CODE(fieldtype);
113505 +
113506 + if (node == fieldtype)
113507 + continue;
113508 +
113509 + if (!is_fptr(fieldtype))
113510 + return 0;
113511 +
113512 + if (code != RECORD_TYPE && code != UNION_TYPE)
113513 + continue;
113514 +
113515 + if (!is_pure_ops_struct(fieldtype))
113516 + return 0;
113517 + }
113518 +
113519 + return 1;
113520 +}
113521 +
113522 +static void randomize_type(tree type)
113523 +{
113524 + tree variant;
113525 +
113526 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113527 +
113528 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113529 + return;
113530 +
113531 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113532 + relayout_struct(type);
113533 +
113534 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113535 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113536 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113537 + }
113538 +#ifdef __DEBUG_PLUGIN
113539 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113540 +#ifdef __DEBUG_VERBOSE
113541 + debug_tree(type);
113542 +#endif
113543 +#endif
113544 +}
113545 +
113546 +static void randomize_layout_finish_decl(void *event_data, void *data)
113547 +{
113548 + tree decl = (tree)event_data;
113549 + tree type;
113550 +
113551 + if (decl == NULL_TREE || decl == error_mark_node)
113552 + return;
113553 +
113554 + type = TREE_TYPE(decl);
113555 +
113556 + if (TREE_CODE(decl) != VAR_DECL)
113557 + return;
113558 +
113559 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113560 + return;
113561 +
113562 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113563 + return;
113564 +
113565 + relayout_decl(decl);
113566 +}
113567 +
113568 +static void finish_type(void *event_data, void *data)
113569 +{
113570 + tree type = (tree)event_data;
113571 +
113572 + if (type == NULL_TREE || type == error_mark_node)
113573 + return;
113574 +
113575 + if (TREE_CODE(type) != RECORD_TYPE)
113576 + return;
113577 +
113578 + if (TYPE_FIELDS(type) == NULL_TREE)
113579 + return;
113580 +
113581 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113582 + return;
113583 +
113584 +#ifdef __DEBUG_PLUGIN
113585 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113586 +#endif
113587 +#ifdef __DEBUG_VERBOSE
113588 + debug_tree(type);
113589 +#endif
113590 + randomize_type(type);
113591 +
113592 + return;
113593 +}
113594 +
113595 +static struct attribute_spec randomize_layout_attr = {
113596 + .name = "randomize_layout",
113597 + // related to args
113598 + .min_length = 0,
113599 + .max_length = 0,
113600 + .decl_required = false,
113601 + // need type declaration
113602 + .type_required = true,
113603 + .function_type_required = false,
113604 + .handler = handle_randomize_layout_attr,
113605 +#if BUILDING_GCC_VERSION >= 4007
113606 + .affects_type_identity = true
113607 +#endif
113608 +};
113609 +
113610 +static struct attribute_spec no_randomize_layout_attr = {
113611 + .name = "no_randomize_layout",
113612 + // related to args
113613 + .min_length = 0,
113614 + .max_length = 0,
113615 + .decl_required = false,
113616 + // need type declaration
113617 + .type_required = true,
113618 + .function_type_required = false,
113619 + .handler = handle_randomize_layout_attr,
113620 +#if BUILDING_GCC_VERSION >= 4007
113621 + .affects_type_identity = true
113622 +#endif
113623 +};
113624 +
113625 +static struct attribute_spec randomize_considered_attr = {
113626 + .name = "randomize_considered",
113627 + // related to args
113628 + .min_length = 0,
113629 + .max_length = 0,
113630 + .decl_required = false,
113631 + // need type declaration
113632 + .type_required = true,
113633 + .function_type_required = false,
113634 + .handler = handle_randomize_considered_attr,
113635 +#if BUILDING_GCC_VERSION >= 4007
113636 + .affects_type_identity = false
113637 +#endif
113638 +};
113639 +
113640 +static struct attribute_spec randomize_performed_attr = {
113641 + .name = "randomize_performed",
113642 + // related to args
113643 + .min_length = 0,
113644 + .max_length = 0,
113645 + .decl_required = false,
113646 + // need type declaration
113647 + .type_required = true,
113648 + .function_type_required = false,
113649 + .handler = handle_randomize_performed_attr,
113650 +#if BUILDING_GCC_VERSION >= 4007
113651 + .affects_type_identity = false
113652 +#endif
113653 +};
113654 +
113655 +static void register_attributes(void *event_data, void *data)
113656 +{
113657 + register_attribute(&randomize_layout_attr);
113658 + register_attribute(&no_randomize_layout_attr);
113659 + register_attribute(&randomize_considered_attr);
113660 + register_attribute(&randomize_performed_attr);
113661 +}
113662 +
113663 +static void check_bad_casts_in_constructor(tree var, tree init)
113664 +{
113665 + unsigned HOST_WIDE_INT idx;
113666 + tree field, val;
113667 + tree field_type, val_type;
113668 +
113669 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113670 + if (TREE_CODE(val) == CONSTRUCTOR) {
113671 + check_bad_casts_in_constructor(var, val);
113672 + continue;
113673 + }
113674 +
113675 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113676 + normal code which all have valid 'field' trees. work around this */
113677 + if (field == NULL_TREE)
113678 + continue;
113679 + field_type = TREE_TYPE(field);
113680 + val_type = TREE_TYPE(val);
113681 +
113682 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113683 + continue;
113684 +
113685 + if (field_type == val_type)
113686 + continue;
113687 +
113688 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113689 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113690 +
113691 + if (field_type == void_type_node)
113692 + continue;
113693 + if (field_type == val_type)
113694 + continue;
113695 + if (TREE_CODE(val_type) != RECORD_TYPE)
113696 + continue;
113697 +
113698 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113699 + continue;
113700 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113701 + }
113702 +}
113703 +
113704 +/* derived from the constify plugin */
113705 +static void check_global_variables(void *event_data, void *data)
113706 +{
113707 + struct varpool_node *node;
113708 + tree init;
113709 +
113710 + FOR_EACH_VARIABLE(node) {
113711 + tree var = NODE_DECL(node);
113712 + init = DECL_INITIAL(var);
113713 + if (init == NULL_TREE)
113714 + continue;
113715 +
113716 + if (TREE_CODE(init) != CONSTRUCTOR)
113717 + continue;
113718 +
113719 + check_bad_casts_in_constructor(var, init);
113720 + }
113721 +}
113722 +
113723 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113724 +{
113725 + basic_block dom;
113726 + gimple dom_stmt;
113727 + gimple call_stmt;
113728 + const_tree dom_lhs;
113729 + const_tree poss_is_err_cond;
113730 + const_tree poss_is_err_func;
113731 + const_tree is_err_arg;
113732 +
113733 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113734 + if (!dom)
113735 + return false;
113736 +
113737 + dom_stmt = last_stmt(dom);
113738 + if (!dom_stmt)
113739 + return false;
113740 +
113741 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113742 + return false;
113743 +
113744 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113745 + return false;
113746 +
113747 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113748 + return false;
113749 +
113750 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113751 +
113752 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113753 + return false;
113754 +
113755 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113756 +
113757 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113758 + return false;
113759 +
113760 + dom_lhs = gimple_get_lhs(call_stmt);
113761 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113762 + if (!poss_is_err_func)
113763 + return false;
113764 + if (dom_lhs != poss_is_err_cond)
113765 + return false;
113766 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113767 + return false;
113768 +
113769 + is_err_arg = gimple_call_arg(call_stmt, 0);
113770 + if (!is_err_arg)
113771 + return false;
113772 +
113773 + if (is_err_arg != rhs)
113774 + return false;
113775 +
113776 + return true;
113777 +}
113778 +
113779 +static void handle_local_var_initializers(void)
113780 +{
113781 + tree var;
113782 + unsigned int i;
113783 +
113784 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113785 + tree init = DECL_INITIAL(var);
113786 + if (!init)
113787 + continue;
113788 + if (TREE_CODE(init) != CONSTRUCTOR)
113789 + continue;
113790 + check_bad_casts_in_constructor(var, init);
113791 + }
113792 +}
113793 +
113794 +/*
113795 + * iterate over all statements to find "bad" casts:
113796 + * those where the address of the start of a structure is cast
113797 + * to a pointer of a structure of a different type, or a
113798 + * structure pointer type is cast to a different structure pointer type
113799 + */
113800 +static unsigned int find_bad_casts(void)
113801 +{
113802 + basic_block bb;
113803 +
113804 + handle_local_var_initializers();
113805 +
113806 + FOR_ALL_BB_FN(bb, cfun) {
113807 + gimple_stmt_iterator gsi;
113808 +
113809 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113810 + gimple stmt;
113811 + const_tree lhs;
113812 + const_tree lhs_type;
113813 + const_tree rhs1;
113814 + const_tree rhs_type;
113815 + const_tree ptr_lhs_type;
113816 + const_tree ptr_rhs_type;
113817 + const_tree op0;
113818 + const_tree op0_type;
113819 + enum tree_code rhs_code;
113820 +
113821 + stmt = gsi_stmt(gsi);
113822 +
113823 +#ifdef __DEBUG_PLUGIN
113824 +#ifdef __DEBUG_VERBOSE
113825 + debug_gimple_stmt(stmt);
113826 + debug_tree(gimple_get_lhs(stmt));
113827 +#endif
113828 +#endif
113829 +
113830 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113831 + continue;
113832 +
113833 +#ifdef __DEBUG_PLUGIN
113834 +#ifdef __DEBUG_VERBOSE
113835 + debug_tree(gimple_assign_rhs1(stmt));
113836 +#endif
113837 +#endif
113838 +
113839 + rhs_code = gimple_assign_rhs_code(stmt);
113840 +
113841 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113842 + continue;
113843 +
113844 + lhs = gimple_get_lhs(stmt);
113845 + lhs_type = TREE_TYPE(lhs);
113846 + rhs1 = gimple_assign_rhs1(stmt);
113847 + rhs_type = TREE_TYPE(rhs1);
113848 +
113849 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113850 + TREE_CODE(lhs_type) != POINTER_TYPE)
113851 + continue;
113852 +
113853 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113854 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113855 +
113856 + if (ptr_rhs_type == void_type_node)
113857 + continue;
113858 +
113859 + if (ptr_lhs_type == void_type_node)
113860 + continue;
113861 +
113862 + if (dominated_by_is_err(rhs1, bb))
113863 + continue;
113864 +
113865 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113866 +#ifndef __DEBUG_PLUGIN
113867 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113868 +#endif
113869 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113870 + continue;
113871 + }
113872 +
113873 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113874 + continue;
113875 +
113876 + if (rhs_code == ADDR_EXPR) {
113877 + op0 = TREE_OPERAND(rhs1, 0);
113878 +
113879 + if (op0 == NULL_TREE)
113880 + continue;
113881 +
113882 + if (TREE_CODE(op0) != VAR_DECL)
113883 + continue;
113884 +
113885 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113886 + if (op0_type == ptr_lhs_type)
113887 + continue;
113888 +
113889 +#ifndef __DEBUG_PLUGIN
113890 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113891 +#endif
113892 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113893 + } else {
113894 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113895 + /* skip bogus type casts introduced by container_of */
113896 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113897 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113898 + continue;
113899 +#ifndef __DEBUG_PLUGIN
113900 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113901 +#endif
113902 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113903 + }
113904 +
113905 + }
113906 + }
113907 + return 0;
113908 +}
113909 +
113910 +#if BUILDING_GCC_VERSION >= 4009
113911 +static const struct pass_data randomize_layout_bad_cast_data = {
113912 +#else
113913 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113914 + .pass = {
113915 +#endif
113916 + .type = GIMPLE_PASS,
113917 + .name = "randomize_layout_bad_cast",
113918 +#if BUILDING_GCC_VERSION >= 4008
113919 + .optinfo_flags = OPTGROUP_NONE,
113920 +#endif
113921 +#if BUILDING_GCC_VERSION >= 4009
113922 + .has_gate = false,
113923 + .has_execute = true,
113924 +#else
113925 + .gate = NULL,
113926 + .execute = find_bad_casts,
113927 + .sub = NULL,
113928 + .next = NULL,
113929 + .static_pass_number = 0,
113930 +#endif
113931 + .tv_id = TV_NONE,
113932 + .properties_required = PROP_cfg,
113933 + .properties_provided = 0,
113934 + .properties_destroyed = 0,
113935 + .todo_flags_start = 0,
113936 + .todo_flags_finish = TODO_dump_func
113937 +#if BUILDING_GCC_VERSION < 4009
113938 + }
113939 +#endif
113940 +};
113941 +
113942 +#if BUILDING_GCC_VERSION >= 4009
113943 +namespace {
113944 +class randomize_layout_bad_cast : public gimple_opt_pass {
113945 +public:
113946 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113947 + unsigned int execute() { return find_bad_casts(); }
113948 +};
113949 +}
113950 +#endif
113951 +
113952 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113953 +{
113954 +#if BUILDING_GCC_VERSION >= 4009
113955 + return new randomize_layout_bad_cast();
113956 +#else
113957 + return &randomize_layout_bad_cast.pass;
113958 +#endif
113959 +}
113960 +
113961 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113962 +{
113963 + int i;
113964 + const char * const plugin_name = plugin_info->base_name;
113965 + const int argc = plugin_info->argc;
113966 + const struct plugin_argument * const argv = plugin_info->argv;
113967 + bool enable = true;
113968 + int obtained_seed = 0;
113969 + struct register_pass_info randomize_layout_bad_cast_info;
113970 +
113971 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113972 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113973 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113974 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113975 +
113976 + if (!plugin_default_version_check(version, &gcc_version)) {
113977 + error(G_("incompatible gcc/plugin versions"));
113978 + return 1;
113979 + }
113980 +
113981 + if (strcmp(lang_hooks.name, "GNU C")) {
113982 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113983 + enable = false;
113984 + }
113985 +
113986 + for (i = 0; i < argc; ++i) {
113987 + if (!strcmp(argv[i].key, "disable")) {
113988 + enable = false;
113989 + continue;
113990 + }
113991 + if (!strcmp(argv[i].key, "performance-mode")) {
113992 + performance_mode = 1;
113993 + continue;
113994 + }
113995 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113996 + }
113997 +
113998 + if (strlen(randstruct_seed) != 64) {
113999 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
114000 + return 1;
114001 + }
114002 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
114003 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
114004 + if (obtained_seed != 4) {
114005 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
114006 + return 1;
114007 + }
114008 +
114009 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
114010 + if (enable) {
114011 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
114012 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
114013 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
114014 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
114015 + }
114016 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
114017 +
114018 + return 0;
114019 +}
114020 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
114021 new file mode 100644
114022 index 0000000..1f0214f
114023 --- /dev/null
114024 +++ b/tools/gcc/size_overflow_plugin/.gitignore
114025 @@ -0,0 +1,3 @@
114026 +randomize_layout_seed.h
114027 +size_overflow_hash.h
114028 +size_overflow_hash_aux.h
114029 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
114030 new file mode 100644
114031 index 0000000..1ae2ed5
114032 --- /dev/null
114033 +++ b/tools/gcc/size_overflow_plugin/Makefile
114034 @@ -0,0 +1,20 @@
114035 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
114036 +always := $($(HOSTLIBS)-y)
114037 +
114038 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
114039 +
114040 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
114041 +
114042 +quiet_cmd_build_size_overflow_hash = GENHASH $@
114043 + cmd_build_size_overflow_hash = \
114044 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
114045 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
114046 + $(call if_changed,build_size_overflow_hash)
114047 +
114048 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
114049 + cmd_build_size_overflow_hash_aux = \
114050 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
114051 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
114052 + $(call if_changed,build_size_overflow_hash_aux)
114053 +
114054 +targets += size_overflow_hash.h size_overflow_hash_aux.h
114055 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114056 new file mode 100644
114057 index 0000000..12b1e3b
114058 --- /dev/null
114059 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114060 @@ -0,0 +1,102 @@
114061 +#!/bin/bash
114062 +
114063 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
114064 +
114065 +header1="size_overflow_hash.h"
114066 +database="size_overflow_hash.data"
114067 +n=65536
114068 +hashtable_name="size_overflow_hash"
114069 +
114070 +usage() {
114071 +cat <<EOF
114072 +usage: $0 options
114073 +OPTIONS:
114074 + -h|--help help
114075 + -o header file
114076 + -d database file
114077 + -n hash array size
114078 + -s name of the hash table
114079 +EOF
114080 + return 0
114081 +}
114082 +
114083 +while true
114084 +do
114085 + case "$1" in
114086 + -h|--help) usage && exit 0;;
114087 + -n) n=$2; shift 2;;
114088 + -o) header1="$2"; shift 2;;
114089 + -d) database="$2"; shift 2;;
114090 + -s) hashtable_name="$2"; shift 2;;
114091 + --) shift 1; break ;;
114092 + *) break ;;
114093 + esac
114094 +done
114095 +
114096 +create_defines() {
114097 + for i in `seq 0 31`
114098 + do
114099 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114100 + done
114101 + echo >> "$header1"
114102 +}
114103 +
114104 +create_structs() {
114105 + rm -f "$header1"
114106 +
114107 + create_defines
114108 +
114109 + cat "$database" | while read data
114110 + do
114111 + data_array=($data)
114112 + struct_hash_name="${data_array[0]}"
114113 + funcn="${data_array[1]}"
114114 + params="${data_array[2]}"
114115 + next="${data_array[4]}"
114116 +
114117 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114118 +
114119 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114120 + echo -en "\t.param\t= " >> "$header1"
114121 + line=
114122 + for param_num in ${params//-/ };
114123 + do
114124 + line="${line}PARAM"$param_num"|"
114125 + done
114126 +
114127 + echo -e "${line%?},\n};\n" >> "$header1"
114128 + done
114129 +}
114130 +
114131 +create_headers() {
114132 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114133 +}
114134 +
114135 +create_array_elements() {
114136 + index=0
114137 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114138 + do
114139 + data_array=($data)
114140 + i="${data_array[3]}"
114141 + hash="${data_array[0]}"
114142 + while [[ $index -lt $i ]]
114143 + do
114144 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114145 + index=$(($index + 1))
114146 + done
114147 + index=$(($index + 1))
114148 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114149 + done
114150 + echo '};' >> $header1
114151 +}
114152 +
114153 +size_overflow_plugin_dir=`dirname $header1`
114154 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114155 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114156 +fi
114157 +
114158 +create_structs
114159 +create_headers
114160 +create_array_elements
114161 +
114162 +exit 0
114163 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114164 new file mode 100644
114165 index 0000000..c43901f
114166 --- /dev/null
114167 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114168 @@ -0,0 +1,748 @@
114169 +/*
114170 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114171 + * Licensed under the GPL v2, or (at your option) v3
114172 + *
114173 + * Homepage:
114174 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114175 + *
114176 + * Documentation:
114177 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114178 + *
114179 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114180 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114181 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114182 + *
114183 + * Usage:
114184 + * $ make
114185 + * $ make run
114186 + */
114187 +
114188 +#include "gcc-common.h"
114189 +#include "size_overflow.h"
114190 +
114191 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114192 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114193 +
114194 +// data for the size_overflow asm stmt
114195 +struct asm_data {
114196 + gimple def_stmt;
114197 + tree input;
114198 + tree output;
114199 +};
114200 +
114201 +#if BUILDING_GCC_VERSION <= 4007
114202 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114203 +#else
114204 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114205 +#endif
114206 +{
114207 + tree list;
114208 +#if BUILDING_GCC_VERSION <= 4007
114209 + VEC(tree, gc) *vec_list = NULL;
114210 +#else
114211 + vec<tree, va_gc> *vec_list = NULL;
114212 +#endif
114213 +
114214 + list = build_tree_list(NULL_TREE, string);
114215 + list = chainon(NULL_TREE, build_tree_list(list, io));
114216 +#if BUILDING_GCC_VERSION <= 4007
114217 + VEC_safe_push(tree, gc, vec_list, list);
114218 +#else
114219 + vec_safe_push(vec_list, list);
114220 +#endif
114221 + return vec_list;
114222 +}
114223 +
114224 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114225 +{
114226 + gimple asm_stmt;
114227 + gimple_stmt_iterator gsi;
114228 +#if BUILDING_GCC_VERSION <= 4007
114229 + VEC(tree, gc) *input, *output = NULL;
114230 +#else
114231 + vec<tree, va_gc> *input, *output = NULL;
114232 +#endif
114233 +
114234 + input = create_asm_io_list(str_input, asm_data->input);
114235 +
114236 + if (asm_data->output)
114237 + output = create_asm_io_list(str_output, asm_data->output);
114238 +
114239 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114240 + gsi = gsi_for_stmt(asm_data->def_stmt);
114241 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114242 +
114243 + if (asm_data->output)
114244 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114245 +}
114246 +
114247 +static void replace_call_lhs(const struct asm_data *asm_data)
114248 +{
114249 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114250 + update_stmt(asm_data->def_stmt);
114251 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114252 +}
114253 +
114254 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114255 +{
114256 + enum mark cur_fndecl_attr;
114257 + gimple phi = get_def_stmt(result);
114258 + unsigned int i, n = gimple_phi_num_args(phi);
114259 +
114260 + pointer_set_insert(visited, phi);
114261 + for (i = 0; i < n; i++) {
114262 + tree arg = gimple_phi_arg_def(phi, i);
114263 +
114264 + cur_fndecl_attr = search_intentional(visited, arg);
114265 + if (cur_fndecl_attr != MARK_NO)
114266 + return cur_fndecl_attr;
114267 + }
114268 + return MARK_NO;
114269 +}
114270 +
114271 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114272 +{
114273 + enum mark cur_fndecl_attr;
114274 + const_tree rhs1, rhs2;
114275 + gimple def_stmt = get_def_stmt(lhs);
114276 +
114277 + rhs1 = gimple_assign_rhs1(def_stmt);
114278 + rhs2 = gimple_assign_rhs2(def_stmt);
114279 +
114280 + cur_fndecl_attr = search_intentional(visited, rhs1);
114281 + if (cur_fndecl_attr != MARK_NO)
114282 + return cur_fndecl_attr;
114283 + return search_intentional(visited, rhs2);
114284 +}
114285 +
114286 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114287 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114288 +{
114289 + const_gimple def_stmt;
114290 +
114291 + if (TREE_CODE(lhs) != SSA_NAME)
114292 + return get_intentional_attr_type(lhs);
114293 +
114294 + def_stmt = get_def_stmt(lhs);
114295 + if (!def_stmt)
114296 + return MARK_NO;
114297 +
114298 + if (pointer_set_contains(visited, def_stmt))
114299 + return MARK_NO;
114300 +
114301 + switch (gimple_code(def_stmt)) {
114302 + case GIMPLE_NOP:
114303 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114304 + case GIMPLE_ASM:
114305 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114306 + return MARK_TURN_OFF;
114307 + return MARK_NO;
114308 + case GIMPLE_CALL:
114309 + return MARK_NO;
114310 + case GIMPLE_PHI:
114311 + return search_intentional_phi(visited, lhs);
114312 + case GIMPLE_ASSIGN:
114313 + switch (gimple_num_ops(def_stmt)) {
114314 + case 2:
114315 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114316 + case 3:
114317 + return search_intentional_binary(visited, lhs);
114318 + }
114319 + case GIMPLE_RETURN:
114320 + return MARK_NO;
114321 + default:
114322 + debug_gimple_stmt((gimple)def_stmt);
114323 + error("%s: unknown gimple code", __func__);
114324 + gcc_unreachable();
114325 + }
114326 +}
114327 +
114328 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114329 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114330 +{
114331 + const_tree fndecl;
114332 + struct pointer_set_t *visited;
114333 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114334 +
114335 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114336 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114337 + decl_attr = MARK_NOT_INTENTIONAL;
114338 + else if (is_yes_intentional_attr(fndecl, argnum))
114339 + decl_attr = MARK_YES;
114340 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114341 + return MARK_TURN_OFF;
114342 + }
114343 +
114344 + visited = pointer_set_create();
114345 + cur_fndecl_attr = search_intentional(visited, arg);
114346 + pointer_set_destroy(visited);
114347 +
114348 + switch (cur_fndecl_attr) {
114349 + case MARK_NO:
114350 + case MARK_TURN_OFF:
114351 + return cur_fndecl_attr;
114352 + default:
114353 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114354 + return MARK_YES;
114355 + }
114356 +}
114357 +
114358 +static void check_missing_size_overflow_attribute(tree var)
114359 +{
114360 + tree orig_fndecl;
114361 + unsigned int num;
114362 +
114363 + if (is_a_return_check(var))
114364 + orig_fndecl = DECL_ORIGIN(var);
114365 + else
114366 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114367 +
114368 + num = get_function_num(var, orig_fndecl);
114369 + if (num == CANNOT_FIND_ARG)
114370 + return;
114371 +
114372 + is_missing_function(orig_fndecl, num);
114373 +}
114374 +
114375 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114376 +{
114377 + gimple phi = get_def_stmt(result);
114378 + unsigned int i, n = gimple_phi_num_args(phi);
114379 +
114380 + pointer_set_insert(visited, phi);
114381 + for (i = 0; i < n; i++) {
114382 + tree arg = gimple_phi_arg_def(phi, i);
114383 +
114384 + search_size_overflow_attribute(visited, arg);
114385 + }
114386 +}
114387 +
114388 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114389 +{
114390 + const_gimple def_stmt = get_def_stmt(lhs);
114391 + tree rhs1, rhs2;
114392 +
114393 + rhs1 = gimple_assign_rhs1(def_stmt);
114394 + rhs2 = gimple_assign_rhs2(def_stmt);
114395 +
114396 + search_size_overflow_attribute(visited, rhs1);
114397 + search_size_overflow_attribute(visited, rhs2);
114398 +}
114399 +
114400 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114401 +{
114402 + const_gimple def_stmt;
114403 +
114404 + if (TREE_CODE(lhs) == PARM_DECL) {
114405 + check_missing_size_overflow_attribute(lhs);
114406 + return;
114407 + }
114408 +
114409 + def_stmt = get_def_stmt(lhs);
114410 + if (!def_stmt)
114411 + return;
114412 +
114413 + if (pointer_set_insert(visited, def_stmt))
114414 + return;
114415 +
114416 + switch (gimple_code(def_stmt)) {
114417 + case GIMPLE_NOP:
114418 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114419 + case GIMPLE_ASM:
114420 + return;
114421 + case GIMPLE_CALL: {
114422 + tree fndecl = gimple_call_fndecl(def_stmt);
114423 +
114424 + if (fndecl == NULL_TREE)
114425 + return;
114426 + check_missing_size_overflow_attribute(fndecl);
114427 + return;
114428 + }
114429 + case GIMPLE_PHI:
114430 + return search_size_overflow_attribute_phi(visited, lhs);
114431 + case GIMPLE_ASSIGN:
114432 + switch (gimple_num_ops(def_stmt)) {
114433 + case 2:
114434 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114435 + case 3:
114436 + return search_size_overflow_attribute_binary(visited, lhs);
114437 + }
114438 + default:
114439 + debug_gimple_stmt((gimple)def_stmt);
114440 + error("%s: unknown gimple code", __func__);
114441 + gcc_unreachable();
114442 + }
114443 +}
114444 +
114445 +// Search missing entries in the hash table (invoked from the gimple pass)
114446 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114447 +{
114448 + tree fndecl = NULL_TREE;
114449 + tree lhs;
114450 + struct pointer_set_t *visited;
114451 +
114452 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114453 + return;
114454 +
114455 + if (num == 0) {
114456 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114457 + lhs = gimple_return_retval(stmt);
114458 + } else {
114459 + gcc_assert(is_gimple_call(stmt));
114460 + lhs = gimple_call_arg(stmt, num - 1);
114461 + fndecl = gimple_call_fndecl(stmt);
114462 + }
114463 +
114464 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114465 + return;
114466 +
114467 + visited = pointer_set_create();
114468 + search_size_overflow_attribute(visited, lhs);
114469 + pointer_set_destroy(visited);
114470 +}
114471 +
114472 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114473 +{
114474 + gimple_stmt_iterator gsi;
114475 + gimple assign;
114476 +
114477 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114478 + gsi = gsi_for_stmt(stmt);
114479 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114480 + asm_data->def_stmt = assign;
114481 +
114482 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114483 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114484 + if (gimple_code(stmt) == GIMPLE_RETURN)
114485 + gimple_return_set_retval(stmt, asm_data->output);
114486 + else
114487 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114488 + update_stmt(stmt);
114489 +}
114490 +
114491 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114492 +{
114493 + const char *fn_name;
114494 + char *asm_comment;
114495 + unsigned int len;
114496 +
114497 + if (argnum == 0)
114498 + fn_name = DECL_NAME_POINTER(current_function_decl);
114499 + else
114500 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114501 +
114502 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114503 + gcc_assert(len > 0);
114504 +
114505 + return asm_comment;
114506 +}
114507 +
114508 +static const char *convert_mark_to_str(enum mark mark)
114509 +{
114510 + switch (mark) {
114511 + case MARK_NO:
114512 + return OK_ASM_STR;
114513 + case MARK_YES:
114514 + case MARK_NOT_INTENTIONAL:
114515 + return YES_ASM_STR;
114516 + case MARK_TURN_OFF:
114517 + return TURN_OFF_ASM_STR;
114518 + }
114519 +
114520 + gcc_unreachable();
114521 +}
114522 +
114523 +/* Create the input of the size_overflow asm stmt.
114524 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114525 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114526 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114527 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114528 + */
114529 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114530 +{
114531 + if (!asm_data->def_stmt) {
114532 + asm_data->input = NULL_TREE;
114533 + return;
114534 + }
114535 +
114536 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114537 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114538 +
114539 + switch (gimple_code(asm_data->def_stmt)) {
114540 + case GIMPLE_ASSIGN:
114541 + case GIMPLE_CALL:
114542 + replace_call_lhs(asm_data);
114543 + break;
114544 + case GIMPLE_PHI:
114545 + create_output_from_phi(stmt, argnum, asm_data);
114546 + break;
114547 + case GIMPLE_NOP: {
114548 + enum mark mark;
114549 + const char *mark_str;
114550 + char *asm_comment;
114551 +
114552 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114553 +
114554 + asm_data->input = asm_data->output;
114555 + asm_data->output = NULL;
114556 + asm_data->def_stmt = stmt;
114557 +
114558 + mark_str = convert_mark_to_str(mark);
114559 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114560 +
114561 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114562 + free(asm_comment);
114563 + asm_data->input = NULL_TREE;
114564 + break;
114565 + }
114566 + case GIMPLE_ASM:
114567 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114568 + asm_data->input = NULL_TREE;
114569 + break;
114570 + }
114571 + default:
114572 + debug_gimple_stmt(asm_data->def_stmt);
114573 + gcc_unreachable();
114574 + }
114575 +}
114576 +
114577 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114578 + * is of the right kind create the appropriate size_overflow asm stmts:
114579 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114580 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114581 + */
114582 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114583 +{
114584 + struct asm_data asm_data;
114585 + const char *mark_str;
114586 + char *asm_comment;
114587 + enum mark mark;
114588 +
114589 + if (is_gimple_constant(output_node))
114590 + return;
114591 +
114592 + asm_data.output = output_node;
114593 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114594 + if (mark != MARK_TURN_OFF)
114595 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114596 +
114597 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114598 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114599 + return;
114600 +
114601 + create_asm_input(stmt, argnum, &asm_data);
114602 + if (asm_data.input == NULL_TREE)
114603 + return;
114604 +
114605 + mark_str = convert_mark_to_str(mark);
114606 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114607 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114608 + free(asm_comment);
114609 +}
114610 +
114611 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114612 +static bool create_mark_asm(gimple stmt, enum mark mark)
114613 +{
114614 + struct asm_data asm_data;
114615 + const char *asm_str;
114616 +
114617 + switch (mark) {
114618 + case MARK_TURN_OFF:
114619 + asm_str = TURN_OFF_ASM_STR;
114620 + break;
114621 + case MARK_NOT_INTENTIONAL:
114622 + case MARK_YES:
114623 + asm_str = YES_ASM_STR;
114624 + break;
114625 + default:
114626 + gcc_unreachable();
114627 + }
114628 +
114629 + asm_data.def_stmt = stmt;
114630 + asm_data.output = gimple_call_lhs(stmt);
114631 +
114632 + if (asm_data.output == NULL_TREE) {
114633 + asm_data.input = gimple_call_arg(stmt, 0);
114634 + if (is_gimple_constant(asm_data.input))
114635 + return false;
114636 + asm_data.output = NULL;
114637 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114638 + return true;
114639 + }
114640 +
114641 + create_asm_input(stmt, 0, &asm_data);
114642 + gcc_assert(asm_data.input != NULL_TREE);
114643 +
114644 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114645 + return true;
114646 +}
114647 +
114648 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114649 +{
114650 + gimple def_stmt;
114651 +
114652 + def_stmt = get_def_stmt(lhs);
114653 + if (!def_stmt)
114654 + return;
114655 +
114656 + if (pointer_set_insert(visited, def_stmt))
114657 + return;
114658 +
114659 + switch (gimple_code(def_stmt)) {
114660 + case GIMPLE_NOP:
114661 + case GIMPLE_ASM:
114662 + case GIMPLE_CALL:
114663 + break;
114664 + case GIMPLE_PHI: {
114665 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114666 +
114667 + pointer_set_insert(visited, def_stmt);
114668 +
114669 + for (i = 0; i < n; i++) {
114670 + tree arg = gimple_phi_arg_def(def_stmt, i);
114671 +
114672 + walk_use_def_ptr(visited, arg);
114673 + }
114674 + }
114675 + case GIMPLE_ASSIGN:
114676 + switch (gimple_num_ops(def_stmt)) {
114677 + case 2:
114678 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114679 + return;
114680 + case 3:
114681 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114682 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114683 + return;
114684 + default:
114685 + return;
114686 + }
114687 + default:
114688 + debug_gimple_stmt((gimple)def_stmt);
114689 + error("%s: unknown gimple code", __func__);
114690 + gcc_unreachable();
114691 + }
114692 +}
114693 +
114694 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114695 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114696 +{
114697 + struct pointer_set_t *visited;
114698 +
114699 + visited = pointer_set_create();
114700 + walk_use_def_ptr(visited, arg);
114701 + pointer_set_destroy(visited);
114702 +}
114703 +
114704 +// Determine the return value and insert the asm stmt to mark the return stmt.
114705 +static void insert_asm_ret(gimple stmt)
114706 +{
114707 + tree ret;
114708 +
114709 + ret = gimple_return_retval(stmt);
114710 + create_size_overflow_asm(stmt, ret, 0);
114711 +}
114712 +
114713 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114714 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114715 +{
114716 + tree arg;
114717 + unsigned int argnum;
114718 +
114719 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114720 + gcc_assert(argnum != 0);
114721 + if (argnum == CANNOT_FIND_ARG)
114722 + return;
114723 +
114724 + arg = gimple_call_arg(stmt, argnum - 1);
114725 + gcc_assert(arg != NULL_TREE);
114726 +
114727 + // skip all ptr - ptr expressions
114728 + insert_mark_not_intentional_asm_at_ptr(arg);
114729 +
114730 + create_size_overflow_asm(stmt, arg, argnum);
114731 +}
114732 +
114733 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114734 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114735 +{
114736 + unsigned int argnum;
114737 + tree attr_value;
114738 +
114739 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114740 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114741 + argnums[argnum] = true;
114742 + }
114743 +}
114744 +
114745 +// If a function arg or the return value is in the hash table then set its index in the array.
114746 +static void set_argnum_hash(tree fndecl, bool *argnums)
114747 +{
114748 + unsigned int num;
114749 + const struct size_overflow_hash *hash;
114750 +
114751 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114752 + if (!hash)
114753 + return;
114754 +
114755 + for (num = 0; num <= MAX_PARAM; num++) {
114756 + if (!(hash->param & (1U << num)))
114757 + continue;
114758 +
114759 + argnums[num] = true;
114760 + }
114761 +}
114762 +
114763 +static bool is_all_the_argnums_empty(bool *argnums)
114764 +{
114765 + unsigned int i;
114766 +
114767 + for (i = 0; i <= MAX_PARAM; i++)
114768 + if (argnums[i])
114769 + return false;
114770 + return true;
114771 +}
114772 +
114773 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114774 +static void search_interesting_args(tree fndecl, bool *argnums)
114775 +{
114776 + const_tree attr;
114777 +
114778 + set_argnum_hash(fndecl, argnums);
114779 + if (!is_all_the_argnums_empty(argnums))
114780 + return;
114781 +
114782 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114783 + if (attr && TREE_VALUE(attr))
114784 + set_argnum_attribute(attr, argnums);
114785 +}
114786 +
114787 +/*
114788 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114789 + * on the callee function.
114790 + */
114791 +static bool is_mark_turn_off_attribute(gimple stmt)
114792 +{
114793 + enum mark mark;
114794 + const_tree fndecl = gimple_call_fndecl(stmt);
114795 +
114796 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114797 + if (mark == MARK_TURN_OFF)
114798 + return true;
114799 + return false;
114800 +}
114801 +
114802 +// 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
114803 +static void handle_interesting_function(gimple stmt)
114804 +{
114805 + unsigned int argnum;
114806 + tree fndecl;
114807 + bool orig_argnums[MAX_PARAM + 1] = {false};
114808 +
114809 + if (gimple_call_num_args(stmt) == 0)
114810 + return;
114811 + fndecl = gimple_call_fndecl(stmt);
114812 + if (fndecl == NULL_TREE)
114813 + return;
114814 + fndecl = DECL_ORIGIN(fndecl);
114815 +
114816 + if (is_mark_turn_off_attribute(stmt)) {
114817 + create_mark_asm(stmt, MARK_TURN_OFF);
114818 + return;
114819 + }
114820 +
114821 + search_interesting_args(fndecl, orig_argnums);
114822 +
114823 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114824 + if (orig_argnums[argnum])
114825 + insert_asm_arg(stmt, argnum);
114826 +}
114827 +
114828 +// 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
114829 +static void handle_interesting_ret(gimple stmt)
114830 +{
114831 + bool orig_argnums[MAX_PARAM + 1] = {false};
114832 +
114833 + search_interesting_args(current_function_decl, orig_argnums);
114834 +
114835 + if (orig_argnums[0])
114836 + insert_asm_ret(stmt);
114837 +}
114838 +
114839 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114840 +static unsigned int search_interesting_functions(void)
114841 +{
114842 + basic_block bb;
114843 +
114844 + FOR_ALL_BB_FN(bb, cfun) {
114845 + gimple_stmt_iterator gsi;
114846 +
114847 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114848 + gimple stmt = gsi_stmt(gsi);
114849 +
114850 + if (is_size_overflow_asm(stmt))
114851 + continue;
114852 +
114853 + if (is_gimple_call(stmt))
114854 + handle_interesting_function(stmt);
114855 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114856 + handle_interesting_ret(stmt);
114857 + }
114858 + }
114859 + return 0;
114860 +}
114861 +
114862 +/*
114863 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114864 + * this pass inserts asm stmts to mark the interesting args
114865 + * that the ipa pass will detect and insert the size overflow checks for.
114866 + */
114867 +#if BUILDING_GCC_VERSION >= 4009
114868 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114869 +#else
114870 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114871 + .pass = {
114872 +#endif
114873 + .type = GIMPLE_PASS,
114874 + .name = "insert_size_overflow_asm",
114875 +#if BUILDING_GCC_VERSION >= 4008
114876 + .optinfo_flags = OPTGROUP_NONE,
114877 +#endif
114878 +#if BUILDING_GCC_VERSION >= 4009
114879 + .has_gate = false,
114880 + .has_execute = true,
114881 +#else
114882 + .gate = NULL,
114883 + .execute = search_interesting_functions,
114884 + .sub = NULL,
114885 + .next = NULL,
114886 + .static_pass_number = 0,
114887 +#endif
114888 + .tv_id = TV_NONE,
114889 + .properties_required = PROP_cfg,
114890 + .properties_provided = 0,
114891 + .properties_destroyed = 0,
114892 + .todo_flags_start = 0,
114893 + .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
114894 +#if BUILDING_GCC_VERSION < 4009
114895 + }
114896 +#endif
114897 +};
114898 +
114899 +#if BUILDING_GCC_VERSION >= 4009
114900 +namespace {
114901 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114902 +public:
114903 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114904 + unsigned int execute() { return search_interesting_functions(); }
114905 +};
114906 +}
114907 +#endif
114908 +
114909 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114910 +{
114911 +#if BUILDING_GCC_VERSION >= 4009
114912 + return new insert_size_overflow_asm_pass();
114913 +#else
114914 + return &insert_size_overflow_asm_pass.pass;
114915 +#endif
114916 +}
114917 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
114918 new file mode 100644
114919 index 0000000..73f0a12
114920 --- /dev/null
114921 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114922 @@ -0,0 +1,943 @@
114923 +/*
114924 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114925 + * Licensed under the GPL v2, or (at your option) v3
114926 + *
114927 + * Homepage:
114928 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114929 + *
114930 + * Documentation:
114931 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114932 + *
114933 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114934 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114935 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114936 + *
114937 + * Usage:
114938 + * $ make
114939 + * $ make run
114940 + */
114941 +
114942 +#include "gcc-common.h"
114943 +#include "size_overflow.h"
114944 +
114945 +#define MIN_CHECK true
114946 +#define MAX_CHECK false
114947 +
114948 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114949 +{
114950 + const_tree type;
114951 + tree new_type;
114952 +
114953 + gcc_assert(node != NULL_TREE);
114954 +
114955 + type = TREE_TYPE(node);
114956 +
114957 + if (pointer_set_contains(visited->my_stmts, stmt))
114958 + return TREE_TYPE(node);
114959 +
114960 + switch (TYPE_MODE(type)) {
114961 + case QImode:
114962 + new_type = size_overflow_type_HI;
114963 + break;
114964 + case HImode:
114965 + new_type = size_overflow_type_SI;
114966 + break;
114967 + case SImode:
114968 + new_type = size_overflow_type_DI;
114969 + break;
114970 + case DImode:
114971 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114972 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114973 + else
114974 + new_type = size_overflow_type_TI;
114975 + break;
114976 + case TImode:
114977 + gcc_assert(!TYPE_UNSIGNED(type));
114978 + new_type = size_overflow_type_TI;
114979 + break;
114980 + default:
114981 + debug_tree((tree)node);
114982 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114983 + gcc_unreachable();
114984 + }
114985 +
114986 + if (TYPE_QUALS(type) != 0)
114987 + return build_qualified_type(new_type, TYPE_QUALS(type));
114988 + return new_type;
114989 +}
114990 +
114991 +static tree get_lhs(const_gimple stmt)
114992 +{
114993 + switch (gimple_code(stmt)) {
114994 + case GIMPLE_ASSIGN:
114995 + case GIMPLE_CALL:
114996 + return gimple_get_lhs(stmt);
114997 + case GIMPLE_PHI:
114998 + return gimple_phi_result(stmt);
114999 + default:
115000 + return NULL_TREE;
115001 + }
115002 +}
115003 +
115004 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
115005 +{
115006 + gimple_stmt_iterator gsi;
115007 + tree lhs;
115008 + gimple new_stmt;
115009 +
115010 + if (rhs == NULL_TREE)
115011 + return NULL_TREE;
115012 +
115013 + gsi = gsi_for_stmt(stmt);
115014 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115015 + pointer_set_insert(visited->my_stmts, new_stmt);
115016 +
115017 + lhs = get_lhs(new_stmt);
115018 + gcc_assert(lhs != NULL_TREE);
115019 + return lhs;
115020 +}
115021 +
115022 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
115023 +{
115024 + tree lhs, dst_type;
115025 + gimple_stmt_iterator gsi;
115026 +
115027 + if (rhs1 == NULL_TREE) {
115028 + debug_gimple_stmt(oldstmt);
115029 + error("%s: rhs1 is NULL_TREE", __func__);
115030 + gcc_unreachable();
115031 + }
115032 +
115033 + switch (gimple_code(oldstmt)) {
115034 + case GIMPLE_ASM:
115035 + lhs = rhs1;
115036 + break;
115037 + case GIMPLE_CALL:
115038 + case GIMPLE_ASSIGN:
115039 + lhs = gimple_get_lhs(oldstmt);
115040 + break;
115041 + default:
115042 + debug_gimple_stmt(oldstmt);
115043 + gcc_unreachable();
115044 + }
115045 +
115046 + gsi = gsi_for_stmt(oldstmt);
115047 + pointer_set_insert(visited->stmts, oldstmt);
115048 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115049 + basic_block next_bb, cur_bb;
115050 + const_edge e;
115051 +
115052 + gcc_assert(before == false);
115053 + gcc_assert(stmt_can_throw_internal(oldstmt));
115054 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115055 + gcc_assert(!gsi_end_p(gsi));
115056 +
115057 + cur_bb = gimple_bb(oldstmt);
115058 + next_bb = cur_bb->next_bb;
115059 + e = find_edge(cur_bb, next_bb);
115060 + gcc_assert(e != NULL);
115061 + gcc_assert(e->flags & EDGE_FALLTHRU);
115062 +
115063 + gsi = gsi_after_labels(next_bb);
115064 + gcc_assert(!gsi_end_p(gsi));
115065 +
115066 + before = true;
115067 + oldstmt = gsi_stmt(gsi);
115068 + }
115069 +
115070 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
115071 +
115072 + if (is_gimple_constant(rhs1))
115073 + return cast_a_tree(dst_type, rhs1);
115074 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
115075 +}
115076 +
115077 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115078 +{
115079 + gimple stmt;
115080 + gimple_stmt_iterator gsi;
115081 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115082 +
115083 + if (pointer_set_contains(visited->my_stmts, oldstmt))
115084 + return lhs;
115085 +
115086 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115087 + rhs1 = gimple_assign_rhs1(oldstmt);
115088 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115089 + }
115090 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115091 + rhs2 = gimple_assign_rhs2(oldstmt);
115092 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115093 + }
115094 +
115095 + stmt = gimple_copy(oldstmt);
115096 + gimple_set_location(stmt, gimple_location(oldstmt));
115097 + pointer_set_insert(visited->my_stmts, stmt);
115098 +
115099 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115100 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115101 +
115102 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115103 +
115104 + new_var = create_new_var(size_overflow_type);
115105 + new_var = make_ssa_name(new_var, stmt);
115106 + gimple_assign_set_lhs(stmt, new_var);
115107 +
115108 + if (rhs1 != NULL_TREE)
115109 + gimple_assign_set_rhs1(stmt, rhs1);
115110 +
115111 + if (rhs2 != NULL_TREE)
115112 + gimple_assign_set_rhs2(stmt, rhs2);
115113 +#if BUILDING_GCC_VERSION >= 4006
115114 + if (rhs3 != NULL_TREE)
115115 + gimple_assign_set_rhs3(stmt, rhs3);
115116 +#endif
115117 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115118 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115119 +
115120 + gsi = gsi_for_stmt(oldstmt);
115121 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115122 + update_stmt(stmt);
115123 + pointer_set_insert(visited->stmts, oldstmt);
115124 + return gimple_assign_lhs(stmt);
115125 +}
115126 +
115127 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115128 +{
115129 + gimple assign;
115130 + gimple_stmt_iterator gsi;
115131 + basic_block first_bb;
115132 +
115133 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115134 +
115135 + if (bb->index == 0) {
115136 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115137 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115138 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115139 + bb = first_bb;
115140 + }
115141 +
115142 + gsi = gsi_after_labels(bb);
115143 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115144 + pointer_set_insert(visited->my_stmts, assign);
115145 +
115146 + return gimple_assign_lhs(assign);
115147 +}
115148 +
115149 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115150 +{
115151 + gimple_stmt_iterator gsi;
115152 + gimple assign, def_stmt = get_def_stmt(new_arg);
115153 +
115154 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115155 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115156 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115157 + } else {
115158 + gsi = gsi_for_stmt(def_stmt);
115159 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115160 + }
115161 +
115162 + pointer_set_insert(visited->my_stmts, assign);
115163 + return gimple_assign_lhs(assign);
115164 +}
115165 +
115166 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115167 +{
115168 + basic_block bb;
115169 + gimple_stmt_iterator gsi;
115170 + const_gimple def_stmt;
115171 + gimple assign;
115172 +
115173 + def_stmt = get_def_stmt(arg);
115174 + bb = gimple_bb(def_stmt);
115175 + gcc_assert(bb->index != 0);
115176 + gsi = gsi_after_labels(bb);
115177 +
115178 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115179 + pointer_set_insert(visited->my_stmts, assign);
115180 + return gimple_assign_lhs(assign);
115181 +}
115182 +
115183 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115184 +{
115185 + tree size_overflow_type;
115186 + tree arg;
115187 + const_gimple def_stmt;
115188 +
115189 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115190 + return new_arg;
115191 +
115192 + arg = gimple_phi_arg_def(oldstmt, i);
115193 + def_stmt = get_def_stmt(arg);
115194 + gcc_assert(def_stmt != NULL);
115195 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115196 +
115197 + switch (gimple_code(def_stmt)) {
115198 + case GIMPLE_PHI:
115199 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115200 + case GIMPLE_NOP: {
115201 + basic_block bb;
115202 +
115203 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115204 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115205 + }
115206 + case GIMPLE_ASM: {
115207 + gimple_stmt_iterator gsi;
115208 + gimple assign, stmt = get_def_stmt(arg);
115209 +
115210 + gsi = gsi_for_stmt(stmt);
115211 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115212 + pointer_set_insert(visited->my_stmts, assign);
115213 + return gimple_assign_lhs(assign);
115214 + }
115215 + default:
115216 + gcc_assert(new_arg != NULL_TREE);
115217 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115218 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115219 + }
115220 +}
115221 +
115222 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115223 +{
115224 + basic_block bb;
115225 + gimple phi;
115226 + gimple_seq seq;
115227 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115228 +
115229 + bb = gsi_bb(gsi);
115230 +
115231 + if (result == NULL_TREE) {
115232 + tree old_result = gimple_phi_result(oldstmt);
115233 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115234 +
115235 + result = create_new_var(size_overflow_type);
115236 + }
115237 +
115238 + phi = create_phi_node(result, bb);
115239 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115240 + seq = phi_nodes(bb);
115241 + gsi = gsi_last(seq);
115242 + gsi_remove(&gsi, false);
115243 +
115244 + gsi = gsi_for_stmt(oldstmt);
115245 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115246 + gimple_set_bb(phi, bb);
115247 + return phi;
115248 +}
115249 +
115250 +#if BUILDING_GCC_VERSION <= 4007
115251 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115252 +#else
115253 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115254 +#endif
115255 +{
115256 + gimple new_phi;
115257 + unsigned int i;
115258 + tree arg, result;
115259 + location_t loc = gimple_location(oldstmt);
115260 +
115261 +#if BUILDING_GCC_VERSION <= 4007
115262 + gcc_assert(!VEC_empty(tree, *args));
115263 +#else
115264 + gcc_assert(!args->is_empty());
115265 +#endif
115266 +
115267 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115268 + result = gimple_phi_result(new_phi);
115269 + ssa_name_var = SSA_NAME_VAR(result);
115270 +
115271 +#if BUILDING_GCC_VERSION <= 4007
115272 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115273 +#else
115274 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115275 +#endif
115276 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115277 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115278 + }
115279 +
115280 +#if BUILDING_GCC_VERSION <= 4007
115281 + VEC_free(tree, heap, *args);
115282 +#else
115283 + vec_free(args);
115284 +#endif
115285 + update_stmt(new_phi);
115286 + pointer_set_insert(visited->my_stmts, new_phi);
115287 + return result;
115288 +}
115289 +
115290 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115291 +{
115292 + tree ssa_name_var = NULL_TREE;
115293 +#if BUILDING_GCC_VERSION <= 4007
115294 + VEC(tree, heap) *args = NULL;
115295 +#else
115296 + vec<tree, va_heap, vl_embed> *args = NULL;
115297 +#endif
115298 + gimple oldstmt = get_def_stmt(orig_result);
115299 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115300 +
115301 + pointer_set_insert(visited->stmts, oldstmt);
115302 + for (i = 0; i < len; i++) {
115303 + tree arg, new_arg;
115304 +
115305 + arg = gimple_phi_arg_def(oldstmt, i);
115306 + new_arg = expand(visited, caller_node, arg);
115307 +
115308 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115309 + ssa_name_var = SSA_NAME_VAR(new_arg);
115310 +
115311 + if (is_gimple_constant(arg)) {
115312 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115313 +
115314 + new_arg = cast_a_tree(size_overflow_type, arg);
115315 + }
115316 +
115317 +#if BUILDING_GCC_VERSION <= 4007
115318 + VEC_safe_push(tree, heap, args, new_arg);
115319 +#else
115320 + vec_safe_push(args, new_arg);
115321 +#endif
115322 + }
115323 +
115324 +#if BUILDING_GCC_VERSION <= 4007
115325 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115326 +#else
115327 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115328 +#endif
115329 +}
115330 +
115331 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115332 +{
115333 + tree rhs1 = gimple_assign_rhs1(stmt);
115334 + tree lhs = gimple_assign_lhs(stmt);
115335 + const_tree rhs1_type = TREE_TYPE(rhs1);
115336 + const_tree lhs_type = TREE_TYPE(lhs);
115337 +
115338 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115339 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115340 +
115341 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115342 +}
115343 +
115344 +static bool skip_lhs_cast_check(const_gimple stmt)
115345 +{
115346 + const_tree rhs = gimple_assign_rhs1(stmt);
115347 + const_gimple def_stmt = get_def_stmt(rhs);
115348 +
115349 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115350 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115351 + return true;
115352 +
115353 + if (is_const_plus_unsigned_signed_truncation(rhs))
115354 + return true;
115355 +
115356 + return false;
115357 +}
115358 +
115359 +static tree create_string_param(tree string)
115360 +{
115361 + tree i_type, a_type;
115362 + const int length = TREE_STRING_LENGTH(string);
115363 +
115364 + gcc_assert(length > 0);
115365 +
115366 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115367 + a_type = build_array_type(char_type_node, i_type);
115368 +
115369 + TREE_TYPE(string) = a_type;
115370 + TREE_CONSTANT(string) = 1;
115371 + TREE_READONLY(string) = 1;
115372 +
115373 + return build1(ADDR_EXPR, ptr_type_node, string);
115374 +}
115375 +
115376 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115377 +{
115378 + gimple cond_stmt;
115379 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115380 +
115381 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115382 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115383 + update_stmt(cond_stmt);
115384 +}
115385 +
115386 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115387 +{
115388 + gimple func_stmt;
115389 + const_gimple def_stmt;
115390 + const_tree loc_line;
115391 + tree loc_file, ssa_name, current_func;
115392 + expanded_location xloc;
115393 + char *ssa_name_buf;
115394 + int len;
115395 + struct cgraph_edge *edge;
115396 + struct cgraph_node *callee_node;
115397 + int frequency;
115398 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115399 +
115400 + def_stmt = get_def_stmt(arg);
115401 + xloc = expand_location(gimple_location(def_stmt));
115402 +
115403 + if (!gimple_has_location(def_stmt)) {
115404 + xloc = expand_location(gimple_location(stmt));
115405 + if (!gimple_has_location(stmt))
115406 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115407 + }
115408 +
115409 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115410 +
115411 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115412 + loc_file = create_string_param(loc_file);
115413 +
115414 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115415 + current_func = create_string_param(current_func);
115416 +
115417 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115418 + call_count++;
115419 + 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);
115420 + gcc_assert(len > 0);
115421 + ssa_name = build_string(len + 1, ssa_name_buf);
115422 + free(ssa_name_buf);
115423 + ssa_name = create_string_param(ssa_name);
115424 +
115425 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115426 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115427 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115428 +
115429 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115430 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115431 +
115432 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115433 + gcc_assert(edge != NULL);
115434 +}
115435 +
115436 +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)
115437 +{
115438 + basic_block cond_bb, join_bb, bb_true;
115439 + edge e;
115440 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115441 +
115442 + cond_bb = gimple_bb(stmt);
115443 + if (before)
115444 + gsi_prev(&gsi);
115445 + if (gsi_end_p(gsi))
115446 + e = split_block_after_labels(cond_bb);
115447 + else
115448 + e = split_block(cond_bb, gsi_stmt(gsi));
115449 + cond_bb = e->src;
115450 + join_bb = e->dest;
115451 + e->flags = EDGE_FALSE_VALUE;
115452 + e->probability = REG_BR_PROB_BASE;
115453 +
115454 + bb_true = create_empty_bb(cond_bb);
115455 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115456 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115457 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115458 +
115459 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115460 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115461 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115462 +
115463 + if (current_loops != NULL) {
115464 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115465 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115466 + }
115467 +
115468 + insert_cond(cond_bb, arg, cond_code, type_value);
115469 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115470 +
115471 +// print_the_code_insertions(stmt);
115472 +}
115473 +
115474 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115475 +{
115476 + const_tree rhs_type = TREE_TYPE(rhs);
115477 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115478 +
115479 + gcc_assert(rhs_type != NULL_TREE);
115480 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115481 + return;
115482 +
115483 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115484 +
115485 + if (is_const_plus_unsigned_signed_truncation(rhs))
115486 + return;
115487 +
115488 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115489 + // typemax (-1) < typemin (0)
115490 + if (TREE_OVERFLOW(type_max))
115491 + return;
115492 +
115493 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115494 +
115495 + cast_rhs_type = TREE_TYPE(cast_rhs);
115496 + type_max_type = TREE_TYPE(type_max);
115497 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115498 +
115499 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115500 +
115501 + // special case: get_size_overflow_type(), 32, u64->s
115502 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115503 + return;
115504 +
115505 + type_min_type = TREE_TYPE(type_min);
115506 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115507 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115508 +}
115509 +
115510 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115511 +{
115512 + bool cast_lhs, cast_rhs;
115513 + tree lhs = gimple_assign_lhs(stmt);
115514 + tree rhs = gimple_assign_rhs1(stmt);
115515 + const_tree lhs_type = TREE_TYPE(lhs);
115516 + const_tree rhs_type = TREE_TYPE(rhs);
115517 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115518 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115519 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115520 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115521 +
115522 + static bool check_lhs[3][4] = {
115523 + // ss su us uu
115524 + { false, true, true, false }, // lhs > rhs
115525 + { false, false, false, false }, // lhs = rhs
115526 + { true, true, true, true }, // lhs < rhs
115527 + };
115528 +
115529 + static bool check_rhs[3][4] = {
115530 + // ss su us uu
115531 + { true, false, true, true }, // lhs > rhs
115532 + { true, false, true, true }, // lhs = rhs
115533 + { true, false, true, true }, // lhs < rhs
115534 + };
115535 +
115536 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115537 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115538 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115539 +
115540 + if (lhs_size > rhs_size) {
115541 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115542 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115543 + } else if (lhs_size == rhs_size) {
115544 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115545 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115546 + } else {
115547 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115548 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115549 + }
115550 +
115551 + if (!cast_lhs && !cast_rhs)
115552 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115553 +
115554 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115555 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115556 +
115557 + if (cast_rhs)
115558 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115559 +
115560 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115561 +}
115562 +
115563 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115564 +{
115565 + enum tree_code rhs_code;
115566 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115567 +
115568 + if (pointer_set_contains(visited->my_stmts, stmt))
115569 + return lhs;
115570 +
115571 + rhs1 = gimple_assign_rhs1(stmt);
115572 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115573 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115574 +
115575 + new_rhs1 = expand(visited, caller_node, rhs1);
115576 +
115577 + if (new_rhs1 == NULL_TREE)
115578 + return create_cast_assign(visited, stmt);
115579 +
115580 + if (pointer_set_contains(visited->no_cast_check, stmt))
115581 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115582 +
115583 + rhs_code = gimple_assign_rhs_code(stmt);
115584 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115585 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115586 +
115587 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115588 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115589 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115590 + }
115591 +
115592 + if (!gimple_assign_cast_p(stmt))
115593 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115594 +
115595 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115596 +}
115597 +
115598 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115599 +{
115600 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115601 + gimple def_stmt = get_def_stmt(lhs);
115602 +
115603 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115604 + rhs1 = gimple_assign_rhs1(def_stmt);
115605 +
115606 + if (is_gimple_constant(rhs1))
115607 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115608 +
115609 + switch (TREE_CODE(rhs1)) {
115610 + case SSA_NAME: {
115611 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115612 +
115613 + if (gimple_assign_cast_p(stmt))
115614 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115615 + return ret;
115616 + }
115617 + case ARRAY_REF:
115618 + case BIT_FIELD_REF:
115619 + case ADDR_EXPR:
115620 + case COMPONENT_REF:
115621 + case INDIRECT_REF:
115622 +#if BUILDING_GCC_VERSION >= 4006
115623 + case MEM_REF:
115624 +#endif
115625 + case TARGET_MEM_REF:
115626 + case VIEW_CONVERT_EXPR:
115627 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115628 + case PARM_DECL:
115629 + case VAR_DECL:
115630 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115631 +
115632 + default:
115633 + debug_gimple_stmt(def_stmt);
115634 + debug_tree(rhs1);
115635 + gcc_unreachable();
115636 + }
115637 +}
115638 +
115639 +static void __unused print_the_code_insertions(const_gimple stmt)
115640 +{
115641 + location_t loc = gimple_location(stmt);
115642 +
115643 + inform(loc, "Integer size_overflow check applied here.");
115644 +}
115645 +
115646 +static bool is_from_cast(const_tree node)
115647 +{
115648 + gimple def_stmt = get_def_stmt(node);
115649 +
115650 + if (!def_stmt)
115651 + return false;
115652 +
115653 + if (gimple_assign_cast_p(def_stmt))
115654 + return true;
115655 +
115656 + return false;
115657 +}
115658 +
115659 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115660 +static bool is_a_ptr_minus(gimple stmt)
115661 +{
115662 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115663 +
115664 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115665 + return false;
115666 +
115667 + rhs1 = gimple_assign_rhs1(stmt);
115668 + if (!is_from_cast(rhs1))
115669 + return false;
115670 +
115671 + rhs2 = gimple_assign_rhs2(stmt);
115672 + if (!is_from_cast(rhs2))
115673 + return false;
115674 +
115675 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115676 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115677 +
115678 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115679 + return false;
115680 +
115681 + return true;
115682 +}
115683 +
115684 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115685 +{
115686 + enum intentional_overflow_type res;
115687 + tree rhs1, rhs2, new_lhs;
115688 + gimple def_stmt = get_def_stmt(lhs);
115689 + tree new_rhs1 = NULL_TREE;
115690 + tree new_rhs2 = NULL_TREE;
115691 +
115692 + if (is_a_ptr_minus(def_stmt))
115693 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115694 +
115695 + rhs1 = gimple_assign_rhs1(def_stmt);
115696 + rhs2 = gimple_assign_rhs2(def_stmt);
115697 +
115698 + /* no DImode/TImode division in the 32/64 bit kernel */
115699 + switch (gimple_assign_rhs_code(def_stmt)) {
115700 + case RDIV_EXPR:
115701 + case TRUNC_DIV_EXPR:
115702 + case CEIL_DIV_EXPR:
115703 + case FLOOR_DIV_EXPR:
115704 + case ROUND_DIV_EXPR:
115705 + case TRUNC_MOD_EXPR:
115706 + case CEIL_MOD_EXPR:
115707 + case FLOOR_MOD_EXPR:
115708 + case ROUND_MOD_EXPR:
115709 + case EXACT_DIV_EXPR:
115710 + case POINTER_PLUS_EXPR:
115711 + case BIT_AND_EXPR:
115712 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115713 + default:
115714 + break;
115715 + }
115716 +
115717 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115718 + if (new_lhs != NULL_TREE)
115719 + return new_lhs;
115720 +
115721 + if (TREE_CODE(rhs1) == SSA_NAME)
115722 + new_rhs1 = expand(visited, caller_node, rhs1);
115723 + if (TREE_CODE(rhs2) == SSA_NAME)
115724 + new_rhs2 = expand(visited, caller_node, rhs2);
115725 +
115726 + res = add_mul_intentional_overflow(def_stmt);
115727 + if (res != NO_INTENTIONAL_OVERFLOW) {
115728 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115729 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115730 + return new_lhs;
115731 + }
115732 +
115733 + if (skip_expr_on_double_type(def_stmt)) {
115734 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115735 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115736 + return new_lhs;
115737 + }
115738 +
115739 + if (is_a_neg_overflow(def_stmt, rhs2))
115740 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115741 + if (is_a_neg_overflow(def_stmt, rhs1))
115742 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115743 +
115744 +
115745 + if (is_a_constant_overflow(def_stmt, rhs2))
115746 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115747 + if (is_a_constant_overflow(def_stmt, rhs1))
115748 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115749 +
115750 + // the const is between 0 and (signed) MAX
115751 + if (is_gimple_constant(rhs1))
115752 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115753 + if (is_gimple_constant(rhs2))
115754 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115755 +
115756 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115757 +}
115758 +
115759 +#if BUILDING_GCC_VERSION >= 4006
115760 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115761 +{
115762 + if (is_gimple_constant(rhs))
115763 + return cast_a_tree(size_overflow_type, rhs);
115764 + if (TREE_CODE(rhs) != SSA_NAME)
115765 + return NULL_TREE;
115766 + return expand(visited, caller_node, rhs);
115767 +}
115768 +
115769 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115770 +{
115771 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115772 + gimple def_stmt = get_def_stmt(lhs);
115773 +
115774 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115775 +
115776 + rhs1 = gimple_assign_rhs1(def_stmt);
115777 + rhs2 = gimple_assign_rhs2(def_stmt);
115778 + rhs3 = gimple_assign_rhs3(def_stmt);
115779 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115780 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115781 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115782 +
115783 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115784 +}
115785 +#endif
115786 +
115787 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115788 +{
115789 + gimple_stmt_iterator gsi;
115790 + gimple next_stmt = NULL;
115791 +
115792 + gsi = gsi_for_stmt(stmt);
115793 +
115794 + do {
115795 + gsi_next(&gsi);
115796 + next_stmt = gsi_stmt(gsi);
115797 +
115798 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115799 + return NULL_TREE;
115800 +
115801 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115802 + break;
115803 +
115804 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115805 + } while (!gsi_end_p(gsi));
115806 +
115807 + gcc_assert(next_stmt);
115808 + return get_lhs(next_stmt);
115809 +}
115810 +
115811 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115812 +{
115813 + gimple_stmt_iterator gsi;
115814 + enum gimple_code code = gimple_code(def_stmt);
115815 +
115816 + if (code == GIMPLE_ASM)
115817 + return NULL_TREE;
115818 +
115819 + gsi = gsi_for_stmt(def_stmt);
115820 + gsi_next(&gsi);
115821 +
115822 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115823 + return NULL_TREE;
115824 + return get_my_stmt_lhs(visited, def_stmt);
115825 +}
115826 +
115827 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115828 +{
115829 + gimple def_stmt;
115830 +
115831 + def_stmt = get_def_stmt(lhs);
115832 +
115833 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115834 + return NULL_TREE;
115835 +
115836 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115837 + return lhs;
115838 +
115839 + if (pointer_set_contains(visited->stmts, def_stmt))
115840 + return expand_visited(visited, def_stmt);
115841 +
115842 + switch (gimple_code(def_stmt)) {
115843 + case GIMPLE_PHI:
115844 + return handle_phi(visited, caller_node, lhs);
115845 + case GIMPLE_CALL:
115846 + case GIMPLE_ASM:
115847 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115848 + case GIMPLE_ASSIGN:
115849 + switch (gimple_num_ops(def_stmt)) {
115850 + case 2:
115851 + return handle_unary_ops(visited, caller_node, def_stmt);
115852 + case 3:
115853 + return handle_binary_ops(visited, caller_node, lhs);
115854 +#if BUILDING_GCC_VERSION >= 4006
115855 + case 4:
115856 + return handle_ternary_ops(visited, caller_node, lhs);
115857 +#endif
115858 + }
115859 + default:
115860 + debug_gimple_stmt(def_stmt);
115861 + error("%s: unknown gimple code", __func__);
115862 + gcc_unreachable();
115863 + }
115864 +}
115865 +
115866 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
115867 new file mode 100644
115868 index 0000000..df50164
115869 --- /dev/null
115870 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115871 @@ -0,0 +1,1141 @@
115872 +/*
115873 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115874 + * Licensed under the GPL v2, or (at your option) v3
115875 + *
115876 + * Homepage:
115877 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115878 + *
115879 + * Documentation:
115880 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115881 + *
115882 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115883 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115884 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115885 + *
115886 + * Usage:
115887 + * $ make
115888 + * $ make run
115889 + */
115890 +
115891 +#include "gcc-common.h"
115892 +#include "size_overflow.h"
115893 +
115894 +#define VEC_LEN 128
115895 +#define RET_CHECK NULL_TREE
115896 +#define WRONG_NODE 32
115897 +#define NOT_INTENTIONAL_ASM NULL
115898 +
115899 +unsigned int call_count;
115900 +
115901 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115902 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115903 +
115904 +struct visited_fns {
115905 + struct visited_fns *next;
115906 + const_tree fndecl;
115907 + unsigned int num;
115908 + const_gimple first_stmt;
115909 +};
115910 +
115911 +struct next_cgraph_node {
115912 + struct next_cgraph_node *next;
115913 + struct cgraph_node *current_function;
115914 + tree callee_fndecl;
115915 + unsigned int num;
115916 +};
115917 +
115918 +// Don't want to duplicate entries in next_cgraph_node
115919 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115920 +{
115921 + const_tree new_callee_fndecl;
115922 + struct next_cgraph_node *cur_node;
115923 +
115924 + if (fndecl == RET_CHECK)
115925 + new_callee_fndecl = NODE_DECL(node);
115926 + else
115927 + new_callee_fndecl = fndecl;
115928 +
115929 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115930 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115931 + continue;
115932 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115933 + continue;
115934 + if (num == cur_node->num)
115935 + return true;
115936 + }
115937 + return false;
115938 +}
115939 +
115940 +/* Add a next_cgraph_node into the list for handle_function().
115941 + * handle_function() iterates over all the next cgraph nodes and
115942 + * starts the overflow check insertion process.
115943 + */
115944 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115945 +{
115946 + struct next_cgraph_node *new_node;
115947 +
115948 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115949 + return head;
115950 +
115951 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115952 + new_node->current_function = node;
115953 + new_node->next = NULL;
115954 + new_node->num = num;
115955 + if (fndecl == RET_CHECK)
115956 + new_node->callee_fndecl = NODE_DECL(node);
115957 + else
115958 + new_node->callee_fndecl = fndecl;
115959 +
115960 + if (!head)
115961 + return new_node;
115962 +
115963 + new_node->next = head;
115964 + return new_node;
115965 +}
115966 +
115967 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115968 +{
115969 + struct cgraph_edge *e;
115970 +
115971 + if (num == 0)
115972 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115973 +
115974 + for (e = node->callers; e; e = e->next_caller) {
115975 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115976 +
115977 + gcc_assert(fndecl != NULL_TREE);
115978 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115979 + }
115980 +
115981 + return head;
115982 +}
115983 +
115984 +struct missing_functions {
115985 + struct missing_functions *next;
115986 + const_tree node;
115987 + tree fndecl;
115988 +};
115989 +
115990 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115991 +{
115992 + struct missing_functions *new_function;
115993 +
115994 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115995 + new_function->node = node;
115996 + new_function->next = NULL;
115997 +
115998 + if (TREE_CODE(node) == FUNCTION_DECL)
115999 + new_function->fndecl = node;
116000 + else
116001 + new_function->fndecl = current_function_decl;
116002 + gcc_assert(new_function->fndecl);
116003 +
116004 + if (!missing_fn_head)
116005 + return new_function;
116006 +
116007 + new_function->next = missing_fn_head;
116008 + return new_function;
116009 +}
116010 +
116011 +/* If the function is missing from the hash table and it is a static function
116012 + * then create a next_cgraph_node from it for handle_function()
116013 + */
116014 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116015 +{
116016 + unsigned int num;
116017 + const_tree orig_fndecl;
116018 + struct cgraph_node *next_node = NULL;
116019 +
116020 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116021 +
116022 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116023 + if (num == CANNOT_FIND_ARG)
116024 + return cnodes;
116025 +
116026 + if (!is_missing_function(orig_fndecl, num))
116027 + return cnodes;
116028 +
116029 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116030 + if (next_node && next_node->local.local)
116031 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116032 + return cnodes;
116033 +}
116034 +
116035 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116036 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116037 + */
116038 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116039 +{
116040 + unsigned int i;
116041 + tree node;
116042 + struct missing_functions *cur, *missing_fn_head = NULL;
116043 +
116044 +#if BUILDING_GCC_VERSION <= 4007
116045 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116046 +#else
116047 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116048 +#endif
116049 + switch (TREE_CODE(node)) {
116050 + case PARM_DECL:
116051 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116052 + break;
116053 + case FUNCTION_DECL:
116054 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116055 + break;
116056 + default:
116057 + break;
116058 + }
116059 + }
116060 +
116061 + while (missing_fn_head) {
116062 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116063 +
116064 + cur = missing_fn_head->next;
116065 + free(missing_fn_head);
116066 + missing_fn_head = cur;
116067 + }
116068 +
116069 + return cnodes;
116070 +}
116071 +
116072 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116073 +{
116074 + gimple phi = get_def_stmt(result);
116075 + unsigned int i, n = gimple_phi_num_args(phi);
116076 +
116077 + pointer_set_insert(visited, phi);
116078 + for (i = 0; i < n; i++) {
116079 + const_tree arg = gimple_phi_arg_def(phi, i);
116080 +
116081 + set_conditions(visited, interesting_conditions, arg);
116082 + }
116083 +}
116084 +
116085 +enum conditions {
116086 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
116087 +};
116088 +
116089 +// Search for constants, cast assignments and binary/ternary assignments
116090 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116091 +{
116092 + gimple def_stmt = get_def_stmt(lhs);
116093 +
116094 + if (is_gimple_constant(lhs)) {
116095 + interesting_conditions[FROM_CONST] = true;
116096 + return;
116097 + }
116098 +
116099 + if (!def_stmt)
116100 + return;
116101 +
116102 + if (pointer_set_contains(visited, def_stmt))
116103 + return;
116104 +
116105 + switch (gimple_code(def_stmt)) {
116106 + case GIMPLE_CALL:
116107 + if (lhs == gimple_call_lhs(def_stmt))
116108 + interesting_conditions[RET] = true;
116109 + return;
116110 + case GIMPLE_NOP:
116111 + case GIMPLE_ASM:
116112 + return;
116113 + case GIMPLE_PHI:
116114 + interesting_conditions[PHI] = true;
116115 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116116 + case GIMPLE_ASSIGN:
116117 + if (gimple_num_ops(def_stmt) == 2) {
116118 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116119 +
116120 + if (gimple_assign_cast_p(def_stmt))
116121 + interesting_conditions[CAST] = true;
116122 +
116123 + return set_conditions(visited, interesting_conditions, rhs);
116124 + } else {
116125 + interesting_conditions[NOT_UNARY] = true;
116126 + return;
116127 + }
116128 + default:
116129 + debug_gimple_stmt(def_stmt);
116130 + gcc_unreachable();
116131 + }
116132 +}
116133 +
116134 +// determine whether duplication will be necessary or not.
116135 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116136 +{
116137 + struct pointer_set_t *visited;
116138 +
116139 + if (gimple_assign_cast_p(cur_node->first_stmt))
116140 + interesting_conditions[CAST] = true;
116141 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116142 + interesting_conditions[NOT_UNARY] = true;
116143 +
116144 + visited = pointer_set_create();
116145 + set_conditions(visited, interesting_conditions, cur_node->node);
116146 + pointer_set_destroy(visited);
116147 +}
116148 +
116149 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116150 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116151 +{
116152 + gimple assign;
116153 + gimple_stmt_iterator gsi;
116154 +
116155 + // already removed
116156 + if (gimple_bb(asm_stmt) == NULL)
116157 + return;
116158 + gsi = gsi_for_stmt(asm_stmt);
116159 +
116160 + assign = gimple_build_assign(lhs, rhs);
116161 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116162 + SSA_NAME_DEF_STMT(lhs) = assign;
116163 +
116164 + gsi_remove(&gsi, true);
116165 +}
116166 +
116167 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116168 + * stmt is a return otherwise it is the callee function.
116169 + */
116170 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116171 +{
116172 + const_tree fndecl;
116173 +
116174 + if (argnum == 0)
116175 + fndecl = current_function_decl;
116176 + else
116177 + fndecl = gimple_call_fndecl(stmt);
116178 +
116179 + if (fndecl == NULL_TREE)
116180 + return NULL_TREE;
116181 +
116182 + return DECL_ORIGIN(fndecl);
116183 +}
116184 +
116185 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116186 +static bool skip_asm(const_tree arg)
116187 +{
116188 + gimple def_stmt = get_def_stmt(arg);
116189 +
116190 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116191 + return false;
116192 +
116193 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116194 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116195 +}
116196 +
116197 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116198 +{
116199 + gimple phi = get_def_stmt(result);
116200 + unsigned int i, n = gimple_phi_num_args(phi);
116201 +
116202 + pointer_set_insert(visited, phi);
116203 + for (i = 0; i < n; i++) {
116204 + tree arg = gimple_phi_arg_def(phi, i);
116205 +
116206 + walk_use_def(visited, cur_node, arg);
116207 + }
116208 +}
116209 +
116210 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116211 +{
116212 + gimple def_stmt = get_def_stmt(lhs);
116213 + tree rhs1, rhs2;
116214 +
116215 + rhs1 = gimple_assign_rhs1(def_stmt);
116216 + rhs2 = gimple_assign_rhs2(def_stmt);
116217 +
116218 + walk_use_def(visited, cur_node, rhs1);
116219 + walk_use_def(visited, cur_node, rhs2);
116220 +}
116221 +
116222 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116223 +{
116224 + unsigned int i;
116225 + tree element;
116226 + enum tree_code code;
116227 +
116228 + gcc_assert(node != NULL_TREE);
116229 +
116230 + if (is_gimple_constant(node))
116231 + return;
116232 +
116233 + code = TREE_CODE(node);
116234 + if (code == VAR_DECL) {
116235 + node = DECL_ORIGIN(node);
116236 + code = TREE_CODE(node);
116237 + }
116238 +
116239 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116240 + return;
116241 +
116242 +#if BUILDING_GCC_VERSION <= 4007
116243 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116244 +#else
116245 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116246 +#endif
116247 + if (operand_equal_p(node, element, 0))
116248 + return;
116249 + }
116250 +
116251 +#if BUILDING_GCC_VERSION <= 4007
116252 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116253 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116254 +#else
116255 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116256 + vec_safe_push(cur_node->last_nodes, node);
116257 +#endif
116258 +}
116259 +
116260 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116261 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116262 +{
116263 + if (!is_size_overflow_asm(stmt))
116264 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116265 +}
116266 +
116267 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116268 + * and component refs (for checking the intentional_overflow attribute).
116269 + */
116270 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116271 +{
116272 + const_gimple def_stmt;
116273 +
116274 + if (TREE_CODE(lhs) != SSA_NAME) {
116275 + insert_last_node(cur_node, lhs);
116276 + return;
116277 + }
116278 +
116279 + def_stmt = get_def_stmt(lhs);
116280 + if (!def_stmt)
116281 + return;
116282 +
116283 + if (pointer_set_insert(visited, def_stmt))
116284 + return;
116285 +
116286 + switch (gimple_code(def_stmt)) {
116287 + case GIMPLE_NOP:
116288 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116289 + case GIMPLE_ASM:
116290 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116291 + case GIMPLE_CALL: {
116292 + tree fndecl = gimple_call_fndecl(def_stmt);
116293 +
116294 + if (fndecl == NULL_TREE)
116295 + return;
116296 + insert_last_node(cur_node, fndecl);
116297 + return;
116298 + }
116299 + case GIMPLE_PHI:
116300 + return walk_use_def_phi(visited, cur_node, lhs);
116301 + case GIMPLE_ASSIGN:
116302 + switch (gimple_num_ops(def_stmt)) {
116303 + case 2:
116304 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116305 + case 3:
116306 + return walk_use_def_binary(visited, cur_node, lhs);
116307 + }
116308 + default:
116309 + debug_gimple_stmt((gimple)def_stmt);
116310 + error("%s: unknown gimple code", __func__);
116311 + gcc_unreachable();
116312 + }
116313 +}
116314 +
116315 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116316 +static void set_last_nodes(struct interesting_node *cur_node)
116317 +{
116318 + struct pointer_set_t *visited;
116319 +
116320 + visited = pointer_set_create();
116321 + walk_use_def(visited, cur_node, cur_node->node);
116322 + pointer_set_destroy(visited);
116323 +}
116324 +
116325 +enum precond {
116326 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116327 +};
116328 +
116329 +/* 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.
116330 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116331 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116332 + * It skips the possible error codes too.
116333 + */
116334 +static enum precond check_preconditions(struct interesting_node *cur_node)
116335 +{
116336 + bool interesting_conditions[5] = {false, false, false, false, false};
116337 +
116338 + set_last_nodes(cur_node);
116339 +
116340 + check_intentional_attribute_ipa(cur_node);
116341 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116342 + return NO_ATTRIBUTE_SEARCH;
116343 +
116344 + search_interesting_conditions(cur_node, interesting_conditions);
116345 +
116346 + // error code: a phi, unary assign (not cast) and returns only
116347 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116348 + return NO_ATTRIBUTE_SEARCH;
116349 +
116350 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116351 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116352 + return NO_ATTRIBUTE_SEARCH;
116353 +
116354 + // unnecessary overflow check
116355 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116356 + return NO_CHECK_INSERT;
116357 +
116358 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116359 + return NO_CHECK_INSERT;
116360 +
116361 + return NONE;
116362 +}
116363 +
116364 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116365 +{
116366 + const_gimple assign;
116367 + tree orig_type = TREE_TYPE(orig_node);
116368 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116369 +
116370 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116371 + return gimple_assign_lhs(assign);
116372 +}
116373 +
116374 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116375 +{
116376 + void (*set_rhs)(gimple, tree);
116377 + gimple stmt = cur_node->first_stmt;
116378 + const_tree orig_node = cur_node->node;
116379 +
116380 + switch (gimple_code(stmt)) {
116381 + case GIMPLE_RETURN:
116382 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116383 + break;
116384 + case GIMPLE_CALL:
116385 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116386 + break;
116387 + case GIMPLE_ASSIGN:
116388 + switch (cur_node->num) {
116389 + case 1:
116390 + set_rhs = &gimple_assign_set_rhs1;
116391 + break;
116392 + case 2:
116393 + set_rhs = &gimple_assign_set_rhs2;
116394 + break;
116395 +#if BUILDING_GCC_VERSION >= 4006
116396 + case 3:
116397 + set_rhs = &gimple_assign_set_rhs3;
116398 + break;
116399 +#endif
116400 + default:
116401 + gcc_unreachable();
116402 + }
116403 +
116404 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116405 + break;
116406 + default:
116407 + debug_gimple_stmt(stmt);
116408 + gcc_unreachable();
116409 + }
116410 +
116411 + update_stmt(stmt);
116412 +}
116413 +
116414 +static struct visited *create_visited(void)
116415 +{
116416 + struct visited *new_node;
116417 +
116418 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116419 + new_node->stmts = pointer_set_create();
116420 + new_node->my_stmts = pointer_set_create();
116421 + new_node->skip_expr_casts = pointer_set_create();
116422 + new_node->no_cast_check = pointer_set_create();
116423 + return new_node;
116424 +}
116425 +
116426 +static void free_visited(struct visited *visited)
116427 +{
116428 + pointer_set_destroy(visited->stmts);
116429 + pointer_set_destroy(visited->my_stmts);
116430 + pointer_set_destroy(visited->skip_expr_casts);
116431 + pointer_set_destroy(visited->no_cast_check);
116432 +
116433 + free(visited);
116434 +}
116435 +
116436 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116437 + * 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
116438 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116439 + */
116440 +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)
116441 +{
116442 + enum precond ret;
116443 + tree new_node, orig_node = cur_node->node;
116444 +
116445 + ret = check_preconditions(cur_node);
116446 + if (ret == NO_ATTRIBUTE_SEARCH)
116447 + return cnodes;
116448 +
116449 + cnodes = search_overflow_attribute(cnodes, cur_node);
116450 +
116451 + if (ret == NO_CHECK_INSERT)
116452 + return cnodes;
116453 +
116454 + new_node = expand(visited, caller_node, orig_node);
116455 + if (new_node == NULL_TREE)
116456 + return cnodes;
116457 +
116458 + change_orig_node(visited, cur_node, new_node);
116459 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116460 +
116461 + return cnodes;
116462 +}
116463 +
116464 +// Check visited_fns interesting nodes.
116465 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116466 +{
116467 + struct interesting_node *cur;
116468 +
116469 + for (cur = head; cur; cur = cur->next) {
116470 + if (!operand_equal_p(node, cur->node, 0))
116471 + continue;
116472 + if (num != cur->num)
116473 + continue;
116474 + if (first_stmt == cur->first_stmt)
116475 + return true;
116476 + }
116477 + return false;
116478 +}
116479 +
116480 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116481 + 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
116482 + 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
116483 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116484 + num: arg count of a call stmt or 0 when it is a ret
116485 + node: the recursion starts from here, it is a call arg or a return value
116486 + 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.
116487 + intentional_attr_decl: intentional_overflow attribute of the callee function
116488 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116489 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116490 + */
116491 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116492 +{
116493 + struct interesting_node *new_node;
116494 + tree fndecl;
116495 + enum gimple_code code;
116496 +
116497 + gcc_assert(node != NULL_TREE);
116498 + code = gimple_code(first_stmt);
116499 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116500 +
116501 + if (num == CANNOT_FIND_ARG)
116502 + return head;
116503 +
116504 + if (skip_types(node))
116505 + return head;
116506 +
116507 + if (skip_asm(node))
116508 + return head;
116509 +
116510 + if (is_gimple_call(first_stmt))
116511 + fndecl = gimple_call_fndecl(first_stmt);
116512 + else
116513 + fndecl = current_function_decl;
116514 +
116515 + if (fndecl == NULL_TREE)
116516 + return head;
116517 +
116518 + if (is_in_interesting_node(head, first_stmt, node, num))
116519 + return head;
116520 +
116521 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116522 +
116523 + new_node->next = NULL;
116524 + new_node->first_stmt = first_stmt;
116525 +#if BUILDING_GCC_VERSION <= 4007
116526 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116527 +#else
116528 + vec_alloc(new_node->last_nodes, VEC_LEN);
116529 +#endif
116530 + new_node->num = num;
116531 + new_node->node = node;
116532 + new_node->fndecl = fndecl;
116533 + new_node->intentional_attr_decl = MARK_NO;
116534 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116535 + new_node->intentional_mark_from_gimple = asm_stmt;
116536 +
116537 + if (!head)
116538 + return new_node;
116539 +
116540 + new_node->next = head;
116541 + return new_node;
116542 +}
116543 +
116544 +/* 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).
116545 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116546 + */
116547 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116548 +{
116549 + struct next_cgraph_node *cur_node;
116550 + tree ret = gimple_return_retval(stmt);
116551 +
116552 + if (ret == NULL_TREE)
116553 + return head;
116554 +
116555 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116556 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116557 + continue;
116558 + if (cur_node->num == 0)
116559 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116560 + }
116561 +
116562 + return head;
116563 +}
116564 +
116565 +/* 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).
116566 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116567 + */
116568 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116569 +{
116570 + unsigned int argnum;
116571 + tree arg;
116572 + const_tree fndecl;
116573 + struct next_cgraph_node *cur_node;
116574 +
116575 + fndecl = gimple_call_fndecl(stmt);
116576 + if (fndecl == NULL_TREE)
116577 + return head;
116578 +
116579 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116580 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116581 + continue;
116582 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116583 + gcc_assert(argnum != CANNOT_FIND_ARG);
116584 + if (argnum == 0)
116585 + continue;
116586 +
116587 + arg = gimple_call_arg(stmt, argnum - 1);
116588 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116589 + }
116590 +
116591 + return head;
116592 +}
116593 +
116594 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116595 +{
116596 + if (!operand_equal_p(orig_node, node, 0))
116597 + return WRONG_NODE;
116598 + if (skip_types(node))
116599 + return WRONG_NODE;
116600 + return ret_count;
116601 +}
116602 +
116603 +// Get the index of the rhs node in an assignment
116604 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116605 +{
116606 + const_tree rhs1, rhs2;
116607 + unsigned int ret;
116608 +
116609 + gcc_assert(stmt);
116610 + gcc_assert(is_gimple_assign(stmt));
116611 +
116612 + rhs1 = gimple_assign_rhs1(stmt);
116613 + gcc_assert(rhs1 != NULL_TREE);
116614 +
116615 + switch (gimple_num_ops(stmt)) {
116616 + case 2:
116617 + return check_ops(node, rhs1, 1);
116618 + case 3:
116619 + ret = check_ops(node, rhs1, 1);
116620 + if (ret != WRONG_NODE)
116621 + return ret;
116622 +
116623 + rhs2 = gimple_assign_rhs2(stmt);
116624 + gcc_assert(rhs2 != NULL_TREE);
116625 + return check_ops(node, rhs2, 2);
116626 + default:
116627 + gcc_unreachable();
116628 + }
116629 +}
116630 +
116631 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116632 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116633 +{
116634 + unsigned int i;
116635 +
116636 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116637 + return CANNOT_FIND_ARG;
116638 +
116639 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116640 + tree node;
116641 +
116642 + node = gimple_call_arg(stmt, i);
116643 + if (!operand_equal_p(arg, node, 0))
116644 + continue;
116645 + if (!skip_types(node))
116646 + return i + 1;
116647 + }
116648 +
116649 + return CANNOT_FIND_ARG;
116650 +}
116651 +
116652 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116653 + * any of return, call or assignment stmts (because of inlining).
116654 + */
116655 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116656 +{
116657 + use_operand_p use_p;
116658 + imm_use_iterator imm_iter;
116659 + unsigned int argnum;
116660 +
116661 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116662 +
116663 + if (pointer_set_insert(visited, node))
116664 + return head;
116665 +
116666 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116667 + gimple stmt = USE_STMT(use_p);
116668 +
116669 + if (stmt == NULL)
116670 + return head;
116671 + if (is_gimple_debug(stmt))
116672 + continue;
116673 +
116674 + switch (gimple_code(stmt)) {
116675 + case GIMPLE_CALL:
116676 + argnum = find_arg_number_gimple(node, stmt);
116677 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116678 + break;
116679 + case GIMPLE_RETURN:
116680 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116681 + break;
116682 + case GIMPLE_ASSIGN:
116683 + argnum = get_assign_ops_count(stmt, node);
116684 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116685 + break;
116686 + case GIMPLE_PHI: {
116687 + tree result = gimple_phi_result(stmt);
116688 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116689 + break;
116690 + }
116691 + case GIMPLE_ASM:
116692 + if (gimple_asm_noutputs(stmt) != 0)
116693 + break;
116694 + if (!is_size_overflow_asm(stmt))
116695 + break;
116696 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116697 + break;
116698 + case GIMPLE_COND:
116699 + case GIMPLE_SWITCH:
116700 + break;
116701 + default:
116702 + debug_gimple_stmt(stmt);
116703 + gcc_unreachable();
116704 + break;
116705 + }
116706 + }
116707 + return head;
116708 +}
116709 +
116710 +static void remove_size_overflow_asm(gimple stmt)
116711 +{
116712 + gimple_stmt_iterator gsi;
116713 + tree input, output;
116714 +
116715 + if (!is_size_overflow_asm(stmt))
116716 + return;
116717 +
116718 + if (gimple_asm_noutputs(stmt) == 0) {
116719 + gsi = gsi_for_stmt(stmt);
116720 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116721 + gsi_remove(&gsi, true);
116722 + return;
116723 + }
116724 +
116725 + input = gimple_asm_input_op(stmt, 0);
116726 + output = gimple_asm_output_op(stmt, 0);
116727 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116728 +}
116729 +
116730 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116731 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116732 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116733 + */
116734 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116735 +{
116736 + const_tree output;
116737 + struct pointer_set_t *visited;
116738 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116739 +
116740 + if (!is_size_overflow_asm(stmt))
116741 + return head;
116742 +
116743 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116744 + intentional_asm = stmt;
116745 +
116746 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116747 +
116748 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116749 + return head;
116750 +
116751 + if (gimple_asm_noutputs(stmt) == 0) {
116752 + const_tree input;
116753 +
116754 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116755 + return head;
116756 +
116757 + input = gimple_asm_input_op(stmt, 0);
116758 + remove_size_overflow_asm(stmt);
116759 + if (is_gimple_constant(TREE_VALUE(input)))
116760 + return head;
116761 + visited = pointer_set_create();
116762 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116763 + pointer_set_destroy(visited);
116764 + return head;
116765 + }
116766 +
116767 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116768 + remove_size_overflow_asm(stmt);
116769 +
116770 + visited = pointer_set_create();
116771 + output = gimple_asm_output_op(stmt, 0);
116772 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116773 + pointer_set_destroy(visited);
116774 + return head;
116775 +}
116776 +
116777 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116778 + * or a call stmt or a return stmt and store them in the interesting_node list
116779 + */
116780 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116781 +{
116782 + basic_block bb;
116783 + struct interesting_node *head = NULL;
116784 +
116785 + FOR_ALL_BB_FN(bb, cfun) {
116786 + gimple_stmt_iterator gsi;
116787 +
116788 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116789 + enum gimple_code code;
116790 + gimple stmt = gsi_stmt(gsi);
116791 +
116792 + code = gimple_code(stmt);
116793 +
116794 + if (code == GIMPLE_ASM)
116795 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116796 +
116797 + if (!next_node)
116798 + continue;
116799 + if (code == GIMPLE_CALL)
116800 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116801 + if (code == GIMPLE_RETURN)
116802 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116803 + }
116804 + }
116805 + return head;
116806 +}
116807 +
116808 +static void free_interesting_node(struct interesting_node *head)
116809 +{
116810 + struct interesting_node *cur;
116811 +
116812 + while (head) {
116813 + cur = head->next;
116814 +#if BUILDING_GCC_VERSION <= 4007
116815 + VEC_free(tree, gc, head->last_nodes);
116816 +#else
116817 + vec_free(head->last_nodes);
116818 +#endif
116819 + free(head);
116820 + head = cur;
116821 + }
116822 +}
116823 +
116824 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116825 +{
116826 + struct visited_fns *new_visited_fns;
116827 +
116828 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116829 + new_visited_fns->fndecl = cur_node->fndecl;
116830 + new_visited_fns->num = cur_node->num;
116831 + new_visited_fns->first_stmt = cur_node->first_stmt;
116832 + new_visited_fns->next = NULL;
116833 +
116834 + if (!head)
116835 + return new_visited_fns;
116836 +
116837 + new_visited_fns->next = head;
116838 + return new_visited_fns;
116839 +}
116840 +
116841 +/* 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
116842 + * it is a visited_fns function.
116843 + */
116844 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116845 +{
116846 + struct visited_fns *cur;
116847 +
116848 + if (!head)
116849 + return false;
116850 +
116851 + for (cur = head; cur; cur = cur->next) {
116852 + if (cur_node->first_stmt != cur->first_stmt)
116853 + continue;
116854 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116855 + continue;
116856 + if (cur_node->num == cur->num)
116857 + return true;
116858 + }
116859 + return false;
116860 +}
116861 +
116862 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116863 +{
116864 + struct next_cgraph_node *cur;
116865 +
116866 + while (head) {
116867 + cur = head->next;
116868 + free(head);
116869 + head = cur;
116870 + }
116871 +}
116872 +
116873 +static void remove_all_size_overflow_asm(void)
116874 +{
116875 + basic_block bb;
116876 +
116877 + FOR_ALL_BB_FN(bb, cfun) {
116878 + gimple_stmt_iterator si;
116879 +
116880 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116881 + remove_size_overflow_asm(gsi_stmt(si));
116882 + }
116883 +}
116884 +
116885 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116886 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116887 + * the newly collected interesting functions (they are interesting if there is control flow between
116888 + * the interesting stmts and them).
116889 + */
116890 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116891 +{
116892 + struct visited *visited;
116893 + struct interesting_node *head, *cur_node;
116894 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116895 +
116896 + set_current_function_decl(NODE_DECL(node));
116897 + call_count = 0;
116898 +
116899 + head = collect_interesting_stmts(next_node);
116900 +
116901 + visited = create_visited();
116902 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116903 + if (is_visited_fns_function(visited_fns, cur_node))
116904 + continue;
116905 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116906 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116907 + }
116908 +
116909 + free_visited(visited);
116910 + free_interesting_node(head);
116911 + remove_all_size_overflow_asm();
116912 + unset_current_function_decl();
116913 +
116914 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116915 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116916 +
116917 + free_next_cgraph_node(cnodes_head);
116918 + return visited_fns;
116919 +}
116920 +
116921 +static void free_visited_fns(struct visited_fns *head)
116922 +{
116923 + struct visited_fns *cur;
116924 +
116925 + while (head) {
116926 + cur = head->next;
116927 + free(head);
116928 + head = cur;
116929 + }
116930 +}
116931 +
116932 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116933 +unsigned int search_function(void)
116934 +{
116935 + struct cgraph_node *node;
116936 + struct visited_fns *visited_fns = NULL;
116937 +
116938 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116939 + gcc_assert(cgraph_function_flags_ready);
116940 +#if BUILDING_GCC_VERSION <= 4007
116941 + gcc_assert(node->reachable);
116942 +#endif
116943 +
116944 + visited_fns = handle_function(node, NULL, visited_fns);
116945 + }
116946 +
116947 + free_visited_fns(visited_fns);
116948 + return 0;
116949 +}
116950 +
116951 +#if BUILDING_GCC_VERSION >= 4009
116952 +static const struct pass_data insert_size_overflow_check_data = {
116953 +#else
116954 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116955 + .pass = {
116956 +#endif
116957 + .type = SIMPLE_IPA_PASS,
116958 + .name = "size_overflow",
116959 +#if BUILDING_GCC_VERSION >= 4008
116960 + .optinfo_flags = OPTGROUP_NONE,
116961 +#endif
116962 +#if BUILDING_GCC_VERSION >= 4009
116963 + .has_gate = false,
116964 + .has_execute = true,
116965 +#else
116966 + .gate = NULL,
116967 + .execute = search_function,
116968 + .sub = NULL,
116969 + .next = NULL,
116970 + .static_pass_number = 0,
116971 +#endif
116972 + .tv_id = TV_NONE,
116973 + .properties_required = 0,
116974 + .properties_provided = 0,
116975 + .properties_destroyed = 0,
116976 + .todo_flags_start = 0,
116977 + .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,
116978 +#if BUILDING_GCC_VERSION < 4009
116979 + },
116980 + .generate_summary = NULL,
116981 + .write_summary = NULL,
116982 + .read_summary = NULL,
116983 +#if BUILDING_GCC_VERSION >= 4006
116984 + .write_optimization_summary = NULL,
116985 + .read_optimization_summary = NULL,
116986 +#endif
116987 + .stmt_fixup = NULL,
116988 + .function_transform_todo_flags_start = 0,
116989 + .function_transform = NULL,
116990 + .variable_transform = NULL,
116991 +#endif
116992 +};
116993 +
116994 +#if BUILDING_GCC_VERSION >= 4009
116995 +namespace {
116996 +class insert_size_overflow_check : public ipa_opt_pass_d {
116997 +public:
116998 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116999 + unsigned int execute() { return search_function(); }
117000 +};
117001 +}
117002 +#endif
117003 +
117004 +struct opt_pass *make_insert_size_overflow_check(void)
117005 +{
117006 +#if BUILDING_GCC_VERSION >= 4009
117007 + return new insert_size_overflow_check();
117008 +#else
117009 + return &insert_size_overflow_check.pass;
117010 +#endif
117011 +}
117012 +
117013 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117014 new file mode 100644
117015 index 0000000..d71d72a
117016 --- /dev/null
117017 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117018 @@ -0,0 +1,736 @@
117019 +/*
117020 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117021 + * Licensed under the GPL v2, or (at your option) v3
117022 + *
117023 + * Homepage:
117024 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117025 + *
117026 + * Documentation:
117027 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117028 + *
117029 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117030 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117031 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117032 + *
117033 + * Usage:
117034 + * $ make
117035 + * $ make run
117036 + */
117037 +
117038 +#include "gcc-common.h"
117039 +#include "size_overflow.h"
117040 +
117041 +/* Get the param of the intentional_overflow attribute.
117042 + * * 0: MARK_NOT_INTENTIONAL
117043 + * * 1..MAX_PARAM: MARK_YES
117044 + * * -1: MARK_TURN_OFF
117045 + */
117046 +static tree get_attribute_param(const_tree decl)
117047 +{
117048 + const_tree attr;
117049 +
117050 + if (decl == NULL_TREE)
117051 + return NULL_TREE;
117052 +
117053 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117054 + if (!attr || !TREE_VALUE(attr))
117055 + return NULL_TREE;
117056 +
117057 + return TREE_VALUE(attr);
117058 +}
117059 +
117060 +// MARK_TURN_OFF
117061 +bool is_turn_off_intentional_attr(const_tree decl)
117062 +{
117063 + const_tree param_head;
117064 +
117065 + param_head = get_attribute_param(decl);
117066 + if (param_head == NULL_TREE)
117067 + return false;
117068 +
117069 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117070 + return true;
117071 + return false;
117072 +}
117073 +
117074 +// MARK_NOT_INTENTIONAL
117075 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117076 +{
117077 + const_tree param_head;
117078 +
117079 + if (argnum == 0)
117080 + return false;
117081 +
117082 + param_head = get_attribute_param(decl);
117083 + if (param_head == NULL_TREE)
117084 + return false;
117085 +
117086 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117087 + return true;
117088 + return false;
117089 +}
117090 +
117091 +// MARK_YES
117092 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117093 +{
117094 + tree param, param_head;
117095 +
117096 + if (argnum == 0)
117097 + return false;
117098 +
117099 + param_head = get_attribute_param(decl);
117100 + for (param = param_head; param; param = TREE_CHAIN(param))
117101 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117102 + return true;
117103 + return false;
117104 +}
117105 +
117106 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117107 +{
117108 + location_t loc;
117109 +
117110 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117111 + return;
117112 +
117113 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117114 + return;
117115 +
117116 + loc = DECL_SOURCE_LOCATION(decl);
117117 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117118 +}
117119 +
117120 +// Get the field decl of a component ref for intentional_overflow checking
117121 +static const_tree search_field_decl(const_tree comp_ref)
117122 +{
117123 + const_tree field = NULL_TREE;
117124 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117125 +
117126 + for (i = 0; i < len; i++) {
117127 + field = TREE_OPERAND(comp_ref, i);
117128 + if (TREE_CODE(field) == FIELD_DECL)
117129 + break;
117130 + }
117131 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117132 + return field;
117133 +}
117134 +
117135 +/* Get the type of the intentional_overflow attribute of a node
117136 + * * MARK_TURN_OFF
117137 + * * MARK_YES
117138 + * * MARK_NO
117139 + * * MARK_NOT_INTENTIONAL
117140 + */
117141 +enum mark get_intentional_attr_type(const_tree node)
117142 +{
117143 + const_tree cur_decl;
117144 +
117145 + if (node == NULL_TREE)
117146 + return MARK_NO;
117147 +
117148 + switch (TREE_CODE(node)) {
117149 + case COMPONENT_REF:
117150 + cur_decl = search_field_decl(node);
117151 + if (is_turn_off_intentional_attr(cur_decl))
117152 + return MARK_TURN_OFF;
117153 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117154 + return MARK_YES;
117155 + break;
117156 + case PARM_DECL: {
117157 + unsigned int argnum;
117158 +
117159 + cur_decl = DECL_ORIGIN(current_function_decl);
117160 + argnum = find_arg_number_tree(node, cur_decl);
117161 + if (argnum == CANNOT_FIND_ARG)
117162 + return MARK_NO;
117163 + if (is_yes_intentional_attr(cur_decl, argnum))
117164 + return MARK_YES;
117165 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117166 + return MARK_NOT_INTENTIONAL;
117167 + break;
117168 + }
117169 + case FUNCTION_DECL:
117170 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117171 + return MARK_TURN_OFF;
117172 + break;
117173 + default:
117174 + break;
117175 + }
117176 + return MARK_NO;
117177 +}
117178 +
117179 +// Search for the intentional_overflow attribute on the last nodes
117180 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117181 +{
117182 + unsigned int i;
117183 + tree last_node;
117184 + enum mark mark = MARK_NO;
117185 +
117186 +#if BUILDING_GCC_VERSION <= 4007
117187 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117188 +#else
117189 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117190 +#endif
117191 + mark = get_intentional_attr_type(last_node);
117192 + if (mark != MARK_NO)
117193 + break;
117194 + }
117195 + return mark;
117196 +}
117197 +
117198 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117199 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117200 + */
117201 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117202 +{
117203 + if (!cur_node->intentional_mark_from_gimple)
117204 + return false;
117205 +
117206 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117207 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117208 + else
117209 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117210 +
117211 + // skip param decls
117212 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117213 + return true;
117214 + return true;
117215 +}
117216 +
117217 +/* Search intentional_overflow attribute on caller and on callee too.
117218 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117219 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117220 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117221 +*/
117222 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117223 +{
117224 + const_tree fndecl;
117225 +
117226 + if (is_intentional_attribute_from_gimple(cur_node))
117227 + return;
117228 +
117229 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117230 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117231 + return;
117232 + }
117233 +
117234 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117235 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117236 + return;
117237 + }
117238 +
117239 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117240 + return;
117241 +
117242 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117243 + if (is_turn_off_intentional_attr(fndecl)) {
117244 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117245 + return;
117246 + }
117247 +
117248 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117249 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117250 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117251 + cur_node->intentional_attr_decl = MARK_YES;
117252 +
117253 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117254 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117255 +}
117256 +
117257 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117258 +{
117259 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117260 + enum machine_mode lhs_mode, rhs_mode;
117261 + gimple def_stmt = get_def_stmt(no_const_rhs);
117262 +
117263 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117264 + return false;
117265 +
117266 + rhs1 = gimple_assign_rhs1(def_stmt);
117267 + lhs = gimple_assign_lhs(def_stmt);
117268 + rhs1_type = TREE_TYPE(rhs1);
117269 + lhs_type = TREE_TYPE(lhs);
117270 + rhs_mode = TYPE_MODE(rhs1_type);
117271 + lhs_mode = TYPE_MODE(lhs_type);
117272 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117273 + return false;
117274 +
117275 + return true;
117276 +}
117277 +
117278 +static unsigned int uses_num(tree node)
117279 +{
117280 + imm_use_iterator imm_iter;
117281 + use_operand_p use_p;
117282 + unsigned int num = 0;
117283 +
117284 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117285 + gimple use_stmt = USE_STMT(use_p);
117286 +
117287 + if (use_stmt == NULL)
117288 + return num;
117289 + if (is_gimple_debug(use_stmt))
117290 + continue;
117291 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117292 + continue;
117293 + num++;
117294 + }
117295 + return num;
117296 +}
117297 +
117298 +static bool no_uses(tree node)
117299 +{
117300 + return !uses_num(node);
117301 +}
117302 +
117303 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117304 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117305 +{
117306 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117307 + gimple def_stmt = get_def_stmt(lhs);
117308 +
117309 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117310 + return false;
117311 +
117312 + rhs1 = gimple_assign_rhs1(def_stmt);
117313 + rhs_type = TREE_TYPE(rhs1);
117314 + lhs_type = TREE_TYPE(lhs);
117315 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117316 + return false;
117317 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117318 + return false;
117319 +
117320 + def_stmt = get_def_stmt(rhs1);
117321 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117322 + return false;
117323 +
117324 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117325 + return false;
117326 +
117327 + rhs1 = gimple_assign_rhs1(def_stmt);
117328 + rhs2 = gimple_assign_rhs2(def_stmt);
117329 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117330 + return false;
117331 +
117332 + if (is_gimple_constant(rhs2))
117333 + not_const_rhs = rhs1;
117334 + else
117335 + not_const_rhs = rhs2;
117336 +
117337 + return no_uses(not_const_rhs);
117338 +}
117339 +
117340 +static bool is_lt_signed_type_max(const_tree rhs)
117341 +{
117342 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117343 +
117344 + if (!TYPE_UNSIGNED(type))
117345 + return true;
117346 +
117347 + switch (TYPE_MODE(type)) {
117348 + case QImode:
117349 + new_type = intQI_type_node;
117350 + break;
117351 + case HImode:
117352 + new_type = intHI_type_node;
117353 + break;
117354 + case SImode:
117355 + new_type = intSI_type_node;
117356 + break;
117357 + case DImode:
117358 + new_type = intDI_type_node;
117359 + break;
117360 + default:
117361 + debug_tree((tree)type);
117362 + gcc_unreachable();
117363 + }
117364 +
117365 + type_max = TYPE_MAX_VALUE(new_type);
117366 + if (!tree_int_cst_lt(type_max, rhs))
117367 + return true;
117368 +
117369 + return false;
117370 +}
117371 +
117372 +static bool is_gt_zero(const_tree rhs)
117373 +{
117374 + const_tree type = TREE_TYPE(rhs);
117375 +
117376 + if (TYPE_UNSIGNED(type))
117377 + return true;
117378 +
117379 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117380 + return true;
117381 +
117382 + return false;
117383 +}
117384 +
117385 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117386 +{
117387 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117388 + return false;
117389 + if (!is_gimple_constant(rhs))
117390 + return false;
117391 +
117392 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117393 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117394 + return false;
117395 +
117396 + return true;
117397 +}
117398 +
117399 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117400 +{
117401 + gimple assign;
117402 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117403 + tree origtype = TREE_TYPE(orig_rhs);
117404 +
117405 + gcc_assert(is_gimple_assign(stmt));
117406 +
117407 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117408 + pointer_set_insert(visited->my_stmts, assign);
117409 + return gimple_assign_lhs(assign);
117410 +}
117411 +
117412 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117413 +{
117414 + tree new_rhs, orig_rhs;
117415 + void (*gimple_assign_set_rhs)(gimple, tree);
117416 + tree rhs1 = gimple_assign_rhs1(stmt);
117417 + tree rhs2 = gimple_assign_rhs2(stmt);
117418 + tree lhs = gimple_assign_lhs(stmt);
117419 +
117420 + if (!check_overflow)
117421 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117422 +
117423 + if (change_rhs == NULL_TREE)
117424 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117425 +
117426 + if (new_rhs2 == NULL_TREE) {
117427 + orig_rhs = rhs1;
117428 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117429 + } else {
117430 + orig_rhs = rhs2;
117431 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117432 + }
117433 +
117434 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117435 +
117436 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117437 + gimple_assign_set_rhs(stmt, new_rhs);
117438 + update_stmt(stmt);
117439 +
117440 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117441 +}
117442 +
117443 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117444 +{
117445 + gimple rhs1_def_stmt, rhs2_def_stmt;
117446 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117447 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117448 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117449 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117450 +
117451 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117452 + return false;
117453 +
117454 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117455 +
117456 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117457 + return false;
117458 +
117459 + rhs1_def_stmt = get_def_stmt(rhs1);
117460 + rhs2_def_stmt = get_def_stmt(rhs2);
117461 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117462 + return false;
117463 +
117464 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117465 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117466 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117467 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117468 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117469 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117470 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117471 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117472 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117473 + return false;
117474 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117475 + return false;
117476 +
117477 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117478 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117479 + return true;
117480 +}
117481 +
117482 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117483 +{
117484 + gimple assign;
117485 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117486 + tree type = TREE_TYPE(rhs1);
117487 + tree lhs = create_new_var(type);
117488 +
117489 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117490 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117491 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117492 +
117493 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117494 + update_stmt(assign);
117495 + pointer_set_insert(visited->my_stmts, assign);
117496 + return assign;
117497 +}
117498 +
117499 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117500 +{
117501 + gimple_stmt_iterator gsi;
117502 + gimple cast_stmt;
117503 + tree type = TREE_TYPE(node);
117504 +
117505 + if (types_compatible_p(type, intTI_type_node))
117506 + return node;
117507 +
117508 + gsi = gsi_for_stmt(stmt);
117509 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117510 + pointer_set_insert(visited->my_stmts, cast_stmt);
117511 + return gimple_assign_lhs(cast_stmt);
117512 +}
117513 +
117514 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117515 +{
117516 + tree rhs1, def_stmt_rhs1;
117517 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117518 +
117519 + def_stmt = get_def_stmt(var);
117520 + if (!gimple_assign_cast_p(def_stmt))
117521 + return NULL_TREE;
117522 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117523 +
117524 + rhs1 = gimple_assign_rhs1(def_stmt);
117525 + rhs1_def_stmt = get_def_stmt(rhs1);
117526 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117527 + return rhs1;
117528 +
117529 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117530 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117531 +
117532 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117533 + case GIMPLE_CALL:
117534 + case GIMPLE_NOP:
117535 + case GIMPLE_ASM:
117536 + case GIMPLE_PHI:
117537 + return def_stmt_rhs1;
117538 + case GIMPLE_ASSIGN:
117539 + return rhs1;
117540 + default:
117541 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117542 + gcc_unreachable();
117543 + }
117544 +}
117545 +
117546 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117547 +{
117548 + tree new_rhs1, new_rhs2;
117549 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117550 + gimple assign, stmt = get_def_stmt(lhs);
117551 + tree rhs1 = gimple_assign_rhs1(stmt);
117552 + tree rhs2 = gimple_assign_rhs2(stmt);
117553 +
117554 + if (!is_subtraction_special(visited, stmt))
117555 + return NULL_TREE;
117556 +
117557 + new_rhs1 = expand(visited, caller_node, rhs1);
117558 + new_rhs2 = expand(visited, caller_node, rhs2);
117559 +
117560 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117561 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117562 +
117563 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117564 + return NULL_TREE;
117565 +
117566 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117567 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117568 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117569 + }
117570 +
117571 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117572 + new_lhs = gimple_assign_lhs(assign);
117573 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117574 +
117575 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117576 +}
117577 +
117578 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117579 +{
117580 + const_gimple def_stmt;
117581 +
117582 + if (TREE_CODE(rhs) != SSA_NAME)
117583 + return false;
117584 +
117585 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117586 + return false;
117587 +
117588 + def_stmt = get_def_stmt(rhs);
117589 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117590 + return false;
117591 +
117592 + return true;
117593 +}
117594 +
117595 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117596 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117597 + * fffffff * 16 > signed max -> truncate
117598 + */
117599 +static bool look_for_mult_and_add(const_gimple stmt)
117600 +{
117601 + const_tree res;
117602 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117603 + const_gimple def_stmt;
117604 +
117605 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117606 + return false;
117607 + if (!is_gimple_assign(stmt))
117608 + return false;
117609 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117610 + return false;
117611 +
117612 + rhs1 = gimple_assign_rhs1(stmt);
117613 + rhs2 = gimple_assign_rhs2(stmt);
117614 + if (is_gimple_constant(rhs1)) {
117615 + const_rhs = rhs1;
117616 + def_stmt = get_def_stmt(rhs2);
117617 + } else if (is_gimple_constant(rhs2)) {
117618 + const_rhs = rhs2;
117619 + def_stmt = get_def_stmt(rhs1);
117620 + } else
117621 + return false;
117622 +
117623 + if (!is_gimple_assign(def_stmt))
117624 + return false;
117625 +
117626 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117627 + return false;
117628 +
117629 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117630 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117631 + if (is_gimple_constant(def_rhs1))
117632 + def_const_rhs = def_rhs1;
117633 + else if (is_gimple_constant(def_rhs2))
117634 + def_const_rhs = def_rhs2;
117635 + else
117636 + return false;
117637 +
117638 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117639 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117640 + return false;
117641 + return true;
117642 +}
117643 +
117644 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117645 +{
117646 + const_gimple def_stmt_1, def_stmt_2;
117647 + const_tree rhs1, rhs2;
117648 + bool add_mul_rhs1, add_mul_rhs2;
117649 +
117650 + rhs1 = gimple_assign_rhs1(stmt);
117651 + def_stmt_1 = get_def_stmt(rhs1);
117652 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117653 +
117654 + rhs2 = gimple_assign_rhs2(stmt);
117655 + def_stmt_2 = get_def_stmt(rhs2);
117656 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117657 +
117658 + if (add_mul_rhs1)
117659 + return RHS1_INTENTIONAL_OVERFLOW;
117660 + if (add_mul_rhs2)
117661 + return RHS2_INTENTIONAL_OVERFLOW;
117662 + return NO_INTENTIONAL_OVERFLOW;
117663 +}
117664 +
117665 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117666 +{
117667 + gimple my_stmt;
117668 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117669 +
117670 + gsi_next(&gsi);
117671 + my_stmt = gsi_stmt(gsi);
117672 +
117673 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117674 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117675 +
117676 + return my_stmt;
117677 +}
117678 +
117679 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117680 + * unsigned type cast to signed type, unsigned type: no more uses
117681 + * e.g., lib/vsprintf.c:simple_strtol()
117682 + * _10 = (unsigned long int) _9
117683 + * _11 = -_10;
117684 + * _12 = (long int) _11; (_11_ no more uses)
117685 + */
117686 +static bool is_call_or_cast(gimple stmt)
117687 +{
117688 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117689 +}
117690 +
117691 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117692 +{
117693 + const_tree rhs;
117694 + gimple def_stmt;
117695 +
117696 + if (node == NULL_TREE)
117697 + return true;
117698 + if (is_gimple_constant(node))
117699 + return true;
117700 +
117701 + def_stmt = get_def_stmt(node);
117702 + if (!def_stmt)
117703 + return false;
117704 +
117705 + if (is_call_or_cast(def_stmt))
117706 + return true;
117707 +
117708 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117709 + return false;
117710 + rhs = gimple_assign_rhs1(def_stmt);
117711 + def_stmt = get_def_stmt(rhs);
117712 + if (!def_stmt)
117713 + return false;
117714 + return is_call_or_cast(def_stmt);
117715 +}
117716 +
117717 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117718 +{
117719 + unsigned int use_num;
117720 + gimple so_stmt;
117721 + const_gimple def_stmt;
117722 + const_tree rhs1, rhs2;
117723 + tree rhs = gimple_assign_rhs1(stmt);
117724 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117725 + const_tree rhs_type = TREE_TYPE(rhs);
117726 +
117727 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117728 + return;
117729 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117730 + return;
117731 + use_num = uses_num(rhs);
117732 + if (use_num != 1)
117733 + return;
117734 +
117735 + def_stmt = get_def_stmt(rhs);
117736 + if (!def_stmt)
117737 + return;
117738 + if (!is_gimple_assign(def_stmt))
117739 + return;
117740 +
117741 + rhs1 = gimple_assign_rhs1(def_stmt);
117742 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117743 + return;
117744 +
117745 + rhs2 = gimple_assign_rhs2(def_stmt);
117746 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117747 + return;
117748 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117749 + return;
117750 +
117751 + so_stmt = get_dup_stmt(visited, stmt);
117752 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117753 +}
117754 +
117755 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117756 new file mode 100644
117757 index 0000000..4bddad2
117758 --- /dev/null
117759 +++ b/tools/gcc/size_overflow_plugin/misc.c
117760 @@ -0,0 +1,203 @@
117761 +/*
117762 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117763 + * Licensed under the GPL v2, or (at your option) v3
117764 + *
117765 + * Homepage:
117766 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117767 + *
117768 + * Documentation:
117769 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117770 + *
117771 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117772 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117773 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117774 + *
117775 + * Usage:
117776 + * $ make
117777 + * $ make run
117778 + */
117779 +
117780 +#include "gcc-common.h"
117781 +#include "size_overflow.h"
117782 +
117783 +void set_current_function_decl(tree fndecl)
117784 +{
117785 + gcc_assert(fndecl != NULL_TREE);
117786 +
117787 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117788 + calculate_dominance_info(CDI_DOMINATORS);
117789 + current_function_decl = fndecl;
117790 +}
117791 +
117792 +void unset_current_function_decl(void)
117793 +{
117794 + free_dominance_info(CDI_DOMINATORS);
117795 + pop_cfun();
117796 + current_function_decl = NULL_TREE;
117797 +}
117798 +
117799 +static bool is_bool(const_tree node)
117800 +{
117801 + const_tree type;
117802 +
117803 + if (node == NULL_TREE)
117804 + return false;
117805 +
117806 + type = TREE_TYPE(node);
117807 + if (!INTEGRAL_TYPE_P(type))
117808 + return false;
117809 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117810 + return true;
117811 + if (TYPE_PRECISION(type) == 1)
117812 + return true;
117813 + return false;
117814 +}
117815 +
117816 +bool skip_types(const_tree var)
117817 +{
117818 + tree type;
117819 + enum tree_code code;
117820 +
117821 + if (is_gimple_constant(var))
117822 + return true;
117823 +
117824 + switch (TREE_CODE(var)) {
117825 + case ADDR_EXPR:
117826 +#if BUILDING_GCC_VERSION >= 4006
117827 + case MEM_REF:
117828 +#endif
117829 + case ARRAY_REF:
117830 + case BIT_FIELD_REF:
117831 + case INDIRECT_REF:
117832 + case TARGET_MEM_REF:
117833 + case COMPONENT_REF:
117834 + case VAR_DECL:
117835 + case VIEW_CONVERT_EXPR:
117836 + return true;
117837 + default:
117838 + break;
117839 + }
117840 +
117841 + code = TREE_CODE(var);
117842 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117843 +
117844 + type = TREE_TYPE(var);
117845 + switch (TREE_CODE(type)) {
117846 + case INTEGER_TYPE:
117847 + case ENUMERAL_TYPE:
117848 + return false;
117849 + case BOOLEAN_TYPE:
117850 + return is_bool(var);
117851 + default:
117852 + return true;
117853 + }
117854 +}
117855 +
117856 +gimple get_def_stmt(const_tree node)
117857 +{
117858 + gcc_assert(node != NULL_TREE);
117859 +
117860 + if (skip_types(node))
117861 + return NULL;
117862 +
117863 + if (TREE_CODE(node) != SSA_NAME)
117864 + return NULL;
117865 + return SSA_NAME_DEF_STMT(node);
117866 +}
117867 +
117868 +tree create_new_var(tree type)
117869 +{
117870 + tree new_var = create_tmp_var(type, "cicus");
117871 +
117872 + add_referenced_var(new_var);
117873 + return new_var;
117874 +}
117875 +
117876 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117877 +{
117878 + const_gimple def_stmt = get_def_stmt(rhs);
117879 +
117880 + if (force)
117881 + return false;
117882 +
117883 + if (is_gimple_constant(rhs))
117884 + return false;
117885 +
117886 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117887 + return false;
117888 +
117889 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117890 + return false;
117891 +
117892 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117893 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117894 + return false;
117895 +
117896 + return true;
117897 +}
117898 +
117899 +tree cast_a_tree(tree type, tree var)
117900 +{
117901 + gcc_assert(type != NULL_TREE);
117902 + gcc_assert(var != NULL_TREE);
117903 + gcc_assert(fold_convertible_p(type, var));
117904 +
117905 + return fold_convert(type, var);
117906 +}
117907 +
117908 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117909 +{
117910 + gimple assign, def_stmt;
117911 +
117912 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117913 + gcc_assert(!is_gimple_constant(rhs));
117914 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117915 + gcc_unreachable();
117916 +
117917 + def_stmt = get_def_stmt(rhs);
117918 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117919 + return def_stmt;
117920 +
117921 + if (lhs == CREATE_NEW_VAR)
117922 + lhs = create_new_var(dst_type);
117923 +
117924 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117925 +
117926 + if (!gsi_end_p(*gsi)) {
117927 + location_t loc = gimple_location(gsi_stmt(*gsi));
117928 + gimple_set_location(assign, loc);
117929 + }
117930 +
117931 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117932 +
117933 + if (before)
117934 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117935 + else
117936 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117937 + update_stmt(assign);
117938 + return assign;
117939 +}
117940 +
117941 +bool is_size_overflow_type(const_tree var)
117942 +{
117943 + const char *name;
117944 + const_tree type_name, type;
117945 +
117946 + if (var == NULL_TREE)
117947 + return false;
117948 +
117949 + type = TREE_TYPE(var);
117950 + type_name = TYPE_NAME(type);
117951 + if (type_name == NULL_TREE)
117952 + return false;
117953 +
117954 + if (DECL_P(type_name))
117955 + name = DECL_NAME_POINTER(type_name);
117956 + else
117957 + name = IDENTIFIER_POINTER(type_name);
117958 +
117959 + if (!strncmp(name, "size_overflow_type", 18))
117960 + return true;
117961 + return false;
117962 +}
117963 +
117964 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117965 new file mode 100644
117966 index 0000000..7c9e6d1
117967 --- /dev/null
117968 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117969 @@ -0,0 +1,138 @@
117970 +/*
117971 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117972 + * Licensed under the GPL v2, or (at your option) v3
117973 + *
117974 + * Homepage:
117975 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117976 + *
117977 + * Documentation:
117978 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117979 + *
117980 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117981 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117982 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117983 + *
117984 + * Usage:
117985 + * $ make
117986 + * $ make run
117987 + */
117988 +
117989 +#include "gcc-common.h"
117990 +#include "size_overflow.h"
117991 +
117992 +bool skip_expr_on_double_type(const_gimple stmt)
117993 +{
117994 + enum tree_code code = gimple_assign_rhs_code(stmt);
117995 +
117996 + switch (code) {
117997 + case RSHIFT_EXPR:
117998 + case TRUNC_DIV_EXPR:
117999 + case CEIL_DIV_EXPR:
118000 + case FLOOR_DIV_EXPR:
118001 + case ROUND_DIV_EXPR:
118002 + case EXACT_DIV_EXPR:
118003 + case RDIV_EXPR:
118004 + case TRUNC_MOD_EXPR:
118005 + case CEIL_MOD_EXPR:
118006 + case FLOOR_MOD_EXPR:
118007 + case ROUND_MOD_EXPR:
118008 + return true;
118009 + default:
118010 + return false;
118011 + }
118012 +}
118013 +
118014 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
118015 +{
118016 + const_tree orig_rhs1;
118017 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
118018 + gimple down_cast, up_cast;
118019 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
118020 +
118021 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118022 + down_lhs = gimple_assign_lhs(down_cast);
118023 +
118024 + gsi = gsi_for_stmt(use_stmt);
118025 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118026 + new_lhs = gimple_assign_lhs(up_cast);
118027 +
118028 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
118029 + if (operand_equal_p(orig_rhs1, rhs, 0))
118030 + gimple_assign_set_rhs1(use_stmt, new_lhs);
118031 + else
118032 + gimple_assign_set_rhs2(use_stmt, new_lhs);
118033 + update_stmt(use_stmt);
118034 +
118035 + pointer_set_insert(visited->my_stmts, up_cast);
118036 + pointer_set_insert(visited->my_stmts, down_cast);
118037 + pointer_set_insert(visited->skip_expr_casts, up_cast);
118038 + pointer_set_insert(visited->skip_expr_casts, down_cast);
118039 +}
118040 +
118041 +static tree get_proper_unsigned_half_type(const_tree node)
118042 +{
118043 + tree new_type, type;
118044 +
118045 + gcc_assert(is_size_overflow_type(node));
118046 +
118047 + type = TREE_TYPE(node);
118048 + switch (TYPE_MODE(type)) {
118049 + case HImode:
118050 + new_type = unsigned_intQI_type_node;
118051 + break;
118052 + case SImode:
118053 + new_type = unsigned_intHI_type_node;
118054 + break;
118055 + case DImode:
118056 + new_type = unsigned_intSI_type_node;
118057 + break;
118058 + case TImode:
118059 + new_type = unsigned_intDI_type_node;
118060 + break;
118061 + default:
118062 + gcc_unreachable();
118063 + }
118064 +
118065 + if (TYPE_QUALS(type) != 0)
118066 + return build_qualified_type(new_type, TYPE_QUALS(type));
118067 + return new_type;
118068 +}
118069 +
118070 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
118071 +{
118072 + tree type;
118073 +
118074 + if (rhs == NULL_TREE)
118075 + return;
118076 + if (!is_size_overflow_type(rhs))
118077 + return;
118078 +
118079 + type = get_proper_unsigned_half_type(rhs);
118080 + if (is_gimple_constant(rhs))
118081 + return;
118082 + create_up_and_down_cast(visited, stmt, type, rhs);
118083 +}
118084 +
118085 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
118086 +{
118087 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
118088 + return;
118089 + gcc_assert(is_size_overflow_type(rhs));
118090 + insert_cast_rhs(visited, stmt, rhs);
118091 +}
118092 +
118093 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
118094 +{
118095 + tree rhs1, rhs2;
118096 +
118097 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118098 + rhs1 = gimple_assign_rhs1(stmt);
118099 + insert_cast(visited, stmt, rhs1);
118100 + }
118101 +
118102 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118103 + rhs2 = gimple_assign_rhs2(stmt);
118104 + insert_cast(visited, stmt, rhs2);
118105 + }
118106 +}
118107 +
118108 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118109 new file mode 100644
118110 index 0000000..e5b4e50
118111 --- /dev/null
118112 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118113 @@ -0,0 +1,127 @@
118114 +#ifndef SIZE_OVERFLOW_H
118115 +#define SIZE_OVERFLOW_H
118116 +
118117 +#define CREATE_NEW_VAR NULL_TREE
118118 +#define CANNOT_FIND_ARG 32
118119 +#define MAX_PARAM 31
118120 +#define BEFORE_STMT true
118121 +#define AFTER_STMT false
118122 +
118123 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118124 +#define YES_ASM_STR "# size_overflow MARK_YES "
118125 +#define OK_ASM_STR "# size_overflow "
118126 +
118127 +enum mark {
118128 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118129 +};
118130 +
118131 +enum intentional_overflow_type {
118132 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118133 +};
118134 +
118135 +struct visited {
118136 + struct pointer_set_t *stmts;
118137 + struct pointer_set_t *my_stmts;
118138 + struct pointer_set_t *skip_expr_casts;
118139 + struct pointer_set_t *no_cast_check;
118140 +};
118141 +
118142 +// size_overflow_plugin.c
118143 +extern tree report_size_overflow_decl;
118144 +extern tree size_overflow_type_HI;
118145 +extern tree size_overflow_type_SI;
118146 +extern tree size_overflow_type_DI;
118147 +extern tree size_overflow_type_TI;
118148 +
118149 +
118150 +// size_overflow_plugin_hash.c
118151 +struct size_overflow_hash {
118152 + const struct size_overflow_hash * const next;
118153 + const char * const name;
118154 + const unsigned int param;
118155 +};
118156 +
118157 +struct interesting_node {
118158 + struct interesting_node *next;
118159 + gimple first_stmt;
118160 + const_tree fndecl;
118161 + tree node;
118162 +#if BUILDING_GCC_VERSION <= 4007
118163 + VEC(tree, gc) *last_nodes;
118164 +#else
118165 + vec<tree, va_gc> *last_nodes;
118166 +#endif
118167 + unsigned int num;
118168 + enum mark intentional_attr_decl;
118169 + enum mark intentional_attr_cur_fndecl;
118170 + gimple intentional_mark_from_gimple;
118171 +};
118172 +
118173 +extern bool is_size_overflow_asm(const_gimple stmt);
118174 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118175 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118176 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118177 +extern bool is_a_return_check(const_tree node);
118178 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118179 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118180 +
118181 +
118182 +// size_overflow_debug.c
118183 +extern struct opt_pass *make_dump_pass(void);
118184 +
118185 +
118186 +// intentional_overflow.c
118187 +extern enum mark get_intentional_attr_type(const_tree node);
118188 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118189 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118190 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118191 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118192 +extern bool is_turn_off_intentional_attr(const_tree decl);
118193 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118194 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118195 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118196 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118197 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118198 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118199 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118200 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118201 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118202 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118203 +
118204 +
118205 +// insert_size_overflow_check_ipa.c
118206 +extern unsigned int search_function(void);
118207 +extern unsigned int call_count;
118208 +extern struct opt_pass *make_insert_size_overflow_check(void);
118209 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118210 +
118211 +
118212 +// insert_size_overflow_asm.c
118213 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118214 +
118215 +
118216 +// misc.c
118217 +extern void set_current_function_decl(tree fndecl);
118218 +extern void unset_current_function_decl(void);
118219 +extern gimple get_def_stmt(const_tree node);
118220 +extern tree create_new_var(tree type);
118221 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118222 +extern bool skip_types(const_tree var);
118223 +extern tree cast_a_tree(tree type, tree var);
118224 +extern bool is_size_overflow_type(const_tree var);
118225 +
118226 +
118227 +// insert_size_overflow_check_core.c
118228 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118229 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118230 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118231 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118232 +
118233 +
118234 +// remove_unnecessary_dup.c
118235 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118236 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118237 +extern bool skip_expr_on_double_type(const_gimple stmt);
118238 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118239 +
118240 +#endif
118241 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118242 new file mode 100644
118243 index 0000000..4378111
118244 --- /dev/null
118245 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118246 @@ -0,0 +1,116 @@
118247 +/*
118248 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118249 + * Licensed under the GPL v2, or (at your option) v3
118250 + *
118251 + * Homepage:
118252 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118253 + *
118254 + * Documentation:
118255 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118256 + *
118257 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118258 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118259 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118260 + *
118261 + * Usage:
118262 + * $ make
118263 + * $ make run
118264 + */
118265 +
118266 +#include "gcc-common.h"
118267 +
118268 +static unsigned int dump_functions(void)
118269 +{
118270 + struct cgraph_node *node;
118271 +
118272 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118273 + basic_block bb;
118274 +
118275 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118276 + current_function_decl = NODE_DECL(node);
118277 +
118278 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118279 +
118280 + FOR_ALL_BB_FN(bb, cfun) {
118281 + gimple_stmt_iterator si;
118282 +
118283 + fprintf(stderr, "<bb %u>:\n", bb->index);
118284 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118285 + debug_gimple_stmt(gsi_stmt(si));
118286 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118287 + debug_gimple_stmt(gsi_stmt(si));
118288 + fprintf(stderr, "\n");
118289 + }
118290 +
118291 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118292 +
118293 + pop_cfun();
118294 + current_function_decl = NULL_TREE;
118295 + }
118296 +
118297 + fprintf(stderr, "###############################################################################\n");
118298 +
118299 + return 0;
118300 +}
118301 +
118302 +#if BUILDING_GCC_VERSION >= 4009
118303 +static const struct pass_data dump_pass_data = {
118304 +#else
118305 +static struct ipa_opt_pass_d dump_pass = {
118306 + .pass = {
118307 +#endif
118308 + .type = SIMPLE_IPA_PASS,
118309 + .name = "dump",
118310 +#if BUILDING_GCC_VERSION >= 4008
118311 + .optinfo_flags = OPTGROUP_NONE,
118312 +#endif
118313 +#if BUILDING_GCC_VERSION >= 4009
118314 + .has_gate = false,
118315 + .has_execute = true,
118316 +#else
118317 + .gate = NULL,
118318 + .execute = dump_functions,
118319 + .sub = NULL,
118320 + .next = NULL,
118321 + .static_pass_number = 0,
118322 +#endif
118323 + .tv_id = TV_NONE,
118324 + .properties_required = 0,
118325 + .properties_provided = 0,
118326 + .properties_destroyed = 0,
118327 + .todo_flags_start = 0,
118328 + .todo_flags_finish = 0,
118329 +#if BUILDING_GCC_VERSION < 4009
118330 + },
118331 + .generate_summary = NULL,
118332 + .write_summary = NULL,
118333 + .read_summary = NULL,
118334 +#if BUILDING_GCC_VERSION >= 4006
118335 + .write_optimization_summary = NULL,
118336 + .read_optimization_summary = NULL,
118337 +#endif
118338 + .stmt_fixup = NULL,
118339 + .function_transform_todo_flags_start = 0,
118340 + .function_transform = NULL,
118341 + .variable_transform = NULL,
118342 +#endif
118343 +};
118344 +
118345 +#if BUILDING_GCC_VERSION >= 4009
118346 +namespace {
118347 +class dump_pass : public ipa_opt_pass_d {
118348 +public:
118349 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118350 + unsigned int execute() { return dump_functions(); }
118351 +};
118352 +}
118353 +#endif
118354 +
118355 +struct opt_pass *make_dump_pass(void)
118356 +{
118357 +#if BUILDING_GCC_VERSION >= 4009
118358 + return new dump_pass();
118359 +#else
118360 + return &dump_pass.pass;
118361 +#endif
118362 +}
118363 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118364 new file mode 100644
118365 index 0000000..f2bd55d
118366 --- /dev/null
118367 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118368 @@ -0,0 +1,6031 @@
118369 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118370 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118371 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118372 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118373 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118374 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118375 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118376 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118377 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118378 +load_msg_95 load_msg 2 95 NULL
118379 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118380 +init_q_132 init_q 4 132 NULL
118381 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118382 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118383 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118384 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118385 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118386 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118387 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118388 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118389 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118390 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
118391 +br_port_info_size_268 br_port_info_size 0 268 NULL
118392 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118393 +SYSC_connect_304 SYSC_connect 3 304 NULL
118394 +syslog_print_307 syslog_print 2 307 NULL
118395 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118396 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118397 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118398 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118399 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118400 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118401 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118402 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118403 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118404 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
118405 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118406 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118407 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118408 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118409 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118410 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118411 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118412 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118413 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118414 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118415 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118416 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118417 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118418 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118419 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118420 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118421 +unlink_queued_645 unlink_queued 4 645 NULL
118422 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118423 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118424 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118425 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118426 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118427 +dvb_video_write_754 dvb_video_write 3 754 NULL
118428 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118429 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118430 +if_writecmd_815 if_writecmd 2 815 NULL
118431 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118432 +error_state_read_859 error_state_read 6 859 NULL
118433 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118434 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118435 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118436 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118437 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118438 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118439 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118440 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118441 +readreg_1017 readreg 0-1 1017 NULL
118442 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118443 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118444 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118445 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118446 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118447 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118448 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118449 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118450 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118451 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118452 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118453 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118454 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118455 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118456 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118457 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118458 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118459 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118460 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118461 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118462 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118463 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118464 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118465 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118466 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118467 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118468 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118469 +ffs_1322 ffs 0 1322 NULL
118470 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118471 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118472 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118473 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118474 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118475 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118476 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118477 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118478 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118479 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118480 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118481 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118482 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118483 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118484 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118485 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118486 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118487 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118488 +fpregs_set_1497 fpregs_set 4 1497 NULL
118489 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118490 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118491 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118492 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118493 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118494 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118495 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118496 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118497 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118498 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118499 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118500 +rmap_add_1677 rmap_add 3 1677 NULL
118501 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118502 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118503 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118504 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118505 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118506 +internal_create_group_1733 internal_create_group 0 1733 NULL
118507 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118508 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118509 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118510 +cosa_write_1774 cosa_write 3 1774 NULL
118511 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118512 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118513 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118514 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118515 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118516 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118517 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118518 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118519 +azx_get_position_1927 azx_get_position 0 1927 NULL
118520 +bdev_erase_1933 bdev_erase 3 1933 NULL
118521 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118522 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118523 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118524 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118525 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118526 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
118527 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118528 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118529 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118530 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118531 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118532 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118533 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118534 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118535 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118536 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118537 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118538 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118539 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118540 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118541 +audit_expand_2098 audit_expand 0 2098 NULL
118542 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118543 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118544 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118545 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118546 +enable_read_2117 enable_read 3 2117 NULL
118547 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118548 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118549 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118550 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118551 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118552 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118553 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118554 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118555 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118556 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118557 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118558 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118559 +do_update_counters_2259 do_update_counters 4 2259 NULL
118560 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118561 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
118562 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118563 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118564 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118565 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118566 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118567 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118568 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118569 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118570 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118571 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118572 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118573 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118574 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118575 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118576 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118577 +raid1_size_2419 raid1_size 0-2 2419 NULL
118578 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118579 +wiphy_new_2482 wiphy_new 2 2482 NULL
118580 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118581 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118582 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118583 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118584 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118585 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118586 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118587 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118588 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118589 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118590 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118591 +slot_bytes_2609 slot_bytes 0 2609 NULL
118592 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118593 +switch_status_2629 switch_status 5 2629 NULL
118594 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118595 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118596 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118597 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118598 +oti6858_write_2692 oti6858_write 4 2692 NULL
118599 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
118600 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118601 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118602 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118603 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118604 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118605 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118606 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118607 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118608 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118609 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118610 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118611 +sock_create_2838 sock_create 0 2838 NULL
118612 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118613 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118614 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118615 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118616 +nla_padlen_2883 nla_padlen 1 2883 NULL
118617 +cmm_write_2896 cmm_write 3 2896 NULL
118618 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118619 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118620 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118621 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118622 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118623 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118624 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118625 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118626 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118627 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118628 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118629 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118630 +depth_write_3021 depth_write 3 3021 NULL
118631 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118632 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118633 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118634 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118635 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118636 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118637 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118638 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118639 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118640 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118641 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118642 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118643 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118644 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
118645 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118646 +rb_alloc_3102 rb_alloc 1 3102 NULL
118647 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118648 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118649 +print_time_3132 print_time 0 3132 NULL
118650 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118651 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118652 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118653 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118654 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118655 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118656 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118657 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118658 +alloc_context_3194 alloc_context 1 3194 NULL
118659 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
118660 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118661 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118662 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118663 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118664 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118665 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118666 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118667 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118668 +key_key_read_3241 key_key_read 3 3241 NULL
118669 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118670 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118671 +cgroup_name_3300 cgroup_name 3 3300 NULL
118672 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118673 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118674 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118675 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118676 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118677 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118678 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118679 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118680 +scnprintf_3360 scnprintf 0-2 3360 NULL
118681 +sr_read_3366 sr_read 3 3366 NULL
118682 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118683 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118684 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118685 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118686 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118687 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118688 +softsynth_write_3455 softsynth_write 3 3455 NULL
118689 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118690 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118691 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118692 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118693 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118694 +SyS_readv_3539 SyS_readv 3 3539 NULL
118695 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
118696 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118697 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118698 +evtchn_read_3569 evtchn_read 3 3569 NULL
118699 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118700 +vc_resize_3585 vc_resize 3-2 3585 NULL
118701 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118702 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118703 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118704 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118705 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118706 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
118707 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118708 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118709 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118710 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118711 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118712 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118713 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118714 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118715 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118716 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
118717 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118718 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118719 +get_fd_set_3866 get_fd_set 1 3866 NULL
118720 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118721 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118722 +nvram_write_3894 nvram_write 3 3894 NULL
118723 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118724 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118725 +vcs_write_3910 vcs_write 3 3910 NULL
118726 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118727 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118728 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118729 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118730 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118731 +do_add_counters_3992 do_add_counters 3 3992 NULL
118732 +userspace_status_4004 userspace_status 4 4004 NULL
118733 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118734 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118735 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118736 +blk_end_request_4024 blk_end_request 3 4024 NULL
118737 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118738 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118739 +read_file_queues_4078 read_file_queues 3 4078 NULL
118740 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118741 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118742 +tm6000_read_4151 tm6000_read 3 4151 NULL
118743 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118744 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118745 +get_alua_req_4166 get_alua_req 3 4166 NULL
118746 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118747 +read_file_bool_4180 read_file_bool 3 4180 NULL
118748 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118749 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118750 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118751 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118752 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118753 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118754 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118755 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118756 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118757 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118758 +count_strings_4315 count_strings 0 4315 NULL nohasharray
118759 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
118760 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118761 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118762 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118763 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118764 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118765 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118766 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118767 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118768 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118769 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118770 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118771 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118772 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118773 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118774 +set_link_security_4502 set_link_security 4 4502 NULL
118775 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118776 +tty_register_device_4544 tty_register_device 2 4544 NULL
118777 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118778 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118779 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118780 +bch_alloc_4593 bch_alloc 1 4593 NULL
118781 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118782 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118783 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118784 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118785 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118786 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118787 +kone_receive_4690 kone_receive 4 4690 NULL
118788 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118789 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118790 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118791 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118792 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118793 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118794 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118795 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118796 +create_subvol_4791 create_subvol 4 4791 NULL
118797 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118798 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118799 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118800 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118801 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118802 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118803 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118804 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118805 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118806 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118807 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118808 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118809 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118810 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118811 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118812 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118813 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118814 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118815 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118816 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118817 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118818 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118819 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118820 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118821 +sound_write_5102 sound_write 3 5102 NULL
118822 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118823 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118824 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118825 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118826 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118827 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118828 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118829 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118830 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118831 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118832 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
118833 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
118834 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118835 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118836 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118837 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118838 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118839 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118840 +cq_free_res_5355 cq_free_res 5 5355 NULL
118841 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118842 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118843 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118844 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118845 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118846 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118847 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
118848 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118849 +tty_write_5494 tty_write 3 5494 NULL
118850 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118851 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118852 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118853 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118854 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118855 +le_readq_5557 le_readq 0 5557 NULL
118856 +inw_5558 inw 0 5558 NULL
118857 +bioset_create_5580 bioset_create 1 5580 NULL
118858 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118859 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118860 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118861 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118862 +get_arg_5694 get_arg 3 5694 NULL
118863 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118864 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118865 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118866 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118867 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118868 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
118869 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
118870 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118871 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118872 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118873 +setup_req_5848 setup_req 3 5848 NULL
118874 +ria_page_count_5849 ria_page_count 0 5849 NULL
118875 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118876 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118877 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118878 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118879 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118880 +port_show_regs_5904 port_show_regs 3 5904 NULL
118881 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118882 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118883 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118884 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118885 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118886 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118887 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118888 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118889 +SyS_semop_5980 SyS_semop 3 5980 NULL
118890 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118891 +alloc_msg_6072 alloc_msg 1 6072 NULL
118892 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118893 +_random_read_6098 _random_read 3 6098 NULL
118894 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118895 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118896 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118897 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118898 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118899 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118900 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118901 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118902 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118903 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118904 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118905 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118906 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118907 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118908 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118909 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118910 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118911 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118912 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118913 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118914 +serial_port_in_6291 serial_port_in 0 6291 NULL
118915 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118916 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118917 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118918 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118919 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118920 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118921 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118922 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118923 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118924 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118925 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118926 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118927 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118928 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118929 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118930 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118931 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118932 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118933 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118934 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118935 +mei_read_6507 mei_read 3 6507 NULL
118936 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118937 +wdm_read_6549 wdm_read 3 6549 NULL
118938 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118939 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118940 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118941 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118942 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118943 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118944 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118945 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118946 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118947 +mpeg_read_6708 mpeg_read 3 6708 NULL
118948 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118949 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118950 +video_proc_write_6724 video_proc_write 3 6724 NULL
118951 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118952 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
118953 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118954 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118955 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118956 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118957 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118958 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118959 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118960 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
118961 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118962 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118963 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
118964 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118965 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118966 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118967 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118968 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118969 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118970 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118971 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118972 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118973 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118974 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118975 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118976 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118977 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118978 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118979 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118980 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118981 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118982 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118983 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118984 +request_key_async_6990 request_key_async 4 6990 NULL
118985 +tpl_write_6998 tpl_write 3 6998 NULL
118986 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118987 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118988 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118989 +wimax_msg_7030 wimax_msg 4 7030 NULL
118990 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118991 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118992 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118993 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118994 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118995 +event_enable_read_7074 event_enable_read 3 7074 NULL
118996 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118997 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118998 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118999 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
119000 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
119001 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
119002 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
119003 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
119004 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
119005 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
119006 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
119007 +get_string_7302 get_string 0 7302 NULL
119008 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
119009 +mgmt_control_7349 mgmt_control 3 7349 NULL
119010 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
119011 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
119012 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
119013 +hweight_long_7388 hweight_long 0-1 7388 NULL
119014 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
119015 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
119016 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
119017 +readb_7401 readb 0 7401 NULL
119018 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
119019 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
119020 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
119021 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
119022 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
119023 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
119024 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
119025 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
119026 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
119027 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
119028 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
119029 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
119030 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
119031 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
119032 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
119033 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
119034 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
119035 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
119036 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
119037 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
119038 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
119039 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
119040 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
119041 +dev_write_7708 dev_write 3 7708 NULL
119042 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
119043 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
119044 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
119045 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
119046 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
119047 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
119048 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
119049 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
119050 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
119051 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
119052 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
119053 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
119054 +config_desc_7878 config_desc 0 7878 NULL
119055 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
119056 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
119057 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
119058 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
119059 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
119060 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
119061 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
119062 +vcs_read_8017 vcs_read 3 8017 NULL
119063 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
119064 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
119065 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
119066 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
119067 +venus_lookup_8121 venus_lookup 4 8121 NULL
119068 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
119069 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
119070 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
119071 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
119072 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
119073 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
119074 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
119075 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
119076 +play_iframe_8219 play_iframe 3 8219 NULL
119077 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
119078 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
119079 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
119080 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
119081 +init_cdev_8274 init_cdev 1 8274 NULL
119082 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
119083 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
119084 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
119085 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
119086 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
119087 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
119088 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
119089 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
119090 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
119091 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
119092 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
119093 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
119094 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119095 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119096 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119097 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119098 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119099 +dev_config_8506 dev_config 3 8506 NULL
119100 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119101 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119102 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119103 +user_on_off_8552 user_on_off 2 8552 NULL
119104 +profile_remove_8556 profile_remove 3 8556 NULL
119105 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119106 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119107 +tower_write_8580 tower_write 3 8580 NULL
119108 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119109 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119110 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119111 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119112 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119113 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119114 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119115 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119116 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119117 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119118 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119119 +arcfb_write_8702 arcfb_write 3 8702 NULL
119120 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119121 +init_header_8703 init_header 0 8703 &i_size_read_8703
119122 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119123 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119124 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119125 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119126 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119127 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
119128 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119129 +compound_order_8750 compound_order 0 8750 NULL
119130 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
119131 +yurex_write_8761 yurex_write 3 8761 NULL
119132 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119133 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119134 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119135 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119136 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119137 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119138 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119139 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119140 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119141 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119142 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119143 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119144 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119145 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119146 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119147 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119148 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119149 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119150 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119151 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119152 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119153 +write_file_ani_8918 write_file_ani 3 8918 NULL
119154 +layout_commit_8926 layout_commit 3 8926 NULL
119155 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119156 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119157 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119158 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119159 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119160 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119161 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119162 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119163 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119164 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119165 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119166 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119167 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119168 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119169 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119170 +nla_put_9042 nla_put 3 9042 NULL
119171 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119172 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119173 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119174 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119175 +create_queues_9088 create_queues 2-3 9088 NULL
119176 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119177 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119178 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119179 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119180 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119181 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119182 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119183 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119184 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119185 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119186 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119187 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119188 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119189 +card_send_command_9215 card_send_command 3 9215 NULL
119190 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119191 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119192 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119193 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119194 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119195 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119196 +flakey_status_9274 flakey_status 5 9274 NULL
119197 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119198 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119199 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119200 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119201 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119202 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119203 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119204 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119205 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119206 +read_9397 read 3 9397 NULL
119207 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119208 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119209 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119210 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119211 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119212 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119213 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119214 +crypt_status_9492 crypt_status 5 9492 NULL
119215 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119216 +lp_write_9511 lp_write 3 9511 NULL
119217 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119218 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119219 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119220 +read_file_dma_9530 read_file_dma 3 9530 NULL
119221 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119222 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119223 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119224 +fw_node_create_9559 fw_node_create 2 9559 NULL
119225 +kobj_map_9566 kobj_map 2-3 9566 NULL
119226 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119227 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119228 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119229 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119230 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119231 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119232 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119233 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119234 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119235 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119236 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119237 +dns_query_9676 dns_query 3 9676 NULL
119238 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119239 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119240 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119241 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119242 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119243 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119244 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119245 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119246 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119247 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119248 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119249 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119250 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119251 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119252 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119253 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119254 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119255 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119256 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119257 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119258 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119259 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119260 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119261 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119262 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119263 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119264 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119265 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119266 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119267 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119268 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119269 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119270 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119271 +read_file_misc_9948 read_file_misc 3 9948 NULL
119272 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119273 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119274 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119275 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119276 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119277 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119278 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119279 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
119280 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119281 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119282 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119283 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119284 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119285 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119286 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119287 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119288 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119289 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119290 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119291 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119292 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119293 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119294 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119295 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119296 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119297 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119298 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119299 +read_emulate_10310 read_emulate 2-4 10310 NULL
119300 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119301 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119302 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119303 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119304 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119305 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119306 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119307 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119308 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119309 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119310 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119311 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119312 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119313 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119314 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119315 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119316 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119317 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119318 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119319 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119320 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119321 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119322 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119323 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119324 +otp_read_10594 otp_read 2-4-5 10594 NULL
119325 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119326 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119327 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119328 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119329 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119330 +parport_write_10669 parport_write 0 10669 NULL
119331 +edge_write_10692 edge_write 4 10692 NULL
119332 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119333 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119334 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119335 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119336 +spi_sync_10731 spi_sync 0 10731 NULL
119337 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119338 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119339 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119340 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119341 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119342 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119343 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119344 +ttm_dma_page_pool_free_10796 ttm_dma_page_pool_free 2-0 10796 NULL
119345 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119346 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119347 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119348 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119349 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119350 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119351 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119352 +get_scq_10897 get_scq 2 10897 NULL
119353 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119354 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119355 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119356 +kobject_add_10919 kobject_add 0 10919 NULL
119357 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119358 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119359 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119360 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119361 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119362 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119363 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119364 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119365 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119366 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
119367 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
119368 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119369 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119370 +count_argc_11083 count_argc 0 11083 NULL
119371 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119372 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119373 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
119374 +page_offset_11120 page_offset 0 11120 NULL
119375 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119376 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119377 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119378 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
119379 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119380 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119381 +of_irq_count_11253 of_irq_count 0 11253 NULL
119382 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119383 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119384 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119385 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119386 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119387 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119388 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119389 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119390 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119391 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119392 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119393 +next_segment_11330 next_segment 0-2-1 11330 NULL
119394 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119395 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119396 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119397 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119398 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119399 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119400 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119401 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119402 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119403 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119404 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119405 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119406 +str_to_user_11411 str_to_user 2 11411 NULL
119407 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119408 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119409 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119410 +trace_options_read_11419 trace_options_read 3 11419 NULL
119411 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119412 +bttv_read_11432 bttv_read 3 11432 NULL
119413 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119414 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119415 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119416 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119417 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119418 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119419 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119420 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119421 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119422 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119423 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119424 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119425 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119426 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119427 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119428 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119429 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119430 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119431 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119432 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119433 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119434 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119435 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119436 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119437 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119438 +split_11691 split 2 11691 NULL
119439 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119440 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119441 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119442 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119443 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119444 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119445 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119446 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119447 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119448 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119449 +umc_device_register_11824 umc_device_register 0 11824 NULL
119450 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119451 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119452 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119453 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119454 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
119455 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119456 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119457 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119458 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119459 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119460 +ti_write_11916 ti_write 4 11916 NULL
119461 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119462 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119463 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119464 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119465 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119466 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119467 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119468 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119469 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119470 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119471 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119472 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119473 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119474 +set_powered_12129 set_powered 4 12129 NULL
119475 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119476 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119477 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119478 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119479 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119480 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119481 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119482 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119483 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119484 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119485 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119486 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119487 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119488 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119489 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119490 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119491 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119492 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119493 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119494 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119495 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119496 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119497 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119498 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119499 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119500 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119501 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119502 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119503 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119504 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119505 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119506 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119507 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119508 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119509 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119510 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119511 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119512 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119513 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119514 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119515 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119516 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119517 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119518 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119519 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119520 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119521 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119522 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119523 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119524 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119525 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119526 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119527 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119528 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119529 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119530 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119531 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119532 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119533 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119534 +ivtv_write_12721 ivtv_write 3 12721 NULL
119535 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119536 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119537 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119538 +listxattr_12769 listxattr 3 12769 NULL
119539 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119540 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119541 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119542 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119543 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119544 +spidev_sync_12842 spidev_sync 0 12842 NULL
119545 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119546 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119547 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119548 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119549 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119550 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119551 +bm_status_write_12964 bm_status_write 3 12964 NULL
119552 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119553 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119554 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119555 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119556 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119557 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119558 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119559 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119560 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119561 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119562 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119563 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119564 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119565 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119566 +blk_update_request_13146 blk_update_request 3 13146 NULL
119567 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119568 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119569 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119570 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119571 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119572 +comedi_read_13199 comedi_read 3 13199 NULL
119573 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119574 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119575 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119576 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119577 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119578 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119579 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119580 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119581 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119582 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119583 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119584 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119585 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119586 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119587 +sd_major_13294 sd_major 0-1 13294 NULL
119588 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119589 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119590 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119591 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119592 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119593 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119594 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119595 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119596 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119597 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119598 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119599 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119600 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119601 +data_read_13494 data_read 3 13494 NULL nohasharray
119602 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119603 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119604 +core_status_13515 core_status 4 13515 NULL
119605 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119606 +bm_init_13529 bm_init 2 13529 NULL
119607 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119608 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119609 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119610 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119611 +cache_write_13589 cache_write 3 13589 NULL
119612 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119613 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119614 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119615 +packet_snd_13634 packet_snd 3 13634 NULL
119616 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119617 +cache_downcall_13666 cache_downcall 3 13666 NULL
119618 +usb_get_string_13693 usb_get_string 0 13693 NULL
119619 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119620 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119621 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119622 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119623 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119624 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
119625 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119626 +random_read_13815 random_read 3 13815 NULL
119627 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119628 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119629 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119630 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119631 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119632 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119633 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119634 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119635 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119636 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119637 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119638 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119639 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119640 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119641 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119642 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119643 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119644 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119645 +qcam_read_13977 qcam_read 3 13977 NULL
119646 +dsp_read_13980 dsp_read 2 13980 NULL
119647 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119648 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119649 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119650 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119651 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119652 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119653 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119654 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119655 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119656 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119657 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119658 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119659 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119660 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119661 +em_canid_change_14150 em_canid_change 3 14150 NULL
119662 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119663 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119664 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119665 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119666 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119667 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119668 +alloc_async_14208 alloc_async 1 14208 NULL
119669 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119670 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119671 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119672 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119673 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119674 +rr_status_14293 rr_status 5 14293 NULL
119675 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119676 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119677 +oo_objects_14319 oo_objects 0 14319 NULL
119678 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119679 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119680 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119681 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119682 +lowpan_read_14369 lowpan_read 3 14369 NULL
119683 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119684 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119685 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119686 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119687 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119688 +block_size_14443 block_size 0 14443 NULL
119689 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119690 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119691 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119692 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119693 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119694 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119695 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119696 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119697 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119698 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119699 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119700 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119701 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119702 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119703 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119704 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119705 +dbJoin_14644 dbJoin 0 14644 NULL
119706 +profile_replace_14652 profile_replace 3 14652 NULL
119707 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119708 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119709 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119710 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119711 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119712 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119713 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119714 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119715 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119716 +vfd_write_14717 vfd_write 3 14717 NULL
119717 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119718 +raid1_resize_14740 raid1_resize 2 14740 NULL
119719 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119720 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119721 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119722 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119723 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119724 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119725 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119726 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119727 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119728 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119729 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119730 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119731 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119732 +lcd_write_14857 lcd_write 3 14857 NULL
119733 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119734 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119735 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119736 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119737 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119738 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119739 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119740 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119741 +queue_cnt_14951 queue_cnt 0 14951 NULL
119742 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119743 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119744 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119745 +setkey_14987 setkey 3 14987 NULL nohasharray
119746 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119747 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119748 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119749 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119750 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119751 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119752 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119753 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119754 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119755 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119756 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119757 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119758 +start_port_15124 start_port 0 15124 NULL
119759 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119760 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119761 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119762 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119763 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119764 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119765 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119766 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119767 +simple_strtol_15273 simple_strtol 0 15273 NULL
119768 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119769 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119770 +ioread16_15342 ioread16 0 15342 NULL
119771 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119772 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
119773 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119774 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119775 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119776 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119777 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119778 +get_modalias_15406 get_modalias 2 15406 NULL
119779 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119780 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119781 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119782 +memweight_15450 memweight 2 15450 NULL
119783 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119784 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119785 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119786 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119787 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119788 +persistent_status_15574 persistent_status 4 15574 NULL
119789 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119790 +vme_user_write_15587 vme_user_write 3 15587 NULL
119791 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119792 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119793 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119794 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119795 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119796 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119797 +fs_path_add_15648 fs_path_add 3 15648 NULL
119798 +xsd_read_15653 xsd_read 3 15653 NULL
119799 +unix_bind_15668 unix_bind 3 15668 NULL
119800 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119801 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119802 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119803 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119804 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119805 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119806 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119807 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119808 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119809 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119810 +table_size_15851 table_size 0-1-2 15851 NULL
119811 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119812 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119813 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119814 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119815 +power_read_15939 power_read 3 15939 NULL
119816 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119817 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119818 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119819 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119820 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119821 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119822 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119823 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119824 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119825 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119826 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119827 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119828 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119829 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119830 +fsm_init_16134 fsm_init 2 16134 NULL
119831 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119832 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119833 +mapping_level_16188 mapping_level 2-0 16188 NULL
119834 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119835 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119836 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119837 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119838 +create_table_16213 create_table 2 16213 NULL
119839 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119840 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119841 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119842 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119843 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119844 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119845 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119846 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119847 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119848 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119849 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119850 +account_16283 account 0-4-2 16283 NULL nohasharray
119851 +mirror_status_16283 mirror_status 5 16283 &account_16283
119852 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119853 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119854 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119855 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119856 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119857 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119858 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119859 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119860 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119861 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119862 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119863 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119864 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119865 +cmdline_store_16442 cmdline_store 4 16442 NULL
119866 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119867 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119868 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119869 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119870 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119871 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119872 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119873 +raid10_resize_16537 raid10_resize 2 16537 NULL
119874 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119875 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119876 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119877 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119878 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119879 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119880 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119881 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119882 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119883 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119884 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119885 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119886 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119887 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119888 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119889 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119890 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119891 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119892 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119893 +st_write_16874 st_write 3 16874 NULL
119894 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119895 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119896 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119897 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119898 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119899 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119900 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119901 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119902 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119903 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119904 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119905 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119906 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119907 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119908 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119909 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119910 +entry_length_17093 entry_length 0 17093 NULL
119911 +write_mem_17114 write_mem 3 17114 NULL
119912 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119913 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119914 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119915 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119916 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119917 +sep_read_17161 sep_read 3 17161 NULL
119918 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119919 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119920 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119921 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119922 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119923 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119924 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119925 +sync_request_17208 sync_request 2 17208 NULL
119926 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119927 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119928 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119929 +alloc_ep_17269 alloc_ep 1 17269 NULL
119930 +pg_read_17276 pg_read 3 17276 NULL
119931 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119932 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119933 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119934 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119935 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119936 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119937 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119938 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119939 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119940 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119941 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119942 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119943 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
119944 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119945 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119946 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119947 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119948 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119949 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119950 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119951 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119952 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119953 +qp_free_res_17541 qp_free_res 5 17541 NULL
119954 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119955 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119956 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119957 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119958 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119959 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119960 +osst_execute_17607 osst_execute 7-6 17607 NULL
119961 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119962 +dma_map_page_17628 dma_map_page 0 17628 NULL
119963 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119964 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119965 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119966 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119967 +venus_rename_17707 venus_rename 4-5 17707 NULL
119968 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119969 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119970 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119971 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119972 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119973 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
119974 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119975 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119976 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119977 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119978 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119979 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119980 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119981 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119982 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119983 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119984 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119985 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119986 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119987 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119988 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119989 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119990 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119991 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119992 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119993 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119994 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119995 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119996 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119997 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119998 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119999 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
120000 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
120001 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
120002 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
120003 +fpregs_get_18066 fpregs_get 4 18066 NULL
120004 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
120005 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
120006 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
120007 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
120008 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
120009 +svc_getnl_18120 svc_getnl 0 18120 NULL
120010 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
120011 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
120012 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
120013 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
120014 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
120015 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
120016 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
120017 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
120018 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
120019 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
120020 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
120021 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
120022 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
120023 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
120024 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
120025 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
120026 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
120027 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
120028 +um_idi_write_18293 um_idi_write 3 18293 NULL
120029 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
120030 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
120031 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
120032 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
120033 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
120034 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
120035 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
120036 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
120037 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
120038 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
120039 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
120040 +ep_io_18367 ep_io 0 18367 NULL
120041 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
120042 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
120043 +ci_role_write_18388 ci_role_write 3 18388 NULL
120044 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
120045 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
120046 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
120047 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
120048 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
120049 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
120050 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
120051 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
120052 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
120053 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
120054 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
120055 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
120056 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
120057 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
120058 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
120059 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
120060 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
120061 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
120062 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
120063 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
120064 +debug_output_18575 debug_output 3 18575 NULL
120065 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
120066 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
120067 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
120068 +from_buffer_18625 from_buffer 3 18625 NULL
120069 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
120070 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
120071 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
120072 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
120073 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
120074 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
120075 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
120076 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
120077 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
120078 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
120079 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
120080 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
120081 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
120082 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
120083 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
120084 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
120085 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
120086 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
120087 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
120088 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
120089 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
120090 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
120091 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
120092 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
120093 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
120094 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120095 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120096 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
120097 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120098 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120099 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120100 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120101 +huge_page_size_19008 huge_page_size 0 19008 NULL
120102 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120103 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120104 +revalidate_19043 revalidate 2 19043 NULL
120105 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120106 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120107 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120108 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120109 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120110 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120111 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120112 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120113 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120114 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120115 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120116 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120117 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120118 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120119 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120120 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120121 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120122 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120123 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120124 +ucma_query_19260 ucma_query 4 19260 NULL
120125 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120126 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120127 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120128 +qc_capture_19298 qc_capture 3 19298 NULL
120129 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120130 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120131 +debug_read_19322 debug_read 3 19322 NULL
120132 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120133 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120134 +closure_sub_19359 closure_sub 2 19359 NULL
120135 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120136 +read_zero_19366 read_zero 3 19366 NULL
120137 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120138 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120139 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120140 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120141 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120142 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120143 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120144 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120145 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120146 +sky2_read16_19475 sky2_read16 0 19475 NULL
120147 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120148 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120149 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120150 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120151 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120152 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120153 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120154 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120155 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120156 +nfsd_read_19568 nfsd_read 5 19568 NULL
120157 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120158 +bm_status_read_19583 bm_status_read 3 19583 NULL
120159 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120160 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120161 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120162 +parser_init_19651 parser_init 2 19651 NULL
120163 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120164 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120165 +read_reg_19723 read_reg 0 19723 NULL
120166 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120167 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120168 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120169 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120170 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120171 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120172 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120173 +readhscx_19769 readhscx 0 19769 NULL
120174 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120175 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120176 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120177 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120178 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120179 +__nla_put_19857 __nla_put 3 19857 NULL
120180 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120181 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120182 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120183 +mangle_name_19923 mangle_name 0 19923 NULL
120184 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
120185 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120186 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120187 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120188 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120189 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120190 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120191 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120192 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120193 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120194 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
120195 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
120196 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120197 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120198 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120199 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120200 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120201 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120202 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120203 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120204 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120205 +target_message_20072 target_message 2 20072 NULL
120206 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120207 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120208 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120209 +team_options_register_20091 team_options_register 3 20091 NULL
120210 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120211 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120212 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120213 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120214 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120215 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120216 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120217 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120218 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120219 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120220 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120221 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120222 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120223 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120224 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120225 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120226 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120227 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120228 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120229 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120230 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120231 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120232 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120233 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120234 +read_buf_20469 read_buf 2 20469 NULL
120235 +bio_trim_20472 bio_trim 2 20472 NULL
120236 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120237 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120238 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120239 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120240 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120241 +venus_create_20555 venus_create 4 20555 NULL
120242 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120243 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120244 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120245 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120246 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120247 +lirc_write_20604 lirc_write 3 20604 NULL
120248 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120249 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120250 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120251 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120252 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120253 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120254 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120255 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120256 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120257 +cpumask_size_20683 cpumask_size 0 20683 NULL
120258 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120259 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120260 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120261 +__maestro_read_20700 __maestro_read 0 20700 NULL
120262 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120263 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120264 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120265 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120266 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120267 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120268 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120269 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120270 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120271 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120272 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120273 +edid_write_20797 edid_write 3 20797 NULL
120274 +lowpan_write_20800 lowpan_write 3 20800 NULL
120275 +strndup_user_20819 strndup_user 2 20819 NULL
120276 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120277 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120278 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120279 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120280 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120281 +get_name_20855 get_name 4 20855 NULL
120282 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120283 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120284 +srq_free_res_20868 srq_free_res 5 20868 NULL
120285 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120286 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120287 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120288 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120289 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120290 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120291 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120292 +htable_bits_20933 htable_bits 0 20933 NULL
120293 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
120294 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120295 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120296 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120297 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120298 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120299 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120300 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120301 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120302 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120303 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120304 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120305 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120306 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120307 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120308 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120309 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120310 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120311 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120312 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120313 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120314 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120315 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120316 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120317 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
120318 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120319 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120320 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120321 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120322 +input_ff_create_21240 input_ff_create 2 21240 NULL
120323 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120324 +fru_length_21257 fru_length 0 21257 NULL
120325 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120326 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120327 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120328 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120329 +add_res_range_21310 add_res_range 4 21310 NULL
120330 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120331 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120332 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120333 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120334 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120335 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120336 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120337 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120338 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120339 +insert_ptr_21386 insert_ptr 6 21386 NULL
120340 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120341 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120342 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120343 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120344 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120345 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120346 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120347 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120348 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120349 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120350 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120351 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120352 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120353 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120354 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120355 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120356 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120357 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120358 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120359 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120360 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120361 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120362 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120363 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120364 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
120365 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
120366 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120367 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120368 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120369 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120370 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120371 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120372 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120373 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120374 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120375 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120376 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120377 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120378 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
120379 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120380 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120381 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120382 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
120383 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
120384 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120385 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120386 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120387 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120388 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120389 +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
120390 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120391 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120392 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120393 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120394 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120395 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120396 +mem_rw_22085 mem_rw 3 22085 NULL
120397 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120398 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120399 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120400 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120401 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120402 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120403 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120404 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120405 +mem_write_22232 mem_write 3 22232 NULL
120406 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120407 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120408 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120409 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120410 +add_res_tree_22263 add_res_tree 7 22263 NULL
120411 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120412 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120413 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120414 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120415 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120416 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120417 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120418 +atomic_read_22342 atomic_read 0 22342 NULL
120419 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120420 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120421 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120422 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120423 +zoran_write_22404 zoran_write 3 22404 NULL
120424 +queue_reply_22416 queue_reply 3 22416 NULL
120425 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120426 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120427 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120428 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120429 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
120430 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
120431 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120432 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120433 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120434 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
120435 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120436 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120437 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120438 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120439 +snapshot_read_22601 snapshot_read 3 22601 NULL
120440 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120441 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120442 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120443 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120444 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120445 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120446 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120447 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120448 +reg_umr_22686 reg_umr 5 22686 NULL
120449 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120450 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120451 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120452 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120453 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120454 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120455 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120456 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120457 +print_frame_22769 print_frame 0 22769 NULL
120458 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120459 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120460 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120461 +create_attr_set_22861 create_attr_set 1 22861 NULL
120462 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120463 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120464 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120465 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120466 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120467 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120468 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120469 +__set_xattr_22923 __set_xattr 0 22923 NULL
120470 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120471 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120472 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120473 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120474 +vme_get_size_22964 vme_get_size 0 22964 NULL
120475 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120476 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120477 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120478 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120479 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120480 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120481 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120482 +st_status_23032 st_status 5 23032 NULL
120483 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120484 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120485 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120486 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120487 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120488 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120489 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120490 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120491 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120492 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120493 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120494 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120495 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120496 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120497 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120498 +__clear_user_23118 __clear_user 0-2 23118 NULL
120499 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120500 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120501 +read_file_ani_23161 read_file_ani 3 23161 NULL
120502 +usblp_write_23178 usblp_write 3 23178 NULL
120503 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120504 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120505 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120506 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
120507 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120508 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120509 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120510 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120511 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120512 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120513 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120514 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120515 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120516 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120517 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120518 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120519 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120520 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120521 +page_readlink_23346 page_readlink 3 23346 NULL
120522 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120523 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120524 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120525 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120526 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120527 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120528 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120529 +linear_conf_23485 linear_conf 2 23485 NULL
120530 +event_filter_read_23494 event_filter_read 3 23494 NULL
120531 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120532 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120533 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120534 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120535 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120536 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120537 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120538 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120539 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120540 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120541 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120542 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120543 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120544 +sInW_23663 sInW 0 23663 NULL
120545 +SyS_connect_23669 SyS_connect 3 23669 NULL
120546 +cx18_read_23699 cx18_read 3 23699 NULL
120547 +at_get_23708 at_get 0 23708 NULL
120548 +get_conn_info_23723 get_conn_info 4 23723 NULL
120549 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120550 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120551 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120552 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120553 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120554 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120555 +map_write_23795 map_write 3 23795 NULL
120556 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120557 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120558 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120559 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120560 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120561 +p54_init_common_23850 p54_init_common 1 23850 NULL
120562 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120563 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120564 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120565 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120566 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120567 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120568 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120569 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120570 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120571 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120572 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120573 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120574 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120575 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120576 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120577 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120578 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
120579 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120580 +give_pages_24021 give_pages 3 24021 NULL
120581 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120582 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120583 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120584 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120585 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120586 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120587 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120588 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120589 +lov_brw_24122 lov_brw 4 24122 NULL
120590 +mpu401_read_24126 mpu401_read 3 24126 NULL
120591 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120592 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120593 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120594 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120595 +adu_read_24177 adu_read 3 24177 NULL
120596 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120597 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120598 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120599 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
120600 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120601 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120602 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120603 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120604 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120605 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120606 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120607 +thin_status_24278 thin_status 5 24278 NULL
120608 +msg_size_24288 msg_size 0 24288 NULL
120609 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120610 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120611 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120612 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120613 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120614 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120615 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120616 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120617 +igetword_24373 igetword 0 24373 NULL
120618 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120619 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120620 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120621 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120622 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
120623 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120624 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120625 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120626 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120627 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120628 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120629 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120630 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120631 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120632 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120633 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120634 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120635 +ttm_page_pool_free_24486 ttm_page_pool_free 2-0 24486 NULL
120636 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120637 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120638 +pd_video_read_24510 pd_video_read 3 24510 NULL
120639 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120640 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120641 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120642 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120643 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120644 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120645 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120646 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
120647 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
120648 +SyS_poll_24620 SyS_poll 2 24620 NULL
120649 +context_alloc_24645 context_alloc 3 24645 NULL
120650 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120651 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120652 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120653 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120654 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120655 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120656 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120657 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120658 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120659 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120660 +cache_read_24790 cache_read 3 24790 NULL
120661 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120662 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120663 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120664 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120665 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120666 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120667 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120668 +queues_read_24877 queues_read 3 24877 NULL
120669 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120670 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120671 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120672 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120673 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120674 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120675 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120676 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
120677 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
120678 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120679 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120680 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120681 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120682 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120683 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120684 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120685 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120686 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120687 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
120688 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120689 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120690 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120691 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120692 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120693 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120694 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120695 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120696 +stripe_status_25259 stripe_status 5 25259 NULL
120697 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120698 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120699 +vfs_writev_25278 vfs_writev 3 25278 NULL
120700 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120701 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
120702 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120703 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120704 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120705 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120706 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120707 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120708 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120709 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120710 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120711 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120712 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120713 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120714 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120715 +sb_permission_25523 sb_permission 0 25523 NULL
120716 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120717 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120718 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120719 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120720 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120721 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120722 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120723 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120724 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120725 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120726 +__direct_map_25647 __direct_map 6-5 25647 NULL
120727 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120728 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120729 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120730 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120731 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120732 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120733 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120734 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120735 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120736 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120737 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120738 +sg_read_25799 sg_read 3 25799 NULL
120739 +system_enable_read_25815 system_enable_read 3 25815 NULL
120740 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120741 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120742 +parport_read_25855 parport_read 0 25855 NULL
120743 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120744 +key_attr_size_25865 key_attr_size 0 25865 NULL
120745 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120746 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120747 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120748 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120749 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120750 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120751 +rcname_read_25919 rcname_read 3 25919 NULL
120752 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120753 +key_flags_read_25931 key_flags_read 3 25931 NULL
120754 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120755 +flush_25957 flush 2 25957 NULL
120756 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120757 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120758 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120759 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120760 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120761 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120762 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120763 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120764 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120765 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120766 +read_sb_page_26119 read_sb_page 5 26119 NULL
120767 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120768 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120769 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120770 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120771 +disk_devt_26180 disk_devt 0 26180 NULL
120772 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120773 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120774 +mce_write_26201 mce_write 3 26201 NULL
120775 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120776 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120777 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120778 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
120779 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120780 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120781 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120782 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120783 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120784 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120785 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120786 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120787 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120788 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120789 +ntty_write_26404 ntty_write 3 26404 NULL
120790 +firmware_store_26408 firmware_store 4 26408 NULL
120791 +pagemap_read_26441 pagemap_read 3 26441 NULL
120792 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120793 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120794 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120795 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120796 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
120797 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
120798 +read_vmcore_26501 read_vmcore 3 26501 NULL
120799 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120800 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120801 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120802 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120803 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120804 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120805 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120806 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120807 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120808 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120809 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120810 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120811 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120812 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120813 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120814 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120815 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120816 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120817 +bos_desc_26752 bos_desc 0 26752 NULL
120818 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120819 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120820 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120821 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120822 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120823 +smk_write_load_26829 smk_write_load 3 26829 NULL
120824 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
120825 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120826 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120827 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120828 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120829 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120830 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120831 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120832 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120833 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120834 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120835 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120836 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120837 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120838 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120839 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120840 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120841 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120842 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120843 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120844 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120845 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120846 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120847 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120848 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120849 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120850 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120851 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120852 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120853 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120854 +pms_capture_27142 pms_capture 4 27142 NULL
120855 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120856 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120857 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120858 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120859 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120860 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120861 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120862 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120863 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120864 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120865 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120866 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120867 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120868 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120869 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120870 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120871 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120872 +seq_read_27411 seq_read 3 27411 NULL
120873 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120874 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120875 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120876 +cypress_write_27423 cypress_write 4 27423 NULL
120877 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120878 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120879 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120880 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120881 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120882 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
120883 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
120884 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120885 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120886 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120887 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120888 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120889 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120890 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120891 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120892 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120893 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120894 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120895 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120896 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120897 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120898 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120899 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120900 +evm_write_key_27715 evm_write_key 3 27715 NULL
120901 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120902 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120903 +load_scode_27738 load_scode 2 27738 NULL
120904 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120905 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120906 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120907 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120908 +SyS_readv_27804 SyS_readv 3 27804 NULL
120909 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120910 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120911 +init_header_complete_27833 init_header_complete 0 27833 NULL
120912 +read_profile_27859 read_profile 3 27859 NULL
120913 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120914 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120915 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120916 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120917 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120918 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120919 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120920 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120921 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120922 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120923 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120924 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120925 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120926 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120927 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120928 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120929 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120930 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120931 +pool_status_28055 pool_status 5 28055 NULL
120932 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120933 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120934 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120935 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120936 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120937 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120938 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120939 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120940 +video_read_28148 video_read 3 28148 NULL
120941 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120942 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120943 +vread_28173 vread 0-3 28173 NULL
120944 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120945 +counter_free_res_28187 counter_free_res 5 28187 NULL
120946 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120947 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120948 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120949 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120950 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120951 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120952 +usemap_size_28281 usemap_size 0 28281 NULL
120953 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120954 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120955 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120956 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120957 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120958 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120959 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120960 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120961 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120962 +snapshot_write_28351 snapshot_write 3 28351 NULL
120963 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120964 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120965 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120966 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120967 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120968 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120969 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120970 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120971 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120972 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120973 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120974 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120975 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120976 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120977 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120978 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120979 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120980 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120981 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120982 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120983 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120984 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120985 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120986 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120987 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120988 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120989 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120990 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120991 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120992 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120993 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120994 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120995 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
120996 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120997 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120998 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120999 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
121000 +spi_execute_28736 spi_execute 5 28736 NULL
121001 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
121002 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
121003 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
121004 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
121005 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
121006 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
121007 +sel_write_member_28800 sel_write_member 3 28800 NULL
121008 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
121009 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
121010 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
121011 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
121012 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
121013 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
121014 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
121015 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
121016 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
121017 +push_rx_28939 push_rx 3 28939 NULL
121018 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
121019 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
121020 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
121021 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
121022 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
121023 +bin_uuid_28999 bin_uuid 3 28999 NULL
121024 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
121025 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
121026 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
121027 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
121028 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
121029 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
121030 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
121031 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
121032 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
121033 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
121034 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
121035 +snprintf_29125 snprintf 0 29125 NULL
121036 +iov_shorten_29130 iov_shorten 0 29130 NULL
121037 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
121038 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
121039 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
121040 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
121041 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
121042 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
121043 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
121044 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
121045 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
121046 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
121047 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
121048 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
121049 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
121050 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
121051 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
121052 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
121053 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
121054 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
121055 +tun_put_user_29337 tun_put_user 5 29337 NULL
121056 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
121057 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
121058 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
121059 +mempool_create_29437 mempool_create 1 29437 NULL
121060 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
121061 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
121062 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
121063 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
121064 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
121065 +do_register_entry_29478 do_register_entry 4 29478 NULL
121066 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
121067 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
121068 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
121069 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
121070 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
121071 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
121072 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
121073 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
121074 +ftrace_write_29551 ftrace_write 3 29551 NULL
121075 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
121076 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
121077 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
121078 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
121079 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
121080 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
121081 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
121082 +slots_per_page_29601 slots_per_page 0 29601 NULL
121083 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
121084 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
121085 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
121086 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
121087 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
121088 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
121089 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
121090 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
121091 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
121092 +probes_write_29711 probes_write 3 29711 NULL
121093 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
121094 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121095 +std_nic_write_29752 std_nic_write 3 29752 NULL
121096 +static_key_count_29771 static_key_count 0 29771 NULL
121097 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
121098 +dbAlloc_29794 dbAlloc 0 29794 NULL
121099 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121100 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121101 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121102 +count_partial_29850 count_partial 0 29850 NULL
121103 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121104 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121105 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121106 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121107 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121108 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121109 +write_file_queue_29922 write_file_queue 3 29922 NULL
121110 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121111 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121112 +zero_iovec_29955 zero_iovec 1 29955 NULL
121113 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121114 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121115 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121116 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121117 +drp_wmove_30043 drp_wmove 4 30043 NULL
121118 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121119 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121120 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121121 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121122 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121123 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121124 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121125 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121126 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121127 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121128 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121129 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121130 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121131 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121132 +SyS_semop_30227 SyS_semop 3 30227 NULL
121133 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121134 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121135 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121136 +compat_readv_30273 compat_readv 3 30273 NULL
121137 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121138 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121139 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121140 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121141 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121142 +i8254_read_30330 i8254_read 0 30330 NULL
121143 +resource_from_user_30341 resource_from_user 3 30341 NULL
121144 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121145 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121146 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121147 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121148 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121149 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121150 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121151 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121152 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121153 +enable_write_30456 enable_write 3 30456 NULL
121154 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121155 +urandom_read_30462 urandom_read 3 30462 NULL
121156 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121157 +adu_write_30487 adu_write 3 30487 NULL
121158 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121159 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121160 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121161 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121162 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121163 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121164 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
121165 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
121166 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121167 +set_le_30581 set_le 4 30581 NULL
121168 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121169 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121170 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121171 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121172 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121173 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121174 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121175 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121176 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121177 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121178 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121179 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121180 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121181 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121182 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121183 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121184 +snapshot_status_30744 snapshot_status 5 30744 NULL
121185 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121186 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121187 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121188 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121189 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121190 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121191 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121192 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121193 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
121194 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121195 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121196 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121197 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
121198 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121199 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121200 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121201 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121202 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121203 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121204 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121205 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121206 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121207 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121208 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121209 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121210 +depth_read_31112 depth_read 3 31112 NULL
121211 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121212 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121213 +size_inside_page_31141 size_inside_page 0 31141 NULL
121214 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121215 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
121216 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121217 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121218 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121219 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121220 +__read_reg_31216 __read_reg 0 31216 NULL
121221 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121222 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121223 +cyy_readb_31240 cyy_readb 0 31240 NULL
121224 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121225 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121226 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121227 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
121228 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121229 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121230 +command_file_write_31318 command_file_write 3 31318 NULL
121231 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121232 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121233 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121234 +outlen_write_31358 outlen_write 3 31358 NULL
121235 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121236 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121237 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121238 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121239 +inb_31388 inb 0 31388 NULL
121240 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121241 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121242 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121243 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121244 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121245 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121246 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121247 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121248 +alg_setkey_31485 alg_setkey 3 31485 NULL
121249 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121250 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121251 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121252 +hidraw_write_31536 hidraw_write 3 31536 NULL
121253 +usbvision_read_31555 usbvision_read 3 31555 NULL
121254 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121255 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121256 +osst_write_31581 osst_write 3 31581 NULL
121257 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121258 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121259 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121260 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121261 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121262 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121263 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121264 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121265 +__lgread_31668 __lgread 4 31668 NULL
121266 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121267 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121268 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121269 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121270 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121271 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121272 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121273 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121274 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121275 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121276 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121277 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121278 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121279 +get_count_order_31800 get_count_order 0 31800 NULL
121280 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121281 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121282 +data_write_31805 data_write 3 31805 NULL
121283 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121284 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121285 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121286 +clone_bio_31854 clone_bio 4-3 31854 NULL
121287 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121288 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121289 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121290 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121291 +xattr_permission_31907 xattr_permission 0 31907 NULL
121292 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121293 +new_dir_31919 new_dir 3 31919 NULL
121294 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121295 +era_status_31934 era_status 5 31934 NULL
121296 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121297 +read_mem_31942 read_mem 3 31942 NULL
121298 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121299 +vb2_write_31948 vb2_write 3 31948 NULL
121300 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121301 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121302 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121303 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121304 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121305 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121306 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121307 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121308 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121309 +calc_hmac_32010 calc_hmac 3 32010 NULL
121310 +aead_len_32021 aead_len 0 32021 NULL
121311 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121312 +stk_read_32038 stk_read 3 32038 NULL
121313 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121314 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121315 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121316 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121317 +bio_alloc_32095 bio_alloc 2 32095 NULL
121318 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121319 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
121320 +disk_status_32120 disk_status 4 32120 NULL
121321 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121322 +venus_link_32165 venus_link 5 32165 NULL
121323 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121324 +do_writepages_32173 do_writepages 0 32173 NULL
121325 +del_ptr_32197 del_ptr 4 32197 NULL
121326 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121327 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121328 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121329 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121330 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121331 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121332 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121333 +SyS_select_32319 SyS_select 1 32319 NULL
121334 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121335 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121336 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121337 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121338 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121339 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121340 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121341 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121342 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121343 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121344 +cache_status_32462 cache_status 5 32462 NULL
121345 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121346 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121347 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121348 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121349 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121350 +disconnect_32521 disconnect 4 32521 NULL
121351 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121352 +ilo_read_32531 ilo_read 3 32531 NULL
121353 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121354 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121355 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121356 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121357 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121358 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121359 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121360 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121361 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121362 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121363 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121364 +kvmalloc_32646 kvmalloc 1 32646 NULL
121365 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121366 +generic_readlink_32654 generic_readlink 3 32654 NULL
121367 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121368 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121369 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121370 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121371 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121372 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121373 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121374 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121375 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121376 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121377 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121378 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121379 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121380 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121381 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121382 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121383 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121384 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121385 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121386 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121387 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121388 +compat_filldir_32999 compat_filldir 3 32999 NULL
121389 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121390 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121391 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121392 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121393 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121394 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121395 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121396 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121397 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121398 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121399 +alloc_tio_33077 alloc_tio 3 33077 NULL
121400 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121401 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121402 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121403 +SyS_poll_33152 SyS_poll 2 33152 NULL
121404 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121405 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121406 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121407 +pp_read_33210 pp_read 3 33210 NULL
121408 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121409 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121410 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121411 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121412 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121413 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121414 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121415 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121416 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121417 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121418 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121419 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121420 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121421 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121422 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121423 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121424 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121425 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121426 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121427 +message_stats_list_33440 message_stats_list 5 33440 NULL
121428 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121429 +create_entry_33479 create_entry 2 33479 NULL
121430 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121431 +res_counter_read_33499 res_counter_read 4 33499 NULL
121432 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121433 +fb_read_33506 fb_read 3 33506 NULL
121434 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121435 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121436 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121437 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121438 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121439 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121440 +count_subheaders_33591 count_subheaders 0 33591 NULL
121441 +scsi_execute_33596 scsi_execute 5 33596 NULL
121442 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121443 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121444 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121445 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121446 +stride_page_count_33641 stride_page_count 2 33641 NULL
121447 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121448 +inw_p_33668 inw_p 0 33668 NULL
121449 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121450 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121451 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121452 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121453 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121454 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121455 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121456 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121457 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121458 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121459 +hashtab_create_33769 hashtab_create 3 33769 NULL
121460 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121461 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121462 +filter_write_33819 filter_write 3 33819 NULL
121463 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121464 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121465 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121466 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121467 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121468 +get_user_pages_33908 get_user_pages 0 33908 NULL
121469 +sg_nents_33909 sg_nents 0 33909 NULL
121470 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121471 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121472 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121473 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121474 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121475 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121476 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121477 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121478 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121479 +ppp_write_34034 ppp_write 3 34034 NULL
121480 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121481 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121482 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121483 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121484 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121485 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121486 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121487 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121488 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121489 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121490 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121491 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121492 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
121493 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
121494 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121495 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121496 +device_private_init_34279 device_private_init 0 34279 NULL
121497 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121498 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121499 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121500 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121501 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121502 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121503 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121504 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121505 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121506 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121507 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121508 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121509 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121510 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121511 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121512 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121513 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121514 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121515 +security_socket_create_34439 security_socket_create 0 34439 NULL
121516 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121517 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121518 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121519 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121520 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121521 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121522 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121523 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121524 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121525 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121526 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121527 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121528 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121529 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121530 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121531 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121532 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121533 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121534 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121535 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121536 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121537 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121538 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121539 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121540 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121541 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121542 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121543 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121544 +port_print_34704 port_print 3 34704 NULL
121545 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121546 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121547 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121548 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121549 +bootmode_store_34762 bootmode_store 4 34762 NULL
121550 +device_add_34766 device_add 0 34766 NULL
121551 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121552 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121553 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121554 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121555 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121556 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121557 +file_page_index_34820 file_page_index 0-2 34820 NULL
121558 +bio_segments_34832 bio_segments 0 34832 NULL
121559 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121560 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121561 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121562 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121563 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121564 +msg_print_text_34889 msg_print_text 0 34889 NULL
121565 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121566 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121567 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121568 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121569 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121570 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121571 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121572 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121573 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121574 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121575 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121576 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121577 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121578 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121579 +proc_setgroups_write_35039 proc_setgroups_write 3 35039 NULL
121580 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121581 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121582 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121583 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121584 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121585 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121586 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121587 +message_stats_print_35158 message_stats_print 6 35158 NULL
121588 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121589 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121590 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121591 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121592 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121593 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121594 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121595 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121596 +set_fd_set_35249 set_fd_set 1 35249 NULL
121597 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121598 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121599 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121600 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121601 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121602 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
121603 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
121604 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121605 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121606 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121607 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121608 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121609 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121610 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121611 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121612 +read_kmem_35372 read_kmem 3 35372 NULL
121613 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121614 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121615 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121616 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121617 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121618 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121619 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121620 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121621 +async_setkey_35521 async_setkey 3 35521 NULL
121622 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121623 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121624 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121625 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121626 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121627 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121628 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121629 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121630 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121631 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121632 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121633 +kernel_readv_35617 kernel_readv 3 35617 NULL
121634 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121635 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121636 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121637 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121638 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121639 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121640 +md_super_write_35703 md_super_write 4 35703 NULL
121641 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121642 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121643 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121644 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121645 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121646 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121647 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121648 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121649 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121650 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121651 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121652 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121653 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121654 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121655 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121656 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121657 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121658 +acl_alloc_35979 acl_alloc 1 35979 NULL
121659 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121660 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121661 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121662 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121663 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121664 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121665 +account_shadowed_36048 account_shadowed 2 36048 NULL
121666 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121667 +write_emulate_36065 write_emulate 2-4 36065 NULL
121668 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121669 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121670 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121671 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121672 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121673 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121674 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121675 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121676 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121677 +twl_set_36154 twl_set 2 36154 NULL
121678 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121679 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121680 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121681 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121682 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121683 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121684 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121685 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121686 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121687 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121688 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121689 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121690 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121691 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121692 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121693 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121694 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121695 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121696 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121697 +lc_create_36332 lc_create 4 36332 NULL
121698 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121699 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121700 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121701 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121702 +to_sector_36361 to_sector 0-1 36361 NULL
121703 +tunables_read_36385 tunables_read 3 36385 NULL
121704 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121705 +sierra_write_36402 sierra_write 4 36402 NULL
121706 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121707 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121708 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121709 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121710 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121711 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121712 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121713 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121714 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121715 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121716 +cmd_loop_36491 cmd_loop 0 36491 NULL
121717 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121718 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121719 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121720 +get_param_l_36518 get_param_l 0 36518 NULL
121721 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121722 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121723 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121724 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121725 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121726 +__erst_read_36579 __erst_read 0 36579 NULL
121727 +put_cmsg_36589 put_cmsg 4 36589 NULL
121728 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121729 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121730 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121731 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121732 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121733 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121734 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121735 +xillybus_read_36678 xillybus_read 3 36678 NULL
121736 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121737 +path_getxattr_36717 path_getxattr 4 36717 NULL
121738 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121739 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121740 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121741 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121742 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121743 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121744 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121745 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121746 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121747 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121748 +cm_write_36858 cm_write 3 36858 NULL
121749 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121750 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121751 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121752 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121753 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121754 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121755 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121756 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121757 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121758 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121759 +setxattr_37006 setxattr 4 37006 NULL
121760 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121761 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121762 +command_file_read_37038 command_file_read 3 37038 NULL
121763 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121764 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121765 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121766 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121767 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121768 +parse_command_37079 parse_command 2 37079 NULL
121769 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121770 +tun_get_user_37094 tun_get_user 5 37094 NULL
121771 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121772 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121773 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121774 +msg_word_37164 msg_word 0 37164 NULL
121775 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121776 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121777 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121778 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121779 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121780 +__do_replace_37227 __do_replace 5 37227 NULL
121781 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121782 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121783 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121784 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121785 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121786 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121787 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121788 +tipc_send_37315 tipc_send 3 37315 NULL
121789 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121790 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121791 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121792 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121793 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121794 +seek_firmware_37372 seek_firmware 2 37372 NULL
121795 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121796 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121797 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121798 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121799 +fru_alloc_37442 fru_alloc 1 37442 NULL
121800 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121801 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121802 +get_est_timing_37484 get_est_timing 0 37484 NULL
121803 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121804 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121805 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121806 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121807 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121808 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121809 +hdr_size_37536 hdr_size 0 37536 NULL
121810 +extent_map_end_37550 extent_map_end 0 37550 NULL
121811 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121812 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121813 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121814 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121815 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121816 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121817 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121818 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121819 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121820 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121821 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121822 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121823 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121824 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121825 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121826 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121827 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121828 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121829 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121830 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121831 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121832 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121833 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121834 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121835 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121836 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121837 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121838 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121839 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121840 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121841 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121842 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121843 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121844 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121845 +write_file_bool_37957 write_file_bool 3 37957 NULL
121846 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121847 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121848 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121849 +vfs_readv_38011 vfs_readv 3 38011 NULL
121850 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121851 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121852 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121853 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121854 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121855 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121856 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121857 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121858 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121859 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121860 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121861 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121862 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121863 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121864 +ep0_read_38095 ep0_read 3 38095 NULL
121865 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121866 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121867 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121868 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121869 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121870 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121871 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121872 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121873 +cdev_add_38176 cdev_add 2-3 38176 NULL
121874 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121875 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121876 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121877 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121878 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121879 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121880 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121881 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121882 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121883 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121884 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121885 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121886 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121887 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121888 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121889 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121890 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121891 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121892 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121893 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121894 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121895 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121896 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121897 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121898 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121899 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121900 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121901 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121902 +dev_names_read_38509 dev_names_read 3 38509 NULL
121903 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121904 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121905 +set_queue_count_38519 set_queue_count 0 38519 NULL
121906 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121907 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121908 +kuc_len_38557 kuc_len 0-1 38557 NULL
121909 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121910 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121911 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121912 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121913 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121914 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121915 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121916 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121917 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121918 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121919 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121920 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121921 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121922 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121923 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121924 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121925 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121926 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121927 +udf_readpages_38761 udf_readpages 4 38761 NULL
121928 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121929 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121930 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121931 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121932 +err_decode_38804 err_decode 2 38804 NULL
121933 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121934 +direct_entry_38836 direct_entry 3 38836 NULL
121935 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121936 +interfaces_38859 interfaces 2 38859 NULL
121937 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121938 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121939 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121940 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121941 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121942 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121943 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121944 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121945 +get_nodes_39012 get_nodes 3 39012 NULL
121946 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121947 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121948 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121949 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121950 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121951 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121952 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121953 +ea_foreach_39133 ea_foreach 0 39133 NULL
121954 +generic_permission_39150 generic_permission 0 39150 NULL
121955 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121956 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121957 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121958 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121959 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
121960 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121961 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121962 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121963 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121964 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121965 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121966 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121967 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121968 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121969 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121970 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121971 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121972 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121973 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121974 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121975 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121976 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121977 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121978 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121979 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121980 +__send_to_port_39386 __send_to_port 3 39386 NULL
121981 +user_power_read_39414 user_power_read 3 39414 NULL
121982 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121983 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121984 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121985 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121986 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121987 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121988 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121989 +int_proc_write_39542 int_proc_write 3 39542 NULL
121990 +pp_write_39554 pp_write 3 39554 NULL
121991 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121992 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121993 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121994 +ext_depth_39607 ext_depth 0 39607 NULL
121995 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121996 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121997 +sdio_readb_39618 sdio_readb 0 39618 NULL
121998 +set_dev_class_39645 set_dev_class 4 39645 NULL
121999 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
122000 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
122001 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
122002 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
122003 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
122004 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
122005 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
122006 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
122007 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
122008 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
122009 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
122010 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
122011 +pkt_add_39897 pkt_add 3 39897 NULL
122012 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
122013 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
122014 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
122015 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
122016 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
122017 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
122018 +__spi_async_39932 __spi_async 0 39932 NULL
122019 +__get_order_39935 __get_order 0 39935 NULL
122020 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
122021 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
122022 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
122023 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
122024 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
122025 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
122026 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
122027 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
122028 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
122029 +server_name2svname_39998 server_name2svname 4 39998 NULL
122030 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
122031 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
122032 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
122033 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
122034 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
122035 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
122036 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
122037 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
122038 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
122039 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
122040 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
122041 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
122042 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
122043 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
122044 +pt_write_40159 pt_write 3 40159 NULL
122045 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
122046 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
122047 +allocate_probes_40204 allocate_probes 1 40204 NULL
122048 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
122049 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
122050 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
122051 +osst_read_40237 osst_read 3 40237 NULL
122052 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
122053 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
122054 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
122055 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
122056 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
122057 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
122058 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
122059 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
122060 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
122061 +SyS_bind_40303 SyS_bind 3 40303 NULL
122062 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
122063 +mmio_read_40348 mmio_read 4 40348 NULL
122064 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
122065 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
122066 +get_chars_40373 get_chars 3 40373 NULL
122067 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
122068 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
122069 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
122070 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
122071 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
122072 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
122073 +SyS_writev_40467 SyS_writev 3 40467 NULL
122074 +SyS_select_40473 SyS_select 1 40473 NULL
122075 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
122076 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
122077 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
122078 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
122079 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
122080 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
122081 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
122082 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
122083 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
122084 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
122085 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
122086 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
122087 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
122088 +fops_read_40672 fops_read 3 40672 NULL
122089 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
122090 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
122091 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
122092 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
122093 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
122094 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122095 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122096 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122097 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122098 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122099 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122100 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122101 +card_send_command_40757 card_send_command 3 40757 NULL
122102 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122103 +pg_write_40766 pg_write 3 40766 NULL
122104 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122105 +show_list_40775 show_list 3-0 40775 NULL
122106 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122107 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122108 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122109 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122110 +add_action_40811 add_action 4 40811 NULL
122111 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122112 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122113 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122114 +read_file_queue_40895 read_file_queue 3 40895 NULL
122115 +waiters_read_40902 waiters_read 3 40902 NULL
122116 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122117 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122118 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122119 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122120 +path_listxattr_40949 path_listxattr 3 40949 NULL
122121 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122122 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122123 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122124 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122125 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122126 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122127 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122128 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122129 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122130 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122131 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122132 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122133 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122134 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122135 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122136 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122137 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122138 +dma_attach_41094 dma_attach 5-6 41094 NULL
122139 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
122140 +provide_user_output_41105 provide_user_output 3 41105 NULL
122141 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122142 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122143 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122144 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122145 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122146 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
122147 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122148 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122149 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122150 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122151 +erst_read_41260 erst_read 0 41260 NULL
122152 +alloc_context_41283 alloc_context 1 41283 NULL
122153 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122154 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122155 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122156 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122157 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122158 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122159 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122160 +kmp_init_41373 kmp_init 2 41373 NULL
122161 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122162 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122163 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122164 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122165 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122166 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122167 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122168 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122169 +se_io_cb_41461 se_io_cb 3 41461 NULL
122170 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122171 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122172 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122173 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122174 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122175 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122176 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122177 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122178 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122179 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122180 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122181 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122182 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122183 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122184 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122185 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122186 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122187 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122188 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122189 +a2mp_send_41615 a2mp_send 4 41615 NULL
122190 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122191 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122192 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122193 +get_std_timing_41654 get_std_timing 0 41654 NULL
122194 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122195 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122196 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122197 +connector_write_41709 connector_write 3 41709 NULL
122198 +fillonedir_41746 fillonedir 3 41746 NULL
122199 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122200 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122201 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122202 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122203 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122204 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122205 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122206 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122207 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122208 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122209 +pci_map_single_41869 pci_map_single 0 41869 NULL
122210 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122211 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122212 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122213 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122214 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122215 +read_gssp_41947 read_gssp 3 41947 NULL
122216 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122217 +portnames_read_41958 portnames_read 3 41958 NULL
122218 +dst_mtu_41969 dst_mtu 0 41969 NULL
122219 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122220 +pool_allocate_42012 pool_allocate 3 42012 NULL
122221 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122222 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122223 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122224 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122225 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122226 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122227 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122228 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122229 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122230 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122231 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122232 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122233 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122234 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122235 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122236 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122237 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122238 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122239 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122240 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122241 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122242 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122243 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122244 +find_last_bit_42260 find_last_bit 0 42260 NULL
122245 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122246 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122247 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122248 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122249 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122250 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122251 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122252 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122253 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122254 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122255 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122256 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122257 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122258 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122259 +krng_get_random_42420 krng_get_random 3 42420 NULL
122260 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122261 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122262 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122263 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122264 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122265 +kuc_free_42455 kuc_free 2 42455 NULL
122266 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122267 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122268 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122269 +bypass_write_42498 bypass_write 3 42498 NULL
122270 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122271 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122272 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122273 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122274 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122275 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122276 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122277 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122278 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122279 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122280 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122281 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122282 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122283 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
122284 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
122285 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122286 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122287 +vb2_read_42703 vb2_read 3 42703 NULL
122288 +read_status_42722 read_status 0 42722 NULL
122289 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122290 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122291 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122292 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122293 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122294 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122295 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122296 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122297 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122298 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122299 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122300 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122301 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122302 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122303 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122304 +set_arg_42824 set_arg 3 42824 NULL
122305 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122306 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122307 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122308 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122309 +hd_end_request_42904 hd_end_request 2 42904 NULL
122310 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122311 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122312 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122313 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
122314 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122315 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122316 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122317 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122318 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122319 +__bioset_create_43059 __bioset_create 1 43059 NULL
122320 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122321 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122322 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122323 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122324 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122325 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122326 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122327 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122328 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122329 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122330 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122331 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122332 +uio_write_43202 uio_write 3 43202 NULL
122333 +iso_callback_43208 iso_callback 3 43208 NULL
122334 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122335 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122336 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122337 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122338 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122339 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122340 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122341 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122342 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122343 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122344 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122345 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122346 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122347 +xenfb_write_43412 xenfb_write 3 43412 NULL
122348 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122349 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122350 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122351 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122352 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122353 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122354 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122355 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122356 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122357 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122358 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122359 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122360 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122361 +read_events_43534 read_events 3 43534 NULL
122362 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122363 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122364 +request_resource_43548 request_resource 0 43548 NULL
122365 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122366 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122367 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122368 +proc_read_43614 proc_read 3 43614 NULL
122369 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122370 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122371 +random_write_43656 random_write 3 43656 NULL
122372 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122373 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122374 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122375 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122376 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122377 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122378 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122379 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122380 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122381 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122382 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122383 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122384 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122385 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122386 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122387 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122388 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122389 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122390 +read_flush_43851 read_flush 3 43851 NULL
122391 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122392 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122393 +SendString_43928 SendString 3 43928 NULL
122394 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122395 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122396 +nla_reserve_43984 nla_reserve 3 43984 NULL
122397 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122398 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122399 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122400 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122401 +emit_flags_44006 emit_flags 4-3 44006 NULL
122402 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122403 +fru_strlen_44046 fru_strlen 0 44046 NULL
122404 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122405 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122406 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122407 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122408 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122409 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122410 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122411 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122412 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122413 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122414 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122415 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122416 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122417 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122418 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122419 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122420 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122421 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122422 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122423 +device_create_file_44285 device_create_file 0 44285 NULL
122424 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122425 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122426 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122427 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122428 +rs_init_44327 rs_init 1 44327 NULL
122429 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122430 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122431 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122432 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122433 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122434 +strlcpy_44400 strlcpy 3 44400 NULL
122435 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122436 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122437 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122438 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122439 +write_file_debug_44476 write_file_debug 3 44476 NULL
122440 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122441 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122442 +bio_advance_44496 bio_advance 2 44496 NULL
122443 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122444 +ac_register_board_44504 ac_register_board 3 44504 NULL
122445 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122446 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122447 +spidev_write_44510 spidev_write 3 44510 NULL
122448 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122449 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122450 +comm_write_44537 comm_write 3 44537 NULL
122451 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122452 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122453 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122454 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122455 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122456 +mpi_resize_44674 mpi_resize 2 44674 NULL
122457 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122458 +ts_read_44687 ts_read 3 44687 NULL
122459 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
122460 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122461 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122462 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122463 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122464 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122465 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122466 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122467 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122468 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
122469 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122470 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122471 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122472 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122473 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122474 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122475 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122476 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122477 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122478 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122479 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122480 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122481 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122482 +sisusb_write_44834 sisusb_write 3 44834 NULL
122483 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122484 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122485 +copydesc_user_44855 copydesc_user 3 44855 NULL
122486 +set_advertising_44870 set_advertising 4 44870 NULL
122487 +init_rs_44873 init_rs 1 44873 NULL
122488 +skb_availroom_44883 skb_availroom 0 44883 NULL
122489 +do_tty_write_44896 do_tty_write 5 44896 NULL
122490 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122491 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122492 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122493 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122494 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122495 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122496 +sel_write_user_45060 sel_write_user 3 45060 NULL
122497 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122498 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122499 +snd_card_new_45104 snd_card_new 5 45104 NULL
122500 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122501 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122502 +usbdev_read_45114 usbdev_read 3 45114 NULL
122503 +send_to_tty_45141 send_to_tty 3 45141 NULL
122504 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122505 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122506 +device_write_45156 device_write 3 45156 NULL nohasharray
122507 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122508 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122509 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122510 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122511 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122512 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122513 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122514 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122515 +event_enable_write_45238 event_enable_write 3 45238 NULL
122516 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122517 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122518 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122519 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122520 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122521 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122522 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122523 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122524 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122525 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122526 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122527 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122528 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122529 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122530 +__node_remap_45458 __node_remap 4 45458 NULL
122531 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122532 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122533 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122534 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122535 +copy_macs_45534 copy_macs 4 45534 NULL
122536 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122537 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122538 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122539 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122540 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122541 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122542 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122543 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122544 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122545 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122546 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122547 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122548 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122549 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122550 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122551 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122552 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122553 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122554 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122555 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122556 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122557 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122558 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122559 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122560 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122561 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122562 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122563 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122564 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122565 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122566 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122567 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122568 +isdn_write_45863 isdn_write 3 45863 NULL
122569 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122570 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122571 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122572 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122573 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122574 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122575 +alloc_mr_45935 alloc_mr 1 45935 NULL
122576 +copy_to_45969 copy_to 3 45969 NULL
122577 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122578 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122579 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122580 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122581 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122582 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122583 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122584 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122585 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122586 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122587 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122588 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122589 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122590 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122591 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122592 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122593 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122594 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122595 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122596 +fq_resize_46195 fq_resize 2 46195 NULL
122597 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122598 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122599 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122600 +dsp_write_46218 dsp_write 2 46218 NULL
122601 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122602 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122603 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122604 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122605 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122606 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122607 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122608 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122609 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122610 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122611 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122612 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122613 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122614 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122615 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122616 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122617 +filldir64_46469 filldir64 3 46469 NULL
122618 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122619 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122620 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122621 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122622 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122623 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
122624 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122625 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122626 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122627 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122628 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122629 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122630 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122631 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122632 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122633 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122634 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122635 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122636 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122637 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122638 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122639 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122640 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122641 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122642 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122643 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122644 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122645 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122646 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122647 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122648 +readreg_46845 readreg 0 46845 NULL
122649 +spi_async_46857 spi_async 0 46857 NULL
122650 +vsnprintf_46863 vsnprintf 0 46863 NULL
122651 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122652 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122653 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122654 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122655 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122656 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
122657 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122658 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122659 +fb_write_46924 fb_write 3 46924 NULL
122660 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122661 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122662 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122663 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122664 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122665 +strlcat_46985 strlcat 3 46985 NULL
122666 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122667 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122668 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122669 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122670 +fs_path_len_47060 fs_path_len 0 47060 NULL
122671 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122672 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122673 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122674 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122675 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122676 +mousedev_read_47123 mousedev_read 3 47123 NULL
122677 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122678 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122679 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122680 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122681 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122682 +options_write_47243 options_write 3 47243 NULL
122683 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122684 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122685 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122686 +vsnprintf_47291 vsnprintf 0 47291 NULL
122687 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122688 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122689 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
122690 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122691 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122692 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
122693 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122694 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122695 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122696 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122697 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122698 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122699 +nametbl_list_47391 nametbl_list 2 47391 NULL
122700 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122701 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122702 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122703 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122704 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122705 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122706 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122707 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122708 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122709 +newpart_47485 newpart 6-4 47485 NULL
122710 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122711 +core_sys_select_47494 core_sys_select 1 47494 NULL
122712 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122713 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122714 +unlink_simple_47506 unlink_simple 3 47506 NULL
122715 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122716 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122717 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122718 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122719 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122720 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122721 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122722 +read_ldt_47570 read_ldt 2 47570 NULL
122723 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122724 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122725 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122726 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122727 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122728 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122729 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122730 +get_size_47644 get_size 1-2 47644 NULL
122731 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122732 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122733 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122734 +save_microcode_47717 save_microcode 3 47717 NULL
122735 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122736 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122737 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122738 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122739 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122740 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122741 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122742 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122743 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122744 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122745 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122746 +lov_packmd_47810 lov_packmd 0 47810 NULL
122747 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122748 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
122749 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122750 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122751 +vhci_read_47878 vhci_read 3 47878 NULL
122752 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122753 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122754 +comedi_write_47926 comedi_write 3 47926 NULL
122755 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122756 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
122757 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122758 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122759 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122760 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122761 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122762 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122763 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122764 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122765 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122766 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122767 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122768 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122769 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122770 +disc_write_48070 disc_write 3 48070 NULL
122771 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122772 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122773 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122774 +load_firmware_48128 load_firmware 2 48128 NULL
122775 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122776 +set_discoverable_48141 set_discoverable 4 48141 NULL
122777 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122778 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122779 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122780 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122781 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122782 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122783 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122784 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122785 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122786 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122787 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122788 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122789 +read_file_recv_48232 read_file_recv 3 48232 NULL
122790 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122791 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122792 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122793 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122794 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122795 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122796 +trace_options_write_48275 trace_options_write 3 48275 NULL
122797 +send_set_info_48288 send_set_info 7 48288 NULL
122798 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122799 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122800 +hash_setkey_48310 hash_setkey 3 48310 NULL
122801 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122802 +skb_add_data_48363 skb_add_data 3 48363 NULL
122803 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122804 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122805 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122806 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122807 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122808 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122809 +print_filtered_48442 print_filtered 2-0 48442 NULL
122810 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122811 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122812 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122813 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122814 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122815 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122816 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122817 +send_control_msg_48498 send_control_msg 6 48498 NULL
122818 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122819 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122820 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122821 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122822 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122823 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122824 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122825 +llog_data_len_48607 llog_data_len 1 48607 NULL
122826 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122827 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122828 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122829 +mtd_read_48655 mtd_read 0 48655 NULL
122830 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122831 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122832 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122833 +altera_drscan_48698 altera_drscan 2 48698 NULL
122834 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122835 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122836 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122837 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122838 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122839 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122840 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122841 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122842 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122843 +azx_get_position_48841 azx_get_position 0 48841 NULL
122844 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122845 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122846 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122847 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122848 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122849 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122850 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122851 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122852 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122853 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122854 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122855 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122856 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122857 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122858 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122859 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122860 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122861 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122862 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122863 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122864 +transient_status_49027 transient_status 4 49027 NULL
122865 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122866 +scsi_register_49094 scsi_register 2 49094 NULL
122867 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122868 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122869 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122870 +pt_read_49136 pt_read 3 49136 NULL nohasharray
122871 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
122872 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122873 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122874 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122875 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122876 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122877 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122878 +print_queue_49191 print_queue 0-4 49191 NULL
122879 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122880 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122881 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122882 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122883 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122884 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122885 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122886 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122887 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122888 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122889 +uio_read_49300 uio_read 3 49300 NULL
122890 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122891 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122892 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122893 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122894 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122895 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122896 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122897 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122898 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122899 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122900 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122901 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122902 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122903 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122904 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122905 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122906 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122907 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122908 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122909 +smk_write_access_49561 smk_write_access 3 49561 NULL
122910 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122911 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122912 +readfifo_49583 readfifo 1 49583 NULL
122913 +tap_write_49595 tap_write 3 49595 NULL
122914 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122915 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122916 +heap_init_49617 heap_init 2 49617 NULL
122917 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122918 +port_fops_read_49626 port_fops_read 3 49626 NULL
122919 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122920 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122921 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122922 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122923 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122924 +write_pool_49718 write_pool 3 49718 NULL
122925 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122926 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122927 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122928 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122929 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122930 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122931 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122932 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122933 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122934 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122935 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122936 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122937 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122938 +add_uuid_49831 add_uuid 4 49831 NULL
122939 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122940 +twl4030_write_49846 twl4030_write 2 49846 NULL
122941 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122942 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122943 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122944 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122945 +osc_brw_49896 osc_brw 4 49896 NULL
122946 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122947 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122948 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122949 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122950 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122951 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122952 +isdn_read_50021 isdn_read 3 50021 NULL
122953 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122954 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
122955 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122956 +ioread8_50049 ioread8 0 50049 NULL
122957 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122958 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122959 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122960 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122961 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122962 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122963 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122964 +read_file_slot_50111 read_file_slot 3 50111 NULL
122965 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122966 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122967 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122968 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122969 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122970 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122971 +odev_update_50169 odev_update 2 50169 NULL
122972 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122973 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122974 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122975 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122976 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122977 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122978 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122979 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122980 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122981 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122982 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122983 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122984 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122985 +do_launder_page_50329 do_launder_page 0 50329 NULL
122986 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122987 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122988 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122989 +tpm_read_50344 tpm_read 3 50344 NULL
122990 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122991 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122992 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122993 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122994 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122995 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122996 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122997 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122998 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122999 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
123000 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
123001 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
123002 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
123003 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
123004 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
123005 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
123006 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
123007 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
123008 +fat_readpages_50582 fat_readpages 4 50582 NULL
123009 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
123010 +xillybus_write_50605 xillybus_write 3 50605 NULL
123011 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
123012 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
123013 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
123014 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
123015 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
123016 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
123017 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
123018 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
123019 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
123020 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
123021 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
123022 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
123023 +tpm_write_50798 tpm_write 3 50798 NULL
123024 +tun_do_read_50800 tun_do_read 4 50800 NULL
123025 +write_flush_50803 write_flush 3 50803 NULL
123026 +dvb_play_50814 dvb_play 3 50814 NULL
123027 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
123028 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
123029 +SetArea_50835 SetArea 4 50835 NULL
123030 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
123031 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
123032 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
123033 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
123034 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
123035 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
123036 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
123037 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
123038 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
123039 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
123040 +show_device_status_50947 show_device_status 0 50947 NULL
123041 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
123042 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
123043 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
123044 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
123045 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
123046 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
123047 +timeout_write_50991 timeout_write 3 50991 NULL
123048 +proc_write_51003 proc_write 3 51003 NULL
123049 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
123050 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
123051 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
123052 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
123053 +dump_midi_51040 dump_midi 3 51040 NULL
123054 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
123055 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
123056 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
123057 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
123058 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
123059 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
123060 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
123061 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
123062 +ti_recv_51110 ti_recv 3 51110 NULL
123063 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
123064 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
123065 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
123066 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
123067 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
123068 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
123069 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
123070 +drm_property_create_51239 drm_property_create 4 51239 NULL
123071 +st_read_51251 st_read 3 51251 NULL
123072 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
123073 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
123074 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
123075 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
123076 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
123077 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
123078 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
123079 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
123080 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
123081 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
123082 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
123083 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
123084 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
123085 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
123086 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
123087 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
123088 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
123089 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
123090 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
123091 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
123092 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
123093 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
123094 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123095 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123096 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123097 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123098 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123099 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123100 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123101 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123102 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123103 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123104 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123105 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123106 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123107 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123108 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123109 +sel_write_access_51704 sel_write_access 3 51704 NULL
123110 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123111 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123112 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123113 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123114 +str_read_51731 str_read 4 51731 NULL
123115 +cm4040_read_51732 cm4040_read 3 51732 NULL
123116 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123117 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123118 +if_write_51756 if_write 3 51756 NULL
123119 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123120 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123121 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123122 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123123 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123124 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123125 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123126 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123127 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123128 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123129 +user_read_51881 user_read 3 51881 NULL
123130 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123131 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123132 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123133 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123134 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123135 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123136 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123137 +get_clock_info_51952 get_clock_info 4 51952 NULL
123138 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123139 +get_zone_51981 get_zone 0-1 51981 NULL
123140 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123141 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123142 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123143 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123144 +rdmalt_52022 rdmalt 0 52022 NULL
123145 +override_release_52032 override_release 2 52032 NULL
123146 +end_port_52042 end_port 0 52042 NULL
123147 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123148 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123149 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123150 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123151 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123152 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123153 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123154 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123155 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123156 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123157 +retry_count_read_52129 retry_count_read 3 52129 NULL
123158 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123159 +sub_alloc_52140 sub_alloc 0 52140 NULL
123160 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123161 +htable_size_52148 htable_size 0-1 52148 NULL
123162 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123163 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123164 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123165 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123166 +print_prefix_52176 print_prefix 0 52176 NULL
123167 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123168 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123169 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123170 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123171 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123172 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123173 +shrink_slab_52261 shrink_slab 2 52261 NULL
123174 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123175 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123176 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123177 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123178 +read_file_reset_52310 read_file_reset 3 52310 NULL
123179 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123180 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123181 +hwflags_read_52318 hwflags_read 3 52318 NULL
123182 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123183 +hur_len_52339 hur_len 0 52339 NULL
123184 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123185 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123186 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123187 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123188 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123189 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123190 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123191 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123192 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123193 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123194 +delay_status_52431 delay_status 5 52431 NULL
123195 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123196 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123197 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123198 +bt_alloc_52457 bt_alloc 2 52457 NULL
123199 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123200 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123201 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123202 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123203 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123204 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123205 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123206 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123207 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123208 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123209 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123210 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123211 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123212 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123213 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123214 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123215 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123216 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123217 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123218 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123219 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123220 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123221 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123222 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123223 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123224 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123225 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123226 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123227 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123228 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123229 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123230 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123231 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123232 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123233 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123234 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123235 +twlreg_write_52880 twlreg_write 3 52880 NULL
123236 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123237 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123238 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123239 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
123240 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123241 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123242 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123243 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123244 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123245 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123246 +num_node_state_52989 num_node_state 0 52989 NULL
123247 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123248 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123249 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123250 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123251 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123252 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123253 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
123254 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123255 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123256 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123257 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123258 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
123259 +verity_status_53120 verity_status 5 53120 NULL
123260 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123261 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123262 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123263 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123264 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123265 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123266 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123267 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123268 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123269 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123270 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123271 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123272 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123273 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123274 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123275 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123276 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123277 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123278 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123279 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123280 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123281 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123282 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123283 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123284 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123285 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123286 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123287 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123288 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123289 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123290 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123291 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123292 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123293 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123294 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123295 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123296 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123297 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123298 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123299 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123300 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123301 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123302 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123303 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123304 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123305 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123306 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123307 +wdm_write_53735 wdm_write 3 53735 NULL
123308 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123309 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123310 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123311 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123312 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123313 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123314 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123315 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123316 +setup_data_read_53822 setup_data_read 3 53822 NULL
123317 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123318 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123319 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123320 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123321 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123322 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123323 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123324 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123325 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123326 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123327 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123328 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123329 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123330 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123331 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123332 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123333 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123334 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123335 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123336 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123337 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123338 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123339 +strn_len_54122 strn_len 0 54122 NULL
123340 +isku_receive_54130 isku_receive 4 54130 NULL
123341 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123342 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123343 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123344 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123345 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123346 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123347 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123348 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123349 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123350 +reada_add_block_54247 reada_add_block 2 54247 NULL
123351 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
123352 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123353 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123354 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123355 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123356 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123357 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123358 +sizeof_long_54276 sizeof_long 0 54276 NULL
123359 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123360 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123361 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123362 +sprintf_54306 sprintf 0 54306 NULL
123363 +path_setxattr_54308 path_setxattr 4 54308 NULL
123364 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123365 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123366 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123367 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123368 +readlink_copy_54366 readlink_copy 2 54366 NULL
123369 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123370 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123371 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123372 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123373 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123374 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
123375 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
123376 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123377 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123378 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123379 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123380 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123381 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123382 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123383 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123384 +viacam_read_54526 viacam_read 3 54526 NULL
123385 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123386 +setsockopt_54539 setsockopt 5 54539 NULL
123387 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123388 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123389 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123390 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123391 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123392 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123393 +port_fops_write_54627 port_fops_write 3 54627 NULL
123394 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123395 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123396 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123397 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123398 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
123399 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123400 +bus_add_device_54665 bus_add_device 0 54665 NULL
123401 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123402 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123403 +evm_read_key_54674 evm_read_key 3 54674 NULL
123404 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123405 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123406 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123407 +kzalloc_54740 kzalloc 1 54740 NULL
123408 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123409 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123410 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123411 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123412 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123413 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123414 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123415 +nfsd_write_54809 nfsd_write 6 54809 NULL
123416 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123417 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123418 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123419 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123420 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123421 +write_rio_54837 write_rio 3 54837 NULL
123422 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123423 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123424 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123425 +printer_read_54851 printer_read 3 54851 NULL
123426 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123427 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123428 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123429 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123430 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123431 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123432 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123433 +add_port_54941 add_port 2 54941 NULL
123434 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123435 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123436 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123437 +c4_add_card_54968 c4_add_card 3 54968 NULL
123438 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123439 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123440 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123441 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123442 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123443 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123444 +read_dma_55086 read_dma 3 55086 NULL
123445 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123446 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123447 +filldir_55137 filldir 3 55137 NULL
123448 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123449 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123450 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123451 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123452 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123453 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123454 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123455 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123456 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
123457 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123458 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123459 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123460 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123461 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123462 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123463 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123464 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123465 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123466 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123467 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123468 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123469 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123470 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123471 +vme_user_read_55338 vme_user_read 3 55338 NULL
123472 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123473 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123474 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123475 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123476 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123477 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123478 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123479 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123480 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123481 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123482 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123483 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123484 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123485 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123486 +ea_get_55522 ea_get 3-0 55522 NULL
123487 +buffer_size_55534 buffer_size 0 55534 NULL
123488 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123489 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123490 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123491 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123492 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123493 +add_partition_55588 add_partition 2 55588 NULL
123494 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123495 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123496 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123497 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123498 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123499 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123500 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123501 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123502 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123503 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123504 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123505 +get_info_55681 get_info 3 55681 NULL
123506 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123507 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123508 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123509 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123510 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123511 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123512 +set_local_name_55757 set_local_name 4 55757 NULL
123513 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123514 +strlen_55778 strlen 0 55778 NULL
123515 +set_spte_55783 set_spte 4-5 55783 NULL
123516 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123517 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123518 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123519 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123520 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123521 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123522 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123523 +hsc_write_55875 hsc_write 3 55875 NULL
123524 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123525 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123526 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123527 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123528 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123529 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123530 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123531 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123532 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123533 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123534 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123535 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123536 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123537 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123538 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123539 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123540 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123541 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123542 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123543 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123544 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123545 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123546 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123547 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123548 +fd_copyin_56247 fd_copyin 3 56247 NULL
123549 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123550 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123551 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123552 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123553 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123554 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123555 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123556 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123557 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123558 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123559 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123560 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123561 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123562 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123563 +dev_read_56369 dev_read 3 56369 NULL
123564 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123565 +lnet_ping_56378 lnet_ping 4 56378 NULL
123566 +write_gssp_56404 write_gssp 3 56404 NULL
123567 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123568 +store_msg_56417 store_msg 3 56417 NULL
123569 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123570 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
123571 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
123572 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123573 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123574 +fl_create_56435 fl_create 5 56435 NULL
123575 +gnttab_map_56439 gnttab_map 2 56439 NULL
123576 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123577 +set_connectable_56458 set_connectable 4 56458 NULL
123578 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123579 +putused_user_56467 putused_user 3 56467 NULL
123580 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123581 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123582 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123583 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123584 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123585 +init_map_ip_56508 init_map_ip 5 56508 NULL
123586 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123587 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123588 +ip_options_get_56538 ip_options_get 4 56538 NULL
123589 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123590 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123591 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123592 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123593 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123594 +event_filter_write_56609 event_filter_write 3 56609 NULL
123595 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123596 +gather_array_56641 gather_array 3 56641 NULL
123597 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123598 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123599 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123600 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123601 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123602 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123603 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123604 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123605 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123606 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123607 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123608 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123609 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123610 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123611 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123612 +do_syslog_56807 do_syslog 3 56807 NULL
123613 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123614 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123615 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123616 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123617 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123618 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123619 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123620 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123621 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123622 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123623 +strcspn_56913 strcspn 0 56913 NULL
123624 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123625 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123626 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123627 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123628 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123629 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123630 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123631 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123632 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123633 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123634 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123635 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123636 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123637 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123638 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123639 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123640 +altera_get_note_57099 altera_get_note 6 57099 NULL
123641 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123642 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123643 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123644 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123645 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123646 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123647 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123648 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123649 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123650 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123651 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123652 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123653 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123654 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123655 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123656 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123657 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123658 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123659 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123660 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123661 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123662 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123663 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123664 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123665 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123666 +write_file_regval_57313 write_file_regval 3 57313 NULL
123667 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123668 +usblp_read_57342 usblp_read 3 57342 NULL
123669 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123670 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123671 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123672 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123673 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123674 +read_file_blob_57406 read_file_blob 3 57406 NULL
123675 +enclosure_register_57412 enclosure_register 3 57412 NULL
123676 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
123677 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123678 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123679 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123680 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123681 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123682 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123683 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123684 +skb_headlen_57501 skb_headlen 0 57501 NULL
123685 +copy_in_user_57502 copy_in_user 3 57502 NULL
123686 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123687 +init_tag_map_57515 init_tag_map 3 57515 NULL
123688 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123689 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123690 +cmm_read_57520 cmm_read 3 57520 NULL
123691 +inode_permission_57531 inode_permission 0 57531 NULL
123692 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123693 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123694 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123695 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123696 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123697 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123698 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123699 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123700 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123701 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
123702 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123703 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123704 +mem_read_57631 mem_read 3 57631 NULL
123705 +r3964_write_57662 r3964_write 4 57662 NULL
123706 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123707 +__lgwrite_57669 __lgwrite 4 57669 NULL
123708 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123709 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123710 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123711 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123712 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123713 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123714 +ld2_57794 ld2 0 57794 NULL
123715 +ivtv_read_57796 ivtv_read 3 57796 NULL
123716 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123717 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123718 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123719 +flash_read_57843 flash_read 3 57843 NULL
123720 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123721 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123722 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123723 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123724 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123725 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123726 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123727 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123728 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123729 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123730 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123731 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123732 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123733 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123734 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123735 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123736 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123737 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123738 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123739 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123740 +mce_async_out_58056 mce_async_out 3 58056 NULL
123741 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123742 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123743 +cm4040_write_58079 cm4040_write 3 58079 NULL
123744 +savemem_58129 savemem 3 58129 NULL
123745 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123746 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123747 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123748 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123749 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123750 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123751 +read_file_debug_58256 read_file_debug 3 58256 NULL
123752 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123753 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123754 +profile_load_58267 profile_load 3 58267 NULL
123755 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123756 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123757 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123758 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123759 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123760 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123761 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123762 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123763 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123764 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123765 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123766 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123767 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123768 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123769 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123770 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123771 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123772 +capabilities_read_58457 capabilities_read 3 58457 NULL
123773 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123774 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123775 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123776 +nv_rd08_58472 nv_rd08 0 58472 NULL
123777 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123778 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123779 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
123780 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123781 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123782 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123783 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123784 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123785 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123786 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123787 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123788 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123789 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123790 +xip_file_read_58592 xip_file_read 3 58592 NULL
123791 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123792 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123793 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123794 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123795 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123796 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123797 +find_zero_58685 find_zero 0-1 58685 NULL
123798 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123799 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123800 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123801 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123802 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123803 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123804 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123805 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123806 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123807 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123808 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123809 +ep_read_58813 ep_read 3 58813 NULL
123810 +command_write_58841 command_write 3 58841 NULL
123811 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123812 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123813 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123814 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123815 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123816 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123817 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123818 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123819 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123820 +init_list_set_59005 init_list_set 3 59005 NULL
123821 +ep_write_59008 ep_write 3 59008 NULL
123822 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123823 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123824 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123825 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123826 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123827 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123828 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123829 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123830 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123831 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123832 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123833 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123834 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123835 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123836 +ksize_59176 ksize 0 59176 NULL
123837 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123838 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123839 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123840 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123841 +dt3155_read_59226 dt3155_read 3 59226 NULL
123842 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123843 +nla_len_59258 nla_len 0 59258 NULL
123844 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123845 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123846 +fd_copyout_59323 fd_copyout 3 59323 NULL
123847 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123848 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123849 +__map_request_59350 __map_request 0 59350 NULL
123850 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123851 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123852 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123853 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123854 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123855 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123856 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123857 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123858 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123859 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123860 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123861 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123862 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123863 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123864 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
123865 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123866 +tunables_write_59563 tunables_write 3 59563 NULL
123867 +bio_split_59564 bio_split 2 59564 NULL
123868 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123869 +write_pbl_59583 write_pbl 4 59583 NULL
123870 +memdup_user_59590 memdup_user 2 59590 NULL
123871 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123872 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123873 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123874 +mtrr_write_59622 mtrr_write 3 59622 NULL
123875 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123876 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123877 +hidraw_read_59650 hidraw_read 3 59650 NULL
123878 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123879 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123880 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123881 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123882 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123883 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123884 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123885 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123886 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123887 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123888 +strnlen_59746 strnlen 0 59746 NULL
123889 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123890 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123891 +venus_remove_59781 venus_remove 4 59781 NULL
123892 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123893 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123894 +ipw_write_59807 ipw_write 3 59807 NULL
123895 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123896 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123897 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123898 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123899 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123900 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123901 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123902 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123903 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123904 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123905 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123906 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123907 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123908 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123909 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123910 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123911 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123912 +copy_items_60009 copy_items 7 60009 NULL
123913 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123914 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123915 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123916 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123917 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123918 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123919 +vcs_size_60050 vcs_size 0 60050 NULL
123920 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123921 +compat_writev_60063 compat_writev 3 60063 NULL
123922 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123923 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123924 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123925 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123926 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123927 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123928 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123929 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
123930 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123931 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123932 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123933 +init_state_60165 init_state 2 60165 NULL
123934 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123935 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123936 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123937 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
123938 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
123939 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123940 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123941 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123942 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123943 +printer_write_60276 printer_write 3 60276 NULL
123944 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123945 +getDataLength_60301 getDataLength 0 60301 NULL
123946 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123947 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123948 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123949 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123950 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123951 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123952 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123953 +driver_names_read_60399 driver_names_read 3 60399 NULL
123954 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123955 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123956 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123957 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123958 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123959 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123960 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123961 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123962 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123963 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123964 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123965 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123966 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123967 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123968 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123969 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123970 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123971 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123972 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123973 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123974 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123975 +raid_status_60755 raid_status 5 60755 NULL
123976 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123977 +opticon_write_60775 opticon_write 4 60775 NULL
123978 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123979 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123980 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123981 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123982 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123983 +generic_writepages_60871 generic_writepages 0 60871 NULL
123984 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123985 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123986 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123987 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123988 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123989 +pti_char_write_60960 pti_char_write 3 60960 NULL
123990 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123991 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123992 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123993 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123994 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123995 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123996 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123997 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
123998 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123999 +symtab_init_61050 symtab_init 2 61050 NULL
124000 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
124001 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
124002 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
124003 +get_derived_key_61100 get_derived_key 4 61100 NULL
124004 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
124005 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
124006 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
124007 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
124008 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
124009 +pair_device_61175 pair_device 4 61175 NULL nohasharray
124010 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
124011 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
124012 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
124013 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
124014 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
124015 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
124016 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
124017 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
124018 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
124019 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
124020 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
124021 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
124022 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
124023 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
124024 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
124025 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
124026 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
124027 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
124028 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
124029 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
124030 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
124031 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
124032 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
124033 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
124034 +system_enable_write_61396 system_enable_write 3 61396 NULL
124035 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
124036 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
124037 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
124038 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
124039 +erst_errno_61526 erst_errno 0 61526 NULL
124040 +proc_write_device_61541 proc_write_device 3 61541 NULL
124041 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
124042 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
124043 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
124044 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
124045 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
124046 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
124047 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
124048 +seq_open_private_61589 seq_open_private 3 61589 NULL
124049 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
124050 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
124051 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
124052 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
124053 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
124054 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
124055 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
124056 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
124057 +resize_stripes_61650 resize_stripes 2 61650 NULL
124058 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
124059 +insert_one_name_61668 insert_one_name 7 61668 NULL
124060 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
124061 +lock_loop_61681 lock_loop 1 61681 NULL
124062 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
124063 +filter_read_61692 filter_read 3 61692 NULL
124064 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
124065 +iov_length_61716 iov_length 0 61716 NULL
124066 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
124067 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
124068 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
124069 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
124070 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
124071 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
124072 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
124073 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
124074 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
124075 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
124076 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
124077 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
124078 +get_fw_name_61874 get_fw_name 3 61874 NULL
124079 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
124080 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
124081 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
124082 +kernfs_name_61910 kernfs_name 3 61910 NULL
124083 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
124084 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
124085 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
124086 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
124087 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
124088 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
124089 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
124090 +fix_read_error_61965 fix_read_error 4 61965 NULL
124091 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
124092 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
124093 +cow_file_range_61979 cow_file_range 3 61979 NULL
124094 +dequeue_event_62000 dequeue_event 3 62000 NULL
124095 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124096 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124097 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124098 +SYSC_select_62024 SYSC_select 1 62024 NULL
124099 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
124100 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124101 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124102 +do_pselect_62061 do_pselect 1 62061 NULL
124103 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124104 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124105 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124106 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124107 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124108 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124109 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124110 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124111 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124112 +video_usercopy_62151 video_usercopy 2 62151 NULL
124113 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124114 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124115 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124116 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124117 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124118 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124119 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124120 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124121 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124122 +get_random_int_62279 get_random_int 0 62279 NULL
124123 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124124 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124125 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124126 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124127 +subseq_list_62332 subseq_list 3-0 62332 NULL
124128 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124129 +flash_write_62354 flash_write 3 62354 NULL
124130 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124131 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124132 +altera_irscan_62396 altera_irscan 2 62396 NULL
124133 +set_ssp_62411 set_ssp 4 62411 NULL
124134 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124135 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124136 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124137 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124138 +debugfs_read_62535 debugfs_read 3 62535 NULL
124139 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124140 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124141 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124142 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124143 +get_subdir_62581 get_subdir 3 62581 NULL
124144 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124145 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124146 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124147 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124148 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124149 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124150 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124151 +rdm_62719 rdm 0 62719 NULL
124152 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124153 +key_replays_read_62746 key_replays_read 3 62746 NULL
124154 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124155 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124156 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124157 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124158 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124159 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124160 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124161 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124162 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124163 +__add_action_62798 __add_action 4 62798 NULL
124164 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124165 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124166 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124167 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124168 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124169 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124170 +aoechr_write_62883 aoechr_write 3 62883 NULL
124171 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124172 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124173 +getdqbuf_62908 getdqbuf 1 62908 NULL
124174 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124175 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124176 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124177 +hwdep_read_62992 hwdep_read 3 62992 NULL
124178 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124179 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124180 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124181 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124182 +unlink1_63059 unlink1 3 63059 NULL
124183 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124184 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124185 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124186 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124187 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124188 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124189 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124190 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124191 +vme_master_read_63221 vme_master_read 0 63221 NULL
124192 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124193 +ptp_read_63251 ptp_read 4 63251 NULL
124194 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124195 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124196 +raid5_resize_63306 raid5_resize 2 63306 NULL
124197 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124198 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124199 +proc_info_read_63344 proc_info_read 3 63344 NULL
124200 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124201 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124202 +idmouse_read_63374 idmouse_read 3 63374 NULL
124203 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124204 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124205 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124206 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124207 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124208 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124209 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124210 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124211 +read_kcore_63488 read_kcore 3 63488 NULL
124212 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124213 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124214 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124215 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124216 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124217 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124218 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124219 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124220 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124221 +write_debug_level_63613 write_debug_level 3 63613 NULL
124222 +__spi_validate_63618 __spi_validate 0 63618 NULL
124223 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124224 +hid_report_len_63637 hid_report_len 0 63637 NULL
124225 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124226 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124227 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124228 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124229 +vbi_read_63673 vbi_read 3 63673 NULL
124230 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124231 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124232 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124233 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
124234 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124235 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124236 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124237 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124238 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124239 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124240 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124241 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124242 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124243 +sel_write_load_63830 sel_write_load 3 63830 NULL
124244 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124245 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124246 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124247 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124248 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124249 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124250 +__team_options_register_63941 __team_options_register 3 63941 NULL
124251 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124252 +set_bredr_63975 set_bredr 4 63975 NULL
124253 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124254 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124255 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124256 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124257 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124258 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124259 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
124260 +__sock_create_64069 __sock_create 0 64069 NULL
124261 +get_u8_64076 get_u8 0 64076 NULL
124262 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124263 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124264 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124265 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124266 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124267 +to_bytes_64103 to_bytes 0-1 64103 NULL
124268 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124269 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124270 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124271 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124272 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124273 +init_bch_64130 init_bch 1-2 64130 NULL
124274 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124275 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124276 +number_of_tds_64156 number_of_tds 0 64156 NULL
124277 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124278 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124279 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124280 +read_pulse_64227 read_pulse 0-3 64227 NULL
124281 +ea_len_64229 ea_len 0 64229 NULL
124282 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124283 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124284 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124285 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124286 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124287 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124288 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124289 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124290 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124291 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124292 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124293 +ts_write_64336 ts_write 3 64336 NULL
124294 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124295 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
124296 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124297 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124298 +reg_create_64372 reg_create 5 64372 NULL nohasharray
124299 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
124300 +ilo_write_64378 ilo_write 3 64378 NULL
124301 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124302 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124303 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124304 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124305 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124306 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124307 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124308 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124309 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124310 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124311 +single_open_size_64483 single_open_size 4 64483 NULL
124312 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124313 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124314 +remove_uuid_64505 remove_uuid 4 64505 NULL
124315 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124316 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124317 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124318 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124319 +SyS_bind_64544 SyS_bind 3 64544 NULL
124320 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124321 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124322 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124323 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124324 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124325 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124326 +do_erase_64574 do_erase 4 64574 NULL
124327 +fanotify_write_64623 fanotify_write 3 64623 NULL
124328 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124329 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124330 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124331 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124332 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124333 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124334 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124335 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124336 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124337 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124338 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124339 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124340 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124341 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124342 +hwdep_write_64776 hwdep_write 3 64776 NULL
124343 +message_for_md_64777 message_for_md 5 64777 NULL
124344 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124345 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124346 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124347 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124348 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124349 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124350 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124351 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124352 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124353 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124354 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124355 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124356 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124357 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124358 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124359 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124360 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124361 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124362 +insert_dent_65034 insert_dent 7 65034 NULL
124363 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124364 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124365 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124366 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124367 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124368 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124369 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124370 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
124371 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124372 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124373 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124374 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124375 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124376 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124377 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124378 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124379 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124380 +get_var_len_65304 get_var_len 0 65304 NULL
124381 +unpack_array_65318 unpack_array 0 65318 NULL
124382 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124383 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124384 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124385 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124386 +SyS_writev_65372 SyS_writev 3 65372 NULL
124387 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124388 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124389 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124390 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124391 +device_add_groups_65423 device_add_groups 0 65423 NULL
124392 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124393 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124394 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124395 +clear_user_65470 clear_user 2 65470 NULL
124396 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124397 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124398 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124399 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124400 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124401 new file mode 100644
124402 index 0000000..560cd7b
124403 --- /dev/null
124404 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124405 @@ -0,0 +1,92 @@
124406 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124407 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124408 +mappedread_2627 mappedread 2 2627 NULL
124409 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124410 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124411 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124412 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124413 +dmu_write_6048 dmu_write 4-3 6048 NULL
124414 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124415 +update_pages_6225 update_pages 2-3 6225 NULL
124416 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124417 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124418 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124419 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124420 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124421 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124422 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124423 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124424 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124425 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124426 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124427 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124428 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124429 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124430 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124431 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124432 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124433 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124434 +uiocopy_18680 uiocopy 2 18680 NULL
124435 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124436 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124437 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124438 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124439 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124440 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124441 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124442 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124443 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124444 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124445 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124446 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124447 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124448 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124449 +splat_write_30943 splat_write 3 30943 NULL
124450 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124451 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124452 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124453 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124454 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124455 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124456 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124457 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124458 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124459 +copyinstr_36980 copyinstr 3 36980 NULL
124460 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124461 +splat_read_38116 splat_read 3 38116 NULL
124462 +sa_setup_38756 sa_setup 4 38756 NULL
124463 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124464 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124465 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124466 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124467 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124468 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124469 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124470 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124471 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124472 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124473 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124474 +kcopy_write_43683 kcopy_write 3 43683 NULL
124475 +uiomove_44355 uiomove 2 44355 NULL
124476 +dmu_read_44418 dmu_read 4-3 44418 NULL
124477 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124478 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124479 +copyin_45945 copyin 3 45945 NULL
124480 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124481 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124482 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124483 +spa_history_write_49650 spa_history_write 3 49650 NULL
124484 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124485 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124486 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124487 +copyout_51409 copyout 3 51409 NULL
124488 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124489 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124490 +get_nvlist_56685 get_nvlist 2 56685 NULL
124491 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124492 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124493 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124494 +zpios_write_61823 zpios_write 3 61823 NULL
124495 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124496 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124497 +zpios_read_64734 zpios_read 3 64734 NULL
124498 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124499 new file mode 100644
124500 index 0000000..95f7abd
124501 --- /dev/null
124502 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124503 @@ -0,0 +1,259 @@
124504 +/*
124505 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124506 + * Licensed under the GPL v2, or (at your option) v3
124507 + *
124508 + * Homepage:
124509 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124510 + *
124511 + * Documentation:
124512 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124513 + *
124514 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124515 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124516 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124517 + *
124518 + * Usage:
124519 + * $ make
124520 + * $ make run
124521 + */
124522 +
124523 +#include "gcc-common.h"
124524 +#include "size_overflow.h"
124525 +
124526 +int plugin_is_GPL_compatible;
124527 +
124528 +tree report_size_overflow_decl;
124529 +
124530 +tree size_overflow_type_HI;
124531 +tree size_overflow_type_SI;
124532 +tree size_overflow_type_DI;
124533 +tree size_overflow_type_TI;
124534 +
124535 +static struct plugin_info size_overflow_plugin_info = {
124536 + .version = "20140725",
124537 + .help = "no-size-overflow\tturn off size overflow checking\n",
124538 +};
124539 +
124540 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124541 +{
124542 + unsigned int arg_count;
124543 + enum tree_code code = TREE_CODE(*node);
124544 +
124545 + switch (code) {
124546 + case FUNCTION_DECL:
124547 + arg_count = type_num_arguments(TREE_TYPE(*node));
124548 + break;
124549 + case FUNCTION_TYPE:
124550 + case METHOD_TYPE:
124551 + arg_count = type_num_arguments(*node);
124552 + break;
124553 + default:
124554 + *no_add_attrs = true;
124555 + error("%s: %qE attribute only applies to functions", __func__, name);
124556 + return NULL_TREE;
124557 + }
124558 +
124559 + for (; args; args = TREE_CHAIN(args)) {
124560 + tree position = TREE_VALUE(args);
124561 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124562 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124563 + *no_add_attrs = true;
124564 + }
124565 + }
124566 + return NULL_TREE;
124567 +}
124568 +
124569 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124570 +{
124571 + unsigned int arg_count;
124572 + enum tree_code code = TREE_CODE(*node);
124573 +
124574 + switch (code) {
124575 + case FUNCTION_DECL:
124576 + arg_count = type_num_arguments(TREE_TYPE(*node));
124577 + break;
124578 + case FUNCTION_TYPE:
124579 + case METHOD_TYPE:
124580 + arg_count = type_num_arguments(*node);
124581 + break;
124582 + case FIELD_DECL:
124583 + return NULL_TREE;
124584 + default:
124585 + *no_add_attrs = true;
124586 + error("%qE attribute only applies to functions", name);
124587 + return NULL_TREE;
124588 + }
124589 +
124590 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124591 + return NULL_TREE;
124592 +
124593 + for (; args; args = TREE_CHAIN(args)) {
124594 + tree position = TREE_VALUE(args);
124595 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124596 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124597 + *no_add_attrs = true;
124598 + }
124599 + }
124600 + return NULL_TREE;
124601 +}
124602 +
124603 +static struct attribute_spec size_overflow_attr = {
124604 + .name = "size_overflow",
124605 + .min_length = 1,
124606 + .max_length = -1,
124607 + .decl_required = true,
124608 + .type_required = false,
124609 + .function_type_required = false,
124610 + .handler = handle_size_overflow_attribute,
124611 +#if BUILDING_GCC_VERSION >= 4007
124612 + .affects_type_identity = false
124613 +#endif
124614 +};
124615 +
124616 +static struct attribute_spec intentional_overflow_attr = {
124617 + .name = "intentional_overflow",
124618 + .min_length = 1,
124619 + .max_length = -1,
124620 + .decl_required = true,
124621 + .type_required = false,
124622 + .function_type_required = false,
124623 + .handler = handle_intentional_overflow_attribute,
124624 +#if BUILDING_GCC_VERSION >= 4007
124625 + .affects_type_identity = false
124626 +#endif
124627 +};
124628 +
124629 +static void register_attributes(void __unused *event_data, void __unused *data)
124630 +{
124631 + register_attribute(&size_overflow_attr);
124632 + register_attribute(&intentional_overflow_attr);
124633 +}
124634 +
124635 +static tree create_typedef(tree type, const char* ident)
124636 +{
124637 + tree new_type, decl;
124638 +
124639 + new_type = build_variant_type_copy(type);
124640 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124641 + DECL_ORIGINAL_TYPE(decl) = type;
124642 + TYPE_NAME(new_type) = decl;
124643 + return new_type;
124644 +}
124645 +
124646 +// Create the noreturn report_size_overflow() function decl.
124647 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124648 +{
124649 + tree const_char_ptr_type_node;
124650 + tree fntype;
124651 +
124652 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124653 +
124654 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124655 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124656 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124657 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124658 +
124659 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124660 + fntype = build_function_type_list(void_type_node,
124661 + const_char_ptr_type_node,
124662 + unsigned_type_node,
124663 + const_char_ptr_type_node,
124664 + const_char_ptr_type_node,
124665 + NULL_TREE);
124666 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124667 +
124668 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124669 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124670 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124671 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124672 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124673 +}
124674 +
124675 +
124676 +extern struct gimple_opt_pass pass_dce;
124677 +
124678 +static struct opt_pass *make_dce_pass(void)
124679 +{
124680 +#if BUILDING_GCC_VERSION >= 4009
124681 + return make_pass_dce(g);
124682 +#else
124683 + return &pass_dce.pass;
124684 +#endif
124685 +}
124686 +
124687 +
124688 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124689 +{
124690 + int i;
124691 + const char * const plugin_name = plugin_info->base_name;
124692 + const int argc = plugin_info->argc;
124693 + const struct plugin_argument * const argv = plugin_info->argv;
124694 + bool enable = true;
124695 + struct register_pass_info insert_size_overflow_asm_pass_info;
124696 + struct register_pass_info __unused dump_before_pass_info;
124697 + struct register_pass_info __unused dump_after_pass_info;
124698 + struct register_pass_info insert_size_overflow_check_info;
124699 + struct register_pass_info dce_pass_info;
124700 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124701 + {
124702 + .base = &report_size_overflow_decl,
124703 + .nelt = 1,
124704 + .stride = sizeof(report_size_overflow_decl),
124705 + .cb = &gt_ggc_mx_tree_node,
124706 + .pchw = &gt_pch_nx_tree_node
124707 + },
124708 + LAST_GGC_ROOT_TAB
124709 + };
124710 +
124711 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124712 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124713 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124714 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124715 +
124716 + dump_before_pass_info.pass = make_dump_pass();
124717 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124718 + dump_before_pass_info.ref_pass_instance_number = 1;
124719 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124720 +
124721 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124722 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124723 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124724 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124725 +
124726 + dump_after_pass_info.pass = make_dump_pass();
124727 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124728 + dump_after_pass_info.ref_pass_instance_number = 1;
124729 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124730 +
124731 + dce_pass_info.pass = make_dce_pass();
124732 + dce_pass_info.reference_pass_name = "vrp";
124733 + dce_pass_info.ref_pass_instance_number = 1;
124734 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124735 +
124736 + if (!plugin_default_version_check(version, &gcc_version)) {
124737 + error(G_("incompatible gcc/plugin versions"));
124738 + return 1;
124739 + }
124740 +
124741 + for (i = 0; i < argc; ++i) {
124742 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124743 + enable = false;
124744 + continue;
124745 + }
124746 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124747 + }
124748 +
124749 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124750 + if (enable) {
124751 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124752 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124753 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124754 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124755 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124756 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124757 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124758 + }
124759 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124760 +
124761 + return 0;
124762 +}
124763 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124764 new file mode 100644
124765 index 0000000..0888f6c
124766 --- /dev/null
124767 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124768 @@ -0,0 +1,364 @@
124769 +/*
124770 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124771 + * Licensed under the GPL v2, or (at your option) v3
124772 + *
124773 + * Homepage:
124774 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124775 + *
124776 + * Documentation:
124777 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124778 + *
124779 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124780 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124781 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124782 + *
124783 + * Usage:
124784 + * $ make
124785 + * $ make run
124786 + */
124787 +
124788 +#include "gcc-common.h"
124789 +#include "size_overflow.h"
124790 +
124791 +#include "size_overflow_hash.h"
124792 +#include "size_overflow_hash_aux.h"
124793 +
124794 +#define CODES_LIMIT 32
124795 +
124796 +static unsigned char get_tree_code(const_tree type)
124797 +{
124798 + switch (TREE_CODE(type)) {
124799 + case ARRAY_TYPE:
124800 + return 0;
124801 + case BOOLEAN_TYPE:
124802 + return 1;
124803 + case ENUMERAL_TYPE:
124804 + return 2;
124805 + case FUNCTION_TYPE:
124806 + return 3;
124807 + case INTEGER_TYPE:
124808 + return 4;
124809 + case POINTER_TYPE:
124810 + return 5;
124811 + case RECORD_TYPE:
124812 + return 6;
124813 + case UNION_TYPE:
124814 + return 7;
124815 + case VOID_TYPE:
124816 + return 8;
124817 + case REAL_TYPE:
124818 + return 9;
124819 + case VECTOR_TYPE:
124820 + return 10;
124821 + case REFERENCE_TYPE:
124822 + return 11;
124823 + case OFFSET_TYPE:
124824 + return 12;
124825 + case COMPLEX_TYPE:
124826 + return 13;
124827 + default:
124828 + debug_tree((tree)type);
124829 + gcc_unreachable();
124830 + }
124831 +}
124832 +
124833 +struct function_hash {
124834 + size_t tree_codes_len;
124835 + unsigned char tree_codes[CODES_LIMIT];
124836 + const_tree fndecl;
124837 + unsigned int hash;
124838 +};
124839 +
124840 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124841 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124842 +{
124843 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124844 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124845 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124846 +
124847 + unsigned int m = 0x57559429;
124848 + unsigned int n = 0x5052acdb;
124849 + const unsigned int *key4 = (const unsigned int *)key;
124850 + unsigned int h = len;
124851 + unsigned int k = len + seed + n;
124852 + unsigned long long p;
124853 +
124854 + while (len >= 8) {
124855 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124856 + len -= 8;
124857 + }
124858 + if (len >= 4) {
124859 + cwmixb(key4[0]) key4 += 1;
124860 + len -= 4;
124861 + }
124862 + if (len)
124863 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124864 + cwmixb(h ^ (k + n));
124865 + return k ^ h;
124866 +
124867 +#undef cwfold
124868 +#undef cwmixa
124869 +#undef cwmixb
124870 +}
124871 +
124872 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124873 +{
124874 + unsigned int fn, codes, seed = 0;
124875 +
124876 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124877 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124878 +
124879 + fn_hash_data->hash = fn ^ codes;
124880 +}
124881 +
124882 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124883 +{
124884 + gcc_assert(type != NULL_TREE);
124885 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124886 +
124887 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124888 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124889 + fn_hash_data->tree_codes_len++;
124890 + type = TREE_TYPE(type);
124891 + }
124892 +}
124893 +
124894 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124895 +{
124896 + const_tree result;
124897 +
124898 + gcc_assert(node != NULL_TREE);
124899 +
124900 + if (DECL_P(node)) {
124901 + result = DECL_RESULT(node);
124902 + if (result != NULL_TREE)
124903 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124904 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124905 + }
124906 +
124907 + gcc_assert(TYPE_P(node));
124908 +
124909 + if (TREE_CODE(node) == FUNCTION_TYPE)
124910 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124911 +
124912 + return set_node_codes(node, fn_hash_data);
124913 +}
124914 +
124915 +static void set_function_codes(struct function_hash *fn_hash_data)
124916 +{
124917 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124918 + enum tree_code code = TREE_CODE(type);
124919 +
124920 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124921 +
124922 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124923 +
124924 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124925 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124926 +}
124927 +
124928 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124929 +{
124930 + while (entry) {
124931 + if (!strcmp(entry->name, func_name))
124932 + return entry;
124933 + entry = entry->next;
124934 + }
124935 + return NULL;
124936 +}
124937 +
124938 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124939 +{
124940 + const struct size_overflow_hash *entry;
124941 + struct function_hash fn_hash_data;
124942 + const char *func_name;
124943 +
124944 + // skip builtins __builtin_constant_p
124945 + if (DECL_BUILT_IN(fndecl))
124946 + return NULL;
124947 +
124948 + fn_hash_data.fndecl = fndecl;
124949 + fn_hash_data.tree_codes_len = 0;
124950 +
124951 + set_function_codes(&fn_hash_data);
124952 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124953 +
124954 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124955 + set_hash(func_name, &fn_hash_data);
124956 +
124957 + entry = size_overflow_hash[fn_hash_data.hash];
124958 + entry = get_proper_hash_chain(entry, func_name);
124959 + if (entry)
124960 + return entry;
124961 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124962 + return get_proper_hash_chain(entry, func_name);
124963 +}
124964 +
124965 +static void print_missing_msg(const_tree func, unsigned int argnum)
124966 +{
124967 + location_t loc;
124968 + const char *curfunc;
124969 + struct function_hash fn_hash_data;
124970 +
124971 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124972 + fn_hash_data.tree_codes_len = 0;
124973 +
124974 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124975 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124976 +
124977 + set_function_codes(&fn_hash_data);
124978 + set_hash(curfunc, &fn_hash_data);
124979 +
124980 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124981 +}
124982 +
124983 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124984 +{
124985 + tree var;
124986 + unsigned int argnum = 1;
124987 +
124988 + if (TREE_CODE(arg) == SSA_NAME)
124989 + arg = SSA_NAME_VAR(arg);
124990 +
124991 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124992 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124993 + continue;
124994 + if (!skip_types(var))
124995 + return argnum;
124996 + }
124997 +
124998 + return CANNOT_FIND_ARG;
124999 +}
125000 +
125001 +static const char *get_asm_string(const_gimple stmt)
125002 +{
125003 + if (!stmt)
125004 + return NULL;
125005 + if (gimple_code(stmt) != GIMPLE_ASM)
125006 + return NULL;
125007 +
125008 + return gimple_asm_string(stmt);
125009 +}
125010 +
125011 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
125012 +{
125013 + const char *str;
125014 +
125015 + str = get_asm_string(stmt);
125016 + if (!str)
125017 + return false;
125018 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
125019 +}
125020 +
125021 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
125022 +{
125023 + const char *str;
125024 +
125025 + str = get_asm_string(stmt);
125026 + if (!str)
125027 + return false;
125028 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
125029 +}
125030 +
125031 +bool is_size_overflow_asm(const_gimple stmt)
125032 +{
125033 + const char *str;
125034 +
125035 + str = get_asm_string(stmt);
125036 + if (!str)
125037 + return false;
125038 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
125039 +}
125040 +
125041 +bool is_a_return_check(const_tree node)
125042 +{
125043 + if (TREE_CODE(node) == FUNCTION_DECL)
125044 + return true;
125045 +
125046 + gcc_assert(TREE_CODE(node) == PARM_DECL);
125047 + return false;
125048 +}
125049 +
125050 +// Get the argnum of a function decl, if node is a return then the argnum is 0
125051 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
125052 +{
125053 + if (is_a_return_check(node))
125054 + return 0;
125055 + else
125056 + return find_arg_number_tree(node, orig_fndecl);
125057 +}
125058 +
125059 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
125060 +{
125061 + const struct size_overflow_hash *hash;
125062 + unsigned int new_argnum;
125063 + tree arg;
125064 + const_tree origarg;
125065 +
125066 + if (argnum == 0)
125067 + return argnum;
125068 +
125069 + hash = get_function_hash(fndecl);
125070 + if (hash && hash->param & (1U << argnum))
125071 + return argnum;
125072 +
125073 + if (DECL_EXTERNAL(fndecl))
125074 + return argnum;
125075 +
125076 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
125077 + argnum--;
125078 + while (origarg && argnum) {
125079 + origarg = TREE_CHAIN(origarg);
125080 + argnum--;
125081 + }
125082 + gcc_assert(argnum == 0);
125083 + gcc_assert(origarg != NULL_TREE);
125084 +
125085 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
125086 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
125087 + return new_argnum;
125088 +
125089 + return CANNOT_FIND_ARG;
125090 +}
125091 +
125092 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
125093 +{
125094 + const struct size_overflow_hash *hash;
125095 +
125096 + hash = get_function_hash(fndecl);
125097 + if (hash && (hash->param & (1U << num)))
125098 + return true;
125099 + return false;
125100 +}
125101 +
125102 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125103 + * If the function is missing everywhere then print the missing message into stderr.
125104 + */
125105 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125106 +{
125107 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125108 +#if BUILDING_GCC_VERSION >= 4008
125109 + case BUILT_IN_BSWAP16:
125110 +#endif
125111 + case BUILT_IN_BSWAP32:
125112 + case BUILT_IN_BSWAP64:
125113 + case BUILT_IN_EXPECT:
125114 + case BUILT_IN_MEMCMP:
125115 + return false;
125116 + default:
125117 + break;
125118 + }
125119 +
125120 + // skip test.c
125121 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125122 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125123 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125124 + }
125125 +
125126 + if (is_in_hash_table(orig_fndecl, num))
125127 + return false;
125128 +
125129 + print_missing_msg(orig_fndecl, num);
125130 + return true;
125131 +}
125132 +
125133 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125134 new file mode 100644
125135 index 0000000..924652b
125136 --- /dev/null
125137 +++ b/tools/gcc/stackleak_plugin.c
125138 @@ -0,0 +1,395 @@
125139 +/*
125140 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125141 + * Licensed under the GPL v2
125142 + *
125143 + * Note: the choice of the license means that the compilation process is
125144 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125145 + * but for the kernel it doesn't matter since it doesn't link against
125146 + * any of the gcc libraries
125147 + *
125148 + * gcc plugin to help implement various PaX features
125149 + *
125150 + * - track lowest stack pointer
125151 + *
125152 + * TODO:
125153 + * - initialize all local variables
125154 + *
125155 + * BUGS:
125156 + * - none known
125157 + */
125158 +
125159 +#include "gcc-common.h"
125160 +
125161 +int plugin_is_GPL_compatible;
125162 +
125163 +static int track_frame_size = -1;
125164 +static const char track_function[] = "pax_track_stack";
125165 +static const char check_function[] = "pax_check_alloca";
125166 +static tree track_function_decl, check_function_decl;
125167 +static bool init_locals;
125168 +
125169 +static struct plugin_info stackleak_plugin_info = {
125170 + .version = "201408011900",
125171 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125172 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125173 +};
125174 +
125175 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125176 +{
125177 + gimple check_alloca;
125178 + tree alloca_size;
125179 +
125180 + // insert call to void pax_check_alloca(unsigned long size)
125181 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125182 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125183 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125184 +}
125185 +
125186 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125187 +{
125188 + gimple track_stack;
125189 +
125190 + // insert call to void pax_track_stack(void)
125191 + track_stack = gimple_build_call(track_function_decl, 0);
125192 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125193 +}
125194 +
125195 +static bool is_alloca(gimple stmt)
125196 +{
125197 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125198 + return true;
125199 +
125200 +#if BUILDING_GCC_VERSION >= 4007
125201 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125202 + return true;
125203 +#endif
125204 +
125205 + return false;
125206 +}
125207 +
125208 +static unsigned int execute_stackleak_tree_instrument(void)
125209 +{
125210 + basic_block bb, entry_bb;
125211 + bool prologue_instrumented = false, is_leaf = true;
125212 +
125213 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125214 +
125215 + // 1. loop through BBs and GIMPLE statements
125216 + FOR_EACH_BB_FN(bb, cfun) {
125217 + gimple_stmt_iterator gsi;
125218 +
125219 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125220 + gimple stmt;
125221 +
125222 + stmt = gsi_stmt(gsi);
125223 +
125224 + if (is_gimple_call(stmt))
125225 + is_leaf = false;
125226 +
125227 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125228 + if (!is_alloca(stmt))
125229 + continue;
125230 +
125231 + // 2. insert stack overflow check before each __builtin_alloca call
125232 + stackleak_check_alloca(&gsi);
125233 +
125234 + // 3. insert track call after each __builtin_alloca call
125235 + stackleak_add_instrumentation(&gsi);
125236 + if (bb == entry_bb)
125237 + prologue_instrumented = true;
125238 + }
125239 + }
125240 +
125241 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125242 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125243 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125244 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125245 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125246 + return 0;
125247 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125248 + return 0;
125249 +
125250 + // 4. insert track call at the beginning
125251 + if (!prologue_instrumented) {
125252 + gimple_stmt_iterator gsi;
125253 +
125254 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125255 + if (dom_info_available_p(CDI_DOMINATORS))
125256 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125257 + gsi = gsi_start_bb(bb);
125258 + stackleak_add_instrumentation(&gsi);
125259 + }
125260 +
125261 + return 0;
125262 +}
125263 +
125264 +static unsigned int execute_stackleak_final(void)
125265 +{
125266 + rtx insn, next;
125267 +
125268 + if (cfun->calls_alloca)
125269 + return 0;
125270 +
125271 + // keep calls only if function frame is big enough
125272 + if (get_frame_size() >= track_frame_size)
125273 + return 0;
125274 +
125275 + // 1. find pax_track_stack calls
125276 + for (insn = get_insns(); insn; insn = next) {
125277 + // 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))
125278 + rtx body;
125279 +
125280 + next = NEXT_INSN(insn);
125281 + if (!CALL_P(insn))
125282 + continue;
125283 + body = PATTERN(insn);
125284 + if (GET_CODE(body) != CALL)
125285 + continue;
125286 + body = XEXP(body, 0);
125287 + if (GET_CODE(body) != MEM)
125288 + continue;
125289 + body = XEXP(body, 0);
125290 + if (GET_CODE(body) != SYMBOL_REF)
125291 + continue;
125292 +// if (strcmp(XSTR(body, 0), track_function))
125293 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125294 + continue;
125295 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125296 + // 2. delete call
125297 + delete_insn_and_edges(insn);
125298 +#if BUILDING_GCC_VERSION >= 4007
125299 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125300 + insn = next;
125301 + next = NEXT_INSN(insn);
125302 + delete_insn_and_edges(insn);
125303 + }
125304 +#endif
125305 + }
125306 +
125307 +// print_simple_rtl(stderr, get_insns());
125308 +// print_rtl(stderr, get_insns());
125309 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125310 +
125311 + return 0;
125312 +}
125313 +
125314 +static bool gate_stackleak_track_stack(void)
125315 +{
125316 + tree section;
125317 +
125318 + if (ix86_cmodel != CM_KERNEL)
125319 + return false;
125320 +
125321 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125322 + if (section && TREE_VALUE(section)) {
125323 + section = TREE_VALUE(TREE_VALUE(section));
125324 +
125325 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125326 + return false;
125327 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125328 + return false;
125329 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125330 + return false;
125331 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125332 + return false;
125333 + }
125334 +
125335 + return track_frame_size >= 0;
125336 +}
125337 +
125338 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125339 +{
125340 + tree fntype;
125341 +
125342 + // void pax_track_stack(void)
125343 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125344 + track_function_decl = build_fn_decl(track_function, fntype);
125345 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125346 + TREE_PUBLIC(track_function_decl) = 1;
125347 + DECL_EXTERNAL(track_function_decl) = 1;
125348 + DECL_ARTIFICIAL(track_function_decl) = 1;
125349 +
125350 + // void pax_check_alloca(unsigned long)
125351 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125352 + check_function_decl = build_fn_decl(check_function, fntype);
125353 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125354 + TREE_PUBLIC(check_function_decl) = 1;
125355 + DECL_EXTERNAL(check_function_decl) = 1;
125356 + DECL_ARTIFICIAL(check_function_decl) = 1;
125357 +}
125358 +
125359 +#if BUILDING_GCC_VERSION >= 4009
125360 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125361 +#else
125362 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125363 + .pass = {
125364 +#endif
125365 + .type = GIMPLE_PASS,
125366 + .name = "stackleak_tree_instrument",
125367 +#if BUILDING_GCC_VERSION >= 4008
125368 + .optinfo_flags = OPTGROUP_NONE,
125369 +#endif
125370 +#if BUILDING_GCC_VERSION >= 4009
125371 + .has_gate = true,
125372 + .has_execute = true,
125373 +#else
125374 + .gate = gate_stackleak_track_stack,
125375 + .execute = execute_stackleak_tree_instrument,
125376 + .sub = NULL,
125377 + .next = NULL,
125378 + .static_pass_number = 0,
125379 +#endif
125380 + .tv_id = TV_NONE,
125381 + .properties_required = PROP_gimple_leh | PROP_cfg,
125382 + .properties_provided = 0,
125383 + .properties_destroyed = 0,
125384 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125385 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125386 +#if BUILDING_GCC_VERSION < 4009
125387 + }
125388 +#endif
125389 +};
125390 +
125391 +#if BUILDING_GCC_VERSION >= 4009
125392 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125393 +#else
125394 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125395 + .pass = {
125396 +#endif
125397 + .type = RTL_PASS,
125398 + .name = "stackleak_final",
125399 +#if BUILDING_GCC_VERSION >= 4008
125400 + .optinfo_flags = OPTGROUP_NONE,
125401 +#endif
125402 +#if BUILDING_GCC_VERSION >= 4009
125403 + .has_gate = true,
125404 + .has_execute = true,
125405 +#else
125406 + .gate = gate_stackleak_track_stack,
125407 + .execute = execute_stackleak_final,
125408 + .sub = NULL,
125409 + .next = NULL,
125410 + .static_pass_number = 0,
125411 +#endif
125412 + .tv_id = TV_NONE,
125413 + .properties_required = 0,
125414 + .properties_provided = 0,
125415 + .properties_destroyed = 0,
125416 + .todo_flags_start = 0,
125417 + .todo_flags_finish = TODO_dump_func
125418 +#if BUILDING_GCC_VERSION < 4009
125419 + }
125420 +#endif
125421 +};
125422 +
125423 +#if BUILDING_GCC_VERSION >= 4009
125424 +namespace {
125425 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125426 +public:
125427 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125428 + bool gate() { return gate_stackleak_track_stack(); }
125429 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125430 +};
125431 +
125432 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125433 +public:
125434 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125435 + bool gate() { return gate_stackleak_track_stack(); }
125436 + unsigned int execute() { return execute_stackleak_final(); }
125437 +};
125438 +}
125439 +
125440 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125441 +{
125442 + return new stackleak_tree_instrument_pass();
125443 +}
125444 +
125445 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125446 +{
125447 + return new stackleak_final_rtl_opt_pass();
125448 +}
125449 +#else
125450 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125451 +{
125452 + return &stackleak_tree_instrument_pass.pass;
125453 +}
125454 +
125455 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125456 +{
125457 + return &stackleak_final_rtl_opt_pass.pass;
125458 +}
125459 +#endif
125460 +
125461 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125462 +{
125463 + const char * const plugin_name = plugin_info->base_name;
125464 + const int argc = plugin_info->argc;
125465 + const struct plugin_argument * const argv = plugin_info->argv;
125466 + int i;
125467 + struct register_pass_info stackleak_tree_instrument_pass_info;
125468 + struct register_pass_info stackleak_final_pass_info;
125469 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125470 + {
125471 + .base = &track_function_decl,
125472 + .nelt = 1,
125473 + .stride = sizeof(track_function_decl),
125474 + .cb = &gt_ggc_mx_tree_node,
125475 + .pchw = &gt_pch_nx_tree_node
125476 + },
125477 + {
125478 + .base = &check_function_decl,
125479 + .nelt = 1,
125480 + .stride = sizeof(check_function_decl),
125481 + .cb = &gt_ggc_mx_tree_node,
125482 + .pchw = &gt_pch_nx_tree_node
125483 + },
125484 + LAST_GGC_ROOT_TAB
125485 + };
125486 +
125487 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125488 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125489 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125490 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125491 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125492 +
125493 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125494 + stackleak_final_pass_info.reference_pass_name = "final";
125495 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125496 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125497 +
125498 + if (!plugin_default_version_check(version, &gcc_version)) {
125499 + error(G_("incompatible gcc/plugin versions"));
125500 + return 1;
125501 + }
125502 +
125503 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125504 +
125505 + for (i = 0; i < argc; ++i) {
125506 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125507 + if (!argv[i].value) {
125508 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125509 + continue;
125510 + }
125511 + track_frame_size = atoi(argv[i].value);
125512 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125513 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125514 + continue;
125515 + }
125516 + if (!strcmp(argv[i].key, "initialize-locals")) {
125517 + if (argv[i].value) {
125518 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125519 + continue;
125520 + }
125521 + init_locals = true;
125522 + continue;
125523 + }
125524 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125525 + }
125526 +
125527 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125528 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125529 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125530 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125531 +
125532 + return 0;
125533 +}
125534 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125535 new file mode 100644
125536 index 0000000..4ee2231
125537 --- /dev/null
125538 +++ b/tools/gcc/structleak_plugin.c
125539 @@ -0,0 +1,274 @@
125540 +/*
125541 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125542 + * Licensed under the GPL v2
125543 + *
125544 + * Note: the choice of the license means that the compilation process is
125545 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125546 + * but for the kernel it doesn't matter since it doesn't link against
125547 + * any of the gcc libraries
125548 + *
125549 + * gcc plugin to forcibly initialize certain local variables that could
125550 + * otherwise leak kernel stack to userland if they aren't properly initialized
125551 + * by later code
125552 + *
125553 + * Homepage: http://pax.grsecurity.net/
125554 + *
125555 + * Usage:
125556 + * $ # for 4.5/4.6/C based 4.7
125557 + * $ 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
125558 + * $ # for C++ based 4.7/4.8+
125559 + * $ 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
125560 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125561 + *
125562 + * TODO: eliminate redundant initializers
125563 + * increase type coverage
125564 + */
125565 +
125566 +#include "gcc-common.h"
125567 +
125568 +// unused C type flag in all versions 4.5-4.9
125569 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125570 +
125571 +int plugin_is_GPL_compatible;
125572 +
125573 +static struct plugin_info structleak_plugin_info = {
125574 + .version = "201401260140",
125575 + .help = "disable\tdo not activate plugin\n",
125576 +};
125577 +
125578 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125579 +{
125580 + *no_add_attrs = true;
125581 +
125582 + // check for types? for now accept everything linux has to offer
125583 + if (TREE_CODE(*node) != FIELD_DECL)
125584 + return NULL_TREE;
125585 +
125586 + *no_add_attrs = false;
125587 + return NULL_TREE;
125588 +}
125589 +
125590 +static struct attribute_spec user_attr = {
125591 + .name = "user",
125592 + .min_length = 0,
125593 + .max_length = 0,
125594 + .decl_required = false,
125595 + .type_required = false,
125596 + .function_type_required = false,
125597 + .handler = handle_user_attribute,
125598 +#if BUILDING_GCC_VERSION >= 4007
125599 + .affects_type_identity = true
125600 +#endif
125601 +};
125602 +
125603 +static void register_attributes(void *event_data, void *data)
125604 +{
125605 + register_attribute(&user_attr);
125606 +// register_attribute(&force_attr);
125607 +}
125608 +
125609 +static tree get_field_type(tree field)
125610 +{
125611 + return strip_array_types(TREE_TYPE(field));
125612 +}
125613 +
125614 +static bool is_userspace_type(tree type)
125615 +{
125616 + tree field;
125617 +
125618 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125619 + tree fieldtype = get_field_type(field);
125620 + enum tree_code code = TREE_CODE(fieldtype);
125621 +
125622 + if (code == RECORD_TYPE || code == UNION_TYPE)
125623 + if (is_userspace_type(fieldtype))
125624 + return true;
125625 +
125626 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125627 + return true;
125628 + }
125629 + return false;
125630 +}
125631 +
125632 +static void finish_type(void *event_data, void *data)
125633 +{
125634 + tree type = (tree)event_data;
125635 +
125636 + if (TYPE_USERSPACE(type))
125637 + return;
125638 +
125639 + if (is_userspace_type(type))
125640 + TYPE_USERSPACE(type) = 1;
125641 +}
125642 +
125643 +static void initialize(tree var)
125644 +{
125645 + basic_block bb;
125646 + gimple_stmt_iterator gsi;
125647 + tree initializer;
125648 + gimple init_stmt;
125649 +
125650 + // this is the original entry bb before the forced split
125651 + // TODO: check further BBs in case more splits occured before us
125652 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125653 +
125654 + // first check if the variable is already initialized, warn otherwise
125655 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125656 + gimple stmt = gsi_stmt(gsi);
125657 + tree rhs1;
125658 +
125659 + // we're looking for an assignment of a single rhs...
125660 + if (!gimple_assign_single_p(stmt))
125661 + continue;
125662 + rhs1 = gimple_assign_rhs1(stmt);
125663 +#if BUILDING_GCC_VERSION >= 4007
125664 + // ... of a non-clobbering expression...
125665 + if (TREE_CLOBBER_P(rhs1))
125666 + continue;
125667 +#endif
125668 + // ... to our variable...
125669 + if (gimple_get_lhs(stmt) != var)
125670 + continue;
125671 + // if it's an initializer then we're good
125672 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125673 + return;
125674 + }
125675 +
125676 + // these aren't the 0days you're looking for
125677 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125678 +
125679 + // build the initializer expression
125680 + initializer = build_constructor(TREE_TYPE(var), NULL);
125681 +
125682 + // build the initializer stmt
125683 + init_stmt = gimple_build_assign(var, initializer);
125684 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125685 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125686 + update_stmt(init_stmt);
125687 +}
125688 +
125689 +static unsigned int handle_function(void)
125690 +{
125691 + basic_block bb;
125692 + unsigned int ret = 0;
125693 + tree var;
125694 + unsigned int i;
125695 +
125696 + // split the first bb where we can put the forced initializers
125697 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125698 + if (dom_info_available_p(CDI_DOMINATORS))
125699 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125700 +
125701 + // enumarate all local variables and forcibly initialize our targets
125702 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125703 + tree type = TREE_TYPE(var);
125704 +
125705 + gcc_assert(DECL_P(var));
125706 + if (!auto_var_in_fn_p(var, current_function_decl))
125707 + continue;
125708 +
125709 + // only care about structure types
125710 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125711 + continue;
125712 +
125713 + // if the type is of interest, examine the variable
125714 + if (TYPE_USERSPACE(type))
125715 + initialize(var);
125716 + }
125717 +
125718 + return ret;
125719 +}
125720 +
125721 +#if BUILDING_GCC_VERSION >= 4009
125722 +static const struct pass_data structleak_pass_data = {
125723 +#else
125724 +static struct gimple_opt_pass structleak_pass = {
125725 + .pass = {
125726 +#endif
125727 + .type = GIMPLE_PASS,
125728 + .name = "structleak",
125729 +#if BUILDING_GCC_VERSION >= 4008
125730 + .optinfo_flags = OPTGROUP_NONE,
125731 +#endif
125732 +#if BUILDING_GCC_VERSION >= 4009
125733 + .has_gate = false,
125734 + .has_execute = true,
125735 +#else
125736 + .gate = NULL,
125737 + .execute = handle_function,
125738 + .sub = NULL,
125739 + .next = NULL,
125740 + .static_pass_number = 0,
125741 +#endif
125742 + .tv_id = TV_NONE,
125743 + .properties_required = PROP_cfg,
125744 + .properties_provided = 0,
125745 + .properties_destroyed = 0,
125746 + .todo_flags_start = 0,
125747 + .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
125748 +#if BUILDING_GCC_VERSION < 4009
125749 + }
125750 +#endif
125751 +};
125752 +
125753 +#if BUILDING_GCC_VERSION >= 4009
125754 +namespace {
125755 +class structleak_pass : public gimple_opt_pass {
125756 +public:
125757 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125758 + unsigned int execute() { return handle_function(); }
125759 +};
125760 +}
125761 +
125762 +static opt_pass *make_structleak_pass(void)
125763 +{
125764 + return new structleak_pass();
125765 +}
125766 +#else
125767 +static struct opt_pass *make_structleak_pass(void)
125768 +{
125769 + return &structleak_pass.pass;
125770 +}
125771 +#endif
125772 +
125773 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125774 +{
125775 + int i;
125776 + const char * const plugin_name = plugin_info->base_name;
125777 + const int argc = plugin_info->argc;
125778 + const struct plugin_argument * const argv = plugin_info->argv;
125779 + bool enable = true;
125780 + struct register_pass_info structleak_pass_info;
125781 +
125782 + structleak_pass_info.pass = make_structleak_pass();
125783 + structleak_pass_info.reference_pass_name = "ssa";
125784 + structleak_pass_info.ref_pass_instance_number = 1;
125785 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125786 +
125787 + if (!plugin_default_version_check(version, &gcc_version)) {
125788 + error(G_("incompatible gcc/plugin versions"));
125789 + return 1;
125790 + }
125791 +
125792 + if (strcmp(lang_hooks.name, "GNU C")) {
125793 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125794 + enable = false;
125795 + }
125796 +
125797 + for (i = 0; i < argc; ++i) {
125798 + if (!strcmp(argv[i].key, "disable")) {
125799 + enable = false;
125800 + continue;
125801 + }
125802 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125803 + }
125804 +
125805 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125806 + if (enable) {
125807 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125808 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125809 + }
125810 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125811 +
125812 + return 0;
125813 +}
125814 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125815 index 88461f0..6fb70a0 100644
125816 --- a/tools/include/linux/compiler.h
125817 +++ b/tools/include/linux/compiler.h
125818 @@ -35,6 +35,14 @@
125819 # define unlikely(x) __builtin_expect(!!(x), 0)
125820 #endif
125821
125822 +#ifndef __size_overflow
125823 +# define __size_overflow(...)
125824 +#endif
125825 +
125826 +#ifndef __intentional_overflow
125827 +# define __intentional_overflow(...)
125828 +#endif
125829 +
125830 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125831
125832 #endif /* _TOOLS_LINUX_COMPILER_H */
125833 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125834 index 36c08b1..87c72d1 100644
125835 --- a/tools/lib/api/Makefile
125836 +++ b/tools/lib/api/Makefile
125837 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
125838
125839 LIBFILE = libapikfs.a
125840
125841 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125842 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125843 EXTLIBS = -lelf -lpthread -lrt -lm
125844 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125845 ALL_LDFLAGS = $(LDFLAGS)
125846 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125847 index 6789d788..4afd019e 100644
125848 --- a/tools/perf/util/include/asm/alternative-asm.h
125849 +++ b/tools/perf/util/include/asm/alternative-asm.h
125850 @@ -5,4 +5,7 @@
125851
125852 #define altinstruction_entry #
125853
125854 + .macro pax_force_retaddr rip=0, reload=0
125855 + .endm
125856 +
125857 #endif
125858 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125859 index 0a578fe..b81f62d 100644
125860 --- a/tools/virtio/linux/uaccess.h
125861 +++ b/tools/virtio/linux/uaccess.h
125862 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125863 ({ \
125864 typeof(ptr) __pu_ptr = (ptr); \
125865 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125866 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125867 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125868 0; \
125869 })
125870
125871 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125872 index 3cee7b1..29cb7d8 100644
125873 --- a/virt/kvm/kvm_main.c
125874 +++ b/virt/kvm/kvm_main.c
125875 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
125876
125877 static cpumask_var_t cpus_hardware_enabled;
125878 static int kvm_usage_count = 0;
125879 -static atomic_t hardware_enable_failed;
125880 +static atomic_unchecked_t hardware_enable_failed;
125881
125882 struct kmem_cache *kvm_vcpu_cache;
125883 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125884
125885 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125886 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125887 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125888 +static struct preempt_ops kvm_preempt_ops = {
125889 + .sched_in = kvm_sched_in,
125890 + .sched_out = kvm_sched_out,
125891 +};
125892
125893 struct dentry *kvm_debugfs_dir;
125894
125895 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125896 /* We can read the guest memory with __xxx_user() later on. */
125897 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125898 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125899 - !access_ok(VERIFY_WRITE,
125900 + !access_ok_noprefault(VERIFY_WRITE,
125901 (void __user *)(unsigned long)mem->userspace_addr,
125902 mem->memory_size)))
125903 goto out;
125904 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125905
125906 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125907 {
125908 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125909 + int r;
125910 + unsigned long addr;
125911
125912 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125913 + addr = gfn_to_hva(kvm, gfn);
125914 + if (kvm_is_error_hva(addr))
125915 + return -EFAULT;
125916 + r = __clear_user((void __user *)addr + offset, len);
125917 + if (r)
125918 + return -EFAULT;
125919 + mark_page_dirty(kvm, gfn);
125920 + return 0;
125921 }
125922 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125923
125924 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125925 return 0;
125926 }
125927
125928 -static struct file_operations kvm_vcpu_fops = {
125929 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125930 .release = kvm_vcpu_release,
125931 .unlocked_ioctl = kvm_vcpu_ioctl,
125932 #ifdef CONFIG_COMPAT
125933 @@ -2650,7 +2663,7 @@ out:
125934 }
125935 #endif
125936
125937 -static struct file_operations kvm_vm_fops = {
125938 +static file_operations_no_const kvm_vm_fops __read_only = {
125939 .release = kvm_vm_release,
125940 .unlocked_ioctl = kvm_vm_ioctl,
125941 #ifdef CONFIG_COMPAT
125942 @@ -2721,7 +2734,7 @@ out:
125943 return r;
125944 }
125945
125946 -static struct file_operations kvm_chardev_ops = {
125947 +static file_operations_no_const kvm_chardev_ops __read_only = {
125948 .unlocked_ioctl = kvm_dev_ioctl,
125949 .compat_ioctl = kvm_dev_ioctl,
125950 .llseek = noop_llseek,
125951 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
125952
125953 if (r) {
125954 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125955 - atomic_inc(&hardware_enable_failed);
125956 + atomic_inc_unchecked(&hardware_enable_failed);
125957 printk(KERN_INFO "kvm: enabling virtualization on "
125958 "CPU%d failed\n", cpu);
125959 }
125960 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
125961
125962 kvm_usage_count++;
125963 if (kvm_usage_count == 1) {
125964 - atomic_set(&hardware_enable_failed, 0);
125965 + atomic_set_unchecked(&hardware_enable_failed, 0);
125966 on_each_cpu(hardware_enable_nolock, NULL, 1);
125967
125968 - if (atomic_read(&hardware_enable_failed)) {
125969 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125970 hardware_disable_all_nolock();
125971 r = -EBUSY;
125972 }
125973 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125974 kvm_arch_vcpu_put(vcpu);
125975 }
125976
125977 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125978 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125979 struct module *module)
125980 {
125981 int r;
125982 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125983 if (!vcpu_align)
125984 vcpu_align = __alignof__(struct kvm_vcpu);
125985 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125986 - 0, NULL);
125987 + SLAB_USERCOPY, NULL);
125988 if (!kvm_vcpu_cache) {
125989 r = -ENOMEM;
125990 goto out_free_3;
125991 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125992 if (r)
125993 goto out_free;
125994
125995 + pax_open_kernel();
125996 kvm_chardev_ops.owner = module;
125997 kvm_vm_fops.owner = module;
125998 kvm_vcpu_fops.owner = module;
125999 + pax_close_kernel();
126000
126001 r = misc_register(&kvm_dev);
126002 if (r) {
126003 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126004
126005 register_syscore_ops(&kvm_syscore_ops);
126006
126007 - kvm_preempt_ops.sched_in = kvm_sched_in;
126008 - kvm_preempt_ops.sched_out = kvm_sched_out;
126009 -
126010 r = kvm_init_debug();
126011 if (r) {
126012 printk(KERN_ERR "kvm: create debugfs files failed\n");